java.util.NavigableMap#get ( )源码实例Demo

下面列出了java.util.NavigableMap#get ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: ambry   文件: BlobStoreCompactorTest.java
/**
 * Gets all the log entries in {@code logSegmentsUnderConsideration} in order of their occurrence in the log.
 * @param logSegmentsUnderConsideration the log segments whose log entries are required.
 * @return the log entries in {@code logSegmentsUnderConsideration} in order of their occurrence in the log.
 * @throws IOException
 * @throws StoreException
 */
private List<LogEntry> getLogEntriesInOrder(List<String> logSegmentsUnderConsideration)
    throws IOException, StoreException {
  List<LogEntry> logEntriesInOrder = new ArrayList<>();
  NavigableMap<Offset, IndexSegment> indexSegments = state.index.getIndexSegments();
  for (String logSegmentName : logSegmentsUnderConsideration) {
    LogSegment logSegment = state.log.getSegment(logSegmentName);
    Offset indexSegmentStartOffset = new Offset(logSegmentName, logSegment.getStartOffset());
    while (indexSegmentStartOffset != null && indexSegmentStartOffset.getName().equals(logSegmentName)) {
      IndexSegment indexSegment = indexSegments.get(indexSegmentStartOffset);
      List<MessageInfo> infos = new ArrayList<>();
      indexSegment.getEntriesSince(null, new FindEntriesCondition(Long.MAX_VALUE), infos, new AtomicLong(0));
      List<IndexEntry> indexEntries = new ArrayList<>();
      for (MessageInfo info : infos) {
        indexSegment.find(info.getStoreKey())
            .forEach(value -> indexEntries.add(new IndexEntry(info.getStoreKey(), value)));
      }
      addToLogEntriesInOrder(indexEntries, logEntriesInOrder);
      indexSegmentStartOffset = indexSegments.higherKey(indexSegmentStartOffset);
    }
  }
  return logEntriesInOrder;
}
 
/**
 * Finds extensions in the project sources and returns a mapping from the extension type name (for
 * old style extensions) or package name (for new style extensions) to the set of file names
 * included in that extension.
 *
 * @param extensionDir Extension asset directory in the project
 * @param files Set of all file names in the project
 * @return A map from the type name or package name of an extension to a set of all files in that
 * extension. We return a NavigableMap to aid in searching for related extensions during an
 * upgrade when the two extensions might share the same package but have been packaged by the
 * old extension system, which was per-class rather than per-package.
 */
private static NavigableMap<String, Set<String>> findExtensions(String extensionDir,
    Set<String> files) {
  NavigableMap<String, Set<String>> extensions = new TreeMap<>();
  for (String s : files) {
    if (s.startsWith(extensionDir)) {
      String[] parts = s.split("/");
      String extensionName = parts[2];
      Set<String> extFiles = extensions.get(extensionName);
      if (extFiles == null) {
        extFiles = new HashSet<>();
        extensions.put(extensionName, extFiles);
      }
      extFiles.add(s);
    }
  }
  return extensions;
}
 
源代码3 项目: hbase-secondary-index   文件: HBaseManager.java
public void testQueryCommodity() throws Exception {

		System.out.println("Get Spin's commodity info");
		Get mathGet = new Get(new String("Spin").getBytes());
		mathGet.addColumn(Bytes.toBytes("cf"), Bytes.toBytes("widgetname"));
		mathGet.setMaxVersions();
		Result rs = table.get(mathGet);

		NavigableMap<byte[], NavigableMap<byte[], NavigableMap<Long, byte[]>>> nMap = rs
				.getMap();
		NavigableMap<byte[], NavigableMap<Long, byte[]>> columnMap = nMap
				.get(Bytes.toBytes("widgetname"));
		NavigableMap<Long, byte[]> qualMap = columnMap.get(new byte[] {});

		if (qualMap.entrySet().size() > 0) {
			for (Map.Entry<Long, byte[]> m : qualMap.entrySet()) {
				System.out.println("Value:" + new String(m.getValue()));
				break;
			}
		}
	}
 
