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

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

Introduction

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

Prototype

public static <T> Iterable<T> skip(final Iterable<T> iterable, final int numberToSkip) 

Source Link

Document

Returns a view of iterable that skips its first numberToSkip elements.

Usage

From source file:org.opendaylight.yangtools.yang.model.util.SchemaContextUtil.java

/**
 * @param context// w  ww.j a v a 2  s .  c o m
 *            Schema Context
 * @param module
 *            Yang Module
 * @param relativeXPath
 *            Non conditional Revision Aware Relative XPath
 * @param actualSchemaNode
 *            actual schema node
 * @return list of QName
 *
 * @throws IllegalArgumentException
 */
private static Iterable<QName> resolveRelativeXPath(final SchemaContext context, final Module module,
        final RevisionAwareXPath relativeXPath, final SchemaNode actualSchemaNode) {
    Preconditions.checkArgument(context != null, "Schema Context reference cannot be NULL");
    Preconditions.checkArgument(module != null, "Module reference cannot be NULL");
    Preconditions.checkArgument(relativeXPath != null, "Non Conditional Revision Aware XPath cannot be NULL");
    Preconditions.checkState(!relativeXPath.isAbsolute(),
            "Revision Aware XPath MUST be relative i.e. MUST contains ../, "
                    + "for non relative Revision Aware XPath use findDataSchemaNode method");
    Preconditions.checkState(actualSchemaNode.getPath() != null,
            "Schema Path reference for Leafref cannot be NULL");

    final Iterable<String> xpaths = SLASH_SPLITTER.split(relativeXPath.toString());

    // Find out how many "parent" components there are
    // FIXME: is .contains() the right check here?
    // FIXME: case ../../node1/node2/../node3/../node4
    int colCount = 0;
    for (final Iterator<String> it = xpaths.iterator(); it.hasNext() && it.next().contains("..");) {
        ++colCount;
    }

    final Iterable<QName> schemaNodePath = actualSchemaNode.getPath().getPathFromRoot();

    if (Iterables.size(schemaNodePath) - colCount >= 0) {
        return Iterables.concat(Iterables.limit(schemaNodePath, Iterables.size(schemaNodePath) - colCount),
                Iterables.transform(Iterables.skip(xpaths, colCount),
                        input -> stringPathPartToQName(context, module, input)));
    }
    return Iterables.concat(schemaNodePath, Iterables.transform(Iterables.skip(xpaths, colCount),
            input -> stringPathPartToQName(context, module, input)));
}

From source file:org.sosy_lab.cpachecker.cpa.invariants.InvariantsTransferRelation.java

private static boolean hasMoreThanNElements(Iterable<?> pIterable, int pN) {
    return !Iterables.isEmpty(Iterables.skip(pIterable, pN));
}

From source file:de.hpi.bp2013n1.anonymizer.Anonymizer.java

private void logBatchInsertError(SQLException e) {
    anonymizerLogger.severe("Error(s) during batch insert: " + e.getMessage());
    for (Throwable chainedException : Iterables.skip(e, 1)) {
        anonymizerLogger.severe("Insert error: " + chainedException.getMessage());
    }//from  ww w . j a v a2 s  .  co  m
}

From source file:org.onos.yangtools.yang.data.impl.leafref.LeafRefValidatation.java

private Iterable<QNameWithPredicate> nextLevel(final Iterable<QNameWithPredicate> path) {
    return Iterables.skip(path, 1);
}

From source file:org.sosy_lab.cpachecker.util.predicates.interpolation.InterpolationManager.java

/** This function implements the paper "Nested Interpolants" with a small modification:
 * instead of a return-edge, we use dummy-edges with simple pathformula "true".
 * Actually the implementation does not use "true", but omits it completely and
 * returns the conjunction of the two interpolants (before and after the (non-existing) dummy edge). */
