import java.util.StringTokenizer; import java.io.*; /** * @author asingh * */ public class NLJoin { /** * @param args */ public static void main(String[] args) { String filename1 = args[0]; String filename2 = args[1]; try { // Open the file that is the first // command line parameter FileInputStream fstream = new FileInputStream(filename1); // Get the object of DataInputStream DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); String strLine; // Read File Line By Line StringTokenizer myToken = null; while ((strLine = br.readLine()) != null) { int value[] = {0}; int runningCount[] = {0}; myToken = new StringTokenizer(strLine); myToken.nextToken(); int lowerRange = Integer.parseInt(myToken.nextToken()); int upperRange = Integer.parseInt(myToken.nextToken()); myToken.nextToken(); if (runMatch(lowerRange, upperRange, value, runningCount, filename2) == true) { System.out.println(lowerRange + ":" + upperRange + " Sum = " + value[0] + " Average = " + value[0] / (upperRange - lowerRange) + " Name " + myToken.nextToken()); } } // Close the input stream in.close(); } catch (Exception e) {// Catch exception if any System.err.println("Error: " + e.getMessage()); } } public static boolean runMatch(int lowerValue, int upperValue, int[] value, int[] count, String filename2) { count[0] = 0; try { // Open the file that is the first // command line parameter FileInputStream fstream = new FileInputStream(filename2); // Get the object of DataInputStream DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); String strLine; // Read File Line By int i = 0; StringTokenizer myToken = null; while ((strLine = br.readLine()) != null) { myToken = new StringTokenizer(strLine); if (myToken.nextToken().equals("19")) { i++; if (i % 9999999 == 0) { System.err.println("Gone through " + i + "rows "); } int readValue = Integer.parseInt(myToken.nextToken()); myToken.nextToken(); if (readValue >= lowerValue && readValue <= upperValue) { value[0] += Integer.parseInt(myToken.nextToken()); count[0]++; } } } // Close the input stream in.close(); } catch (Exception e) {// Catch exception if any System.err.println("Error: " + e.getMessage()); } if (count[0] > 0) return true; else return false; } }