Search in sources :

Example 66 with SortedMap

use of java.util.SortedMap in project geode by apache.

the class RangeIndex method addValuesToResult.

/**
   * 
   * @param entriesMap SortedMap object containing the indexed key as the key & the value being
   *        RegionEntryToValues Map object containing the indexed results
   * @param result Index Results holder Collection used for fetching the index results
   * @param keysToRemove Set containing the index keys for which index results should not be taken
   *        from the entriesMap
   */
private void addValuesToResult(Object entriesMap, Collection result, Set keysToRemove, int limit, ExecutionContext context) {
    if (entriesMap == null || result == null)
        return;
    QueryObserver observer = QueryObserverHolder.getInstance();
    if (verifyLimit(result, limit)) {
        observer.limitAppliedAtIndexLevel(this, limit, result);
        return;
    }
    if (entriesMap instanceof SortedMap) {
        if (((Map) entriesMap).isEmpty()) {
            // bug#40514
            return;
        }
        SortedMap sortedMap = (SortedMap) entriesMap;
        Iterator entriesIter = sortedMap.entrySet().iterator();
        Map.Entry entry = null;
        while (entriesIter.hasNext()) {
            entry = (Map.Entry) entriesIter.next();
            Object key = entry.getKey();
            if (keysToRemove == null || !keysToRemove.remove(key)) {
                RegionEntryToValuesMap rvMap = (RegionEntryToValuesMap) entry.getValue();
                rvMap.addValuesToCollection(result, limit, context);
                if (verifyLimit(result, limit)) {
                    observer.limitAppliedAtIndexLevel(this, limit, result);
                    return;
                }
            }
        }
    } else if (entriesMap instanceof RegionEntryToValuesMap) {
        // We have already been passed the collection to add, assuming keys to remove is null or
        // already been applied
        RegionEntryToValuesMap rvMap = (RegionEntryToValuesMap) entriesMap;
        rvMap.addValuesToCollection(result, limit, context);
        if (limit != -1 && result.size() == limit) {
            observer.limitAppliedAtIndexLevel(this, limit, result);
            return;
        }
    } else {
        throw new RuntimeException(LocalizedStrings.RangeIndex_PROBLEM_IN_INDEX_QUERY.toLocalizedString());
    }
}
Also used : QueryObserver(org.apache.geode.cache.query.internal.QueryObserver) SortedMap(java.util.SortedMap) CloseableIterator(org.apache.geode.internal.cache.persistence.query.CloseableIterator) RuntimeIterator(org.apache.geode.cache.query.internal.RuntimeIterator) Iterator(java.util.Iterator) Object2ObjectOpenHashMap(it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap) Map(java.util.Map) ConcurrentNavigableMap(java.util.concurrent.ConcurrentNavigableMap) NavigableMap(java.util.NavigableMap) ConcurrentSkipListMap(java.util.concurrent.ConcurrentSkipListMap) SortedMap(java.util.SortedMap)

Example 67 with SortedMap

use of java.util.SortedMap in project geode by apache.

the class RangeIndex method addValuesToResult.

private void addValuesToResult(Object entriesMap, Collection result, Object keyToRemove, CompiledValue iterOps, RuntimeIterator runtimeItr, ExecutionContext context, List projAttrib, SelectResults intermediateResults, boolean isIntersection, int limit) throws FunctionDomainException, TypeMismatchException, NameResolutionException, QueryInvocationTargetException {
    boolean limitApplied = false;
    if (entriesMap == null || result == null) {
        if (verifyLimit(result, limit)) {
            QueryObserver observer = QueryObserverHolder.getInstance();
            if (observer != null) {
                observer.limitAppliedAtIndexLevel(this, limit, result);
            }
        }
        return;
    }
    QueryObserver observer = QueryObserverHolder.getInstance();
    if (entriesMap instanceof SortedMap) {
        Iterator entriesIter = ((Map) entriesMap).entrySet().iterator();
        Map.Entry entry = null;
        boolean foundKeyToRemove = false;
        // null maps
        if (keyToRemove == null) {
            foundKeyToRemove = true;
        }
        while (entriesIter.hasNext()) {
            entry = (Map.Entry) entriesIter.next();
            // Object key = entry.getKey();
            if (foundKeyToRemove || !keyToRemove.equals(entry.getKey())) {
                RegionEntryToValuesMap rvMap = (RegionEntryToValuesMap) entry.getValue();
                rvMap.addValuesToCollection(result, iterOps, runtimeItr, context, projAttrib, intermediateResults, isIntersection, limit);
                if (verifyLimit(result, limit)) {
                    observer.limitAppliedAtIndexLevel(this, limit, result);
                    break;
                }
            } else {
                foundKeyToRemove = true;
            }
        }
    } else if (entriesMap instanceof RegionEntryToValuesMap) {
        RegionEntryToValuesMap rvMap = (RegionEntryToValuesMap) entriesMap;
        rvMap.addValuesToCollection(result, iterOps, runtimeItr, context, projAttrib, intermediateResults, isIntersection, limit);
    } else {
        throw new RuntimeException(LocalizedStrings.RangeIndex_PROBLEM_IN_INDEX_QUERY.toLocalizedString());
    }
}
Also used : QueryObserver(org.apache.geode.cache.query.internal.QueryObserver) SortedMap(java.util.SortedMap) CloseableIterator(org.apache.geode.internal.cache.persistence.query.CloseableIterator) RuntimeIterator(org.apache.geode.cache.query.internal.RuntimeIterator) Iterator(java.util.Iterator) Object2ObjectOpenHashMap(it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap) Map(java.util.Map) ConcurrentNavigableMap(java.util.concurrent.ConcurrentNavigableMap) NavigableMap(java.util.NavigableMap) ConcurrentSkipListMap(java.util.concurrent.ConcurrentSkipListMap) SortedMap(java.util.SortedMap)

