Example usage for com.google.common.collect Iterables unmodifiableIterable

List of usage examples for com.google.common.collect Iterables unmodifiableIterable

Introduction

In this page you can find the example usage for com.google.common.collect Iterables unmodifiableIterable.

Prototype

@Deprecated
public static <E> Iterable<E> unmodifiableIterable(ImmutableCollection<E> iterable) 

Source Link

Document

Simply returns its argument.

Usage

From source file:fr.putnami.pwt.core.model.client.model.AbstractModel.java

@Override
public Iterable<String> getPropertyNames() {
    Set<String> propertyNames = Sets.newLinkedHashSet();
    if (this.parentModel != null) {
        propertyNames = Sets.newLinkedHashSet(this.parentModel.getPropertyNames());
    } else {/*from  ww  w  .  jav  a  2 s  .c  om*/
        propertyNames = Sets.newLinkedHashSet();
    }
    propertyNames.addAll(this.getProperties().keySet());
    return Iterables.unmodifiableIterable(propertyNames);
}

From source file:org.ow2.mind.plugin.ConfigurationElementImpl.java

public Iterable<ConfigurationElement> getChildren() {
    return Iterables.unmodifiableIterable(children);
}

From source file:com.github.jsdossier.jscomp.DossierModuleRegistry.java

public Iterable<DossierModule> getModules() {
    return Iterables.unmodifiableIterable(scriptToModule.values());
}

From source file:com.facebook.buck.graph.AcyclicDepthFirstPostOrderTraversal.java

/**
 * Performs a depth-first, post-order traversal over a DAG.
 * @param initialNodes The nodes from which to perform the traversal. Not allowed to contain
 *     {@code null}.//from w  w w. ja v  a 2 s. c  om
 * @throws CycleException if a cycle is found while performing the traversal.
 */
@SuppressWarnings("PMD.PrematureDeclaration")
public Iterable<T> traverse(Iterable<? extends T> initialNodes) throws CycleException {
    // This corresponds to the current chain of nodes being explored. Enforcing this invariant makes
    // this data structure useful for debugging.
    Deque<Explorable> toExplore = Lists.newLinkedList();
    for (T node : initialNodes) {
        toExplore.add(new Explorable(node));
    }

    Set<T> inProgress = Sets.newHashSet();
    LinkedHashSet<T> explored = Sets.newLinkedHashSet();

    while (!toExplore.isEmpty()) {
        Explorable explorable = toExplore.peek();
        T node = explorable.node;

        // This could happen if one of the initial nodes is a dependency of the other, for example.
        if (explored.contains(node)) {
            toExplore.removeFirst();
            continue;
        }

        inProgress.add(node);

        // Find children that need to be explored to add to the stack.
        int stackSize = toExplore.size();
        for (Iterator<T> iter = explorable.children; iter.hasNext();) {
            T child = iter.next();
            if (inProgress.contains(child)) {
                throw createCycleException(child, toExplore);
            } else if (!explored.contains(child)) {
                toExplore.addFirst(new Explorable(child));

                // Without this break statement:
                // (1) Children will be explored in reverse order instead of the specified order.
                // (2) CycleException may contain extra nodes.
                // Comment out the break statement and run the unit test to verify this for yourself.
                break;
            }
        }

        if (stackSize == toExplore.size()) {
            // Nothing was added to toExplore, so the current node can be popped off the stack and
            // marked as explored.
            toExplore.removeFirst();
            inProgress.remove(node);
            explored.add(node);
        }
    }

    Preconditions.checkState(inProgress.isEmpty(), "No more nodes should be in progress.");

    return Iterables.unmodifiableIterable(explored);
}

From source file:io.druid.query.groupby.epinephelinae.GroupByMergingQueryRunnerV2.java

public GroupByMergingQueryRunnerV2(GroupByQueryConfig config, ExecutorService exec, QueryWatcher queryWatcher,
        Iterable<QueryRunner<Row>> queryables, int concurrencyHint, BlockingPool<ByteBuffer> mergeBufferPool,
        ObjectMapper spillMapper) {/* w w  w . j  ava 2s  . c om*/
    this.config = config;
    this.exec = MoreExecutors.listeningDecorator(exec);
    this.queryWatcher = queryWatcher;
    this.queryables = Iterables.unmodifiableIterable(Iterables.filter(queryables, Predicates.notNull()));
    this.concurrencyHint = concurrencyHint;
    this.mergeBufferPool = mergeBufferPool;
    this.spillMapper = spillMapper;
}

From source file:com.facebook.buck.graph.AbstractAcyclicDepthFirstPostOrderTraversal.java

/**
 * Performs a depth-first, post-order traversal over a DAG.
 * @param initialNodes The nodes from which to perform the traversal. Not allowed to contain
 *     {@code null}.//from   www  .  java2 s  .  c o m
 * @throws CycleException if a cycle is found while performing the traversal.
 */
