Example usage for com.google.common.collect ImmutableList get

List of usage examples for com.google.common.collect ImmutableList get

Introduction

In this page you can find the example usage for com.google.common.collect ImmutableList get.

Prototype

E get(int index);

Source Link

Document

Returns the element at the specified position in this list.

Usage

From source file:com.google.jimfs.AttributeService.java

private static String getSingleAttribute(String attribute) {
    ImmutableList<String> attributeNames = getAttributeNames(attribute);

    if (attributeNames.size() != 1 || ALL_ATTRIBUTES.equals(attributeNames.get(0))) {
        throw new IllegalArgumentException("must specify a single attribute: " + attribute);
    }/* w  w w  .j a  va  2s. co m*/

    return attributeNames.get(0);
}

From source file:com.spectralogic.ds3autogen.utils.ResponsePayloadUtil.java

/**
 * Gets the non-error, non-null code associated with a list of Ds3ResponseCodes
 *///from   ww  w .j  a  va  2 s.co  m
public static Integer getPayloadResponseCode(final ImmutableList<Ds3ResponseCode> responseCodes) {

    final ImmutableList<Integer> codes = getAllNonErrorResponseCodes(responseCodes);
    switch (codes.size()) {
    case 0:
        //Log instead of throw error since GetObject and HeadBucket will have no values
        LOG.debug("There are no non-error non-null response codes for this request");
        return null;
    case 1:
        return codes.get(0);
    default:
        throw new IllegalArgumentException("There are multiple non-error response codes for this request");
    }
}

From source file:org.geogit.geotools.plumbing.ExportDiffOp.java

private static Iterator<SimpleFeature> getFeatures(Iterator<DiffEntry> diffs, final boolean old,
        final ObjectDatabase database, final ObjectId metadataId, final ProgressListener progressListener) {

    final SimpleFeatureType featureType = addFidAttribute(database.getFeatureType(metadataId));
    final RevFeatureType revFeatureType = RevFeatureType.build(featureType);
    final SimpleFeatureBuilder featureBuilder = new SimpleFeatureBuilder(featureType);

    Function<DiffEntry, SimpleFeature> asFeature = new Function<DiffEntry, SimpleFeature>() {

        @Override//  w w w  . j  a  v a  2 s .c o  m
        @Nullable
        public SimpleFeature apply(final DiffEntry input) {
            NodeRef nodeRef = old ? input.getOldObject() : input.getNewObject();
            if (nodeRef == null) {
                return null;
            }
            final RevFeature revFeature = database.getFeature(nodeRef.objectId());
            ImmutableList<Optional<Object>> values = revFeature.getValues();
            for (int i = 0; i < values.size(); i++) {
                String name = featureType.getDescriptor(i + 1).getLocalName();
                Object value = values.get(i).orNull();
                featureBuilder.set(name, value);
            }
            featureBuilder.set("geogit_fid", nodeRef.name());
            Feature feature = featureBuilder.buildFeature(nodeRef.name());
            feature.getUserData().put(Hints.USE_PROVIDED_FID, true);
            feature.getUserData().put(RevFeature.class, revFeature);
            feature.getUserData().put(RevFeatureType.class, revFeatureType);

            if (feature instanceof SimpleFeature) {
                return (SimpleFeature) feature;
            }
            return null;
        }

    };

    Iterator<SimpleFeature> asFeatures = Iterators.transform(diffs, asFeature);

    UnmodifiableIterator<SimpleFeature> filterNulls = Iterators.filter(asFeatures, Predicates.notNull());

    return filterNulls;
}

From source file:com.google.auto.value.processor.escapevelocity.Reparser.java

/**
 * Returns a copy of the given list where spaces have been moved where appropriate after {@code
 * #set}. This hack is needed to match what appears to be special treatment in Apache Velocity of
 * spaces before {@code #set} directives. If you have <i>thing</i> <i>whitespace</i> {@code #set},
 * then the whitespace is deleted if the <i>thing</i> is a comment ({@code ##...\n}); a reference
 * ({@code $x} or {@code $x.foo} etc); a macro definition; or another {@code #set}.
 *///ww w.j a  v  a 2s  .  c o m
private static ImmutableList<Node> removeSpaceBeforeSet(ImmutableList<Node> nodes) {
    assert Iterables.getLast(nodes) instanceof EofNode;
    // Since the last node is EofNode, the i + 1 and i + 2 accesses below are safe.
    ImmutableList.Builder<Node> newNodes = ImmutableList.builder();
    for (int i = 0; i < nodes.size(); i++) {
        Node nodeI = nodes.get(i);
        newNodes.add(nodeI);
        if (shouldDeleteSpaceBetweenThisAndSet(nodeI) && isWhitespaceLiteral(nodes.get(i + 1))
                && nodes.get(i + 2) instanceof SetNode) {
            // Skip the space.
            i++;
        }
    }
    return newNodes.build();
}

From source file:org.geogit.osm.internal.OSMUnmapOp.java

private static int getPropertyIndex(RevFeatureType type, String name) {

    ImmutableList<PropertyDescriptor> descriptors = type.sortedDescriptors();
    for (int i = 0; i < descriptors.size(); i++) {
        if (descriptors.get(i).getName().getLocalPart().equals(name)) {
            return i;
        }// w  w w  .  j av a  2s  .co m
    }
    // shouldn't reach this
    throw new RuntimeException("wrong field name");
}

From source file:net.femtoparsec.binding.property.BeanPropertyHelper.java

/**
 * <p>Complete a chained list of bean properties with a extra path.</p>
 *
 * @param parentPath the parent chained list of properties
 * @param path the path to append to the chain
 * @return the new chained list of bean properties
 *///from ww w  .  j  a  v a  2  s  .  co  m