Example 68 with SortedMap

use of java.util.SortedMap in project ceylon-compiler by ceylon.

the class ClassDoc method loadInheritedMembers.

private void loadInheritedMembers(MemberSpecification specification, List<TypeDeclaration> superClassOrInterfaceList, Map<MemberSpecification, Map<TypeDeclaration, SortedMap<String, Declaration>>> superClassOrInterfaceInheritedMemebers) {
    LinkedHashMap<TypeDeclaration, SortedMap<String, Declaration>> inheritedMembersMap = new LinkedHashMap<TypeDeclaration, SortedMap<String, Declaration>>();
    for (TypeDeclaration superClassOrInterface : superClassOrInterfaceList) {
        SortedMap<String, Declaration> inheritedMembers = new TreeMap<String, Declaration>();
        for (Declaration member : superClassOrInterface.getMembers()) {
            if (specification.isSatisfiedBy(member) && tool.shouldInclude(member)) {
                inheritedMembers.put(Util.getDeclarationName(member), member);
                for (String alias : member.getAliases()) {
                    inheritedMembers.put(alias, member);
                }
            }
        }
        if (!inheritedMembers.isEmpty()) {
            inheritedMembersMap.put(superClassOrInterface, inheritedMembers);
        }
    }
    superClassOrInterfaceInheritedMemebers.put(specification, inheritedMembersMap);
}
Also used : SortedMap(java.util.SortedMap) TypedDeclaration(com.redhat.ceylon.model.typechecker.model.TypedDeclaration) Declaration(com.redhat.ceylon.model.typechecker.model.Declaration) TypeDeclaration(com.redhat.ceylon.model.typechecker.model.TypeDeclaration) TreeMap(java.util.TreeMap) TypeDeclaration(com.redhat.ceylon.model.typechecker.model.TypeDeclaration) LinkedHashMap(java.util.LinkedHashMap)

Example 69 with SortedMap

use of java.util.SortedMap in project ceylon-compiler by ceylon.

the class CeylonP2Tool method printUnitFeature.

