Search in sources :

Example 46 with SortedSet

use of java.util.SortedSet in project lucene-solr by apache.

the class LastFieldValueUpdateProcessorFactory method pickSubset.

@Override
public Collection<Object> pickSubset(Collection<Object> values) {
    Object result = null;
    if (values instanceof List) {
        // optimize index lookup
        List l = (List) values;
        result = l.get(l.size() - 1);
    } else if (values instanceof SortedSet) {
        // optimize tail lookup
        result = ((SortedSet) values).last();
    } else {
        // trust the iterator
        for (Object o : values) {
            result = o;
        }
    }
    return Collections.singletonList(result);
}
Also used : List(java.util.List) SortedSet(java.util.SortedSet)

Example 47 with SortedSet

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

the class InternalDistributedSystem method canonicalizeLocators.

/**
   * Canonicalizes a locators string so that they may be compared.
   * 
   * @since GemFire 4.0
   */
private static String canonicalizeLocators(String locators) {
    SortedSet sorted = new TreeSet();
    StringTokenizer st = new StringTokenizer(locators, ",");
    while (st.hasMoreTokens()) {
        String l = st.nextToken();
        StringBuilder canonical = new StringBuilder();
        DistributionLocatorId locId = new DistributionLocatorId(l);
        String addr = locId.getBindAddress();
        if (addr != null && addr.trim().length() > 0) {
            canonical.append(addr);
        } else {
            canonical.append(locId.getHost().getHostAddress());
        }
        canonical.append("[");
        canonical.append(String.valueOf(locId.getPort()));
        canonical.append("]");
        sorted.add(canonical.toString());
    }
    StringBuilder sb = new StringBuilder();
    for (Iterator iter = sorted.iterator(); iter.hasNext(); ) {
        sb.append((String) iter.next());
        if (iter.hasNext()) {
            sb.append(",");
        }
    }
    return sb.toString();
}
Also used : StringTokenizer(java.util.StringTokenizer) DistributionLocatorId(org.apache.geode.internal.admin.remote.DistributionLocatorId) TreeSet(java.util.TreeSet) Iterator(java.util.Iterator) SortedSet(java.util.SortedSet)

Example 48 with SortedSet

use of java.util.SortedSet in project robovm by robovm.

the class CollectionsTest method test_unmodifiableSortedSetLjava_util_SortedSet.

/**
     * java.util.Collections#unmodifiableSortedSet(java.util.SortedSet)
     */
public void test_unmodifiableSortedSetLjava_util_SortedSet() {
    // Test for method java.util.SortedSet
    // java.util.Collections.unmodifiableSortedSet(java.util.SortedSet)
    boolean exception = false;
    SortedSet ss = new TreeSet();
    ss.addAll(s);
    SortedSet c = Collections.unmodifiableSortedSet(ss);
    assertTrue("Returned set is of incorrect size", c.size() == ss.size());
    Iterator i = ll.iterator();
    while (i.hasNext()) assertTrue("Returned set missing elements", c.contains(i.next()));
    try {
        c.add(new Object());
    } catch (UnsupportedOperationException e) {
        exception = true;
    // Correct
    }
    if (!exception) {
        fail("Allowed modification of set");
    }
    try {
        c.remove(new Object());
    } catch (UnsupportedOperationException e) {
        // Correct
        return;
    }
    fail("Allowed modification of set");
}
Also used : TreeSet(java.util.TreeSet) ListIterator(java.util.ListIterator) Iterator(java.util.Iterator) SortedSet(java.util.SortedSet)

Example 49 with SortedSet

use of java.util.SortedSet in project redisson by redisson.

the class RedissonLiveObjectService method detach.

