PRIVATE CLASSES /*
The set class is backed by a binary tree (treap) structure. Therefore,
it can be traversed more efficiently using a custom iterator. This class implements a tree iterator.
169095
function TreeIterator(tree) {

    // the tree, current slot index, and previous and next pointers are private attributes
    // so methods that use them are defined in the constructor
    var currentSlot = 0;  // the slot before the first item
    var previous = undefined;
    var next = minimum(tree.root);

    this.toStart = function() {
        currentSlot = 0;  // the slot before the first item
        previous = undefined;
        next = minimum(tree.root);
    };

    this.toSlot = function(slot) {
        currentSlot = slot;
        previous = tree.node(slot - 1);  // javascript index of item before the slot
        next = successor(previous);
    };

    this.toEnd = function() {
        currentSlot = tree.size;  // the slot after the last item
        previous = maximum(tree.root);
        next = undefined;
    };

    this.hasPrevious = function() {
        return currentSlot > 0;
    };

    this.hasNext = function() {
        return currentSlot < tree.size;
    };

    this.getPrevious = function() {
        if (!this.hasPrevious()) return;
        const value = previous.value;
        next = previous;
        previous = predecessor(next);
        currentSlot--;
        return value;
    };

    this.getNext = function() {
        if (!this.hasNext()) return;
        const value = next.value;
        previous = next;
        next = successor(previous);
        currentSlot++;
        return value;
    };

    return this;
}
1033467
public synchronized Set<Map.Entry<Object,Object>> entrySet() {
        checkInitialized();
        if (entrySet == null) {
            if (entrySetCallCount++ == 0)  // Initial call
                entrySet = Collections.unmodifiableMap(this).entrySet();
            else
                return super.entrySet();   // Recursive call
        }

        // This exception will be thrown if the implementation of
        // Collections.unmodifiableMap.entrySet() is changed such that it
        // no longer calls entrySet() on the backing Map.  (Provider's
        // entrySet implementation depends on this "implementation detail",
        // which is unlikely to change.
        if (entrySetCallCount != 2)
            throw new RuntimeException("Internal error.");

        return entrySet;
    }
478998
function treeSet (address, tree, value) {
  if (address.length === 0) {
    return value
  } else {
    const [ k, rest ] = head(address)
    return (typeof k === 'string' ?
            { ...tree, [k]: treeSet(rest, treeGet([ k ], tree), value) } :
            [ ...tree.slice(0, k), treeSet(rest, treeGet([ k ], tree), value),
              ...tree.slice(k + 1) ])
  }
}
1184108
@Override
    public Object set(PageContext pc, Collection.Key key, Object value) throws PageException {
	if (pc == null) pc = ThreadLocalPageContext.get();
	if (triggerDataMember(pc) && isInit) {
	    if (!isPrivate(pc)) {
		return callSetter(pc, key, value);
	    }
	}
	return _set(pc, key, value);
    }
769842
@Override
    public Iterator<Tree> iterator() {
        return new Iterator<Tree>() {
            @Override
            public boolean hasNext() {
                return next != null;
            }

            @Override
            public Tree next() {
                Tree t = next.leaf;
                next = next.parent;
                return t;
            }

            @Override
            public void remove() {
                throw new UnsupportedOperationException();
            }

            private TreePath next = TreePath.this;
        };
    }
107965
private boolean setNextIterator()
    {
        boolean retval = false;
        // first, check if the activeIterator is null, and set it.
        if (m_activeIterator == null)
        {
            if (m_rsIterators.size() > 0)
            {
                m_activeIteratorIndex = 0;
                m_currentCursorPosition = 0;
                m_activeIterator = (OJBIterator) m_rsIterators.get(m_activeIteratorIndex);
            }
        }
        else if (!m_activeIterator.hasNext())
        {
            if (m_rsIterators.size() > (m_activeIteratorIndex + 1))
            {
                // we still have iterators in the collection, move to the
                // next one, increment the counter, and set the active
                // iterator.
                m_activeIteratorIndex++;
                m_currentCursorPosition = 0;
                m_activeIterator = (OJBIterator) m_rsIterators.get(m_activeIteratorIndex);
                retval = true;
            }
        }

        return retval;
    }
280783
@SuppressWarnings("unchecked")
    public <T> Set<T> getSet(String key) {
        return Reflection.toType(get(key), Set.class);
    }
1161265
public static <T> Set<T> iterableToSet(Iterable<T> iterable) {
        if (iterable == null) {
            return Collections.emptySet();
        }
        if (iterable instanceof Set) {
            return (Set<T>) iterable;
        }
        Iterator<T> i = iterable.iterator();
        if (i.hasNext()) {
            Set<T> list = new HashSet<>();
            while (i.hasNext()) {
                list.add(i.next());
            }
            return list;
        }
        return Collections.emptySet();
    }
1186653
public Set entrySet() throws ObjectManagerException {
        return new AbstractSetView() {
            public long size() {
                return size;
            }

            public boolean contains(Object object) throws ObjectManagerException {
                if (object instanceof Map.Entry) {
                    Map.Entry entry = (Map.Entry) object;
                    Object v1 = get(entry.getKey()), v2 = entry.getValue();
                    return v1 == null ? v2 == null : v1.equals(v2);
                }
                return false;
            }

            public Iterator iterator() throws ObjectManagerException {
                return makeTreeMapIterator(new AbstractMapEntry.Type() {
                    public Object get(AbstractMapEntry entry) {
                        return entry;
                    }
                });
            }
        };
    }
1073066
public static <T> Collector<T, Set<T>> toSet() {
    return new Collector<T, Set<T>>() {
      @Override
      public Set<T> collect(Stream<? extends T> stream) {
        return Sets.newHashSet(stream.iterator());
      }
    };
  }
670642
public Iterator<T> iterator() {
        List<Iterator<T>> iters = new ArrayList<Iterator<T>>(sets.size());
        for (Set<T> s : sets)
            iters.add(s.iterator());
        return new CombinedIterator<T>(iters);
    }
905274
@Override
    public Set<String> keySet() {
        Set<String> keys = new HashSet<>();
        keysR(root.getLeft(), -1, keys);
        return keys;
    }
163925
Set<Class<?>> allClasses() {
        final Set<Class<?>> allClasses = new HashSet<>(getClasses());
        for (Object singleton : getSingletons()) {
            allClasses.add(singleton.getClass());
        }
        return allClasses;
    }
363751
public static <T> Set<T> toSet(Iterator<T> iterator)
    {
        Objects.requireNonNull(iterator, "The iterator is null");
        return Iterators.toCollection(iterator, new LinkedHashSet<T>());
    }
717350
def t(root, children=None, debug=False, root_id=None):
    ""
    if isinstance(root, Tree):
        if children is None:
            return root
        return root.__class__(root, children, root_id)

    elif isinstance(root, basestring):
        root = debug_root_label(root, debug, root_id)

        # Beware: (DGParented)Tree is a subclass of list!
        if isinstance(children, Tree):
            child_trees = [children]

        elif isinstance(children, list):
            child_trees = []
            for child in children:
                if isinstance(child, Tree):
                    child_trees.append(child)
                elif isinstance(child, list):
                    child_trees.extend(child)
                elif isinstance(child, tuple):
                    child_trees.append(t(*child))
                elif isinstance(child, basestring):
                    child_trees.append(child)
                else:
                    raise NotImplementedError

        elif isinstance(children, basestring):
            # this tree does only have one child, a leaf node
            # TODO: this is a workaround for the following problem:
            # Tree('foo', [Tree('bar', [])]) != Tree('foo', ['bar'])
            child_trees = [Tree(children, [])]

        else:
            # this tree only consists of one leaf node
            assert children is None
            child_trees = []

        return DGParentedTree(root, child_trees, root_id)

    else:
        raise NotImplementedError
425651
public static <T> ImmutableSet<ImmutableSet<T>> immutablePowerSet(Set<T> set)
    {
        return powerSet(set).collect(new Function<MutableSet<T>, ImmutableSet<T>>()
        {
            public ImmutableSet<T> valueOf(MutableSet<T> set)
            {
                return set.toImmutable();
            }
        }).toImmutable();
    }
1353840
Class<?> getSetterPropertyType( Clazz<?> clazz, String name )
	{
		ClassInfoCache cache = retrieveCache( clazz );
		Class<?> res = cache.getSetterType( name );
		if( res != null )
			return res;

		String setterName = "set" + capitalizeFirstLetter( name );
		Method setter = clazz.getMethod( setterName );
		if( setter != null && setter.getParameterTypes().size() == 1 )
		{
			res = setter.getParameterTypes().get( 0 );
		}
		else
		{
			Field field = clazz.getAllField( name );
			if( field != null )
				res = field.getType();
		}

		if( res != null )
			cache.setSetterType( name, res );

		return res;
	}