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

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

Introduction

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

Prototype

boolean contains(Object o);

Source Link

Document

Returns true if this list contains the specified element.

Usage

From source file:google.registry.request.auth.RequestAuthenticator.java

/** Validates an Auth object, checking for invalid setting combinations. */
void checkAuthConfig(Auth auth) {
    ImmutableList<Auth.AuthMethod> authMethods = ImmutableList.copyOf(auth.methods());
    checkArgument(!authMethods.isEmpty(), "Must specify at least one auth method");
    checkArgument(/* www  . j  ava 2  s  .co  m*/
            Ordering.explicit(Auth.AuthMethod.INTERNAL, Auth.AuthMethod.API, Auth.AuthMethod.LEGACY)
                    .isStrictlyOrdered(authMethods),
            "Auth methods must be unique and strictly in order - INTERNAL, API, LEGACY");
    checkArgument(authMethods.contains(Auth.AuthMethod.INTERNAL),
            "Auth method INTERNAL must always be specified, and as the first auth method");
    if (authMethods.equals(ImmutableList.of(Auth.AuthMethod.INTERNAL))) {
        checkArgument(!auth.minimumLevel().equals(AuthLevel.USER),
                "Actions with only INTERNAL auth may not require USER auth level");
    } else {
        checkArgument(!auth.userPolicy().equals(Auth.UserPolicy.IGNORED),
                "Actions with auth methods beyond INTERNAL must not specify the IGNORED user policy");
    }
}

From source file:fr.inria.linuxtools.ctf.core.event.EventDefinition.java

/**
 * Gets the context of this event within a stream
 *
 * @return the context in struct form/* www  . j  a  v a2s  .c o  m*/
 */
public StructDefinition getContext() {

    /* Most common case so far */
    if (fStreamContext == null) {
        return fEventContext;
    }

    /* streamContext is not null, but the context of the event is null */
    if (fEventContext == null) {
        return fStreamContext;
    }

    // TODO: cache if this is a performance issue

    /* The stream context and event context are assigned. */
    StructDeclaration mergedDeclaration = new StructDeclaration(1);

    Builder<String> builder = ImmutableList.<String>builder();
    List<Definition> fieldValues = new ArrayList<>();

    /* Add fields from the stream */
    for (String fieldName : fStreamContext.getFieldNames()) {
        Definition definition = fStreamContext.getDefinition(fieldName);
        mergedDeclaration.addField(fieldName, definition.getDeclaration());
        builder.add(fieldName);
        fieldValues.add(definition);
    }

    ImmutableList<String> fieldNames = builder.build();
    /*
     * Add fields from the event context, overwrite the stream ones if
     * needed.
     */
    for (String fieldName : fEventContext.getFieldNames()) {
        Definition definition = fEventContext.getDefinition(fieldName);
        mergedDeclaration.addField(fieldName, definition.getDeclaration());
        if (fieldNames.contains(fieldName)) {
            fieldValues.set((fieldNames.indexOf(fieldName)), definition);
        } else {
            builder.add(fieldName);
            fieldValues.add(definition);
        }
    }
    fieldNames = builder.build();
    StructDefinition mergedContext = new StructDefinition(mergedDeclaration, this, "context", //$NON-NLS-1$
            fieldNames, fieldValues.toArray(new Definition[fieldValues.size()]));
    return mergedContext;
}

From source file:retrofit.processor.EclipseHack.java

private void reorderProperties(TypeElement type, List<RetrofitProcessor.Property> properties) {
    PropertyOrderer propertyOrderer = getPropertyOrderer(type);
    if (propertyOrderer == null) {
        return;//from w  w w.j  av a2  s . co m
    }
    final ImmutableList<String> order;
    try {
        order = propertyOrderer.determinePropertyOrder();
    } catch (IOException e) {
        processingEnv.getMessager().printMessage(Diagnostic.Kind.NOTE, e.toString());
        return;
    }
    // We expect that all the properties will be found, but if not then we won't try reordering.
    boolean allFound = true;
    for (RetrofitProcessor.Property property : properties) {
        allFound &= order.contains(property.getGetter());
    }
    if (allFound) {
        // We successfully found the abstract methods corresponding to all the properties, so now
        // reorder the List<Property> to reflect the order of the methods.
        Comparator<RetrofitProcessor.Property> comparator = new Comparator<RetrofitProcessor.Property>() {
            @Override
            public int compare(RetrofitProcessor.Property a, RetrofitProcessor.Property b) {
                String aName = a.getGetter();
                String bName = b.getGetter();
                return order.indexOf(aName) - order.indexOf(bName);
            }
        };
        Collections.sort(properties, comparator);
    }
}