源代码4 项目: hraven   文件: JobDetails.java
/**
 * return an enum value from the NavigableMap for hadoop version
 * @param key
 * @param infoValues
 * @return value as a enum or default of hadoop ONE
 */
private HadoopVersion getHadoopVersionFromResult(final JobHistoryKeys key,
    final NavigableMap<byte[], byte[]> infoValues) {
  byte[] value = infoValues.get(JobHistoryKeys.KEYS_TO_BYTES.get(key));
  if (value != null) {
    String hv = Bytes.toString(value);
    // could throw an NPE or IllegalArgumentException
    return HadoopVersion.valueOf(hv);
  } else {
    // default is hadoop 1
    return HadoopVersion.ONE;
  }
}
 
源代码5 项目: kareldb   文件: VersionedCache.java
public boolean setCommit(Comparable[] key, long version, long commit) {
    NavigableMap<Long, VersionedValue> rowData = cache.getOrDefault(key, new ConcurrentSkipListMap<>());
    VersionedValue value = rowData.get(version);
    if (value == null) {
        return false;
    }
    if (commit == INVALID_TX) {
        rowData.remove(version);
    } else {
        rowData.put(version, new VersionedValue(version, commit, value.isDeleted(), value.getValue()));
    }
    garbageCollect(rowData);
    cache.put(key, rowData);
    return true;
}
 
源代码6 项目: hraven   文件: ByteUtil.java
/**
 * return a value from the NavigableMap as a Double
 * @param key to be looked up for the value
 * @param infoValues - the map containing the key values
 * @return value as Double or 0.0
 */
public static double getValueAsDouble(byte[] key,
    NavigableMap<byte[], byte[]> infoValues) {
  byte[] value = infoValues.get(key);
  if (value != null) {
    return Bytes.toDouble(value);
  } else {
    return 0.0;
  }
}
 
源代码7 项目: titan1withtp3.1   文件: HBaseBinaryRecordReader.java
@Override
public Iterable<Entry> getCurrentValue() throws IOException, InterruptedException {
    Result result = (Result)reader.getCurrentValue();
    NavigableMap<byte[],NavigableMap<byte[],NavigableMap<Long,byte[]>>> nm = result.getMap();
    return new HBaseMapIterable(nm.get(edgestoreFamilyBytes));
    // return new HBaseMapIterable(reader.getCurrentValue().getMap().get(edgestoreFamilyBytes));
}
 
源代码8 项目: j2objc   文件: TreeSubMapTest.java
/**
 * get(null) of nonempty map throws NPE
 */
public void testGet_NullPointerException() {
    NavigableMap c = map5();
    try {
        c.get(null);
        shouldThrow();
    } catch (NullPointerException success) {}
}
 
源代码9 项目: hbase-secondary-index   文件: HBaseManager.java
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;
		}
	}
 
源代码10 项目: jstarcraft-core   文件: MapStoreConverter.java
@Override
public Object decode(LuceneContext context, String path, Field field, LuceneStore annotation, Type type, NavigableMap<String, IndexableField> indexables) {
    String from = path;
    char character = path.charAt(path.length() - 1);
    character++;
    String to = path.substring(0, path.length() - 1) + character;
    indexables = indexables.subMap(from, true, to, false);
    Class<?> clazz = TypeUtility.getRawType(type, null);
    // 兼容UniMi
    type = TypeUtility.refineType(type, Map.class);
    ParameterizedType parameterizedType = ParameterizedType.class.cast(type);
    Type[] types = parameterizedType.getActualTypeArguments();
    Type keyType = types[0];
    Class<?> keyClazz = TypeUtility.getRawType(keyType, null);
    Type valueType = types[1];
    Class<?> valueClazz = TypeUtility.getRawType(valueType, null);

    try {
        // TODO 此处需要代码重构
        Map<Object, Object> map = (Map) context.getInstance(clazz);
        Specification keySpecification = Specification.getSpecification(keyClazz);
        StoreConverter keyConverter = context.getStoreConverter(keySpecification);
        Specification valueSpecification = Specification.getSpecification(valueClazz);
        StoreConverter valueConverter = context.getStoreConverter(valueSpecification);

        IndexableField indexable = indexables.get(path + ".size");
        int size = indexable.numericValue().intValue();
        for (int index = 0; index < size; index++) {
            Object key = keyConverter.decode(context, path + "[" + index + "_key]", field, annotation, keyType, indexables);
            Object value = valueConverter.decode(context, path + "[" + index + "_value]", field, annotation, valueType, indexables);
            map.put(key, value);
        }
        return map;
    } catch (Exception exception) {
        // TODO
        throw new StorageException(exception);
    }
}
 