private <T> BooleanFormula getNestedInterpolant(
        final List<Triple<BooleanFormula, AbstractState, Integer>> orderedFormulas,
        final List<BooleanFormula> interpolants,
        final Deque<Triple<BooleanFormula, BooleanFormula, CFANode>> callstack,
        final Interpolator<T> interpolator, int positionOfA, BooleanFormula lastItp)
        throws InterruptedException, SolverException {

    // use a new prover, because we use several distinct queries
    try (final InterpolatingProverEnvironment<T> itpProver = interpolator.newEnvironment()) {

        final List<T> A = new ArrayList<>();
        final List<T> B = new ArrayList<>();

        // If we have entered or exited a function, update the stack of entry points
        final AbstractState abstractionState = checkNotNull(orderedFormulas.get(positionOfA).getSecond());
        final CFANode node = AbstractStates.extractLocation(abstractionState);

        if (node instanceof FunctionEntryNode && callHasReturn(orderedFormulas, positionOfA)) {
            // && (positionOfA > 0)) {
            // case 2 from paper
            final BooleanFormula call = orderedFormulas.get(positionOfA).getFirst();
            callstack.addLast(Triple.of(lastItp, call, node));
            final BooleanFormula itp = bfmgr.makeBoolean(true);
            interpolants.add(itp);//from w  ww. j a v a  2  s  .c  om
            return itp; // PSIminus = True --> PSI = True, for the 3rd rule ITP is True
        }

        A.add(itpProver.push(lastItp));
        A.add(itpProver.push(orderedFormulas.get(positionOfA).getFirst()));

        // add all remaining PHI_j
        for (Triple<BooleanFormula, AbstractState, Integer> t : Iterables.skip(orderedFormulas,
                positionOfA + 1)) {
            B.add(itpProver.push(t.getFirst()));
        }

        // add all previous function calls
        for (Triple<BooleanFormula, BooleanFormula, CFANode> t : callstack) {
            B.add(itpProver.push(t.getFirst())); // add PSI_k
            B.add(itpProver.push(t.getSecond())); // ... and PHI_k
        }

        // update prover with new formulas.
        // this is the expensive step, that is distinct from other strategies.
        // TODO improve! example: reverse ordering of formulas for re-usage of the solver-stack
        boolean unsat = itpProver.isUnsat();
        assert unsat : "formulas were unsat before, they have to be unsat now.";

        // get interpolant of A and B, for B we use the complementary set of A
        final BooleanFormula itp = itpProver.getInterpolant(A);

        if (!callstack.isEmpty() && node instanceof FunctionExitNode) {
            // case 4, we are returning from a function, rule 4
            Triple<BooleanFormula, BooleanFormula, CFANode> scopingItp = callstack.removeLast();

            final InterpolatingProverEnvironment<T> itpProver2 = interpolator.newEnvironment();
            final List<T> A2 = new ArrayList<>();
            final List<T> B2 = new ArrayList<>();

            A2.add(itpProver2.push(itp));
            //A2.add(itpProver2.push(orderedFormulas.get(positionOfA).getFirst()));

            A2.add(itpProver2.push(scopingItp.getFirst()));
            A2.add(itpProver2.push(scopingItp.getSecond()));

            // add all remaining PHI_j
            for (Triple<BooleanFormula, AbstractState, Integer> t : Iterables.skip(orderedFormulas,
                    positionOfA + 1)) {
                B2.add(itpProver2.push(t.getFirst()));
            }

            // add all previous function calls
            for (Triple<BooleanFormula, BooleanFormula, CFANode> t : callstack) {
                B2.add(itpProver2.push(t.getFirst())); // add PSI_k
                B2.add(itpProver2.push(t.getSecond())); // ... and PHI_k
            }

            boolean unsat2 = itpProver2.isUnsat();
            assert unsat2 : "formulas2 were unsat before, they have to be unsat now.";

            // get interpolant of A and B, for B we use the complementary set of A
            BooleanFormula itp2 = itpProver2.getInterpolant(A2);
            itpProver2.close();

            interpolants.add(rebuildInterpolant(itp, itp2));
            return itp2;

        } else {
            interpolants.add(itp);
            return itp;
        }
    }
}

From source file:com.eucalyptus.compute.vpc.VpcManager.java

