Search in sources :

Example 91 with TreeMap

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);
    }
}
Also used : TreeMap(java.util.TreeMap) TreeMap(java.util.TreeMap) Map(java.util.Map) ParcelFileDescriptor(android.os.ParcelFileDescriptor) FileDescriptor(java.io.FileDescriptor)

Example 92 with TreeMap

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;
}
Also used : DiffSets(org.neo4j.kernel.impl.util.diffsets.DiffSets) RelationshipDiffSets(org.neo4j.kernel.impl.util.diffsets.RelationshipDiffSets) ReadableDiffSets(org.neo4j.storageengine.api.txstate.ReadableDiffSets) ReadableRelationshipDiffSets(org.neo4j.storageengine.api.txstate.ReadableRelationshipDiffSets) OrderedPropertyValues(org.neo4j.kernel.api.schema_new.OrderedPropertyValues) Map(java.util.Map) HashMap(java.util.HashMap) TreeMap(java.util.TreeMap)

Example 93 with TreeMap

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);
}
Also used : ApplicationAgentList(com.navercorp.pinpoint.web.vo.ApplicationAgentList) ArrayList(java.util.ArrayList) ApplicationAgentList(com.navercorp.pinpoint.web.vo.ApplicationAgentList) ArrayList(java.util.ArrayList) ApplicationAgentHostList(com.navercorp.pinpoint.web.vo.ApplicationAgentHostList) List(java.util.List) AgentInfo(com.navercorp.pinpoint.web.vo.AgentInfo) TreeMap(java.util.TreeMap)

Example 94 with TreeMap

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);
    }
}
Also used : MutableLong(org.apache.commons.lang3.mutable.MutableLong) IOException(java.io.IOException) TreeMap(java.util.TreeMap) Map(java.util.Map) TreeMap(java.util.TreeMap) Test(org.junit.Test)

Example 95 with TreeMap

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);
}
Also used : Response(javax.ws.rs.core.Response) DruidServer(io.druid.client.DruidServer) AuthConfig(io.druid.server.security.AuthConfig) HashMap(java.util.HashMap) Map(java.util.Map) TreeMap(java.util.TreeMap) Interval(org.joda.time.Interval) Test(org.junit.Test)

Aggregations

TreeMap (java.util.TreeMap)4400 Map (java.util.Map)1245 ArrayList (java.util.ArrayList)930 HashMap (java.util.HashMap)871 Test (org.junit.Test)614 List (java.util.List)542 Before (org.junit.Before)505 IOException (java.io.IOException)402 HashSet (java.util.HashSet)301 Set (java.util.Set)268 File (java.io.File)267 SortedMap (java.util.SortedMap)240 TreeSet (java.util.TreeSet)213 LinkedHashMap (java.util.LinkedHashMap)196 Key (org.apache.accumulo.core.data.Key)156 Value (org.apache.accumulo.core.data.Value)156 Iterator (java.util.Iterator)149 NavigableMap (java.util.NavigableMap)124 Collection (java.util.Collection)115 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)111