Search in sources :

Example 31 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 32 with SortedSet

use of java.util.SortedSet in project hibernate-orm by hibernate.

the class PersistentSortedSet method subSet.

@Override
@SuppressWarnings("unchecked")
public SortedSet subSet(Object fromElement, Object toElement) {
    read();
    final SortedSet subSet = ((SortedSet) set).subSet(fromElement, toElement);
    return new SubSetProxy(subSet);
}
Also used : SortedSet(java.util.SortedSet)

Example 33 with SortedSet

use of java.util.SortedSet in project hibernate-orm by hibernate.

the class PersistentSortedSet method headSet.

@Override
@SuppressWarnings("unchecked")
public SortedSet headSet(Object toElement) {
    read();
    final SortedSet headSet = ((SortedSet) set).headSet(toElement);
    return new SubSetProxy(headSet);
}
Also used : SortedSet(java.util.SortedSet)

Example 34 with SortedSet

use of java.util.SortedSet in project j2objc by google.

the class TreeSetTest method test_subSetLjava_lang_ObjectLjava_lang_Object.

/**
	 * @tests java.util.TreeSet#subSet(java.lang.Object, java.lang.Object)
	 */
public void test_subSetLjava_lang_ObjectLjava_lang_Object() {
    // Test for method java.util.SortedSet
    // java.util.TreeSet.subSet(java.lang.Object, java.lang.Object)
    final int startPos = objArray.length / 4;
    final int endPos = 3 * objArray.length / 4;
    SortedSet aSubSet = ts.subSet(objArray[startPos], objArray[endPos]);
    assertTrue("Subset has wrong number of elements", aSubSet.size() == (endPos - startPos));
    for (int counter = startPos; counter < endPos; counter++) assertTrue("Subset does not contain all the elements it should", aSubSet.contains(objArray[counter]));
    int result;
    try {
        ts.subSet(objArray[3], objArray[0]);
        result = 0;
    } catch (IllegalArgumentException e) {
        result = 1;
    }
    assertEquals("end less than start should throw", 1, result);
}
Also used : SortedSet(java.util.SortedSet)

Example 35 with SortedSet

use of java.util.SortedSet in project hibernate-orm by hibernate.

the class Baz method setDefaults.

public void setDefaults() {
    SortedSet set = new TreeSet();
    set.add("foo");
    set.add("bar");
    set.add("baz");
    setStringSet(set);
    Map map = new TreeMap();
    map.put("now", new Date());
    map.put("never", null);
    map.put("big bang", new Date(0));
    setStringDateMap(map);
    List list = new ArrayList();
    list.addAll(set);
    setStringList(list);
    setIntArray(new int[] { 1, 3, 3, 7 });
    setFooArray(new Foo[0]);
    setStringArray((String[]) list.toArray(new String[0]));
    customs = new ArrayList();
    customs.add(new String[] { "foo", "bar" });
    customs.add(new String[] { "A", "B" });
    customs.add(new String[] { "1", "2" });
    fooSet = new HashSet();
    components = new FooComponent[] { new FooComponent("foo", 42, null, null), new FooComponent("bar", 88, null, new FooComponent("sub", 69, null, null)) };
    timeArray = new Date[] { new Date(), new Date(), null, new Date(0) };
    TreeSet x = new TreeSet();
    x.add("w");
    x.add("x");
    x.add("y");
    x.add("z");
    TreeSet a = new TreeSet();
    a.add("a");
    a.add("b");
    a.add("d");
    a.add("c");
    count = 667;
    name = "Bazza";
    topComponents = new ArrayList();
    topComponents.add(new FooComponent("foo", 11, new Date[] { new Date(), new Date(123) }, null));
    topComponents.add(new FooComponent("bar", 22, new Date[] { new Date(7), new Date(456) }, null));
    topComponents.add(null);
    bag = new ArrayList();
    bag.add("duplicate");
    bag.add("duplicate");
    bag.add("duplicate");
    bag.add("unique");
    cached = new TreeSet();
    CompositeElement ce = new CompositeElement();
    ce.setFoo("foo");
    ce.setBar("bar");
    CompositeElement ce2 = new CompositeElement();
    ce2.setFoo("fooxxx");
    ce2.setBar("barxxx");
    cached.add(ce);
    cached.add(ce2);
    cachedMap = new TreeMap();
    cachedMap.put(this, ce);
    text = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
    for (int i = 0; i < 10; i++) text += text;
}
Also used : TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) TreeMap(java.util.TreeMap) SortedSet(java.util.SortedSet) TreeMap(java.util.TreeMap) Map(java.util.Map) Date(java.util.Date) HashSet(java.util.HashSet)

Aggregations

SortedSet (java.util.SortedSet)377 TreeSet (java.util.TreeSet)174 Iterator (java.util.Iterator)116 HashMap (java.util.HashMap)94 Map (java.util.Map)94 Set (java.util.Set)90 ArrayList (java.util.ArrayList)78 List (java.util.List)78 TreeMap (java.util.TreeMap)61 HashSet (java.util.HashSet)60 IOException (java.io.IOException)58 NavigableSet (java.util.NavigableSet)56 Test (org.junit.Test)50 Collectors (java.util.stream.Collectors)35 Collections (java.util.Collections)34 SortedMap (java.util.SortedMap)31 ImmutableSortedSet (com.google.common.collect.ImmutableSortedSet)30 Comparator (java.util.Comparator)30 File (java.io.File)28 Collection (java.util.Collection)28