public CreateNetworkInterfaceResponseType createNetworkInterface(final CreateNetworkInterfaceType request)
        throws EucalyptusCloudException {
    final CreateNetworkInterfaceResponseType reply = request.getReply();
    final Context ctx = Contexts.lookup();
    final AccountFullName accountFullName = ctx.getUserFullName().asAccountFullName();
    final String subnetId = Identifier.subnet.normalize(request.getSubnetId());
    final String privateIp = request.getPrivateIpAddress() != null ? request.getPrivateIpAddress()
            : request.getPrivateIpAddressesSet() != null
                    && !request.getPrivateIpAddressesSet().getItem().isEmpty()
                            ? request.getPrivateIpAddressesSet().getItem().get(0).getPrivateIpAddress()
                            : null;/*from  w w  w .  ja va2 s .  c  om*/
    final Supplier<NetworkInterface> allocator = new Supplier<NetworkInterface>() {
        @Override
        public NetworkInterface get() {
            try {
                final Subnet subnet = subnets.lookupByName(accountFullName, subnetId,
                        Functions.<Subnet>identity());
                final Vpc vpc = subnet.getVpc();
                final Set<NetworkGroup> groups = request.getGroupSet() == null
                        || request.getGroupSet().groupIds().isEmpty()
                                ? Sets.newHashSet(securityGroups.lookupDefault(vpc.getDisplayName(),
                                        Functions.<NetworkGroup>identity()))
                                : Sets.newHashSet(Iterables.transform(request.getGroupSet().groupIds(),
                                        RestrictedTypes.resolver(NetworkGroup.class)));
                if (groups.size() > VpcConfiguration.getSecurityGroupsPerNetworkInterface()) {
                    throw new ClientComputeException("SecurityGroupsPerInterfaceLimitExceeded",
                            "Security group limit exceeded");
                }
                if (!Collections.singleton(vpc.getDisplayName())
                        .equals(Sets.newHashSet(Iterables.transform(groups, NetworkGroup.vpcId())))) {
                    throw Exceptions.toUndeclared(new ClientComputeException("InvalidParameterValue",
                            "Invalid security groups (inconsistent VPC)"));
                }
                final String identifier = Identifier.eni.generate();
                if (privateIp != null) {
                    final Cidr cidr = Cidr.parse(subnet.getCidr());
                    if (!cidr.contains(privateIp)) {
                        throw new ClientComputeException("InvalidParameterValue",
                                "Address does not fall within the subnet's address range");
                    } else if (!Iterables.contains(Iterables.skip(IPRange.fromCidr(cidr), 3),
                            PrivateAddresses.asInteger(privateIp))) {
                        throw new ClientComputeException("InvalidParameterValue",
                                "Address is in subnet's reserved address range");
                    }
                }
                final String mac = NetworkInterfaceHelper.mac(identifier);
                final String ip = NetworkInterfaceHelper.allocate(vpc.getDisplayName(), subnet.getDisplayName(),
                        identifier, mac, privateIp);
                return networkInterfaces.save(NetworkInterface.create(ctx.getUserFullName(), vpc, subnet,
                        groups, identifier, mac, ip,
                        vpc.getDnsHostnames() ? VmInstances.dnsName(ip, DomainNames.internalSubdomain()) : null,
                        firstNonNull(request.getDescription(), "")));
            } catch (VpcMetadataNotFoundException ex) {
                throw Exceptions.toUndeclared(new ClientComputeException("InvalidSubnetID.NotFound",
                        "Subnet not found '" + request.getSubnetId() + "'"));
            } catch (ResourceAllocationException ex) {
                throw Exceptions
                        .toUndeclared(new ClientComputeException("InvalidParameterValue", ex.getMessage()));
            } catch (Exception ex) {
                final NoSuchMetadataException e = Exceptions.findCause(ex, NoSuchMetadataException.class);
                if (e != null) {
                    throw Exceptions.toUndeclared(
                            new ClientComputeException("InvalidSecurityGroupID.NotFound", e.getMessage()));
                }
                throw new RuntimeException(ex);
            }
        }
    };
    reply.setNetworkInterface(allocate(allocator, NetworkInterface.class, NetworkInterfaceType.class));
    return reply;
}

From source file:org.geoserver.catalog.impl.DefaultCatalogFacade.java

