Java Code Examples for java.util.NavigableMap#entrySet()

The following examples show how to use java.util.NavigableMap#entrySet() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ADAPInterface.java    From mzmine3 with GNU General Public License v2.0 6 votes vote down vote up
@Nonnull
public static Feature peakToFeature(@Nonnull RawDataFile file, @Nonnull Peak peak) {

  NavigableMap<Double, Double> chromatogram = peak.getChromatogram();

  double[] retTimes = new double[chromatogram.size()];
  double[] intensities = new double[chromatogram.size()];
  int index = 0;
  for (Entry<Double, Double> e : chromatogram.entrySet()) {
    retTimes[index] = e.getKey();
    intensities[index] = e.getValue();
    ++index;
  }

  BetterPeak betterPeak = new BetterPeak(peak.getInfo().peakID,
      new Chromatogram(retTimes, intensities), peak.getInfo());

  return peakToFeature(file, betterPeak);
}
 
Example 2
Source File: HBaseLogByRowkeyReader.java    From Eagle with Apache License 2.0 6 votes vote down vote up
private InternalLog buildLog(Result result) {
	final InternalLog log = new InternalLog();
	final byte[] rowkey = result.getRow();
	log.setEncodedRowkey(EagleBase64Wrapper.encodeByteArray2URLSafeString(rowkey));
	long timestamp = ByteUtil.bytesToLong(rowkey, 4);
	timestamp = Long.MAX_VALUE - timestamp;
	log.setTimestamp(timestamp);
	Map<String, byte[]> qualifierValues = new HashMap<String, byte[]>();
	log.setQualifierValues(qualifierValues);
	NavigableMap<byte[], byte[]> map = result.getFamilyMap(this.columnFamily.getBytes());
	if(map == null){
		throw new NoSuchRowException(EagleBase64Wrapper.encodeByteArray2URLSafeString(rowkey));
	}
	for(Map.Entry<byte[], byte[]> entry : map.entrySet()){
		byte[] qualifier = entry.getKey();
		byte[] value = entry.getValue();
		qualifierValues.put(new String(qualifier), value);
	}
	return log;
}
 
Example 3
Source File: TreeSubMapTest.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * entrySet contains all pairs
 */
public void testDescendingEntrySet() {
    NavigableMap map = dmap5();
    Set s = map.entrySet();
    assertEquals(5, s.size());
    Iterator it = s.iterator();
    while (it.hasNext()) {
        Map.Entry e = (Map.Entry) it.next();
        assertTrue(
                   (e.getKey().equals(m1) && e.getValue().equals("A")) ||
                   (e.getKey().equals(m2) && e.getValue().equals("B")) ||
                   (e.getKey().equals(m3) && e.getValue().equals("C")) ||
                   (e.getKey().equals(m4) && e.getValue().equals("D")) ||
                   (e.getKey().equals(m5) && e.getValue().equals("E")));
    }
}
 
Example 4
Source File: AppSummaryService.java    From hraven with Apache License 2.0 6 votes vote down vote up
/**
 * constructs App key from the result set based on cluster, user, appId picks
 * those results that satisfy the time range criteria
 * @param result
 * @param startTime
 * @param endTime
 * @return flow key
 * @throws IOException
 */
private AppKey getNewAppKeyFromResult(Result result, long startTime,
    long endTime) throws IOException {

  byte[] rowKey = result.getRow();
  byte[][] keyComponents = ByteUtil.split(rowKey, Constants.SEP_BYTES);
  String cluster = Bytes.toString(keyComponents[0]);
  String user = Bytes.toString(keyComponents[1]);
  String appId = Bytes.toString(keyComponents[2]);

  NavigableMap<byte[], byte[]> valueMap =
      result.getFamilyMap(Constants.INFO_FAM_BYTES);
  long runId = Long.MAX_VALUE;
  for (Map.Entry<byte[], byte[]> entry : valueMap.entrySet()) {
    long tsl = Bytes.toLong(entry.getValue());
    // get the earliest runid, which indicates the first time this app ran
    if (tsl < runId) {
      runId = tsl;
    }
  }
  if ((runId >= startTime) && (runId <= endTime)) {
    AppKey ak = new AppKey(cluster, user, appId);
    return ak;
  }
  return null;
}
 