@SuppressWarnings("unchecked")
private <T> T detach(T attachedObject, Map<String, Object> alreadyDetached) {
    validateAttached(attachedObject);
    try {
        T detached = instantiateDetachedObject((Class<T>) attachedObject.getClass().getSuperclass(), asLiveObject(attachedObject).getLiveObjectId());
        BeanCopy.beans(attachedObject, detached).declared(true, true).copy();
        alreadyDetached.put(getMap(attachedObject).getName(), detached);
        for (Entry<String, Object> obj : getMap(attachedObject).entrySet()) {
            if (!checkCascade(attachedObject, RCascadeType.DETACH, obj.getKey())) {
                continue;
            }
            if (obj.getValue() instanceof RSortedSet) {
                SortedSet<Object> redissonSet = (SortedSet<Object>) obj.getValue();
                Set<Object> set = new TreeSet<Object>(redissonSet.comparator());
                for (Object object : redissonSet) {
                    if (isLiveObject(object)) {
                        Object detachedObject = alreadyDetached.get(getMap(object).getName());
                        if (detachedObject == null) {
                            detachedObject = detach(object, alreadyDetached);
                        }
                        object = detachedObject;
                    }
                    set.add(object);
                }
                ClassUtils.setField(detached, obj.getKey(), set);
            } else if (obj.getValue() instanceof RDeque) {
                Collection<Object> redissonDeque = (Collection<Object>) obj.getValue();
                Deque<Object> deque = new LinkedList<Object>();
                for (Object object : redissonDeque) {
                    if (isLiveObject(object)) {
                        Object detachedObject = alreadyDetached.get(getMap(object).getName());
                        if (detachedObject == null) {
                            detachedObject = detach(object, alreadyDetached);
                        }
                        object = detachedObject;
                    }
                    deque.add(object);
                }
                ClassUtils.setField(detached, obj.getKey(), deque);
            } else if (obj.getValue() instanceof RQueue) {
                Collection<Object> redissonQueue = (Collection<Object>) obj.getValue();
                Queue<Object> queue = new LinkedList<Object>();
                for (Object object : redissonQueue) {
                    if (isLiveObject(object)) {
                        Object detachedObject = alreadyDetached.get(getMap(object).getName());
                        if (detachedObject == null) {
                            detachedObject = detach(object, alreadyDetached);
                        }
                        object = detachedObject;
                    }
                    queue.add(object);
                }
                ClassUtils.setField(detached, obj.getKey(), queue);
            } else if (obj.getValue() instanceof RSet) {
                Set<Object> set = new HashSet<Object>();
                Collection<Object> redissonSet = (Collection<Object>) obj.getValue();
                for (Object object : redissonSet) {
                    if (isLiveObject(object)) {
                        Object detachedObject = alreadyDetached.get(getMap(object).getName());
                        if (detachedObject == null) {
                            detachedObject = detach(object, alreadyDetached);
                        }
                        object = detachedObject;
                    }
                    set.add(object);
                }
                ClassUtils.setField(detached, obj.getKey(), set);
            } else if (obj.getValue() instanceof RList) {
                List<Object> list = new ArrayList<Object>();
                Collection<Object> redissonList = (Collection<Object>) obj.getValue();
                for (Object object : redissonList) {
                    if (isLiveObject(object)) {
                        Object detachedObject = alreadyDetached.get(getMap(object).getName());
                        if (detachedObject == null) {
                            detachedObject = detach(object, alreadyDetached);
                        }
                        object = detachedObject;
                    }
                    list.add(object);
                }
                ClassUtils.setField(detached, obj.getKey(), list);
            } else if (isLiveObject(obj.getValue())) {
                Object detachedObject = alreadyDetached.get(getMap(obj.getValue()).getName());
                if (detachedObject == null) {
                    detachedObject = detach(obj.getValue(), alreadyDetached);
                }
                ClassUtils.setField(detached, obj.getKey(), detachedObject);
            } else if (obj.getValue() instanceof RMap) {
                Map<Object, Object> map = new LinkedHashMap<Object, Object>();
                Map<Object, Object> redissonMap = (Map<Object, Object>) obj.getValue();
                for (Entry<Object, Object> entry : redissonMap.entrySet()) {
                    Object key = entry.getKey();
                    Object value = entry.getValue();
                    if (isLiveObject(key)) {
                        Object detachedObject = alreadyDetached.get(getMap(key).getName());
                        if (detachedObject == null) {
                            detachedObject = detach(key, alreadyDetached);
                        }
                        key = detachedObject;
                    }
                    if (isLiveObject(value)) {
                        Object detachedObject = alreadyDetached.get(getMap(value).getName());
                        if (detachedObject == null) {
                            detachedObject = detach(value, alreadyDetached);
                        }
                        value = detachedObject;
                    }
                    map.put(key, value);
                }
                ClassUtils.setField(detached, obj.getKey(), map);
            } else {
                validateAnnotation(detached, obj.getKey());
            }
        }
        return detached;
    } catch (Exception ex) {
        throw ex instanceof RuntimeException ? (RuntimeException) ex : new RuntimeException(ex);
    }
}
Also used : SortedSet(java.util.SortedSet) Set(java.util.Set) RSortedSet(org.redisson.api.RSortedSet) RSet(org.redisson.api.RSet) TreeSet(java.util.TreeSet) HashSet(java.util.HashSet) RQueue(org.redisson.api.RQueue) ArrayList(java.util.ArrayList) RMap(org.redisson.api.RMap) SortedSet(java.util.SortedSet) RSortedSet(org.redisson.api.RSortedSet) LinkedHashMap(java.util.LinkedHashMap) TreeSet(java.util.TreeSet) RSet(org.redisson.api.RSet) Deque(java.util.Deque) RDeque(org.redisson.api.RDeque) LinkedList(java.util.LinkedList) RDeque(org.redisson.api.RDeque) RList(org.redisson.api.RList) Collection(java.util.Collection) RObject(org.redisson.api.RObject) RLiveObject(org.redisson.api.RLiveObject) RSortedSet(org.redisson.api.RSortedSet) Map(java.util.Map) HashMap(java.util.HashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) LinkedHashMap(java.util.LinkedHashMap) RMap(org.redisson.api.RMap)