@Override
public <T extends CatalogInfo> CloseableIterator<T> list(final Class<T> of, final Filter filter,
        @Nullable Integer offset, @Nullable Integer count, @Nullable SortBy... sortOrder) {

    if (sortOrder != null) {
        for (SortBy so : sortOrder) {
            if (sortOrder != null && !canSort(of, so.getPropertyName().getPropertyName())) {
                throw new IllegalArgumentException(
                        "Can't sort objects of type " + of.getName() + " by " + so.getPropertyName());
            }/*  www.  j a va  2  s.c om*/
        }
    }

    Iterable<T> iterable = iterable(of, filter, sortOrder);

    if (offset != null && offset.intValue() > 0) {
        iterable = Iterables.skip(iterable, offset.intValue());
    }

    if (count != null && count.intValue() >= 0) {
        iterable = Iterables.limit(iterable, count.intValue());
    }

    Iterator<T> iterator = iterable.iterator();

    return new CloseableIteratorAdapter<T>(iterator);
}

From source file:org.sosy_lab.cpachecker.util.predicates.interpolation.InterpolationManager.java

/** check, if there exists a function-exit-node to the current call-node. */
private boolean callHasReturn(List<Triple<BooleanFormula, AbstractState, Integer>> orderedFormulas,
        int callIndex) {
    // TODO caching as optimisation to reduce from  k*O(n)  to  O(n)+k*O(1)  ?
    final Deque<CFANode> callstack = new ArrayDeque<>();

    {/*from w w  w.  j ava2s  . c o  m*/
        final AbstractState abstractionState = orderedFormulas.get(callIndex).getSecond();
        final CFANode node = AbstractStates.extractLocation(abstractionState);
        assert (node instanceof FunctionEntryNode) : "call needed as input param";
        callstack.addLast(node);
    }

    // walk along path and track the callstack
    for (Triple<BooleanFormula, AbstractState, Integer> t : Iterables.skip(orderedFormulas, callIndex + 1)) {
        assert !callstack.isEmpty() : "should have returned when callstack is empty";

        final AbstractState abstractionState = checkNotNull(t.getSecond());
        final CFANode node = AbstractStates.extractLocation(abstractionState);

        if (node instanceof FunctionEntryNode) {
            callstack.addLast(node);
        }

        final CFANode lastEntryNode = callstack.getLast();
        if ((node instanceof FunctionExitNode && ((FunctionExitNode) node).getEntryNode() == lastEntryNode)
        //|| (node.getEnteringSummaryEdge() != null
        // && node.getEnteringSummaryEdge().getPredecessor().getLeavingEdge(0).getSuccessor() == lastEntryNode)
        ) {
            callstack.removeLast();

            // we found the function exit for the input param
            if (callstack.isEmpty()) {
                return true;
            }
        }
    }
    return false;
}

From source file:io.druid.segment.IndexMaker.java