Example 5
Source File: TestAppendTimeRange.java    From hbase with Apache License 2.0 6 votes vote down vote up
@Override
public Result preAppend(final ObserverContext<RegionCoprocessorEnvironment> e,
    final Append append) throws IOException {
  NavigableMap<byte [], List<Cell>> map = append.getFamilyCellMap();
  for (Map.Entry<byte [], List<Cell>> entry : map.entrySet()) {
    for (Cell cell : entry.getValue()) {
      String appendStr = Bytes.toString(cell.getValueArray(), cell.getValueOffset(),
          cell.getValueLength());
      if (appendStr.equals("b")) {
        tr10 = append.getTimeRange();
      } else if (appendStr.equals("c") && !append.getTimeRange().isAllTime()) {
        tr2 = append.getTimeRange();
      }
    }
  }
  return null;
}
 
Example 6
Source File: TraceDto.java    From SkyEye with GNU General Public License v3.0 6 votes vote down vote up
@Override
public TraceDto mapRow(Result res, int rowNum) throws Exception {

    String traceId = new String(res.getRow());
    NavigableMap<byte[], byte[]> data = res.getFamilyMap(Constants.TABLE_TRACE_COLUMN_FAMILY.getBytes());

    String spanId;
    JSONObject spanDetail;
    TreeMap<String, JSONObject> map = new TreeMap<>();
    Set<Map.Entry<byte[], byte[]>> spanEntrySet = data.entrySet();
    for (Map.Entry<byte[], byte[]> entry : spanEntrySet) {
        spanId = new String(entry.getKey());
        spanDetail = JSON.parseObject(new String(entry.getValue()));
        map.put(spanId, spanDetail);
    }
    Set<Map.Entry<String, JSONObject>> spans = map.entrySet();


    TraceDto rtn = new TraceDto();
    rtn.setTraceId(traceId).setSpans(spans);
    return rtn;
}
 
Example 7
Source File: SortedOplogSetJUnitTest.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
@Override
protected SortedReader<ByteBuffer> createReader(NavigableMap<byte[], byte[]> data) 
    throws IOException {
  set = createSoplogSet("test");
  
  int i = 0;
  int flushes = 0;
  FlushCounter fc = new FlushCounter();
  
  for (Entry<byte[], byte[]> entry : data.entrySet()) {
    set.put(entry.getKey(), entry.getValue());
    if (i++ % 13 == 0) {
      flushes++;
      set.flush(null, fc);
    }
  }
  
  while (!fc.flushes.compareAndSet(flushes, 0));
  return set;
}
 
Example 8
Source File: GridDhtPartitionsStateValidator.java    From ignite with Apache License 2.0 6 votes vote down vote up
/**
 * Folds given map of invalid partition states to string representation in the following format:
 * Part [id]: [consistentId=value*]
 *
 * Value can be both update counter or cache size.
 *
 * @param topVer Last topology version.
 * @param invalidPartitions Invalid partitions map.
 * @return String representation of invalid partitions.
 */
private String fold(AffinityTopologyVersion topVer, Map<Integer, Map<UUID, Long>> invalidPartitions) {
    SB sb = new SB();

    NavigableMap<Integer, Map<UUID, Long>> sortedPartitions = new TreeMap<>(invalidPartitions);

    for (Map.Entry<Integer, Map<UUID, Long>> p : sortedPartitions.entrySet()) {
        sb.a("Part ").a(p.getKey()).a(": [");
        for (Map.Entry<UUID, Long> e : p.getValue().entrySet()) {
            Object consistentId = cctx.discovery().node(topVer, e.getKey()).consistentId();
            sb.a(consistentId).a("=").a(e.getValue()).a(" ");
        }
        sb.a("] ");
    }

    return sb.toString();
}
 