public static ImmutableList<BeanProperty> completeBeanPropertyList(ImmutableList<BeanProperty> parentPath,
        String path) {
    final List<String> tokens = Arrays.asList(path.split("\\."));
    //get the type of the last token in the parent path and use it to construct the rest of the path
    final TypeToken<?> last = parentPath.get(parentPath.size() - 1).getPropertyType();
    return buildBeanPropertyList(last, tokens, parentPath);
}

From source file:com.opengamma.strata.collect.io.CsvFile.java

static ImmutableMap<String, Integer> buildSearchHeaders(ImmutableList<String> headers) {
    // need to allow duplicate headers and only store the first instance
    Map<String, Integer> searchHeaders = new HashMap<>();
    for (int i = 0; i < headers.size(); i++) {
        String searchHeader = headers.get(i).toLowerCase(Locale.ENGLISH);
        searchHeaders.putIfAbsent(searchHeader, i);
    }/* w  w  w .j a v  a2  s. c  o m*/
    return ImmutableMap.copyOf(searchHeaders);
}

From source file:com.google.javascript.rhino.jstype.TemplateTypeMap.java

private static boolean checkEquivalenceHelper(EquivalenceMethod eqMethod, TemplateTypeMap thisMap,
        TemplateTypeMap thatMap) {//  w  ww  . ja  v  a  2  s  . co  m
    ImmutableList<TemplateType> thisKeys = thisMap.getTemplateKeys();
    ImmutableList<TemplateType> thatKeys = thatMap.getTemplateKeys();

    for (int i = 0; i < thisKeys.size(); i++) {
        TemplateType thisKey = thisKeys.get(i);
        JSType thisType = thisMap.getResolvedTemplateType(thisKey);
        EquivalenceMatch thisMatch = EquivalenceMatch.NO_KEY_MATCH;

        for (int j = 0; j < thatKeys.size(); j++) {
            TemplateType thatKey = thatKeys.get(j);
            JSType thatType = thatMap.getResolvedTemplateType(thatKey);

            // Cross-compare every key-value pair in this TemplateTypeMap with
            // those in that TemplateTypeMap. Update the Equivalence match for both
            // key-value pairs involved.
            if (thisKey == thatKey) {
                EquivalenceMatch newMatchType = EquivalenceMatch.VALUE_MISMATCH;
                if (thisType.checkEquivalenceHelper(thatType, eqMethod)) {
                    newMatchType = EquivalenceMatch.VALUE_MATCH;
                }

                if (thisMatch != EquivalenceMatch.VALUE_MATCH) {
                    thisMatch = newMatchType;
                }
            }
        }

        if (failedEquivalenceCheck(thisMatch, eqMethod)) {
            return false;
        }
    }
    return true;
}

From source file:org.locationtech.geogig.geotools.plumbing.ExportDiffOp.java

private static Iterator<SimpleFeature> getFeatures(Iterator<DiffEntry> diffs, final boolean old,
        final ObjectDatabase database, final ObjectId metadataId, final ProgressListener progressListener) {

    final SimpleFeatureType featureType = addChangeTypeAttribute(database.getFeatureType(metadataId));
    final RevFeatureType revFeatureType = RevFeatureTypeImpl.build(featureType);
    final SimpleFeatureBuilder featureBuilder = new SimpleFeatureBuilder(featureType);

    Function<DiffEntry, SimpleFeature> asFeature = new Function<DiffEntry, SimpleFeature>() {

        @Override//  www.jav  a  2s  . c  o  m
        @Nullable
        public SimpleFeature apply(final DiffEntry input) {
            NodeRef nodeRef = old ? input.getOldObject() : input.getNewObject();
            if (nodeRef == null) {
                return null;
            }
            final RevFeature revFeature = database.getFeature(nodeRef.objectId());
            ImmutableList<Optional<Object>> values = revFeature.getValues();
            for (int i = 0; i < values.size(); i++) {
                String name = featureType.getDescriptor(i + 1).getLocalName();
                Object value = values.get(i).orNull();
                featureBuilder.set(name, value);
            }
            featureBuilder.set(CHANGE_TYPE_NAME, input.changeType().name().charAt(0));
            Feature feature = featureBuilder.buildFeature(nodeRef.name());
            feature.getUserData().put(Hints.USE_PROVIDED_FID, true);
            feature.getUserData().put(RevFeature.class, revFeature);
            feature.getUserData().put(RevFeatureType.class, revFeatureType);

            if (feature instanceof SimpleFeature) {
                return (SimpleFeature) feature;
            }
            return null;
        }

    };

    Iterator<SimpleFeature> asFeatures = Iterators.transform(diffs, asFeature);

    UnmodifiableIterator<SimpleFeature> filterNulls = Iterators.filter(asFeatures, Predicates.notNull());

    return filterNulls;
}

From source file:com.github.rinde.opt.localsearch.Swaps.java

static <C, T> Iterator<Swap<T>> swapIterator(Schedule<C, T> schedule) {
    final ImmutableList.Builder<Iterator<Swap<T>>> iteratorBuilder = ImmutableList.builder();
    final Set<T> seen = newLinkedHashSet();
    for (int i = 0; i < schedule.routes.size(); i++) {
        final ImmutableList<T> row = schedule.routes.get(i);
        for (int j = 0; j < row.size(); j++) {
            final T t = row.get(j);
            if (j >= schedule.startIndices.getInt(i) && !seen.contains(t)) {
                iteratorBuilder.add(oneItemSwapIterator(schedule, schedule.startIndices, t, i));
            }//www  . ja  va  2s.  co  m
            seen.add(t);
        }
    }
    return Iterators.concat(iteratorBuilder.build().iterator());
}