private static void makeDimColumn(final FileSmoosher v9Smoosher, final List<IndexableAdapter> adapters,
        final ProgressIndicator progress, final Iterable<Rowboat> theRows, final int dimIndex,
        final String dimension, final Map<String, ColumnCapabilitiesImpl> columnCapabilities,
        final Map<String, Iterable<String>> dimensionValuesLookup, final List<IntBuffer> rowNumConversions,
        final BitmapSerdeFactory bitmapSerdeFactory,
        final CompressedObjectStrategy.CompressionStrategy compressionStrategy) throws IOException {
    final String section = String.format("make %s", dimension);
    progress.startSection(section);//from   w w w. j  av a  2 s.  c  o m

    final ColumnDescriptor.Builder dimBuilder = ColumnDescriptor.builder();
    dimBuilder.setValueType(ValueType.STRING);

    final List<ByteBuffer> outParts = Lists.newArrayList();

    ByteArrayOutputStream nameBAOS = new ByteArrayOutputStream();
    serializerUtils.writeString(nameBAOS, dimension);
    outParts.add(ByteBuffer.wrap(nameBAOS.toByteArray()));

    boolean hasMultipleValues = columnCapabilities.get(dimension).hasMultipleValues();
    dimBuilder.setHasMultipleValues(hasMultipleValues);

    // make dimension columns
    List<Integer> singleValCol;
    final VSizeIndexed multiValCol;

    ColumnDictionaryEntryStore adder = hasMultipleValues ? new MultiValColumnDictionaryEntryStore()
            : new SingleValColumnDictionaryEntryStore();

    final BitmapFactory bitmapFactory = bitmapSerdeFactory.getBitmapFactory();
    MutableBitmap nullSet = null;
    int rowCount = 0;

    for (Rowboat theRow : theRows) {
        if (dimIndex > theRow.getDims().length) {
            if (nullSet == null) {
                nullSet = bitmapFactory.makeEmptyMutableBitmap();
            }
            nullSet.add(rowCount);
            adder.add(null);
        } else {
            int[] dimVals = theRow.getDims()[dimIndex];
            if (dimVals == null || dimVals.length == 0) {
                if (nullSet == null) {
                    nullSet = bitmapFactory.makeEmptyMutableBitmap();
                }
                nullSet.add(rowCount);
            }
            adder.add(dimVals);
        }
        rowCount++;
    }

    final Iterable<String> dimensionValues = dimensionValuesLookup.get(dimension);
    GenericIndexed<String> dictionary = GenericIndexed.fromIterable(dimensionValues,
            GenericIndexed.STRING_STRATEGY);
    boolean bumpDictionary = false;

    if (hasMultipleValues) {
        final List<List<Integer>> vals = ((MultiValColumnDictionaryEntryStore) adder).get();
        if (nullSet != null) {
            log.info("Dimension[%s] has null rows.", dimension);

            if (Iterables.getFirst(dimensionValues, "") != null) {
                bumpDictionary = true;
                log.info("Dimension[%s] has no null value in the dictionary, expanding...", dimension);

                dictionary = GenericIndexed.fromIterable(
                        Iterables.concat(Collections.<String>singleton(null), dimensionValues),
                        GenericIndexed.STRING_STRATEGY);

                final int dictionarySize = dictionary.size();

                singleValCol = null;
                multiValCol = VSizeIndexed.fromIterable(
                        Iterables.transform(vals, new Function<List<Integer>, VSizeIndexedInts>() {
                            @Override
                            public VSizeIndexedInts apply(final List<Integer> input) {
                                if (input == null) {
                                    return VSizeIndexedInts.fromList(ImmutableList.<Integer>of(0),
                                            dictionarySize);
                                } else {
                                    return VSizeIndexedInts.fromList(
                                            new NullsAtZeroConvertingIntList(input, false), dictionarySize);
                                }
                            }
                        }));
            } else {
                final int dictionarySize = dictionary.size();
                singleValCol = null;
                multiValCol = VSizeIndexed.fromIterable(
                        Iterables.transform(vals, new Function<List<Integer>, VSizeIndexedInts>() {
                            @Override
                            public VSizeIndexedInts apply(List<Integer> input) {
                                if (input == null) {
                                    return VSizeIndexedInts.fromList(ImmutableList.<Integer>of(0),
                                            dictionarySize);
                                } else {
                                    return VSizeIndexedInts.fromList(input, dictionarySize);
                                }
                            }
                        }));
            }
        } else {
            final int dictionarySize = dictionary.size();
            singleValCol = null;
            multiValCol = VSizeIndexed
                    .fromIterable(Iterables.transform(vals, new Function<List<Integer>, VSizeIndexedInts>() {
                        @Override
                        public VSizeIndexedInts apply(List<Integer> input) {
                            return VSizeIndexedInts.fromList(input, dictionarySize);
                        }
                    }));
        }
    } else {
        final List<Integer> vals = ((SingleValColumnDictionaryEntryStore) adder).get();

        if (nullSet != null) {
            log.info("Dimension[%s] has null rows.", dimension);

            if (Iterables.getFirst(dimensionValues, "") != null) {
                bumpDictionary = true;
                log.info("Dimension[%s] has no null value in the dictionary, expanding...", dimension);

                final List<String> nullList = Lists.newArrayList();
                nullList.add(null);

                dictionary = GenericIndexed.fromIterable(Iterables.concat(nullList, dimensionValues),
                        GenericIndexed.STRING_STRATEGY);
                multiValCol = null;
                singleValCol = new NullsAtZeroConvertingIntList(vals, false);
            } else {
                multiValCol = null;
                singleValCol = new NullsAtZeroConvertingIntList(vals, true);
            }
        } else {
            multiValCol = null;
            singleValCol = new AbstractList<Integer>() {
                @Override
                public Integer get(int index) {
                    return vals.get(index);
                }

                @Override
                public int size() {
                    return vals.size();
                }
            };
        }
    }

    // Make bitmap indexes
    List<MutableBitmap> mutableBitmaps = Lists.newArrayList();
    for (String dimVal : dimensionValues) {
        List<Iterable<Integer>> convertedInverteds = Lists.newArrayListWithCapacity(adapters.size());
        for (int j = 0; j < adapters.size(); ++j) {
            convertedInverteds.add(new ConvertingIndexedInts(adapters.get(j).getBitmapIndex(dimension, dimVal),
                    rowNumConversions.get(j)));
        }

        MutableBitmap bitset = bitmapSerdeFactory.getBitmapFactory().makeEmptyMutableBitmap();
        for (Integer row : CombiningIterable.createSplatted(convertedInverteds,
                Ordering.<Integer>natural().nullsFirst())) {
            if (row != INVALID_ROW) {
                bitset.add(row);
            }
        }

        mutableBitmaps.add(bitset);
    }

    GenericIndexed<ImmutableBitmap> bitmaps;

    if (nullSet != null) {
        final ImmutableBitmap theNullSet = bitmapFactory.makeImmutableBitmap(nullSet);
        if (bumpDictionary) {
            bitmaps = GenericIndexed.fromIterable(Iterables.concat(Arrays.asList(theNullSet),
                    Iterables.transform(mutableBitmaps, new Function<MutableBitmap, ImmutableBitmap>() {
                        @Override
                        public ImmutableBitmap apply(MutableBitmap input) {
                            return bitmapFactory.makeImmutableBitmap(input);
                        }
                    })), bitmapSerdeFactory.getObjectStrategy());
        } else {
            Iterable<ImmutableBitmap> immutableBitmaps = Iterables.transform(mutableBitmaps,
                    new Function<MutableBitmap, ImmutableBitmap>() {
                        @Override
                        public ImmutableBitmap apply(MutableBitmap input) {
                            return bitmapFactory.makeImmutableBitmap(input);
                        }
                    });

            bitmaps = GenericIndexed.fromIterable(Iterables.concat(
                    Arrays.asList(theNullSet.union(Iterables.getFirst(immutableBitmaps, null))),
                    Iterables.skip(immutableBitmaps, 1)), bitmapSerdeFactory.getObjectStrategy());
        }
    } else {
        bitmaps = GenericIndexed.fromIterable(
                Iterables.transform(mutableBitmaps, new Function<MutableBitmap, ImmutableBitmap>() {
                    @Override
                    public ImmutableBitmap apply(MutableBitmap input) {
                        return bitmapFactory.makeImmutableBitmap(input);
                    }
                }), bitmapSerdeFactory.getObjectStrategy());
    }

    // Make spatial indexes
    ImmutableRTree spatialIndex = null;
    boolean hasSpatialIndexes = columnCapabilities.get(dimension).hasSpatialIndexes();
    RTree tree = null;
    if (hasSpatialIndexes) {
        tree = new RTree(2, new LinearGutmanSplitStrategy(0, 50, bitmapSerdeFactory.getBitmapFactory()),
                bitmapSerdeFactory.getBitmapFactory());
    }

    int dimValIndex = 0;
    for (String dimVal : dimensionValuesLookup.get(dimension)) {
        if (hasSpatialIndexes) {
            if (dimVal != null && !dimVal.isEmpty()) {
                List<String> stringCoords = Lists.newArrayList(SPLITTER.split(dimVal));
                float[] coords = new float[stringCoords.size()];
                for (int j = 0; j < coords.length; j++) {
                    coords[j] = Float.valueOf(stringCoords.get(j));
                }
                tree.insert(coords, mutableBitmaps.get(dimValIndex));
            }
            dimValIndex++;
        }
    }
    if (hasSpatialIndexes) {
        spatialIndex = ImmutableRTree.newImmutableFromMutable(tree);
    }

    log.info("Completed dimension[%s] with cardinality[%,d]. Starting write.", dimension, dictionary.size());

    final DictionaryEncodedColumnPartSerde.Builder dimPartBuilder = DictionaryEncodedColumnPartSerde.builder()
            .withDictionary(dictionary).withBitmapSerdeFactory(bitmapSerdeFactory).withBitmaps(bitmaps)
            .withSpatialIndex(spatialIndex).withByteOrder(IndexIO.BYTE_ORDER);

    if (singleValCol != null) {
        if (compressionStrategy != null) {
            dimPartBuilder.withSingleValuedColumn(
                    CompressedVSizeIntsIndexedSupplier.fromList(singleValCol, dictionary.size(),
                            CompressedVSizeIntsIndexedSupplier.maxIntsInBufferForValue(dictionary.size()),
                            IndexIO.BYTE_ORDER, compressionStrategy));
        } else {
            dimPartBuilder.withSingleValuedColumn(VSizeIndexedInts.fromList(singleValCol, dictionary.size()));
        }
    } else if (compressionStrategy != null) {
        dimPartBuilder.withMultiValuedColumn(CompressedVSizeIndexedSupplier.fromIterable(multiValCol,
                dictionary.size(), IndexIO.BYTE_ORDER, compressionStrategy));
    } else {
        dimPartBuilder.withMultiValuedColumn(multiValCol);
    }

    writeColumn(v9Smoosher, dimPartBuilder.build(), dimBuilder, dimension);

    progress.stopSection(section);
}