Example 9
Source File: HFileSortedOplogJUnitTest.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
@Override
protected SortedReader<ByteBuffer> createReader(NavigableMap<byte[], byte[]> data) 
    throws IOException {
  SortedOplogConfiguration config = new SortedOplogConfiguration("test");
  hfile = new HFileSortedOplog(new File("test.soplog"), config);

  SortedOplogWriter wtr = hfile.createWriter();
  for (Entry<byte[], byte[]> entry : data.entrySet()) {
    wtr.append(entry.getKey(), entry.getValue());
  }
  wtr.close(null);

  return hfile.createReader();
}
 
Example 10
Source File: HBaseManager.java    From hbase-secondary-index with GNU General Public License v3.0 5 votes vote down vote up
public void testQueryRS() throws Exception {

		Scan scanner = new Scan();
		scanner.addColumn(Bytes.toBytes("cf"), Bytes.toBytes("description"));
		scanner.setMaxVersions();
		ResultScanner rsScanner = table.getScanner(scanner);
		System.out.println(rsScanner.toString());
		Result rs = rsScanner.next();
		int count = 0;
		while (null != rs) {
			++count;
			System.out.println(rs.size());
			NavigableMap<byte[], NavigableMap<byte[], NavigableMap<Long, byte[]>>> nMap = rs
					.getMap();
			NavigableMap<byte[], NavigableMap<Long, byte[]>> columnMap = nMap
					.get(Bytes.toBytes("description"));
			NavigableMap<Long, byte[]> qualMap = columnMap.get(new byte[] {});

			if (qualMap.entrySet().size() > 0) {
				System.out.println("---------------------------");
				for (Map.Entry<Long, byte[]> m : qualMap.entrySet()) {
					System.out.println("Value:" + new String(m.getValue()));
				}
			}
			rs = rsScanner.next();
			if (count > 10)
				break;
		}
	}
 
Example 11
Source File: AclTableMigrationTool.java    From kylin with Apache License 2.0 5 votes vote down vote up
private Map<String, LegacyAceInfo> getAllAceInfo(Result result) throws IOException {
    Map<String, LegacyAceInfo> allAceInfoMap = new HashMap<>();
    NavigableMap<byte[], byte[]> familyMap = result.getFamilyMap(Bytes.toBytes(AclConstant.ACL_ACES_FAMILY));

    if (familyMap != null && !familyMap.isEmpty()) {
        for (Map.Entry<byte[], byte[]> entry : familyMap.entrySet()) {
            String sid = new String(entry.getKey(), StandardCharsets.UTF_8);
            LegacyAceInfo aceInfo = aceSerializer.deserialize(entry.getValue());
            if (null != aceInfo) {
                allAceInfoMap.put(sid, aceInfo);
            }
        }
    }
    return allAceInfoMap;
}
 
Example 12
Source File: TestFromClientSide5.java    From hbase with Apache License 2.0 5 votes vote down vote up
@Test
public void testClientPoolRoundRobin() throws IOException {
  final TableName tableName = name.getTableName();

  int poolSize = 3;
  int numVersions = poolSize * 2;
  Configuration conf = TEST_UTIL.getConfiguration();
  conf.set(HConstants.HBASE_CLIENT_IPC_POOL_TYPE, "round-robin");
  conf.setInt(HConstants.HBASE_CLIENT_IPC_POOL_SIZE, poolSize);

  try (Table table =
               TEST_UTIL.createTable(tableName, new byte[][] { FAMILY }, Integer.MAX_VALUE)) {

    final long ts = EnvironmentEdgeManager.currentTime();
    Get get = new Get(ROW);
    get.addColumn(FAMILY, QUALIFIER);
    get.readAllVersions();

    for (int versions = 1; versions <= numVersions; versions++) {
      Put put = new Put(ROW);
      put.addColumn(FAMILY, QUALIFIER, ts + versions, VALUE);
      table.put(put);

      Result result = table.get(get);
      NavigableMap<Long, byte[]> navigableMap = result.getMap().get(FAMILY)
              .get(QUALIFIER);

      assertEquals("The number of versions of '" + Bytes.toString(FAMILY) + ":"
              + Bytes.toString(QUALIFIER) + " did not match", versions, navigableMap.size());
      for (Map.Entry<Long, byte[]> entry : navigableMap.entrySet()) {
        assertTrue("The value at time " + entry.getKey()
                        + " did not match what was put",
                Bytes.equals(VALUE, entry.getValue()));
      }
    }
  }
}
 
