use of java.util.NavigableMap in project mapdb by jankotek.
the class TreeSubMapTest method testKeySetOrder.
/**
* keySet is ordered
*/
public void testKeySetOrder() {
NavigableMap map = map5();
Set s = map.keySet();
Iterator i = s.iterator();
Integer last = (Integer) i.next();
assertEquals(last, one);
while (i.hasNext()) {
Integer k = (Integer) i.next();
assertTrue(last.compareTo(k) < 0);
last = k;
}
}
use of java.util.NavigableMap in project mapdb by jankotek.
the class TreeSubMapTest method testDescendingDescendingKeySetToArray.
/**
* descendingkeySet.toArray returns contains all keys
*/
public void testDescendingDescendingKeySetToArray() {
NavigableMap map = dmap5();
Set s = map.descendingKeySet();
Object[] ar = s.toArray();
assertEquals(5, ar.length);
assertTrue(s.containsAll(Arrays.asList(ar)));
ar[0] = m10;
assertFalse(s.containsAll(Arrays.asList(ar)));
}
use of java.util.NavigableMap in project mapdb by jankotek.
the class TreeSubMapTest method testDescendingGet_NullPointerException.
// Exception testDescendings
/**
* get(null) of nonempty map throws NPE
*/
public void testDescendingGet_NullPointerException() {
NavigableMap c = dmap5();
try {
c.get(null);
shouldThrow();
} catch (NullPointerException success) {
}
}
use of java.util.NavigableMap in project hadoop by apache.
the class TimelineEntityReader method readMetrics.
/**
* Helper method for reading and deserializing {@link TimelineMetric} objects
* using the specified column prefix. The timeline metrics then are added to
* the given timeline entity.
*
* @param entity {@link TimelineEntity} object.
* @param result {@link Result} object retrieved from backend.
* @param columnPrefix Metric column prefix
* @throws IOException if any exception is encountered while reading metrics.
*/
protected void readMetrics(TimelineEntity entity, Result result, ColumnPrefix<?> columnPrefix) throws IOException {
NavigableMap<String, NavigableMap<Long, Number>> metricsResult = columnPrefix.readResultsWithTimestamps(result, stringKeyConverter);
for (Map.Entry<String, NavigableMap<Long, Number>> metricResult : metricsResult.entrySet()) {
TimelineMetric metric = new TimelineMetric();
metric.setId(metricResult.getKey());
// Simply assume that if the value set contains more than 1 elements, the
// metric is a TIME_SERIES metric, otherwise, it's a SINGLE_VALUE metric
TimelineMetric.Type metricType = metricResult.getValue().size() > 1 ? TimelineMetric.Type.TIME_SERIES : TimelineMetric.Type.SINGLE_VALUE;
metric.setType(metricType);
metric.addValues(metricResult.getValue());
entity.addMetric(metric);
}
}
use of java.util.NavigableMap in project hadoop by apache.
the class FlowRunCoprocessor method prePut.
/*
* (non-Javadoc)
*
* This method adds the tags onto the cells in the Put. It is presumed that
* all the cells in one Put have the same set of Tags. The existing cell
* timestamp is overwritten for non-metric cells and each such cell gets a new
* unique timestamp generated by {@link TimestampGenerator}
*
* @see
* org.apache.hadoop.hbase.coprocessor.BaseRegionObserver#prePut(org.apache
* .hadoop.hbase.coprocessor.ObserverContext,
* org.apache.hadoop.hbase.client.Put,
* org.apache.hadoop.hbase.regionserver.wal.WALEdit,
* org.apache.hadoop.hbase.client.Durability)
*/
@Override
public void prePut(ObserverContext<RegionCoprocessorEnvironment> e, Put put, WALEdit edit, Durability durability) throws IOException {
Map<String, byte[]> attributes = put.getAttributesMap();
if (!isFlowRunRegion) {
return;
}
// Assumption is that all the cells in a put are the same operation.
List<Tag> tags = new ArrayList<>();
if ((attributes != null) && (attributes.size() > 0)) {
for (Map.Entry<String, byte[]> attribute : attributes.entrySet()) {
Tag t = HBaseTimelineStorageUtils.getTagFromAttribute(attribute);
tags.add(t);
}
byte[] tagByteArray = Tag.fromList(tags);
NavigableMap<byte[], List<Cell>> newFamilyMap = new TreeMap<>(Bytes.BYTES_COMPARATOR);
for (Map.Entry<byte[], List<Cell>> entry : put.getFamilyCellMap().entrySet()) {
List<Cell> newCells = new ArrayList<>(entry.getValue().size());
for (Cell cell : entry.getValue()) {
// for each cell in the put add the tags
// Assumption is that all the cells in
// one put are the same operation
// also, get a unique cell timestamp for non-metric cells
// this way we don't inadvertently overwrite cell versions
long cellTimestamp = getCellTimestamp(cell.getTimestamp(), tags);
newCells.add(CellUtil.createCell(CellUtil.cloneRow(cell), CellUtil.cloneFamily(cell), CellUtil.cloneQualifier(cell), cellTimestamp, KeyValue.Type.Put, CellUtil.cloneValue(cell), tagByteArray));
}
newFamilyMap.put(entry.getKey(), newCells);
}
// for each entry
// Update the family map for the Put
put.setFamilyCellMap(newFamilyMap);
}
}
Aggregations