源代码11 项目: jstarcraft-core   文件: ArrayStoreConverter.java
@Override
public Object decode(LuceneContext context, String path, Field field, LuceneStore annotation, Type type, NavigableMap<String, IndexableField> indexables) {
    String from = path;
    char character = path.charAt(path.length() - 1);
    character++;
    String to = path.substring(0, path.length() - 1) + character;
    indexables = indexables.subMap(from, true, to, false);
    Class<?> componentClass = null;
    Type componentType = null;
    if (type instanceof GenericArrayType) {
        GenericArrayType genericArrayType = GenericArrayType.class.cast(type);
        componentType = genericArrayType.getGenericComponentType();
        componentClass = TypeUtility.getRawType(componentType, null);
    } else {
        Class<?> clazz = TypeUtility.getRawType(type, null);
        componentType = clazz.getComponentType();
        componentClass = clazz.getComponentType();
    }
    Specification specification = Specification.getSpecification(componentClass);
    StoreConverter converter = context.getStoreConverter(specification);
    IndexableField indexable = indexables.get(path + ".size");
    int size = indexable.numericValue().intValue();
    Object array = Array.newInstance(componentClass, size);
    for (int index = 0; index < size; index++) {
        Object element = converter.decode(context, path + "[" + index + "]", field, annotation, componentType, indexables);
        Array.set(array, index, element);
    }
    return array;
}
 
源代码12 项目: sketch   文件: SizeConfigStrategy.java
private void decrementBitmapOfSize(Integer size, Bitmap.Config config) {
    NavigableMap<Integer, Integer> sizes = getSizesForConfig(config);
    Integer current = sizes.get(size);
    if (current == 1) {
        sizes.remove(size);
    } else {
        sizes.put(size, current - 1);
    }
}
 
源代码13 项目: hadoop-arch-book   文件: ValidationRules.java
public static ValidationRules buildValidationRules(NavigableMap<byte[], byte[]> familyMap) throws Exception {

      if (familyMap != null) {
        byte[] bytes = familyMap.get(HBaseTableMetaModel.validationRulesRowKey);

        return new ValidationRules(Bytes.toString(bytes));
      } else {
        LOG.warn("No Validation Rules Found in HBase");
        return new ValidationRules();
      }
    }
 
源代码14 项目: j2objc   文件: TreeSubMapTest.java
/**
 * get(null) of nonempty map throws NPE
 */
public void testDescendingGet_NullPointerException() {
    NavigableMap c = dmap5();
    try {
        c.get(null);
        shouldThrow();
    } catch (NullPointerException success) {}
}
 
源代码15 项目: openjdk-jdk9   文件: TreeSubMapTest.java
/**
 * get(null) of nonempty map throws NPE
 */
public void testDescendingGet_NullPointerException() {
    NavigableMap c = dmap5();
    try {
        c.get(null);
        shouldThrow();
    } catch (NullPointerException success) {}
}
 
源代码16 项目: pentaho-hadoop-shims   文件: FakeHBaseConnection.java
public byte[] getValue( byte[] colFam, byte[] colName ) {
  NavigableMap<byte[], NavigableMap<Long, byte[]>> colMapForFam = m_row
    .get( colFam );
  if ( colMapForFam == null ) {
    return null;
  }

  NavigableMap<Long, byte[]> versionsOfCol = colMapForFam.get( colName );
  if ( versionsOfCol == null ) {
    return null;
  }

  return versionsOfCol.lastEntry().getValue();
}
 