private void printUnitFeature(XMLStreamWriter writer, Feature feature, boolean group) throws XMLStreamException {
    writer.writeStartElement("unit");
    String name = feature.name + (group ? ".feature.group" : ".feature.jar");
    writer.writeAttribute("id", name);
    writer.writeAttribute("version", feature.version);
    if (group) {
        writer.writeAttribute("singleton", "false");
        {
            writer.writeEmptyElement("update");
            writer.writeAttribute("id", name);
            writer.writeAttribute("range", "[0.0.0," + feature.version + ")");
            writer.writeAttribute("severity", "0");
        }
    }
    {
        writer.writeStartElement("properties");
        SortedMap<String, String> properties = feature.getProperties();
        writer.writeAttribute("size", String.valueOf(properties.size() + (group ? 1 : 0)));
        for (Map.Entry<String, String> property : properties.entrySet()) {
            writer.writeEmptyElement("property");
            writer.writeAttribute("name", property.getKey());
            writer.writeAttribute("value", property.getValue());
        }
        if (group) {
            writer.writeEmptyElement("property");
            writer.writeAttribute("name", "org.eclipse.equinox.p2.type.group");
            writer.writeAttribute("value", "true");
        }
        writer.writeEndElement();
    }
    {
        writer.writeStartElement("provides");
        writer.writeAttribute("size", group ? "1" : "3");
        {
            writer.writeEmptyElement("provided");
            writer.writeAttribute("namespace", "org.eclipse.equinox.p2.iu");
            writer.writeAttribute("name", name);
            writer.writeAttribute("version", feature.version);
        }
        if (!group) {
            {
                writer.writeEmptyElement("provided");
                writer.writeAttribute("namespace", "org.eclipse.equinox.p2.eclipse.type");
                writer.writeAttribute("name", "feature");
                writer.writeAttribute("version", "1.0.0");
            }
            {
                writer.writeEmptyElement("provided");
                writer.writeAttribute("namespace", "org.eclipse.update.feature");
                writer.writeAttribute("name", feature.name);
                writer.writeAttribute("version", feature.version);
            }
        }
        writer.writeEndElement();
    }
    if (group) {
        writer.writeStartElement("requires");
        List<ModuleSpec> importedModules = feature.getImportedModules();
        writer.writeAttribute("size", String.valueOf(importedModules.size() + 1));
        for (ModuleSpec mod : importedModules) {
            writer.writeEmptyElement("required");
            writer.writeAttribute("namespace", "org.eclipse.equinox.p2.iu");
            writer.writeAttribute("name", mod.getName());
            writer.writeAttribute("range", "[" + mod.getVersion() + "," + mod.getVersion() + "]");
        }
        {
            writer.writeStartElement("required");
            writer.writeAttribute("namespace", "org.eclipse.equinox.p2.iu");
            writer.writeAttribute("name", feature.name + ".feature.jar");
            writer.writeAttribute("range", "[" + feature.version + "," + feature.version + "]");
            {
                writer.writeStartElement("filter");
                writer.writeCharacters("(org.eclipse.update.install.features=true)");
                writer.writeEndElement();
            }
            writer.writeEndElement();
        }
        writer.writeEndElement();
    } else {
        writer.writeStartElement("filter");
        writer.writeCharacters("(org.eclipse.update.install.features=true)");
        writer.writeEndElement();
        {
            writer.writeStartElement("artifacts");
            writer.writeAttribute("size", "1");
            {
                writer.writeEmptyElement("artifact");
                writer.writeAttribute("classifier", "org.eclipse.update.feature");
                writer.writeAttribute("id", feature.name);
                writer.writeAttribute("version", feature.version);
            }
            writer.writeEndElement();
        }
    }
    {
        writer.writeEmptyElement("touchpoint");
        writer.writeAttribute("id", group ? "null" : "org.eclipse.equinox.p2.osgi");
        writer.writeAttribute("version", group ? "0.0.0" : "1.0.0");
    }
    if (!group) {
        writer.writeStartElement("touchpointData");
        writer.writeAttribute("size", "1");
        {
            writer.writeStartElement("instructions");
            writer.writeAttribute("size", "1");
            {
                writer.writeStartElement("instruction");
                writer.writeAttribute("key", "zipped");
                writer.writeCharacters("true");
                writer.writeEndElement();
            }
            writer.writeEndElement();
        }
        writer.writeEndElement();
    }
    {
        writer.writeStartElement("licenses");
        writer.writeAttribute("size", "1");
        {
            writer.writeStartElement("license");
            writer.writeAttribute("uri", "");
            writer.writeAttribute("url", "");
            writer.writeCharacters(feature.getLicense());
            writer.writeEndElement();
        }
        writer.writeEndElement();
    }
    {
        writer.writeStartElement("copyright");
        writer.writeCharacters(feature.getCopyright());
        writer.writeEndElement();
    }
    writer.writeEndElement();
}
Also used : Entry(java.util.Map.Entry) ModuleSpec(com.redhat.ceylon.common.tools.ModuleSpec) SortedMap(java.util.SortedMap)

Example 70 with SortedMap

use of java.util.SortedMap in project cdap by caskdata.

the class MetricsTableOnTable method putBytes.

@Override
public void putBytes(SortedMap<byte[], ? extends SortedMap<byte[], byte[]>> updates) {
    for (Map.Entry<byte[], ? extends SortedMap<byte[], byte[]>> rowUpdate : updates.entrySet()) {
        Put put = new Put(rowUpdate.getKey());
        for (Map.Entry<byte[], byte[]> columnUpdate : rowUpdate.getValue().entrySet()) {
            put.add(columnUpdate.getKey(), columnUpdate.getValue());
        }
        table.put(put);
    }
}
Also used : Map(java.util.Map) NavigableMap(java.util.NavigableMap) SortedMap(java.util.SortedMap) Put(co.cask.cdap.api.dataset.table.Put)

Aggregations

SortedMap (java.util.SortedMap)228 Map (java.util.Map)174 TreeMap (java.util.TreeMap)115 HashMap (java.util.HashMap)66 NavigableMap (java.util.NavigableMap)33 ArrayList (java.util.ArrayList)31 Iterator (java.util.Iterator)31 Test (org.junit.Test)25 ImmutableMap (com.google.common.collect.ImmutableMap)21 IOException (java.io.IOException)20 List (java.util.List)17 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)17 JASIExpr (org.matheclipse.core.convert.JASIExpr)16 IExpr (org.matheclipse.core.interfaces.IExpr)16 ImmutableSortedMap (com.google.common.collect.ImmutableSortedMap)14 File (java.io.File)14 Entry (java.util.Map.Entry)13 ConcurrentMap (java.util.concurrent.ConcurrentMap)12 ConcurrentNavigableMap (java.util.concurrent.ConcurrentNavigableMap)12 LinkedHashMap (java.util.LinkedHashMap)11