use of java.util.TreeMap in project android_frameworks_base by ParanoidAndroid.
the class BackupHelperDispatcher method performBackup.
public void performBackup(ParcelFileDescriptor oldState, BackupDataOutput data, ParcelFileDescriptor newState) throws IOException {
// First, do the helpers that we've already done, since they're already in the state
// file.
int err;
Header header = new Header();
TreeMap<String, BackupHelper> helpers = (TreeMap<String, BackupHelper>) mHelpers.clone();
FileDescriptor oldStateFD = null;
FileDescriptor newStateFD = newState.getFileDescriptor();
if (oldState != null) {
oldStateFD = oldState.getFileDescriptor();
while ((err = readHeader_native(header, oldStateFD)) >= 0) {
if (err == 0) {
BackupHelper helper = helpers.get(header.keyPrefix);
Log.d(TAG, "handling existing helper '" + header.keyPrefix + "' " + helper);
if (helper != null) {
doOneBackup(oldState, data, newState, header, helper);
helpers.remove(header.keyPrefix);
} else {
skipChunk_native(oldStateFD, header.chunkSize);
}
}
}
}
// Then go through and do the rest that we haven't done.
for (Map.Entry<String, BackupHelper> entry : helpers.entrySet()) {
header.keyPrefix = entry.getKey();
Log.d(TAG, "handling new helper '" + header.keyPrefix + "'");
BackupHelper helper = entry.getValue();
doOneBackup(oldState, data, newState, header, helper);
}
}
use of java.util.TreeMap in project neo4j by neo4j.
the class TxState method getIndexUpdatesForRangeSeekByPrefix.
private ReadableDiffSets<Long> getIndexUpdatesForRangeSeekByPrefix(NewIndexDescriptor descriptor, String prefix) {
TreeMap<OrderedPropertyValues, DiffSets<Long>> sortedUpdates = getSortedIndexUpdates(descriptor.schema());
if (sortedUpdates == null) {
return null;
}
//TODO: get working with composite indexes
OrderedPropertyValues floor = OrderedPropertyValues.ofUndefined(prefix);
DiffSets<Long> diffs = new DiffSets<>();
for (Map.Entry<OrderedPropertyValues, DiffSets<Long>> entry : sortedUpdates.tailMap(floor).entrySet()) {
OrderedPropertyValues key = entry.getKey();
if (key.getSinglePropertyValue().toString().startsWith(prefix)) {
DiffSets<Long> diffSets = entry.getValue();
diffs.addAll(diffSets.getAdded().iterator());
diffs.removeAll(diffSets.getRemoved().iterator());
} else {
break;
}
}
return diffs;
}
use of java.util.TreeMap in project pinpoint by naver.
the class AgentInfoServiceImpl method getApplicationAgentList.
@Override
public ApplicationAgentList getApplicationAgentList(ApplicationAgentList.Key applicationAgentListKey, String applicationName, long timestamp) {
if (applicationName == null) {
throw new NullPointerException("applicationName must not be null");
}
if (applicationAgentListKey == null) {
throw new NullPointerException("applicationAgentListKey must not be null");
}
final List<String> agentIdList = this.applicationIndexDao.selectAgentIds(applicationName);
if (logger.isDebugEnabled()) {
logger.debug("agentIdList={}", agentIdList);
}
if (CollectionUtils.isEmpty(agentIdList)) {
logger.debug("agentIdList is empty. applicationName={}", applicationName);
return new ApplicationAgentList(new TreeMap<String, List<AgentInfo>>());
}
// key = hostname
// value= list fo agentinfo
SortedMap<String, List<AgentInfo>> result = new TreeMap<>();
List<AgentInfo> agentInfos = this.agentInfoDao.getAgentInfos(agentIdList, timestamp);
this.agentLifeCycleDao.populateAgentStatuses(agentInfos, timestamp);
for (AgentInfo agentInfo : agentInfos) {
if (agentInfo != null) {
String hostname = applicationAgentListKey.getKey(agentInfo);
if (result.containsKey(hostname)) {
result.get(hostname).add(agentInfo);
} else {
List<AgentInfo> list = new ArrayList<>();
list.add(agentInfo);
result.put(hostname, list);
}
}
}
for (List<AgentInfo> agentInfoList : result.values()) {
Collections.sort(agentInfoList, AgentInfo.AGENT_NAME_ASC_COMPARATOR);
}
logger.info("getApplicationAgentList={}", result);
return new ApplicationAgentList(result);
}
use of java.util.TreeMap in project neo4j by neo4j.
the class GBPTreeIT method shouldStayCorrectAfterRandomModifications.
@Test
public void shouldStayCorrectAfterRandomModifications() throws Exception {
// GIVEN
GBPTree<MutableLong, MutableLong> index = createIndex(256);
Comparator<MutableLong> keyComparator = layout;
Map<MutableLong, MutableLong> data = new TreeMap<>(keyComparator);
int count = 100;
int totalNumberOfRounds = 10;
for (int i = 0; i < count; i++) {
data.put(randomKey(random.random()), randomKey(random.random()));
}
// WHEN
try (Writer<MutableLong, MutableLong> writer = index.writer()) {
for (Map.Entry<MutableLong, MutableLong> entry : data.entrySet()) {
writer.put(entry.getKey(), entry.getValue());
}
}
for (int round = 0; round < totalNumberOfRounds; round++) {
// THEN
for (int i = 0; i < count; i++) {
MutableLong first = randomKey(random.random());
MutableLong second = randomKey(random.random());
MutableLong from, to;
if (first.longValue() < second.longValue()) {
from = first;
to = second;
} else {
from = second;
to = first;
}
Map<MutableLong, MutableLong> expectedHits = expectedHits(data, from, to, keyComparator);
try (RawCursor<Hit<MutableLong, MutableLong>, IOException> result = index.seek(from, to)) {
while (result.next()) {
MutableLong key = result.get().key();
if (expectedHits.remove(key) == null) {
fail("Unexpected hit " + key + " when searching for " + from + " - " + to);
}
assertTrue(keyComparator.compare(key, from) >= 0);
assertTrue(keyComparator.compare(key, to) < 0);
}
if (!expectedHits.isEmpty()) {
fail("There were results which were expected to be returned, but weren't:" + expectedHits + " when searching range " + from + " - " + to);
}
}
}
index.checkpoint(IOLimiter.unlimited());
randomlyModifyIndex(index, data, random.random(), (double) round / totalNumberOfRounds);
}
}
use of java.util.TreeMap in project druid by druid-io.
the class DatasourcesResourceTest method testGetSegmentDataSourceSpecificInterval.
@Test
public void testGetSegmentDataSourceSpecificInterval() {
server = new DruidServer("who", "host", 1234, "historical", "tier1", 0);
server.addDataSegment(dataSegmentList.get(0).getIdentifier(), dataSegmentList.get(0));
server.addDataSegment(dataSegmentList.get(1).getIdentifier(), dataSegmentList.get(1));
server.addDataSegment(dataSegmentList.get(2).getIdentifier(), dataSegmentList.get(2));
EasyMock.expect(inventoryView.getInventory()).andReturn(ImmutableList.of(server)).atLeastOnce();
EasyMock.replay(inventoryView);
DatasourcesResource datasourcesResource = new DatasourcesResource(inventoryView, null, null, new AuthConfig());
Response response = datasourcesResource.getSegmentDataSourceSpecificInterval("invalidDataSource", "2010-01-01/P1D", null, null);
Assert.assertEquals(null, response.getEntity());
response = datasourcesResource.getSegmentDataSourceSpecificInterval("datasource1", "2010-03-01/P1D", null, null);
// interval not present in the datasource
Assert.assertEquals(ImmutableSet.of(), response.getEntity());
response = datasourcesResource.getSegmentDataSourceSpecificInterval("datasource1", "2010-01-01/P1D", null, null);
Assert.assertEquals(ImmutableSet.of(dataSegmentList.get(0).getIdentifier()), response.getEntity());
response = datasourcesResource.getSegmentDataSourceSpecificInterval("datasource1", "2010-01-01/P1M", null, null);
Assert.assertEquals(ImmutableSet.of(dataSegmentList.get(1).getIdentifier(), dataSegmentList.get(0).getIdentifier()), response.getEntity());
response = datasourcesResource.getSegmentDataSourceSpecificInterval("datasource1", "2010-01-01/P1M", "simple", null);
HashMap<Interval, Map<String, Object>> results = ((HashMap<Interval, Map<String, Object>>) response.getEntity());
Assert.assertEquals(2, results.size());
int i;
for (i = 0; i < 2; i++) {
Assert.assertTrue(results.containsKey(dataSegmentList.get(i).getInterval()));
Assert.assertEquals(1, (results.get(dataSegmentList.get(i).getInterval())).get("count"));
}
response = datasourcesResource.getSegmentDataSourceSpecificInterval("datasource1", "2010-01-01/P1M", null, "full");
TreeMap<Interval, Map<String, Object>> results1 = ((TreeMap<Interval, Map<String, Object>>) response.getEntity());
i = 1;
for (Map.Entry<Interval, Map<String, Object>> entry : results1.entrySet()) {
Assert.assertEquals(dataSegmentList.get(i).getInterval(), entry.getKey());
Assert.assertEquals(dataSegmentList.get(i), ((Map<String, Object>) entry.getValue().get(dataSegmentList.get(i).getIdentifier())).get("metadata"));
i--;
}
EasyMock.verify(inventoryView);
}
Aggregations