@SuppressWarnings("PMD.PrematureDeclaration")
public void traverse(Iterable<? extends T> initialNodes) throws CycleException, IOException {
    // This corresponds to the current chain of nodes being explored. Enforcing this invariant makes
    // this data structure useful for debugging.
    Deque<Explorable> toExplore = Lists.newLinkedList();
    for (T node : initialNodes) {
        toExplore.add(new Explorable(node));
    }

    Set<T> inProgress = Sets.newHashSet();
    LinkedHashSet<T> explored = Sets.newLinkedHashSet();

    while (!toExplore.isEmpty()) {
        Explorable explorable = toExplore.peek();
        T node = explorable.node;

        // This could happen if one of the initial nodes is a dependency of the other, for example.
        if (explored.contains(node)) {
            toExplore.removeFirst();
            continue;
        }

        inProgress.add(node);

        // Find children that need to be explored to add to the stack.
        int stackSize = toExplore.size();
        for (Iterator<T> iter = explorable.children; iter.hasNext();) {
            T child = iter.next();
            if (inProgress.contains(child)) {
                throw createCycleException(child, toExplore);
            } else if (!explored.contains(child)) {
                toExplore.addFirst(new Explorable(child));

                // Without this break statement:
                // (1) Children will be explored in reverse order instead of the specified order.
                // (2) CycleException may contain extra nodes.
                // Comment out the break statement and run the unit test to verify this for yourself.
                break;
            }
        }

        if (stackSize == toExplore.size()) {
            // Nothing was added to toExplore, so the current node can be popped off the stack and
            // marked as explored.
            toExplore.removeFirst();
            inProgress.remove(node);
            explored.add(node);

            // Now that the internal state of this traversal has been updated, notify the observer.
            onNodeExplored(node);
        }
    }

    Preconditions.checkState(inProgress.isEmpty(), "No more nodes should be in progress.");

    onTraversalComplete(Iterables.unmodifiableIterable(explored));
}

From source file:com.google.javascript.jscomp.XtbMessageBundle.java

@Override
public Iterable<JsMessage> getAllMessages() {
    return Iterables.unmodifiableIterable(messages.values());
}

From source file:org.opendaylight.mdsal.binding.javav2.spec.base.InstanceIdentifier.java

/**
 * Return the path argument chain which makes up this instance identifier.
 *
 * @return Path argument chain. Immutable and does not contain nulls.
 *//*from   w  w  w  .j  a  v  a  2  s  .  c o  m*/
public final Iterable<TreeArgument> getPathArguments() {
    return Iterables.unmodifiableIterable(pathArguments);
}

From source file:org.opendaylight.yangtools.yang.binding.InstanceIdentifier.java

/**
 * Return the path argument chain which makes up this instance identifier.
 *
 * @return Path argument chain. Immutable and does not contain nulls.
 *///  www.jav a2  s  .  c  o  m
public final Iterable<PathArgument> getPathArguments() {
    return Iterables.unmodifiableIterable(pathArguments);
}

From source file:org.apache.kylin.cube.model.validation.rule.AggregationGroupRule.java

