@Test public void testMapRange() throws Exception { List<String> values = new ArrayList<String>(); values.add("2012-01-24"); values.add("2012-12-30"); Pair<String, String> results = lookupTable.mapRange("CAL_DT", "2012-01-24", "2012-12-30", "QTR_BEG_DT"); Assert.assertTrue(results != null); System.out.println("The first qtr_beg_dt is " + results.getFirst()); System.out.println("The last qtr_beg_dt is " + results.getSecond()); Assert.assertEquals("2012-01-01", results.getFirst()); Assert.assertEquals( "2012-10-01" , results.getSecond()); }
public Pair<T, T> mapRange(String col, T beginValue, T endValue, String returnCol) { int colIdx = tableDesc.findColumnByName(col).getZeroBasedIndex(); int returnIdx = tableDesc.findColumnByName(returnCol).getZeroBasedIndex(); T returnBegin = null; T returnEnd = null; for (T[] row : data.values()) { if (between(beginValue, row[colIdx], endValue)) { T returnValue = row[returnIdx]; if (returnBegin == null || returnValue.compareTo(returnBegin) < 0) { returnBegin = returnValue; } if (returnEnd == null || returnValue.compareTo(returnEnd) > 0) { returnEnd = returnValue; } } } if (returnBegin == null && returnEnd == null) return null; else return new Pair<T, T>(returnBegin, returnEnd); }
LookupTable { public Pair<T, T> mapRange(String col, T beginValue, T endValue, String returnCol) { int colIdx = tableDesc.findColumnByName(col).getZeroBasedIndex(); int returnIdx = tableDesc.findColumnByName(returnCol).getZeroBasedIndex(); T returnBegin = null; T returnEnd = null; for (T[] row : data.values()) { if (between(beginValue, row[colIdx], endValue)) { T returnValue = row[returnIdx]; if (returnBegin == null || returnValue.compareTo(returnBegin) < 0) { returnBegin = returnValue; } if (returnEnd == null || returnValue.compareTo(returnEnd) > 0) { returnEnd = returnValue; } } } if (returnBegin == null && returnEnd == null) return null; else return new Pair<T, T>(returnBegin, returnEnd); } }
LookupTable { public Pair<T, T> mapRange(String col, T beginValue, T endValue, String returnCol) { int colIdx = tableDesc.findColumnByName(col).getZeroBasedIndex(); int returnIdx = tableDesc.findColumnByName(returnCol).getZeroBasedIndex(); T returnBegin = null; T returnEnd = null; for (T[] row : data.values()) { if (between(beginValue, row[colIdx], endValue)) { T returnValue = row[returnIdx]; if (returnBegin == null || returnValue.compareTo(returnBegin) < 0) { returnBegin = returnValue; } if (returnEnd == null || returnValue.compareTo(returnEnd) > 0) { returnEnd = returnValue; } } } if (returnBegin == null && returnEnd == null) return null; else return new Pair<T, T>(returnBegin, returnEnd); } LookupTable(TableDesc tableDesc, String[] keyColumns, ReadableTable table); }
LookupTable { public Pair<T, T> mapRange(String col, T beginValue, T endValue, String returnCol) { int colIdx = tableDesc.findColumnByName(col).getZeroBasedIndex(); int returnIdx = tableDesc.findColumnByName(returnCol).getZeroBasedIndex(); T returnBegin = null; T returnEnd = null; for (T[] row : data.values()) { if (between(beginValue, row[colIdx], endValue)) { T returnValue = row[returnIdx]; if (returnBegin == null || returnValue.compareTo(returnBegin) < 0) { returnBegin = returnValue; } if (returnEnd == null || returnValue.compareTo(returnEnd) > 0) { returnEnd = returnValue; } } } if (returnBegin == null && returnEnd == null) return null; else return new Pair<T, T>(returnBegin, returnEnd); } LookupTable(TableDesc tableDesc, String[] keyColumns, ReadableTable table); T[] getRow(Array<T> key); Collection<T[]> getAllRows(); List<T> scan(String col, List<T> values, String returnCol); Pair<T, T> mapRange(String col, T beginValue, T endValue, String returnCol); Set<T> mapValues(String col, Set<T> values, String returnCol); String toString(); void dump(); }
LookupTable { public Pair<T, T> mapRange(String col, T beginValue, T endValue, String returnCol) { int colIdx = tableDesc.findColumnByName(col).getZeroBasedIndex(); int returnIdx = tableDesc.findColumnByName(returnCol).getZeroBasedIndex(); T returnBegin = null; T returnEnd = null; for (T[] row : data.values()) { if (between(beginValue, row[colIdx], endValue)) { T returnValue = row[returnIdx]; if (returnBegin == null || returnValue.compareTo(returnBegin) < 0) { returnBegin = returnValue; } if (returnEnd == null || returnValue.compareTo(returnEnd) > 0) { returnEnd = returnValue; } } } if (returnBegin == null && returnEnd == null) return null; else return new Pair<T, T>(returnBegin, returnEnd); } LookupTable(TableDesc tableDesc, String[] keyColumns, ReadableTable table); T[] getRow(Array<T> key); Collection<T[]> getAllRows(); List<T> scan(String col, List<T> values, String returnCol); Pair<T, T> mapRange(String col, T beginValue, T endValue, String returnCol); Set<T> mapValues(String col, Set<T> values, String returnCol); String toString(); void dump();  }