List of usage examples for java.util SortedMap entrySet
Set<Map.Entry<K, V>> entrySet();
From source file:org.apache.hadoop.hive.accumulo.mr.TestHiveAccumuloTableInputFormat.java
@Test public void testDegreesAndMillis() throws Exception { Connector con = mockInstance.getConnector(USER, new PasswordToken(PASS.getBytes())); Scanner scan = con.createScanner(TEST_TABLE, new Authorizations("blah")); IteratorSetting is = new IteratorSetting(1, PrimitiveComparisonFilter.FILTER_PREFIX + 1, PrimitiveComparisonFilter.class); is.addOption(PrimitiveComparisonFilter.P_COMPARE_CLASS, DoubleCompare.class.getName()); is.addOption(PrimitiveComparisonFilter.COMPARE_OPT_CLASS, GreaterThanOrEqual.class.getName()); is.addOption(PrimitiveComparisonFilter.CONST_VAL, new String(Base64.encodeBase64(parseDoubleBytes("55.6")))); is.addOption(PrimitiveComparisonFilter.COLUMN, "cf:dgrs"); scan.addScanIterator(is);//from www .j ava2 s . com IteratorSetting is2 = new IteratorSetting(2, PrimitiveComparisonFilter.FILTER_PREFIX + 2, PrimitiveComparisonFilter.class); is2.addOption(PrimitiveComparisonFilter.P_COMPARE_CLASS, LongCompare.class.getName()); is2.addOption(PrimitiveComparisonFilter.COMPARE_OPT_CLASS, LessThan.class.getName()); is2.addOption(PrimitiveComparisonFilter.CONST_VAL, new String(Base64.encodeBase64(parseLongBytes("778")))); is2.addOption(PrimitiveComparisonFilter.COLUMN, "cf:mills"); scan.addScanIterator(is2); boolean foundDennis = false; int totalCount = 0; for (Map.Entry<Key, Value> kv : scan) { boolean foundName = false; boolean foundSid = false; boolean foundDegrees = false; boolean foundMillis = false; SortedMap<Key, Value> items = PrimitiveComparisonFilter.decodeRow(kv.getKey(), kv.getValue()); for (Map.Entry<Key, Value> item : items.entrySet()) { SortedMap<Key, Value> nestedItems = PrimitiveComparisonFilter.decodeRow(item.getKey(), item.getValue()); for (Map.Entry<Key, Value> nested : nestedItems.entrySet()) { if (nested.getKey().getRow().toString().equals("r3")) { foundDennis = true; } if (nested.getKey().getColumnQualifier().equals(NAME)) { foundName = true; } else if (nested.getKey().getColumnQualifier().equals(SID)) { foundSid = true; } else if (nested.getKey().getColumnQualifier().equals(DEGREES)) { foundDegrees = true; } else if (nested.getKey().getColumnQualifier().equals(MILLIS)) { foundMillis = true; } } } totalCount++; assertTrue(foundDegrees & foundMillis & foundName & foundSid); } assertTrue(foundDennis); assertEquals(totalCount, 1); }
From source file:es.uvigo.ei.sing.gc.model.entities.ExpertResult.java
private synchronized void initClassificationPerformance() { if (this.performance == null && this.samples != null && !this.samples.isEmpty()) { final Set<Object> classes = new HashSet<Object>(); Boolean multi = null;//ww w . jav a 2s . co m for (SampleClassification sample : this.samples) { if (multi == null) { multi = sample.isMultiStep(); } else if (multi != sample.isMultiStep()) { throw new IllegalStateException("Different sample types"); } classes.add(sample.getRealClass()); } final Object[] classArray = classes.toArray(new Object[classes.size()]); if (multi) { final SortedMap<Integer, List<SampleClassification>> sampleMap = new TreeMap<Integer, List<SampleClassification>>(); for (SampleClassification sample : this.samples) { if (!sampleMap.containsKey(sample.getStep())) { sampleMap.put(sample.getStep(), new LinkedList<SampleClassification>()); } sampleMap.get(sample.getStep()).add(sample); } for (Map.Entry<Integer, List<SampleClassification>> entry : sampleMap.entrySet()) { if (this.performance == null) { this.performance = new DefaultMultiStepClassificationPerformance( ExpertResult.createClassificationPerformance( Integer.toString(this.getId()) + "-Step " + entry.getKey(), classArray, entry.getValue())); } else { this.performance = this.performance.merge(ExpertResult.createClassificationPerformance( Integer.toString(this.getId()) + "-Step " + entry.getKey(), classArray, entry.getValue())); } } } else { this.performance = ExpertResult.createClassificationPerformance(Integer.toString(this.getId()), classArray, samples); } } }
From source file:com.aurel.track.report.dashboard.AverageTimeToCloseItem.java
public Double getMaxPlannedValue(SortedMap<Date, EarnedValueTimeSlice> earnedValueTimeSliceMap) { Double maxValue = -1.0;// w ww. j av a 2 s .c om for (Map.Entry<Date, EarnedValueTimeSlice> entry : earnedValueTimeSliceMap.entrySet()) { Double d1 = entry.getValue().getPlannedValue(); if (Double.compare(d1, maxValue) > 0) { maxValue = entry.getValue().getPlannedValue(); } } return maxValue; }
From source file:com.aurel.track.report.dashboard.AverageTimeToCloseItem.java
public Double getMaxEarnedValue(SortedMap<Date, EarnedValueTimeSlice> earnedValueTimeSliceMap) { Double maxValue = -1.0;//from ww w. j a va2s . c om for (Map.Entry<Date, EarnedValueTimeSlice> entry : earnedValueTimeSliceMap.entrySet()) { if (entry.getValue().getEarnedvalue() != null) { Double d1 = entry.getValue().getEarnedvalue(); if (Double.compare(d1, maxValue) > 0) { maxValue = entry.getValue().getEarnedvalue(); } } } return maxValue; }
From source file:org.apache.ctakes.ytex.libsvm.LibSVMGramMatrixExporterImpl.java
/** * export the train or test gram matrix. the train gram matrix is square and * symmetric. the test gram matrix is rectangular - each column corresponds * to a training instance each row corresponds to a test instance. * /*w ww . ja v a 2 s .co m*/ * @param gramMatrix * square symmetric matrix with all available instance data * @param instanceIdToClassMap * folds * @param train * true - export train set, false - export test set * @param mapInstanceIdToIndex * map of instance id to index in gramMatrix * @param filePrefix * - prefix to which we add train_data.txt * @param mapClassToIndex * @throws IOException */ private void exportFold(double[][] gramMatrix, Map<Boolean, SortedMap<Long, String>> instanceIdToClassMap, boolean train, Map<Long, Integer> mapInstanceIdToIndex, String filePrefix, Map<String, Integer> mapClassToIndex) throws IOException { String fileName = new StringBuilder(filePrefix).append("_data.txt").toString(); String idFileName = new StringBuilder(filePrefix).append("_id.txt").toString(); BufferedWriter w = null; BufferedWriter wId = null; // for both training and test sets, the column instance ids // are the training instance ids. This is already sorted, // but we stuff it in a list, so make sure it is sorted // the order has to be the same in both the train and test files List<Long> colInstanceIds = new ArrayList<Long>(instanceIdToClassMap.get(true).keySet()); Collections.sort(colInstanceIds); // the rows - train or test instance ids and their class labels SortedMap<Long, String> rowInstanceToClassMap = instanceIdToClassMap.get(train); try { w = new BufferedWriter(new FileWriter(fileName)); wId = new BufferedWriter(new FileWriter(idFileName)); int rowIndex = 0; // the rows in the gramMatrix correspond to the entries in the // instanceLabelMap // both are in the same order for (Map.Entry<Long, String> instanceClass : rowInstanceToClassMap.entrySet()) { // classId - we assume that this is value is valid for libsvm // this can be a real number (for regression) String classId = instanceClass.getValue(); // the instance id of this row long rowInstanceId = instanceClass.getKey(); // the index to gramMatrix corresponding to this instance int rowInstanceIndex = mapInstanceIdToIndex.get(rowInstanceId); // write class Id w.write(mapClassToIndex.get(classId).toString()); w.write("\t"); // write row number - libsvm uses 1-based indexing w.write("0:"); w.write(Integer.toString(rowIndex + 1)); // write column entries for (int columnIndex = 0; columnIndex < colInstanceIds.size(); columnIndex++) { // column instance id long colInstanceId = colInstanceIds.get(columnIndex); // index into gram matrix for this instance id int colInstanceIndex = mapInstanceIdToIndex.get(colInstanceId); w.write("\t"); // write column number w.write(Integer.toString(columnIndex + 1)); w.write(":"); // write value - gramMatrix is symmetric, so this will work // both ways w.write(Double.toString(gramMatrix[rowInstanceIndex][colInstanceIndex])); } // don't want carriage return, even on windows w.write("\n"); // increment the row number rowIndex++; // write id to file wId.write(Long.toString(rowInstanceId)); wId.write("\n"); } } finally { if (w != null) w.close(); if (wId != null) wId.close(); } }
From source file:org.apache.hadoop.hive.metastore.hbase.HBaseUtils.java
/** * Produce a hash for the storage descriptor * @param sd storage descriptor to hash/*from ww w. jav a 2 s . c om*/ * @param md message descriptor to use to generate the hash * @return the hash as a byte array */ public static byte[] hashStorageDescriptor(StorageDescriptor sd, MessageDigest md) { // Note all maps and lists have to be absolutely sorted. Otherwise we'll produce different // results for hashes based on the OS or JVM being used. md.reset(); for (FieldSchema fs : sd.getCols()) { md.update(fs.getName().getBytes(ENCODING)); md.update(fs.getType().getBytes(ENCODING)); if (fs.getComment() != null) md.update(fs.getComment().getBytes(ENCODING)); } if (sd.getInputFormat() != null) { md.update(sd.getInputFormat().getBytes(ENCODING)); } if (sd.getOutputFormat() != null) { md.update(sd.getOutputFormat().getBytes(ENCODING)); } md.update(sd.isCompressed() ? "true".getBytes(ENCODING) : "false".getBytes(ENCODING)); md.update(Integer.toString(sd.getNumBuckets()).getBytes(ENCODING)); if (sd.getSerdeInfo() != null) { SerDeInfo serde = sd.getSerdeInfo(); if (serde.getName() != null) { md.update(serde.getName().getBytes(ENCODING)); } if (serde.getSerializationLib() != null) { md.update(serde.getSerializationLib().getBytes(ENCODING)); } if (serde.getParameters() != null) { SortedMap<String, String> params = new TreeMap<>(serde.getParameters()); for (Map.Entry<String, String> param : params.entrySet()) { md.update(param.getKey().getBytes(ENCODING)); md.update(param.getValue().getBytes(ENCODING)); } } } if (sd.getBucketCols() != null) { List<String> bucketCols = new ArrayList<>(sd.getBucketCols()); for (String bucket : bucketCols) md.update(bucket.getBytes(ENCODING)); } if (sd.getSortCols() != null) { SortedSet<Order> orders = new TreeSet<>(sd.getSortCols()); for (Order order : orders) { md.update(order.getCol().getBytes(ENCODING)); md.update(Integer.toString(order.getOrder()).getBytes(ENCODING)); } } if (sd.getSkewedInfo() != null) { SkewedInfo skewed = sd.getSkewedInfo(); if (skewed.getSkewedColNames() != null) { SortedSet<String> colnames = new TreeSet<>(skewed.getSkewedColNames()); for (String colname : colnames) md.update(colname.getBytes(ENCODING)); } if (skewed.getSkewedColValues() != null) { SortedSet<String> sortedOuterList = new TreeSet<>(); for (List<String> innerList : skewed.getSkewedColValues()) { SortedSet<String> sortedInnerList = new TreeSet<>(innerList); sortedOuterList.add(StringUtils.join(sortedInnerList, ".")); } for (String colval : sortedOuterList) md.update(colval.getBytes(ENCODING)); } if (skewed.getSkewedColValueLocationMaps() != null) { SortedMap<String, String> sortedMap = new TreeMap<>(); for (Map.Entry<List<String>, String> smap : skewed.getSkewedColValueLocationMaps().entrySet()) { SortedSet<String> sortedKey = new TreeSet<>(smap.getKey()); sortedMap.put(StringUtils.join(sortedKey, "."), smap.getValue()); } for (Map.Entry<String, String> e : sortedMap.entrySet()) { md.update(e.getKey().getBytes(ENCODING)); md.update(e.getValue().getBytes(ENCODING)); } } md.update(sd.isStoredAsSubDirectories() ? "true".getBytes(ENCODING) : "false".getBytes(ENCODING)); } return md.digest(); }
From source file:de.gbv.ole.Marc21ToOleBulk.java
/** * Schreibt die Exemplare sortiert nach Exemplarnummer. * @param ppn PPN der Exemplare.// w w w. j av a 2s .c o m * @param record Record, zu dem das Exemplar gehrt * @param exemplare Zu konvertierende und schreibende Exemplare. * @throws IOException bei Ausgabefehler */ void write(String ppn, Record record, Map<String, Exemplar> exemplare) throws IOException { SortedMap<String, Exemplar> sort = new TreeMap<String, Exemplar>(exemplare); for (Map.Entry<String, Exemplar> e : sort.entrySet()) { String exemplarnummer = e.getKey(); Exemplar exemplar = e.getValue(); fetchItemType(record, exemplar); write(ppn, exemplarnummer, exemplar); } }
From source file:org.apache.cassandra.hadoop.pig.CassandraStorage.java
@Override public Tuple getNext() throws IOException { try {// www .j a v a 2s . c o m // load the next pair if (!reader.nextKeyValue()) return null; CfDef cfDef = getCfDef(); ByteBuffer key = (ByteBuffer) reader.getCurrentKey(); SortedMap<ByteBuffer, IColumn> cf = (SortedMap<ByteBuffer, IColumn>) reader.getCurrentValue(); assert key != null && cf != null; // and wrap it in a tuple Tuple tuple = TupleFactory.getInstance().newTuple(2); ArrayList<Tuple> columns = new ArrayList<Tuple>(); tuple.set(0, new DataByteArray(key.array(), key.position() + key.arrayOffset(), key.limit() + key.arrayOffset())); for (Map.Entry<ByteBuffer, IColumn> entry : cf.entrySet()) { columns.add(columnToTuple(entry.getKey(), entry.getValue(), cfDef)); } tuple.set(1, new DefaultDataBag(columns)); return tuple; } catch (InterruptedException e) { throw new IOException(e.getMessage()); } }
From source file:at.nhmwien.schema_mapping_tool.ProcessMappingWindow.java
/** Creates new form ProcessMappingWindow */ public ProcessMappingWindow() { initComponents();//from w w w.j av a2 s .c om // Disable the abort button by default this.abortButton.setEnabled(false); // Add the available file types to the dropdown String[] fpTypes = ProcessorHandler.self().getProcessors(); DefaultComboBoxModel iffCbModel = new DefaultComboBoxModel(); DefaultComboBoxModel offCbModel = new DefaultComboBoxModel(); for (int i = 0; i < fpTypes.length; i++) { iffCbModel.addElement(fpTypes[i]); offCbModel.addElement(fpTypes[i]); // Get all valid file-types for this handler and add a filenameextensionfilter for it /*String[] fpFileTypes = ProcessorHandler.self().getSupportedFilesForType(fpTypes[i]); if( fpFileTypes != null ) { String fpFTDescription = fpTypes[i] + " (*." + fpFileTypes[0]; for( int j = 1; j < fpFileTypes.length; j++ ) { fpFTDescription += ", *." + fpFileTypes[j]; } fpFTDescription += ")"; //FileNameExtensionFilter filter = new FileNameExtensionFilter( fpFTDescription, fpFileTypes ); //fc.addChoosableFileFilter(filter); }*/ } this.inputFileFormatComboBox.setModel(iffCbModel); this.outputFileFormatComboBox.setModel(offCbModel); // Add all available character encodings to the drop-down DefaultComboBoxModel ifECbModel = new DefaultComboBoxModel(); DefaultComboBoxModel ofECbModel = new DefaultComboBoxModel(); SortedMap<String, Charset> availChars = Charset.availableCharsets(); Iterator<Map.Entry<String, Charset>> acIt = availChars.entrySet().iterator(); while (acIt.hasNext()) { Map.Entry<String, Charset> currEntry = acIt.next(); ifECbModel.addElement(currEntry.getValue()); ofECbModel.addElement(currEntry.getValue()); } this.ifEncodingComboBox.setModel(ifECbModel); this.ofEncodingComboBox.setModel(ofECbModel); this.mp = new MappingProcess(); // Create our initial settings windows inputFileFormatComboBoxActionPerformed(null); outputFileFormatComboBoxActionPerformed(null); }
From source file:edu.mit.ll.graphulo.pig.backend.GraphuloOneTableStorage.java
@Override protected Tuple getTuple(Key key, Value value) throws IOException { SortedMap<Key, Value> rowKVs = WholeRowIterator.decodeRow(key, value); Tuple tuple = TupleFactory.getInstance().newTuple(columns.size() + 1); final Text cfHolder = new Text(); final Text cqHolder = new Text(); final Text row = key.getRow(); int tupleOffset = 0; tuple.set(tupleOffset, new DataByteArray(Text.decode(row.getBytes(), 0, row.getLength()))); for (Column column : this.columns) { tupleOffset++;//from w w w . j av a2 s . c o m switch (column.getType()) { case LITERAL: cfHolder.set(column.getColumnFamily()); if (null != column.getColumnQualifier()) { cqHolder.set(column.getColumnQualifier()); } else { cqHolder.set(EMPTY_TEXT); } // Get the key where our literal would exist (accounting for // "colf:colq" or "colf:" empty colq) Key literalStartKey = new Key(row, cfHolder, cqHolder); SortedMap<Key, Value> tailMap = rowKVs.tailMap(literalStartKey); // Find the element if (tailMap.isEmpty()) { tuple.set(tupleOffset, EMPTY_DATA_BYTE_ARRAY); } else { Key actualKey = tailMap.firstKey(); // Only place it in the tuple if it matches the user // request, avoid using a value from a // key with the wrong colqual if (0 == literalStartKey.compareTo(actualKey, PartialKey.ROW_COLFAM_COLQUAL)) { tuple.set(tupleOffset, new DataByteArray(tailMap.get(actualKey).get())); } else { // This row doesn't have the column we were looking for tuple.set(tupleOffset, EMPTY_DATA_BYTE_ARRAY); } } break; case COLFAM_PREFIX: cfHolder.set(column.getColumnFamily()); Range colfamPrefixRange = Range.prefix(row, cfHolder); Key colfamPrefixStartKey = new Key(row, cfHolder); SortedMap<Key, Value> cfTailMap = rowKVs.tailMap(colfamPrefixStartKey); // Find the element if (cfTailMap.isEmpty()) { tuple.set(tupleOffset, EMPTY_DATA_BYTE_ARRAY); } else { HashMap<String, DataByteArray> tupleMap = new HashMap<String, DataByteArray>(); // Build up a map for all the entries in this row that match // the colfam prefix for (Entry<Key, Value> entry : cfTailMap.entrySet()) { if (colfamPrefixRange.contains(entry.getKey())) { entry.getKey().getColumnFamily(cfHolder); entry.getKey().getColumnQualifier(cqHolder); DataByteArray val = new DataByteArray(entry.getValue().get()); // Avoid adding an extra ':' when colqual is empty if (0 == cqHolder.getLength()) { tupleMap.put(cfHolder.toString(), val); } else { tupleMap.put(cfHolder.toString() + COLON + cqHolder.toString(), val); } } else { break; } } if (!tupleMap.isEmpty()) { tuple.set(tupleOffset, tupleMap); } } break; case COLQUAL_PREFIX: cfHolder.set(column.getColumnFamily()); cqHolder.set(column.getColumnQualifier()); Range colqualPrefixRange = Range.prefix(row, cfHolder, cqHolder); Key colqualPrefixStartKey = new Key(row, cfHolder, cqHolder); SortedMap<Key, Value> cqTailMap = rowKVs.tailMap(colqualPrefixStartKey); if (cqTailMap.isEmpty()) { tuple.set(tupleOffset, EMPTY_DATA_BYTE_ARRAY); } else { HashMap<String, DataByteArray> tupleMap = new HashMap<String, DataByteArray>(); // Build up a map for all the entries in this row that match // the colqual prefix for (Entry<Key, Value> entry : cqTailMap.entrySet()) { if (colqualPrefixRange.contains(entry.getKey())) { entry.getKey().getColumnFamily(cfHolder); entry.getKey().getColumnQualifier(cqHolder); DataByteArray val = new DataByteArray(entry.getValue().get()); // Avoid the extra ':' on empty colqual if (0 == cqHolder.getLength()) { tupleMap.put(cfHolder.toString(), val); } else { tupleMap.put(cfHolder.toString() + COLON + cqHolder.toString(), val); } } else { break; } } if (!tupleMap.isEmpty()) { tuple.set(tupleOffset, tupleMap); } } break; default: break; } } return tuple; }