From source file:auto.json.processor.EclipseHack.java

private void reorderProperties(TypeElement type, List<AutoJsonProcessor.Property> properties) {
    PropertyOrderer propertyOrderer = getPropertyOrderer(type);
    if (propertyOrderer == null) {
        return;/*  ww  w  .jav  a2s.  c o m*/
    }
    final ImmutableList<String> order;
    try {
        order = propertyOrderer.determinePropertyOrder();
    } catch (IOException e) {
        processingEnv.getMessager().printMessage(Diagnostic.Kind.NOTE, e.toString());
        return;
    }
    // We expect that all the properties will be found, but if not then we won't try reordering.
    boolean allFound = true;
    for (AutoJsonProcessor.Property property : properties) {
        allFound &= order.contains(property.getGetter());
    }
    if (allFound) {
        // We successfully found the abstract methods corresponding to all the properties, so now
        // reorder the List<Property> to reflect the order of the methods.
        Comparator<AutoJsonProcessor.Property> comparator = new Comparator<AutoJsonProcessor.Property>() {
            @Override
            public int compare(AutoJsonProcessor.Property a, AutoJsonProcessor.Property b) {
                String aName = a.getGetter();
                String bName = b.getGetter();
                return order.indexOf(aName) - order.indexOf(bName);
            }
        };
        Collections.sort(properties, comparator);
    }
}

From source file:auto.cursor.processor.EclipseHack.java

private void reorderProperties(TypeElement type, List<AutoCursorProcessor.Property> properties) {
    PropertyOrderer propertyOrderer = getPropertyOrderer(type);
    if (propertyOrderer == null) {
        return;/* ww  w . j  a v a  2 s  .co  m*/
    }
    final ImmutableList<String> order;
    try {
        order = propertyOrderer.determinePropertyOrder();
    } catch (IOException e) {
        processingEnv.getMessager().printMessage(Diagnostic.Kind.NOTE, e.toString());
        return;
    }
    // We expect that all the properties will be found, but if not then we won't try reordering.
    boolean allFound = true;
    for (AutoCursorProcessor.Property property : properties) {
        allFound &= order.contains(property.getGetter());
    }
    if (allFound) {
        // We successfully found the abstract methods corresponding to all the properties, so now
        // reorder the List<Property> to reflect the order of the methods.
        Comparator<AutoCursorProcessor.Property> comparator = new Comparator<AutoCursorProcessor.Property>() {
            @Override
            public int compare(AutoCursorProcessor.Property a, AutoCursorProcessor.Property b) {
                String aName = a.getGetter();
                String bName = b.getGetter();
                return order.indexOf(aName) - order.indexOf(bName);
            }
        };
        Collections.sort(properties, comparator);
    }
}

From source file:auto.parcel.processor.EclipseHack.java

private void reorderProperties(TypeElement type, List<AutoParcelProcessor.Property> properties) {
    PropertyOrderer propertyOrderer = getPropertyOrderer(type);
    if (propertyOrderer == null) {
        return;//w  w  w .  ja v  a2  s .com
    }
    final ImmutableList<String> order;
    try {
        order = propertyOrderer.determinePropertyOrder();
    } catch (IOException e) {
        processingEnv.getMessager().printMessage(Diagnostic.Kind.NOTE, e.toString());
        return;
    }
    // We expect that all the properties will be found, but if not then we won't try reordering.
    boolean allFound = true;
    for (AutoParcelProcessor.Property property : properties) {
        allFound &= order.contains(property.getGetter());
    }
    if (allFound) {
        // We successfully found the abstract methods corresponding to all the properties, so now
        // reorder the List<Property> to reflect the order of the methods.
        Comparator<AutoParcelProcessor.Property> comparator = new Comparator<AutoParcelProcessor.Property>() {
            @Override
            public int compare(AutoParcelProcessor.Property a, AutoParcelProcessor.Property b) {
                String aName = a.getGetter();
                String bName = b.getGetter();
                return order.indexOf(aName) - order.indexOf(bName);
            }
        };
        Collections.sort(properties, comparator);
    }
}

From source file:retroweibo.processor.EclipseHack.java

