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

The following examples show how to use java.util.NavigableMap#get() . 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: HBaseManager.java    From hbase-secondary-index with GNU General Public License v3.0 6 votes vote down vote up
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;
			}
		}
	}
 
Example 2
Source File: ComponentServiceImpl.java    From appinventor-extensions with Apache License 2.0 6 votes vote down vote up
/**
 * 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;
}
 
Example 3
Source File: BlobStoreCompactorTest.java    From ambry with Apache License 2.0 6 votes vote down vote up
/**
 * 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;
}
 
Example 4
Source File: SizeConfigStrategy.java    From sketch with Apache License 2.0 5 votes vote down vote up
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);
    }
}
 
Example 5
Source File: SizeConfigStrategy.java    From sketch with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example 6
Source File: FakeHBaseConnection.java    From pentaho-hadoop-shims with Apache License 2.0 5 votes vote down vote up
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();
}
 
Example 7
Source File: TreeSubMapTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * get(null) of nonempty map throws NPE
 */
public void testDescendingGet_NullPointerException() {
    NavigableMap c = dmap5();
    try {
        c.get(null);
        shouldThrow();
    } catch (NullPointerException success) {}
}
 
Example 8
Source File: TreeSubMapTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * get(null) of nonempty map throws NPE
 */
public void testDescendingGet_NullPointerException() {
    NavigableMap c = dmap5();
    try {
        c.get(null);
        shouldThrow();
    } catch (NullPointerException success) {}
}
 
Example 9
Source File: ValidationRules.java    From hadoop-arch-book with Apache License 2.0 5 votes vote down vote up
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();
      }
    }
 
Example 10
Source File: JobDetails.java    From hraven with Apache License 2.0 5 votes vote down vote up
/**
 * 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;
  }
}
 
Example 11
Source File: ArrayStoreConverter.java    From jstarcraft-core with Apache License 2.0 5 votes vote down vote up
@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;
}
 
Example 12
Source File: MapStoreConverter.java    From jstarcraft-core with Apache License 2.0 5 votes vote down vote up
@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);
    }
}
 
Example 13
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 14
Source File: TreeSubMapTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * get(null) of nonempty map throws NPE
 */
public void testGet_NullPointerException() {
    NavigableMap c = map5();
    try {
        c.get(null);
        shouldThrow();
    } catch (NullPointerException success) {}
}
 
Example 15
Source File: HBaseBinaryRecordReader.java    From titan1withtp3.1 with Apache License 2.0 5 votes vote down vote up
@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));
}
 
Example 16
Source File: ByteUtil.java    From hraven with Apache License 2.0 5 votes vote down vote up
/**
 * 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;
  }
}
 
Example 17
Source File: VersionedCache.java    From kareldb with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example 18
Source File: HBaseUtilDataComparer.java    From antsdb with GNU Lesser General Public License v3.0 4 votes vote down vote up
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);
        }
	}
 
Example 19
Source File: Helper.java    From antsdb with GNU Lesser General Public License v3.0 4 votes vote down vote up
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;
}
 
Example 20
Source File: MockHTable.java    From metron with Apache License 2.0 3 votes vote down vote up
/**
 * 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;
}