Example 13
Source File: LogFileService.java    From c5-replicator with Apache License 2.0 5 votes vote down vote up
/**
 * Delete links to all logs for a given quorum except the current log, effectively
 * removing the past logs from the record but keeping the data.
 *
 * @throws IOException
 */
public void archiveAllButCurrent(String quorumId) throws IOException {
  NavigableMap<Long, Path> linkPathMap = getLinkPathMap(quorumId);
  if (linkPathMap.isEmpty()) {
    return;
  }

  long lastLinkId = linkPathMap.lastEntry().getKey();
  for (Map.Entry<Long, Path> linkEntry : linkPathMap.entrySet()) {
    if (linkEntry.getKey() != lastLinkId) {
      Files.delete(linkEntry.getValue());
    }
  }
}
 
Example 14
Source File: HBaseRow.java    From geowave with Apache License 2.0 5 votes vote down vote up
public HBaseRow(final Result result, final int partitionKeyLength) {
  // TODO: GEOWAVE-1018 - can we do something more clever that lazily
  // parses only whats required by the getter (and caches anything else
  // that is parsed)?
  key = new GeoWaveKeyImpl(result.getRow(), partitionKeyLength);

  final NavigableMap<byte[], NavigableMap<byte[], NavigableMap<Long, byte[]>>> rowMapping =
      result.getMap();
  final List<GeoWaveValue> fieldValueList = new ArrayList();

  for (final Entry<byte[], NavigableMap<byte[], NavigableMap<Long, byte[]>>> cfEntry : rowMapping.entrySet()) {
    for (final Entry<byte[], NavigableMap<Long, byte[]>> cqEntry : cfEntry.getValue().entrySet()) {
      for (final Entry<Long, byte[]> cqEntryValue : cqEntry.getValue().entrySet()) {
        final byte[] byteValue = cqEntryValue.getValue();
        final byte[] qualifier = cqEntry.getKey();

        fieldValueList.add(new GeoWaveValueImpl(qualifier, null, byteValue));
      }
    }
  }

  fieldValues = new GeoWaveValue[fieldValueList.size()];
  int i = 0;

  for (final GeoWaveValue gwValue : fieldValueList) {
    fieldValues[i++] = gwValue;
  }
}
 
Example 15
Source File: NoFileSortedOplogJUnitTest.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
@Override
protected SortedReader<ByteBuffer> createReader(NavigableMap<byte[], byte[]> data) throws IOException {
  mfile = new NoFileSortedOplog(new SortedOplogConfiguration("nofile"));

  SortedOplogWriter wtr = mfile.createWriter();
  for (Entry<byte[], byte[]> entry : data.entrySet()) {
    wtr.append(entry.getKey(), entry.getValue());
  }
  wtr.close(null);

  return mfile.createReader();
}
 
Example 16
Source File: ProviderBinder.java    From everrest with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * @param mediaTypeToContextResolverMap
 *         map that contains ProviderFactories that may produce objects that are instance of T
 * @param mediaType
 *         media type that can be used to restrict context resolver choose
 * @return ContextResolver or null if nothing was found
 */
@SuppressWarnings("unchecked")
private <T> ContextResolver<T> doGetContextResolver(NavigableMap<MediaType, ObjectFactory<ProviderDescriptor>> mediaTypeToContextResolverMap, MediaType mediaType) {
    for (Map.Entry<MediaType, ObjectFactory<ProviderDescriptor>> e : mediaTypeToContextResolverMap.entrySet()) {
        if (mediaType.isCompatible(e.getKey())) {
            return (ContextResolver<T>)e.getValue().getInstance(ApplicationContext.getCurrent());
        }
    }
    return null;
}
 