源代码17 项目: sketch   文件: SizeConfigStrategy.java
@Override
public void put(Bitmap bitmap) {
    int size = SketchUtils.getByteCount(bitmap);
    Key key = keyPool.get(size, bitmap.getConfig());

    groupedMap.put(key, bitmap);

    NavigableMap<Integer, Integer> sizes = getSizesForConfig(bitmap.getConfig());
    Integer current = sizes.get(key.size);
    sizes.put(key.size, current == null ? 1 : current + 1);
}
 
源代码18 项目: antsdb   文件: HBaseUtilDataComparer.java
void compareOneRow(TableMeta tableMeta, Row row, Result r) throws Exception{
	
		if (row == null) {
			throw new Exception("row is null");
		}
		
		byte[] antsKey = KeyBytes.create(row.getKeyAddress()).get();	
		if (r == null || r.isEmpty()) {
			throw new Exception("Row can't be found in hbase - key: " + bytesToHex(antsKey));
		}
		
		// some preparation
		
//	    NavigableMap<byte[], byte[]> sysFamilyMap = r.getFamilyMap(Helper.SYS_COLUMN_FAMILY_BYTES);
	    NavigableMap<byte[], byte[]> dataFamilyMap = r.getFamilyMap(Helper.DATA_COLUMN_FAMILY_BYTES);
//	    byte[] colDataType = sysFamilyMap.get(Helper.SYS_COLUMN_DATATYPE_BYTES);
//	    byte[] versionBytes = sysFamilyMap.get(Helper.SYS_COLUMN_VERSION_BYTES);
//	    byte[] sizeBytes = sysFamilyMap.get(Helper.SYS_COLUMN_SIZE_BYTES);
//	    long version = Bytes.toLong(versionBytes);
//	    int size = Bytes.toInt(sizeBytes);
	    
		byte[] key = Helper.hbaseKeyToAnts(r.getRow());
		if (!Arrays.equals(key, antsKey)) {
			throw new Exception("Row key not match - ANTS: " + bytesToHex(antsKey) + ", HBASE: " + bytesToHex(key));
		}
		
		int maxColumnId = row.getMaxColumnId();
//		byte[] types = new byte[maxColumnId+1];
		String errMsg = "";
        for (int i=0; i<=maxColumnId; i++) {
			byte[] qualifier = tableColumnQualifierList.get(i);
    		if (qualifier == null) {
    			continue;
    		}
    		
        	long pValue = row.getFieldAddress(i); 
    		byte[] antsValue = Helper.toBytes(pValue);
    		byte[] value = dataFamilyMap.get(qualifier);
    		
    		if (!Arrays.equals(antsValue,  value)) {
    			String columnName = new String(qualifier, StandardCharsets.US_ASCII);
    			if (errMsg.length() == 0) {
    				errMsg += "Row Key=[" + bytesToHex(key) + "]";
    			}
    			errMsg += String.format("\n    Column %1$d '%2$s'[%3$s] not match - ANTS:[%4$s] HBASE:[%5$s]",
						i, columnName, bytesToHex(qualifier), bytesToHex(antsValue), bytesToHex(value));
    		}
        }
        
        if (errMsg != "") {
        	throw new Exception(errMsg);
        }
	}
 
源代码19 项目: antsdb   文件: Helper.java
public static long getVersion(Result r) {
    NavigableMap<byte[], byte[]> sys = r.getFamilyMap(DATA_COLUMN_FAMILY_BYTES);
    byte[] versionBytes = sys.get(SYS_COLUMN_VERSION_BYTES);
    long version = Bytes.toLong(versionBytes);
    return version;
}
 
源代码20 项目: metron   文件: MockHTable.java
/**
 * Helper method to find a key in a map. If key is not found, newObject is
 * added to map and returned
 *
 * @param map
 *          map to extract value from
 * @param key
 *          key to look for
 * @param newObject
 *          set key to this if not found
 * @return found value or newObject if not found
 */
private <K, V> V forceFind(NavigableMap<K, V> map, K key, V newObject){
  V data = map.get(key);
  if (data == null){
    data = newObject;
    map.put(key, data);
  }
  return data;
}