private void reorderProperties(TypeElement type, List<RetroWeiboProcessor.Property> properties) {
    PropertyOrderer propertyOrderer = getPropertyOrderer(type);
    if (propertyOrderer == null) {
        return;/*w  ww.j a  v a2s . com*/
    }
    final ImmutableList<String> order;
    try {
        order = propertyOrderer.determinePropertyOrder();
    } catch (IOException e) {
        processingEnv.getMessager().printMessage(Diagnostic.Kind.NOTE, e.toString());
        return;
    }
    // We expect that all the properties will be found, but if not then we won't try reordering.
    boolean allFound = true;
    for (RetroWeiboProcessor.Property property : properties) {
        allFound &= order.contains(property.getGetter());
    }
    if (allFound) {
        // We successfully found the abstract methods corresponding to all the properties, so now
        // reorder the List<Property> to reflect the order of the methods.
        Comparator<RetroWeiboProcessor.Property> comparator = new Comparator<RetroWeiboProcessor.Property>() {
            @Override
            public int compare(RetroWeiboProcessor.Property a, RetroWeiboProcessor.Property b) {
                String aName = a.getGetter();
                String bName = b.getGetter();
                return order.indexOf(aName) - order.indexOf(bName);
            }
        };
        Collections.sort(properties, comparator);
    }
}

From source file:org.locationtech.geogig.porcelain.ApplyPatchOp.java

private void applyPatch(Patch patch) {
    final WorkingTree workTree = workingTree();
    final ObjectStore indexDb = objectDatabase();
    if (reverse) {
        patch = patch.reversed();//from  w ww. j  ava2  s .c  o  m
    }

    objectDatabase().putAll(patch.getFeatureTypes().iterator());

    List<FeatureInfo> removed = patch.getRemovedFeatures();
    for (FeatureInfo feature : removed) {
        workTree.delete(feature.getPath());
    }
    List<FeatureInfo> added = patch.getAddedFeatures();
    for (FeatureInfo feature : added) {
        workTree.insert(feature);
    }
    List<FeatureDiff> diffs = patch.getModifiedFeatures();
    for (FeatureDiff diff : diffs) {
        String path = diff.getPath();
        DepthSearch depthSearch = new DepthSearch(indexDb);
        Optional<NodeRef> noderef = depthSearch.find(workTree.getTree(), path);
        RevFeatureType oldRevFeatureType = command(RevObjectParse.class)
                .setObjectId(noderef.get().getMetadataId()).call(RevFeatureType.class).get();
        String refSpec = Ref.WORK_HEAD + ":" + path;
        RevFeature feature = command(RevObjectParse.class).setRefSpec(refSpec).call(RevFeature.class).get();

        RevFeatureType newRevFeatureType = getFeatureType(diff, feature, oldRevFeatureType);
        ImmutableList<PropertyDescriptor> oldDescriptors = oldRevFeatureType.descriptors();
        ImmutableList<PropertyDescriptor> newDescriptors = newRevFeatureType.descriptors();
        SimpleFeatureBuilder featureBuilder = new SimpleFeatureBuilder(
                (SimpleFeatureType) newRevFeatureType.type());
        Map<Name, Object> attrs = Maps.newHashMap();
        for (int i = 0; i < oldDescriptors.size(); i++) {
            PropertyDescriptor descriptor = oldDescriptors.get(i);
            if (newDescriptors.contains(descriptor)) {
                Optional<Object> value = feature.get(i);
                attrs.put(descriptor.getName(), value.orNull());
            }
        }
        Set<Entry<PropertyDescriptor, AttributeDiff>> featureDiffs = diff.getDiffs().entrySet();
        for (Iterator<Entry<PropertyDescriptor, AttributeDiff>> iterator = featureDiffs.iterator(); iterator
                .hasNext();) {
            Entry<PropertyDescriptor, AttributeDiff> entry = iterator.next();
            if (!entry.getValue().getType().equals(TYPE.REMOVED)) {
                Object oldValue = attrs.get(entry.getKey().getName());
                attrs.put(entry.getKey().getName(), entry.getValue().applyOn(oldValue));
            }
        }
        Set<Entry<Name, Object>> entries = attrs.entrySet();
        for (Iterator<Entry<Name, Object>> iterator = entries.iterator(); iterator.hasNext();) {
            Entry<Name, Object> entry = iterator.next();
            featureBuilder.set(entry.getKey(), entry.getValue());

        }

        SimpleFeature f = featureBuilder.buildFeature(NodeRef.nodeFromPath(path));
        RevFeature featureToInsert = RevFeatureBuilder.build(f);
        FeatureInfo featureInfo = FeatureInfo.insert(featureToInsert, newRevFeatureType.getId(), path);
        workTree.insert(featureInfo);

    }
    ImmutableList<FeatureTypeDiff> alteredTrees = patch.getAlteredTrees();
    for (FeatureTypeDiff diff : alteredTrees) {
        Optional<RevFeatureType> featureType;
        if (diff.getOldFeatureType().isNull()) {
            featureType = patch.getFeatureTypeFromId(diff.getNewFeatureType());
            workTree.createTypeTree(diff.getPath(), featureType.get().type());
        } else if (diff.getNewFeatureType().isNull()) {
            workTree.delete(diff.getPath());
        } else {
            featureType = patch.getFeatureTypeFromId(diff.getNewFeatureType());
            workTree.updateTypeTree(diff.getPath(), featureType.get().type());
        }
    }

}

