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:io.druid.query.aggregation.atomcube.AtomCubeQueryRunner.java

private ListenableFuture<List<ImmutableBitmap>> prepareFutures(final AtomCubeQuery atomQ) {
    final Map<String, Query> queries = atomQ.getQueries();
    Iterable<Query> queryIterables = Iterables
            .unmodifiableIterable(Iterables.filter(queries.values(), Predicates.notNull()));
    return Futures.allAsList(
            Iterables.transform(queryIterables, new Function<Query, ListenableFuture<ImmutableBitmap>>() {

                @Nullable//w  w  w.  j a  v  a  2 s .co m
                @Override
                public ListenableFuture<ImmutableBitmap> apply(@Nullable final Query input) {
                    if (input == null) {
                        throw new ISE("Null query!??");
                    }
                    final String queryName = getQueryName(queries, input);
                    final StringBuilder debugsb = new StringBuilder();
                    debugsb.append("** add query to list, query:").append(queryName).append("\n");
                    final Query query = input;
                    int priority = BaseQuery.getContextPriority(query, 0);
                    return ((ListeningExecutorService) executorService)
                            .submit(new AbstractPrioritizedCallable<ImmutableBitmap>(priority) {
                                @Override
                                public ImmutableBitmap call() {
                                    debugsb.append("** running query:").append(queryName).append("\n");
                                    long begin = System.currentTimeMillis();
                                    Yielder yielder = null;
                                    try {
                                        yielder = Query(query, debugsb);
                                    } catch (IOException e) {
                                        e.printStackTrace();
                                        log.error(e.getMessage());
                                        debugsb.append("** subquery failed:").append(e.getMessage())
                                                .append("\n");
                                    } catch (Throwable throwable) {
                                        debugsb.append("** * subquery failed:").append(throwable.getMessage())
                                                .append("\n");
                                    }
                                    debugsb.append("** query done:").append(queryName).append(" time:")
                                            .append(System.currentTimeMillis() - begin).append("\n");
                                    log.debug("--- inner query use " + (System.currentTimeMillis() - begin)
                                            + "millis");
                                    ImmutableBitmap immutableBitmap = mm.get(query.getType()).apply(query,
                                            yielder);
                                    if (immutableBitmap == null) {
                                        immutableBitmap = AtomCubeAggregatorFactory.BITMAP_FACTORY
                                                .makeEmptyImmutableBitmap();
                                    }
                                    debugsb.append("** done query:").append(queryName).append(" time:")
                                            .append(System.currentTimeMillis() - begin).append("\n");
                                    queue.offer(Pair.of(queryName, immutableBitmap));
                                    queryStack.put(queryName, debugsb);
                                    if (immutableBitmap.isEmpty()) {
                                        log.warn("returned bitmap is empty:\n" + debugsb.toString());
                                    }
                                    return immutableBitmap;
                                }
                            });
                }
            }));
}

From source file:fr.putnami.pwt.core.widget.client.InputList.java

@Override
public Iterable<Error> getErrors() {
    return this.errors == null ? Collections.<Error>emptyList() : Iterables.unmodifiableIterable(this.errors);
}

From source file:org.apache.giraph.ooc.DiskBackedPartitionStore.java

@Override
public Iterable<Integer> getPartitionIds() {
    return Iterables.unmodifiableIterable(partitions.keySet());
}

From source file:org.apache.giraph.partition.DiskBackedOnlineComputePartitionStore.java

@Override
public Iterable<Integer> getPartitionIds() {
    try {/*w w w .  ja va 2s.  c om*/
        return pool.submit(new Callable<Iterable<Integer>>() {

            @Override
            public Iterable<Integer> call() throws Exception {
                wLock.lock();
                try {
                    return Iterables.unmodifiableIterable(partitionIds);
                } finally {
                    wLock.unlock();
                }
            }
        }).get();
    } catch (InterruptedException e) {
        throw new IllegalStateException("getPartitionIds: cannot retrieve partition ids", e);
    } catch (ExecutionException e) {
        throw new IllegalStateException("getPartitionIds: cannot retrieve partition ids", e);
    }
}

From source file:fr.putnami.pwt.core.widget.client.InputDatePicker.java

@Override
public Iterable<Error> getErrors() {
    return Iterables.unmodifiableIterable(this.errors);
}

From source file:org.apache.kylin.cube.model.CubeDesc.java