Example 17
Source File: HFileSortedOplogJUnitTest.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
@Override
protected SortedReader<ByteBuffer> createReader(NavigableMap<byte[], byte[]> data) 
    throws IOException {
  SortedOplogConfiguration config = new SortedOplogConfiguration("test");
  hfile = new HFileSortedOplog(new File("test.soplog"), config);

  SortedOplogWriter wtr = hfile.createWriter();
  for (Entry<byte[], byte[]> entry : data.entrySet()) {
    wtr.append(entry.getKey(), entry.getValue());
  }
  wtr.close(null);

  return hfile.createReader();
}
 
Example 18
Source File: PVTopTen.java    From MapReduce-Demo with MIT License 5 votes vote down vote up
public void cleanup(Context context) throws IOException, InterruptedException {
	//将TreeMap反序处理(降序),遍历输出top10
	NavigableMap<Integer, Text> reverseMap = map.descendingMap();
	for ( Entry<Integer, Text> entry  : reverseMap.entrySet() ) {
		context.write(entry.getValue(), NullWritable.get());
	}
}
 
Example 19
Source File: AbstractNavigableMapTest.java    From adaptive-radix-tree with MIT License 5 votes vote down vote up
public void testLastEntry() {
	assertNull(this.makeObject().lastEntry());
	NavigableMap<K, V> nm = this.makeFullMap();
	Map.Entry<K, V> last = null;

	for (Map.Entry<K, V> kvEntry : nm.entrySet()) {
		last = kvEntry;
	}

	assertEquals(last, nm.lastEntry());
}
 
Example 20
Source File: MethodPrototype.java    From cfr with MIT License 4 votes vote down vote up
public void setMethodScopedSyntheticConstructorParameters(NavigableMap<Integer, JavaTypeInstance> missing) {
    List<Slot> missingList = ListFactory.newList();
    //
    int expected = 0;
    for (Map.Entry<Integer, JavaTypeInstance> missingItem : missing.entrySet()) {
        Integer thisOffset = missingItem.getKey();
        JavaTypeInstance type = missingItem.getValue();
        // If the prototype is completely hosed, we're left with not much good.....
        while (thisOffset > expected) {
            missingList.add(new Slot(expected == 0 ? RawJavaType.REF : RawJavaType.NULL, expected++));
        }
        missingList.add(new Slot(type, thisOffset));
        expected = thisOffset + type.getStackType().getComputationCategory();
    }
    if (missingList.size() < 2) {
        return;
    }
    // Can we improve this with a descriptor proto?
    if (descriptorProto != null) {
        // Try and line our existing args up with the descriptor proto, then infer synthetic
        // data from that.

        List<JavaTypeInstance> descriptorArgs = descriptorProto.args;
        for (int x = 0; x< descriptorArgs.size()- this.args.size(); ++x) {

            if (satisfies(descriptorArgs, x, this.args)) {
                // Right... let's take that.
                int s = args.size() + x;
                args.clear();
                args.addAll(descriptorArgs);
                for (int y=0;y<x;++y) {
                    hide(y);
                }
                for (int y = s;y<args.size();++y) {
                    hide(y);
                }
            }
        }
    }

    // The first element MUST be a reference, which is the implicit 'this'.
    if (missingList.get(0).getJavaTypeInstance() != RawJavaType.REF) return;
    //noinspection unused
    Slot removed = missingList.remove(0);
    // Can we satisfy all of args at 0, or at 1?
    boolean all0 = satisfiesSlots(missingList, 0, args);
    boolean all1 = satisfiesSlots(missingList, 1, args);
    if (all1) {
        syntheticArgs.add(missingList.remove(0));
    } else if (!all0) {
        // Can't find anywhere in usages where args line up - this means we're struggling to reconstruct the
        // 'real' full signature.
        // This is very unsatisfactory
        syntheticArgs.add(missingList.remove(0));
    }
    for (int x=args.size();x<missingList.size();++x) {
        syntheticCaptureArgs.add(missingList.get(x));
    }
}