Example 50 with SortedSet

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

the class SourceWriter method setLineMap.

private void setLineMap(Code_attribute attr) {
    SortedMap<Integer, SortedSet<Integer>> map = new TreeMap<Integer, SortedSet<Integer>>();
    SortedSet<Integer> allLines = new TreeSet<Integer>();
    for (Attribute a : attr.attributes) {
        if (a instanceof LineNumberTable_attribute) {
            LineNumberTable_attribute t = (LineNumberTable_attribute) a;
            for (LineNumberTable_attribute.Entry e : t.line_number_table) {
                int start_pc = e.start_pc;
                int line = e.line_number;
                SortedSet<Integer> pcLines = map.get(start_pc);
                if (pcLines == null) {
                    pcLines = new TreeSet<Integer>();
                    map.put(start_pc, pcLines);
                }
                pcLines.add(line);
                allLines.add(line);
            }
        }
    }
    lineMap = map;
    lineList = new ArrayList<Integer>(allLines);
}
Also used : Attribute(com.sun.tools.classfile.Attribute) TreeSet(java.util.TreeSet) TreeMap(java.util.TreeMap) SortedSet(java.util.SortedSet) LineNumberTable_attribute(com.sun.tools.classfile.LineNumberTable_attribute)

Aggregations

SortedSet (java.util.SortedSet)127 TreeSet (java.util.TreeSet)49 Iterator (java.util.Iterator)43 HashMap (java.util.HashMap)24 NavigableSet (java.util.NavigableSet)22 ArrayList (java.util.ArrayList)20 Map (java.util.Map)20 List (java.util.List)19 Set (java.util.Set)19 TreeMap (java.util.TreeMap)18 HashSet (java.util.HashSet)15 Test (org.junit.Test)13 IOException (java.io.IOException)12 Collection (java.util.Collection)10 Comparator (java.util.Comparator)7 LinkedHashMap (java.util.LinkedHashMap)7 LinkedList (java.util.LinkedList)5 SolverException (cbit.vcell.solver.SolverException)3 TestStringSortedSetGenerator (com.google.common.collect.testing.TestStringSortedSetGenerator)3 File (java.io.File)3