public void validateAggregationGroups() {
    int index = 0;

    for (AggregationGroup agg : getAggregationGroups()) {
        if (agg.getIncludes() == null) {
            logger.error("Aggregation group " + index + " 'includes' field not set");
            throw new IllegalStateException("Aggregation group " + index + " includes field not set");
        }//from   www . j  av  a 2  s  .c  om

        if (agg.getSelectRule() == null) {
            logger.error("Aggregation group " + index + " 'select_rule' field not set");
            throw new IllegalStateException("Aggregation group " + index + " select rule field not set");
        }

        Set<String> includeDims = new TreeSet<>(String.CASE_INSENSITIVE_ORDER);
        getDims(includeDims, agg.getIncludes());

        Set<String> mandatoryDims = new TreeSet<>(String.CASE_INSENSITIVE_ORDER);
        getDims(mandatoryDims, agg.getSelectRule().mandatoryDims);

        ArrayList<Set<String>> hierarchyDimsList = Lists.newArrayList();
        Set<String> hierarchyDims = new TreeSet<>(String.CASE_INSENSITIVE_ORDER);
        getDims(hierarchyDimsList, hierarchyDims, agg.getSelectRule().hierarchyDims);

        ArrayList<Set<String>> jointDimsList = Lists.newArrayList();
        Set<String> jointDims = new TreeSet<>(String.CASE_INSENSITIVE_ORDER);
        getDims(jointDimsList, jointDims, agg.getSelectRule().jointDims);

        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);
                }
            }
            Collections.sort(notIncluded);
            logger.error("Aggregation group " + index
                    + " Include dimensions not containing all the used dimensions");
            throw new IllegalStateException("Aggregation group " + index
                    + " 'includes' dimensions not include all the dimensions:" + notIncluded.toString());
        }

        if (CollectionUtils.containsAny(mandatoryDims, hierarchyDims)) {
            logger.warn(
                    "Aggregation group " + index + " mandatory dimensions overlap with hierarchy dimensions: "
                            + ensureOrder(CollectionUtils.intersection(mandatoryDims, hierarchyDims)));
        }
        if (CollectionUtils.containsAny(mandatoryDims, jointDims)) {
            logger.warn("Aggregation group " + index + " mandatory dimensions overlap with joint dimensions: "
                    + ensureOrder(CollectionUtils.intersection(mandatoryDims, jointDims)));
        }

        if (CollectionUtils.containsAny(hierarchyDims, jointDims)) {
            logger.error("Aggregation group " + index + " hierarchy dimensions overlap with joint dimensions");
            throw new IllegalStateException(
                    "Aggregation group " + index + " hierarchy dimensions overlap with joint dimensions: "
                            + ensureOrder(CollectionUtils.intersection(hierarchyDims, jointDims)));
        }

        if (hasSingleOrNone(hierarchyDimsList)) {
            logger.error("Aggregation group " + index + " require at least 2 dimensions in a hierarchy");
            throw new IllegalStateException(
                    "Aggregation group " + index + " require at least 2 dimensions in a hierarchy.");
        }
        if (hasSingleOrNone(jointDimsList)) {
            logger.error("Aggregation group " + index + " require at least 2 dimensions in a joint");
            throw new IllegalStateException(
                    "Aggregation group " + index + " require at least 2 dimensions in a joint");
        }

        Pair<Boolean, Set<String>> overlap = hasOverlap(hierarchyDimsList, hierarchyDims);
        if (overlap.getFirst() == true) {
            logger.error("Aggregation group " + index + " a dimension exist in more than one hierarchy: "
                    + ensureOrder(overlap.getSecond()));
            throw new IllegalStateException("Aggregation group " + index
                    + " a dimension exist in more than one hierarchy: " + ensureOrder(overlap.getSecond()));
        }

        overlap = hasOverlap(jointDimsList, jointDims);
        if (overlap.getFirst() == true) {
            logger.error("Aggregation group " + index + " a dimension exist in more than one joint: "
                    + ensureOrder(overlap.getSecond()));
            throw new IllegalStateException("Aggregation group " + index
                    + " a dimension exist in more than one joint: " + ensureOrder(overlap.getSecond()));
        }

        index++;
    }
}

From source file:org.apache.abdera2.activities.extra.Extra.java

public static <T extends ASBase> Iterable<T> filterEquivalent(Iterable<T> items, Equivalence<? super T> equiv,
        Comparator<T> comp) {
    EquivalenceSet<T> a = new EquivalenceSet<T>(equiv);
    Iterables.addAll(a, sorted(items, comp));
    return Iterables.unmodifiableIterable(a);
}

From source file:org.apache.abdera2.activities.extra.Extra.java

public static <T extends ASBase> Iterable<T> filterEquivalent(Iterable<T> items, Equivalence<? super T> equiv) {
    EquivalenceSet<T> a = new EquivalenceSet<T>(equiv);
    Iterables.addAll(a, items);//from  w  w w  . j a va 2  s  .com
    return Iterables.unmodifiableIterable(a);
}