private void inner(CubeDesc cube, ValidateContext context) {

    if (cube.getAggregationGroups() == null || cube.getAggregationGroups().size() == 0) {
        context.addResult(ResultLevel.ERROR, "Cube should have at least one Aggregation group.");
        return;/*from  ww w.  j a  va 2  s . c  o  m*/
    }

    int index = 0;
    for (AggregationGroup agg : cube.getAggregationGroups()) {
        if (agg.getIncludes() == null) {
            context.addResult(ResultLevel.ERROR, "Aggregation group " + index + " 'includes' field not set");
            continue;
        }

        if (agg.getSelectRule() == null) {
            context.addResult(ResultLevel.ERROR, "Aggregation group " + index + " 'select rule' field not set");
            continue;
        }

        Set<String> includeDims = new TreeSet<>(String.CASE_INSENSITIVE_ORDER);
        if (agg.getIncludes() != null) {
            for (String include : agg.getIncludes()) {
                includeDims.add(include);
            }
        }

        Set<String> mandatoryDims = new TreeSet<>(String.CASE_INSENSITIVE_ORDER);
        if (agg.getSelectRule().mandatoryDims != null) {
            for (String m : agg.getSelectRule().mandatoryDims) {
                mandatoryDims.add(m);
            }
        }

        Set<String> hierarchyDims = new TreeSet<>(String.CASE_INSENSITIVE_ORDER);
        if (agg.getSelectRule().hierarchyDims != null) {
            for (String[] ss : agg.getSelectRule().hierarchyDims) {
                for (String s : ss) {
                    hierarchyDims.add(s);
                }
            }
        }

        Set<String> jointDims = new TreeSet<>(String.CASE_INSENSITIVE_ORDER);
        if (agg.getSelectRule().jointDims != null) {
            for (String[] ss : agg.getSelectRule().jointDims) {
                for (String s : ss) {
                    jointDims.add(s);
                }
            }
        }

        if (!includeDims.containsAll(mandatoryDims) || !includeDims.containsAll(hierarchyDims)
                || !includeDims.containsAll(jointDims)) {
            List<String> notIncluded = Lists.newArrayList();
            final Iterable<String> all = Iterables
                    .unmodifiableIterable(Iterables.concat(mandatoryDims, hierarchyDims, jointDims));
            for (String dim : all) {
                if (includeDims.contains(dim) == false) {
                    notIncluded.add(dim);
                }
            }
            context.addResult(ResultLevel.ERROR, "Aggregation group " + index
                    + " 'includes' dimensions not include all the dimensions:" + notIncluded.toString());
            continue;
        }

        if (CollectionUtils.containsAny(mandatoryDims, hierarchyDims)) {
            Set<String> intersection = new HashSet<>(mandatoryDims);
            intersection.retainAll(hierarchyDims);
            context.addResult(ResultLevel.ERROR, "Aggregation group " + index
                    + " mandatory dimension has overlap with hierarchy dimension: " + intersection.toString());
            continue;
        }
        if (CollectionUtils.containsAny(mandatoryDims, jointDims)) {
            Set<String> intersection = new HashSet<>(mandatoryDims);
            intersection.retainAll(jointDims);
            context.addResult(ResultLevel.ERROR, "Aggregation group " + index
                    + " mandatory dimension has overlap with joint dimension: " + intersection.toString());
            continue;
        }

        int jointDimNum = 0;
        if (agg.getSelectRule().jointDims != null) {
            for (String[] joints : agg.getSelectRule().jointDims) {

                Set<String> oneJoint = new TreeSet<>(String.CASE_INSENSITIVE_ORDER);
                for (String s : joints) {
                    oneJoint.add(s);
                }

                if (oneJoint.size() < 2) {
                    context.addResult(ResultLevel.ERROR, "Aggregation group " + index
                            + " require at least 2 dimensions in a joint: " + oneJoint.toString());
                    continue;
                }
                jointDimNum += oneJoint.size();

                int overlapHierarchies = 0;
                if (agg.getSelectRule().hierarchyDims != null) {
                    for (String[] oneHierarchy : agg.getSelectRule().hierarchyDims) {
                        Set<String> share = new TreeSet<>(String.CASE_INSENSITIVE_ORDER);
                        share.addAll(CollectionUtils.intersection(oneJoint, Arrays.asList(oneHierarchy)));

                        if (!share.isEmpty()) {
                            overlapHierarchies++;
                        }
                        if (share.size() > 1) {
                            context.addResult(ResultLevel.ERROR, "Aggregation group " + index
                                    + " joint dimensions has overlap with more than 1 dimensions in same hierarchy: "
                                    + share.toString());
                            continue;
                        }
                    }

                    if (overlapHierarchies > 1) {
                        context.addResult(ResultLevel.ERROR, "Aggregation group " + index
                                + " joint dimensions has overlap with more than 1 hierarchies");
                        continue;
                    }
                }
            }

            if (jointDimNum != jointDims.size()) {

                Set<String> existing = new TreeSet<>(String.CASE_INSENSITIVE_ORDER);
                Set<String> overlap = new TreeSet<>(String.CASE_INSENSITIVE_ORDER);
                for (String[] joints : agg.getSelectRule().jointDims) {
                    Set<String> oneJoint = new TreeSet<>(String.CASE_INSENSITIVE_ORDER);
                    for (String s : joints) {
                        oneJoint.add(s);
                    }
                    if (CollectionUtils.containsAny(existing, oneJoint)) {
                        overlap.addAll(CollectionUtils.intersection(existing, oneJoint));
                    }
                    existing.addAll(oneJoint);
                }
                context.addResult(ResultLevel.ERROR, "Aggregation group " + index
                        + " a dimension exists in more than one joint: " + overlap.toString());
                continue;
            }
        }
        long combination = 0;
        try {
            combination = agg.calculateCuboidCombination();
        } catch (Exception ex) {
            combination = getMaxCombinations(cube) + 1;
        } finally {
            if (combination > getMaxCombinations(cube)) {
                String msg = "Aggregation group " + index
                        + " has too many combinations, current combination is " + combination
                        + ", max allowed combination is " + getMaxCombinations(cube)
                        + "; use 'mandatory'/'hierarchy'/'joint' to optimize; or update 'kylin.cube.aggrgroup.max-combination' to a bigger value.";
                context.addResult(ResultLevel.ERROR, msg);
                continue;
            }
        }

        index++;
    }
}