From source file:retrofacebook.processor.EclipseHack.java

private void reorderProperties(TypeElement type, List<RetroFacebookProcessor.Property> properties) {
    PropertyOrderer propertyOrderer = getPropertyOrderer(type);
    if (propertyOrderer == null) {
        return;//from   ww  w  . j  ava  2s  .  c  o m
    }
    final ImmutableList<String> order;
    try {
        order = propertyOrderer.determinePropertyOrder();
    } catch (IOException e) {
        processingEnv.getMessager().printMessage(Diagnostic.Kind.NOTE, e.toString());
        return;
    }
    // We expect that all the properties will be found, but if not then we won't try reordering.
    boolean allFound = true;
    for (RetroFacebookProcessor.Property property : properties) {
        allFound &= order.contains(property.getGetter());
    }
    if (allFound) {
        // We successfully found the abstract methods corresponding to all the properties, so now
        // reorder the List<Property> to reflect the order of the methods.
        Comparator<RetroFacebookProcessor.Property> comparator = new Comparator<RetroFacebookProcessor.Property>() {
            @Override
            public int compare(RetroFacebookProcessor.Property a, RetroFacebookProcessor.Property b) {
                String aName = a.getGetter();
                String bName = b.getGetter();
                return order.indexOf(aName) - order.indexOf(bName);
            }
        };
        Collections.sort(properties, comparator);
    }
}

From source file:org.elasticsearch.repositories.blobstore.BlobStoreRepository.java

/**
 * {@inheritDoc}//from   w  w  w.  j av  a2s . c  o m
 */
@Override
public void deleteSnapshot(SnapshotId snapshotId) {
    Snapshot snapshot = readSnapshot(snapshotId);
    MetaData metaData = readSnapshotMetaData(snapshotId, snapshot.indices());
    try {
        String blobName = snapshotBlobName(snapshotId);
        // Delete snapshot file first so we wouldn't end up with partially deleted snapshot that looks OK
        snapshotsBlobContainer.deleteBlob(blobName);
        snapshotsBlobContainer.deleteBlob(metaDataBlobName(snapshotId));
        // Delete snapshot from the snapshot list
        ImmutableList<SnapshotId> snapshotIds = snapshots();
        if (snapshotIds.contains(snapshotId)) {
            ImmutableList.Builder<SnapshotId> builder = ImmutableList.builder();
            for (SnapshotId id : snapshotIds) {
                if (!snapshotId.equals(id)) {
                    builder.add(id);
                }
            }
            snapshotIds = builder.build();
        }
        writeSnapshotList(snapshotIds);
        // Now delete all indices
        for (String index : snapshot.indices()) {
            BlobPath indexPath = basePath().add("indices").add(index);
            ImmutableBlobContainer indexMetaDataBlobContainer = blobStore().immutableBlobContainer(indexPath);
            try {
                indexMetaDataBlobContainer.deleteBlob(blobName);
            } catch (IOException ex) {
                throw new SnapshotException(snapshotId, "failed to delete metadata", ex);
            }
            IndexMetaData indexMetaData = metaData.index(index);
            for (int i = 0; i < indexMetaData.getNumberOfShards(); i++) {
                indexShardRepository.delete(snapshotId, new ShardId(index, i));
            }
        }
    } catch (IOException ex) {
        throw new RepositoryException(this.repositoryName, "failed to update snapshot in repository", ex);
    }
}