From source file:org.pantsbuild.tools.jar.JarBuilder.java

private Optional<ReadableEntry> processEntries(Predicate<CharSequence> skipPath,
        DuplicateHandler duplicateHandler, String jarPath, Collection<ReadableEntry> itemEntries) {

    if (skipPath.apply(jarPath)) {
        listener.onSkip(Optional.<Entry>absent(), itemEntries);
        return Optional.absent();
    }//from   w  ww . ja v a 2 s. c o  m

    if (itemEntries.size() < 2) {
        ReadableEntry entry = Iterables.getOnlyElement(itemEntries);
        listener.onWrite(entry);
        return Optional.of(entry);
    }

    DuplicateAction action = duplicateHandler.actionFor(jarPath);
    switch (action) {
    case SKIP: {
        ReadableEntry original = Iterables.get(itemEntries, 0);
        listener.onSkip(Optional.of(original), Iterables.skip(itemEntries, 1));
        return Optional.of(original);
    }

    case REPLACE: {
        ReadableEntry replacement = Iterables.getLast(itemEntries);
        listener.onReplace(Iterables.limit(itemEntries, itemEntries.size() - 1), replacement);
        return Optional.of(replacement);
    }
    case CONCAT: {
        ByteSource concat = ByteSource.concat(Iterables.transform(itemEntries, ReadableEntry.GET_CONTENTS));

        ReadableEntry concatenatedEntry = new ReadableEntry(
                NamedByteSource.create(memorySource(), jarPath, concat), jarPath);

        listener.onConcat(jarPath, itemEntries);
        return Optional.of(concatenatedEntry);
    }

    case CONCAT_TEXT: {
        ByteSource concat_text = ByteSource
                .concat(Iterables.transform(itemEntries, ReadableTextEntry.GET_CONTENTS));

        ReadableEntry concatenatedTextEntry = new ReadableEntry(
                NamedByteSource.create(memorySource(), jarPath, concat_text), jarPath);

        listener.onConcat(jarPath, itemEntries);
        return Optional.of(concatenatedTextEntry);
    }

    case THROW:
        throw new DuplicateEntryException(Iterables.get(itemEntries, 1));

    default:
        throw new IllegalArgumentException("Unrecognized DuplicateAction " + action);
    }
}