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:org.elasticsearch.repositories.blobstore.BlobStoreRepository.java

/**
 * {@inheritDoc}//from   w  w w . j  av a 2s.  c  o m
 */
@Override
public Snapshot finalizeSnapshot(SnapshotId snapshotId, String failure, int totalShards,
        ImmutableList<SnapshotShardFailure> shardFailures) {
    BlobStoreSnapshot snapshot = (BlobStoreSnapshot) readSnapshot(snapshotId);
    if (snapshot == null) {
        throw new SnapshotMissingException(snapshotId);
    }
    if (snapshot.state().completed()) {
        throw new SnapshotException(snapshotId, "snapshot is already closed");
    }
    try {
        String blobName = snapshotBlobName(snapshotId);
        BlobStoreSnapshot.Builder updatedSnapshot = BlobStoreSnapshot.builder().snapshot(snapshot);
        if (failure == null) {
            if (shardFailures.isEmpty()) {
                updatedSnapshot.success();
            } else {
                updatedSnapshot.partial();
            }
            updatedSnapshot.failures(totalShards, shardFailures);
        } else {
            updatedSnapshot.failed(failure);
        }
        updatedSnapshot.endTime(System.currentTimeMillis());
        snapshot = updatedSnapshot.build();
        BytesStreamOutput bStream = writeSnapshot(snapshot);
        BytesReference bRef = bStream.bytes();
        snapshotsBlobContainer.writeBlob(blobName, bRef.streamInput(), bRef.length());
        ImmutableList<SnapshotId> snapshotIds = snapshots();
        if (!snapshotIds.contains(snapshotId)) {
            snapshotIds = ImmutableList.<SnapshotId>builder().addAll(snapshotIds).add(snapshotId).build();
        }
        writeSnapshotList(snapshotIds);
        return snapshot;
    } catch (IOException ex) {
        throw new RepositoryException(this.repositoryName, "failed to update snapshot in repository", ex);
    }
}

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

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

    List<FeatureInfo> removed = patch.getRemovedFeatures();
    for (FeatureInfo feature : removed) {
        workTree.delete(NodeRef.parentPath(feature.getPath()), NodeRef.nodeFromPath(feature.getPath()));
    }
    List<FeatureInfo> added = patch.getAddedFeatures();
    for (FeatureInfo feature : added) {
        workTree.insert(NodeRef.parentPath(feature.getPath()), feature.getFeature());
    }
    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<Optional<Object>> values = feature.getValues();
        ImmutableList<PropertyDescriptor> oldDescriptors = oldRevFeatureType.sortedDescriptors();
        ImmutableList<PropertyDescriptor> newDescriptors = newRevFeatureType.sortedDescriptors();
        SimpleFeatureBuilder featureBuilder = new SimpleFeatureBuilder(
                (SimpleFeatureType) newRevFeatureType.type());
        Map<Name, Optional<?>> attrs = Maps.newHashMap();
        for (int i = 0; i < oldDescriptors.size(); i++) {
            PropertyDescriptor descriptor = oldDescriptors.get(i);
            if (newDescriptors.contains(descriptor)) {
                Optional<Object> value = values.get(i);
                attrs.put(descriptor.getName(), value);
            }
        }
        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)) {
                Optional<?> oldValue = attrs.get(entry.getKey().getName());
                attrs.put(entry.getKey().getName(), entry.getValue().applyOn(oldValue));
            }
        }
        Set<Entry<Name, Optional<?>>> entries = attrs.entrySet();
        for (Iterator<Entry<Name, Optional<?>>> iterator = entries.iterator(); iterator.hasNext();) {
            Entry<Name, Optional<?>> entry = iterator.next();
            featureBuilder.set(entry.getKey(), entry.getValue().orNull());

        }

        SimpleFeature featureToInsert = featureBuilder.buildFeature(NodeRef.nodeFromPath(path));
        workTree.insert(NodeRef.parentPath(path), featureToInsert);

    }
    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:org.geogit.api.porcelain.ApplyPatchOp.java

private void applyPatch(Patch patch) {

    if (reverse) {
        patch = patch.reversed();/*  w ww .  j  a  v  a2s .c  o m*/
    }

    List<FeatureInfo> removed = patch.getRemovedFeatures();
    for (FeatureInfo feature : removed) {
        workTree.delete(NodeRef.parentPath(feature.getPath()), NodeRef.nodeFromPath(feature.getPath()));
    }
    List<FeatureInfo> added = patch.getAddedFeatures();
    for (FeatureInfo feature : added) {
        workTree.insert(NodeRef.parentPath(feature.getPath()), feature.getFeature());
    }
    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<Optional<Object>> values = feature.getValues();
        ImmutableList<PropertyDescriptor> oldDescriptors = oldRevFeatureType.sortedDescriptors();
        ImmutableList<PropertyDescriptor> newDescriptors = newRevFeatureType.sortedDescriptors();
        SimpleFeatureBuilder featureBuilder = new SimpleFeatureBuilder(
                (SimpleFeatureType) newRevFeatureType.type());
        Map<Name, Optional<?>> attrs = Maps.newHashMap();
        for (int i = 0; i < oldDescriptors.size(); i++) {
            PropertyDescriptor descriptor = oldDescriptors.get(i);
            if (newDescriptors.contains(descriptor)) {
                Optional<Object> value = values.get(i);
                attrs.put(descriptor.getName(), value);
            }
        }
        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)) {
                Optional<?> oldValue = attrs.get(entry.getKey().getName());
                attrs.put(entry.getKey().getName(), entry.getValue().applyOn(oldValue));
            }
        }
        Set<Entry<Name, Optional<?>>> entries = attrs.entrySet();
        for (Iterator<Entry<Name, Optional<?>>> iterator = entries.iterator(); iterator.hasNext();) {
            Entry<Name, Optional<?>> entry = iterator.next();
            featureBuilder.set(entry.getKey(), entry.getValue().orNull());

        }

        SimpleFeature featureToInsert = featureBuilder.buildFeature(NodeRef.nodeFromPath(path));
        workTree.insert(NodeRef.parentPath(path), featureToInsert);

    }
    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:org.locationtech.geogig.api.plumbing.diff.VerifyPatchOp.java

/**
 * Executes the verify command/*from  w  ww. jav a2s  .  c  o  m*/
 * 
 * @return the result of checking if the patch can be applied
 */
protected VerifyPatchResults _call() throws RuntimeException {
    Preconditions.checkArgument(patch != null, "No patch file provided");

    Patch patch = reverse ? this.patch.reversed() : this.patch;

    Patch toApply = new Patch();
    Patch toReject = new Patch();
    for (RevFeatureType ft : patch.getFeatureTypes()) {
        toApply.addFeatureType(ft);
        toReject.addFeatureType(ft);
    }
    String path;
    Optional<RevObject> obj;
    List<FeatureDiff> diffs = patch.getModifiedFeatures();
    for (FeatureDiff diff : diffs) {
        path = diff.getPath();
        String refSpec = Ref.WORK_HEAD + ":" + path;
        obj = command(RevObjectParse.class).setRefSpec(refSpec).call();
        if (!obj.isPresent()) {
            toReject.addModifiedFeature(diff);
            break;
        }
        RevFeature feature = (RevFeature) obj.get();
        DepthSearch depthSearch = new DepthSearch(objectDatabase());
        Optional<NodeRef> noderef = depthSearch.find(workingTree().getTree(), path);
        RevFeatureType featureType = command(RevObjectParse.class).setObjectId(noderef.get().getMetadataId())
                .call(RevFeatureType.class).get();
        ImmutableList<PropertyDescriptor> descriptors = featureType.sortedDescriptors();
        Set<Entry<PropertyDescriptor, AttributeDiff>> attrDiffs = diff.getDiffs().entrySet();
        boolean ok = true;
        for (Iterator<Entry<PropertyDescriptor, AttributeDiff>> iterator = attrDiffs.iterator(); iterator
                .hasNext();) {
            Entry<PropertyDescriptor, AttributeDiff> entry = iterator.next();
            AttributeDiff attrDiff = entry.getValue();
            PropertyDescriptor descriptor = entry.getKey();
            switch (attrDiff.getType()) {
            case ADDED:
                if (descriptors.contains(descriptor)) {
                    ok = false;
                }
                break;
            case REMOVED:
            case MODIFIED:
                if (!descriptors.contains(descriptor)) {
                    ok = false;
                    break;
                }
                for (int i = 0; i < descriptors.size(); i++) {
                    if (descriptors.get(i).equals(descriptor)) {
                        Optional<Object> value = feature.getValues().get(i);
                        if (!attrDiff.canBeAppliedOn(value)) {
                            ok = false;
                        }
                        break;
                    }
                }
            }
        }
        if (!ok) {
            toReject.addModifiedFeature(diff);
        } else {
            toApply.addModifiedFeature(diff);
        }
    }
    List<FeatureInfo> added = patch.getAddedFeatures();
    for (FeatureInfo feature : added) {
        String refSpec = Ref.WORK_HEAD + ":" + feature.getPath();
        obj = command(RevObjectParse.class).setRefSpec(refSpec).call();
        if (obj.isPresent()) {
            toReject.addAddedFeature(feature.getPath(), feature.getFeature(), feature.getFeatureType());
        } else {
            toApply.addAddedFeature(feature.getPath(), feature.getFeature(), feature.getFeatureType());
        }

    }
    List<FeatureInfo> removed = patch.getRemovedFeatures();
    for (FeatureInfo feature : removed) {
        String refSpec = Ref.WORK_HEAD + ":" + feature.getPath();
        obj = command(RevObjectParse.class).setRefSpec(refSpec).call();
        if (!obj.isPresent()) {
            toReject.addRemovedFeature(feature.getPath(), feature.getFeature(), feature.getFeatureType());
        } else {
            RevFeature revFeature = (RevFeature) obj.get();
            DepthSearch depthSearch = new DepthSearch(objectDatabase());
            Optional<NodeRef> noderef = depthSearch.find(workingTree().getTree(), feature.getPath());
            RevFeatureType revFeatureType = command(RevObjectParse.class)
                    .setObjectId(noderef.get().getMetadataId()).call(RevFeatureType.class).get();
            RevFeature patchRevFeature = RevFeatureBuilder.build(feature.getFeature());
            if (revFeature.equals(patchRevFeature) && revFeatureType.equals(feature.getFeatureType())) {
                toApply.addRemovedFeature(feature.getPath(), feature.getFeature(), feature.getFeatureType());
            } else {
                toReject.addRemovedFeature(feature.getPath(), feature.getFeature(), feature.getFeatureType());
            }
        }
    }
    ImmutableList<FeatureTypeDiff> alteredTrees = patch.getAlteredTrees();
    for (FeatureTypeDiff diff : alteredTrees) {
        DepthSearch depthSearch = new DepthSearch(objectDatabase());
        Optional<NodeRef> noderef = depthSearch.find(workingTree().getTree(), diff.getPath());
        ObjectId metadataId = noderef.isPresent() ? noderef.get().getMetadataId() : ObjectId.NULL;
        if (Objects.equal(metadataId, diff.getOldFeatureType())) {
            toApply.addAlteredTree(diff);
        } else {
            toReject.addAlteredTree(diff);
        }
    }

    return new VerifyPatchResults(toApply, toReject);

}

From source file:org.geogit.api.plumbing.diff.VerifyPatchOp.java

/**
 * Executes the verify command//from  w  w  w.  j  av  a  2 s  . co  m
 * 
 * @return the result of checking if the patch can be applied
 */
public VerifyPatchResults call() throws RuntimeException {
    Preconditions.checkArgument(patch != null, "No patch file provided");

    Patch patch = reverse ? this.patch.reversed() : this.patch;

    Patch toApply = new Patch();
    Patch toReject = new Patch();
    for (RevFeatureType ft : patch.getFeatureTypes()) {
        toApply.addFeatureType(ft);
        toReject.addFeatureType(ft);
    }
    String path;
    Optional<RevObject> obj;
    List<FeatureDiff> diffs = patch.getModifiedFeatures();
    for (FeatureDiff diff : diffs) {
        path = diff.getPath();
        String refSpec = Ref.WORK_HEAD + ":" + path;
        obj = command(RevObjectParse.class).setRefSpec(refSpec).call();
        if (!obj.isPresent()) {
            toReject.addModifiedFeature(diff);
            break;
        }
        RevFeature feature = (RevFeature) obj.get();
        DepthSearch depthSearch = new DepthSearch(getIndex().getDatabase());
        Optional<NodeRef> noderef = depthSearch.find(getWorkTree().getTree(), path);
        RevFeatureType featureType = command(RevObjectParse.class).setObjectId(noderef.get().getMetadataId())
                .call(RevFeatureType.class).get();
        ImmutableList<PropertyDescriptor> descriptors = featureType.sortedDescriptors();
        Set<Entry<PropertyDescriptor, AttributeDiff>> attrDiffs = diff.getDiffs().entrySet();
        boolean ok = true;
        for (Iterator<Entry<PropertyDescriptor, AttributeDiff>> iterator = attrDiffs.iterator(); iterator
                .hasNext();) {
            Entry<PropertyDescriptor, AttributeDiff> entry = iterator.next();
            AttributeDiff attrDiff = entry.getValue();
            PropertyDescriptor descriptor = entry.getKey();
            switch (attrDiff.getType()) {
            case ADDED:
                if (descriptors.contains(descriptor)) {
                    ok = false;
                }
                break;
            case REMOVED:
            case MODIFIED:
                if (!descriptors.contains(descriptor)) {
                    ok = false;
                    break;
                }
                for (int i = 0; i < descriptors.size(); i++) {
                    if (descriptors.get(i).equals(descriptor)) {
                        Optional<Object> value = feature.getValues().get(i);
                        if (!attrDiff.canBeAppliedOn(value)) {
                            ok = false;
                        }
                        break;
                    }
                }
            }
        }
        if (!ok) {
            toReject.addModifiedFeature(diff);
        } else {
            toApply.addModifiedFeature(diff);
        }
    }
    List<FeatureInfo> added = patch.getAddedFeatures();
    for (FeatureInfo feature : added) {
        String refSpec = Ref.WORK_HEAD + ":" + feature.getPath();
        obj = command(RevObjectParse.class).setRefSpec(refSpec).call();
        if (obj.isPresent()) {
            toReject.addAddedFeature(feature.getPath(), feature.getFeature(), feature.getFeatureType());
        } else {
            toApply.addAddedFeature(feature.getPath(), feature.getFeature(), feature.getFeatureType());
        }

    }
    List<FeatureInfo> removed = patch.getRemovedFeatures();
    for (FeatureInfo feature : removed) {
        String refSpec = Ref.WORK_HEAD + ":" + feature.getPath();
        obj = command(RevObjectParse.class).setRefSpec(refSpec).call();
        if (!obj.isPresent()) {
            toReject.addRemovedFeature(feature.getPath(), feature.getFeature(), feature.getFeatureType());
        } else {
            RevFeature revFeature = (RevFeature) obj.get();
            DepthSearch depthSearch = new DepthSearch(getIndex().getDatabase());
            Optional<NodeRef> noderef = depthSearch.find(getWorkTree().getTree(), feature.getPath());
            RevFeatureType revFeatureType = command(RevObjectParse.class)
                    .setObjectId(noderef.get().getMetadataId()).call(RevFeatureType.class).get();
            RevFeature patchRevFeature = new RevFeatureBuilder().build(feature.getFeature());
            if (revFeature.equals(patchRevFeature) && revFeatureType.equals(feature.getFeatureType())) {
                toApply.addRemovedFeature(feature.getPath(), feature.getFeature(), feature.getFeatureType());
            } else {
                toReject.addRemovedFeature(feature.getPath(), feature.getFeature(), feature.getFeatureType());
            }
        }
    }
    ImmutableList<FeatureTypeDiff> alteredTrees = patch.getAlteredTrees();
    for (FeatureTypeDiff diff : alteredTrees) {
        DepthSearch depthSearch = new DepthSearch(getIndex().getDatabase());
        Optional<NodeRef> noderef = depthSearch.find(getWorkTree().getTree(), diff.getPath());
        ObjectId metadataId = noderef.isPresent() ? noderef.get().getMetadataId() : ObjectId.NULL;
        if (Objects.equal(metadataId, diff.getOldFeatureType())) {
            toApply.addAlteredTree(diff);
        } else {
            toReject.addAlteredTree(diff);
        }
    }

    return new VerifyPatchResults(toApply, toReject);

}

From source file:org.locationtech.geogig.plumbing.diff.VerifyPatchOp.java

/**
 * Executes the verify command//from w ww  .  java2  s.c o  m
 * 
 * @return the result of checking if the patch can be applied
 */
protected VerifyPatchResults _call() throws RuntimeException {
    Preconditions.checkArgument(patch != null, "No patch file provided");

    Patch patch = reverse ? this.patch.reversed() : this.patch;

    Map<ObjectId, RevFeatureType> typeCache = patch.featureTypes();

    Patch toApply = new Patch(typeCache);
    Patch toReject = new Patch(typeCache);

    String path;
    Optional<RevObject> obj;
    List<FeatureDiff> diffs = patch.getModifiedFeatures();
    for (FeatureDiff diff : diffs) {
        path = diff.getPath();
        String refSpec = Ref.WORK_HEAD + ":" + path;
        obj = command(RevObjectParse.class).setRefSpec(refSpec).call();
        if (!obj.isPresent()) {
            toReject.addModifiedFeature(diff);
            break;
        }
        RevFeature feature = (RevFeature) obj.get();
        DepthSearch depthSearch = new DepthSearch(objectDatabase());
        Optional<NodeRef> noderef = depthSearch.find(workingTree().getTree(), path);
        RevFeatureType featureType = command(RevObjectParse.class).setObjectId(noderef.get().getMetadataId())
                .call(RevFeatureType.class).get();
        ImmutableList<PropertyDescriptor> descriptors = featureType.descriptors();
        Set<Entry<PropertyDescriptor, AttributeDiff>> attrDiffs = diff.getDiffs().entrySet();
        boolean ok = true;
        for (Iterator<Entry<PropertyDescriptor, AttributeDiff>> iterator = attrDiffs.iterator(); iterator
                .hasNext();) {
            Entry<PropertyDescriptor, AttributeDiff> entry = iterator.next();
            AttributeDiff attrDiff = entry.getValue();
            PropertyDescriptor descriptor = entry.getKey();
            switch (attrDiff.getType()) {
            case ADDED:
                if (descriptors.contains(descriptor)) {
                    ok = false;
                }
                break;
            case REMOVED:
            case MODIFIED:
                if (!descriptors.contains(descriptor)) {
                    ok = false;
                    break;
                }
                for (int i = 0; i < descriptors.size(); i++) {
                    if (descriptors.get(i).equals(descriptor)) {
                        Optional<Object> value = feature.get(i);
                        if (!attrDiff.canBeAppliedOn(value.orNull())) {
                            ok = false;
                        }
                        break;
                    }
                }
            case NO_CHANGE:
                break;// nothing to do
            }
        }
        if (!ok) {
            toReject.addModifiedFeature(diff);
        } else {
            toApply.addModifiedFeature(diff);
        }
    }
    List<FeatureInfo> added = patch.getAddedFeatures();
    for (FeatureInfo feature : added) {
        String refSpec = Ref.WORK_HEAD + ":" + feature.getPath();
        obj = command(RevObjectParse.class).setRefSpec(refSpec).call();
        if (obj.isPresent()) {
            toReject.addAddedFeature(feature.getPath(), feature.getFeature(),
                    getType(feature.getFeatureTypeId(), typeCache));
        } else {
            toApply.addAddedFeature(feature.getPath(), feature.getFeature(),
                    getType(feature.getFeatureTypeId(), typeCache));
        }

    }
    List<FeatureInfo> removed = patch.getRemovedFeatures();
    for (FeatureInfo feature : removed) {
        String refSpec = Ref.WORK_HEAD + ":" + feature.getPath();
        obj = command(RevObjectParse.class).setRefSpec(refSpec).call();
        if (!obj.isPresent()) {
            toReject.addRemovedFeature(feature.getPath(), feature.getFeature(),
                    getType(feature.getFeatureTypeId(), typeCache));
        } else {
            RevFeature revFeature = (RevFeature) obj.get();
            DepthSearch depthSearch = new DepthSearch(objectDatabase());
            Optional<NodeRef> noderef = depthSearch.find(workingTree().getTree(), feature.getPath());
            ObjectId revFeatureTypeId = noderef.get().getMetadataId();
            RevFeature patchRevFeature = feature.getFeature();
            if (revFeature.equals(patchRevFeature) && revFeatureTypeId.equals(feature.getFeatureTypeId())) {
                toApply.addRemovedFeature(feature.getPath(), feature.getFeature(),
                        getType(feature.getFeatureTypeId(), typeCache));
            } else {
                toReject.addRemovedFeature(feature.getPath(), feature.getFeature(),
                        getType(feature.getFeatureTypeId(), typeCache));
            }
        }
    }
    ImmutableList<FeatureTypeDiff> alteredTrees = patch.getAlteredTrees();
    for (FeatureTypeDiff diff : alteredTrees) {
        DepthSearch depthSearch = new DepthSearch(objectDatabase());
        Optional<NodeRef> noderef = depthSearch.find(workingTree().getTree(), diff.getPath());
        ObjectId metadataId = noderef.isPresent() ? noderef.get().getMetadataId() : ObjectId.NULL;
        if (Objects.equal(metadataId, diff.getOldFeatureType())) {
            toApply.addAlteredTree(diff);
        } else {
            toReject.addAlteredTree(diff);
        }
    }

    return new VerifyPatchResults(toApply, toReject);

}

From source file:com.google.javascript.jscomp.newtypes.JSTypeCreatorFromJSDoc.java

private JSType lookupTypeByName(String name, Node n, DeclaredTypeRegistry registry,
        ImmutableList<String> outerTypeParameters) throws UnknownTypeException {
    if (outerTypeParameters.contains(name)) {
        return JSType.fromTypeVar(name);
    }/*from www .j av a2s  .c  o m*/
    Declaration decl = registry.getDeclaration(QualifiedName.fromQualifiedString(name), true);
    if (decl == null) {
        unknownTypeNames.put(n, name);
        throw new UnknownTypeException("Unhandled type: " + name);
    }
    // It's either a typedef, an enum, a type variable or a nominal type
    if (decl.getTypedef() != null) {
        return getTypedefType(decl.getTypedef(), registry);
    }
    if (decl.getEnum() != null) {
        return getEnumPropType(decl.getEnum(), registry);
    }
    if (decl.isTypeVar()) {
        howmanyTypeVars++;
        return decl.getTypeOfSimpleDecl();
    }
    if (decl.getNominal() != null) {
        return getNominalTypeHelper(decl.getNominal(), n, registry, outerTypeParameters);
    }
    return JSType.UNKNOWN;
}

From source file:com.amazonaws.services.kinesis.stormspout.state.zookeeper.ZookeeperStateManager.java

private void updateLocalState(ImmutableList<String> shardAssignment) {
    // first initialization of shardStates
    if (shardStates == null) {
        shardStates = new HashMap<>();
    }/*  ww  w.jav a 2 s  .co  m*/
    // remove shard state that we're not longer responsible for
    Iterator<Entry<String, LocalShardState>> iter = shardStates.entrySet().iterator();
    while (iter.hasNext()) {
        Entry<String, LocalShardState> entry = iter.next();
        final String shardId = entry.getKey();
        if (!shardAssignment.contains(shardId)) {
            LOG.info(this + " removing stale shard state for shard " + shardId);
            iter.remove();
        }
    }

    for (final String shardId : shardAssignment) {
        // first check for pre-existing shard state...
        if (shardStates.containsKey(shardId)) {
            final LocalShardState st = shardStates.get(shardId);
            LOG.info(this + " keeping existing shard state for shard " + shardId
                    + " with earliest inflight seqnum " + st.getEarliestInflightRecord());
            continue;
        }
        // otherwise fallback to zk committed shard state
        String latestValidSeqNum;
        try {
            latestValidSeqNum = zk.getLastCommittedSeqNum(shardId);
            LOG.info(this + " fell back to zk record with seqnum (" + latestValidSeqNum + ") for shard "
                    + shardId);
        } catch (Exception e) {
            latestValidSeqNum = "";
            LOG.error(this + " could not retrieve last committed seqnum for " + shardId
                    + " from ZooKeeper. Starting from default getter position.");
        }
        shardStates.put(shardId, new LocalShardState(shardId, latestValidSeqNum, config.getRecordRetryLimit()));
    }
}

From source file:com.google.devtools.build.lib.rules.cpp.FeatureSelection.java

/**
 * @return a {@link FeatureConfiguration} that reflects the set of activated features and action
 *     configs./* w  w w  .j av a 2s  . co  m*/
 */
FeatureConfiguration run() throws CollidingProvidesException {
    for (CrosstoolSelectable selectable : requestedSelectables) {
        enableAllImpliedBy(selectable);
    }

    disableUnsupportedActivatables();
    ImmutableList.Builder<CrosstoolSelectable> enabledActivatablesInOrderBuilder = ImmutableList.builder();
    for (CrosstoolSelectable selectable : selectables) {
        if (enabled.contains(selectable)) {
            enabledActivatablesInOrderBuilder.add(selectable);
        }
    }

    ImmutableList<CrosstoolSelectable> enabledActivatablesInOrder = enabledActivatablesInOrderBuilder.build();
    ImmutableList<Feature> enabledFeaturesInOrder = enabledActivatablesInOrder.stream()
            .filter(a -> a instanceof Feature).map(f -> (Feature) f).collect(ImmutableList.toImmutableList());
    Iterable<ActionConfig> enabledActionConfigsInOrder = Iterables.filter(enabledActivatablesInOrder,
            ActionConfig.class);

    for (String provided : provides.keys()) {
        List<String> conflicts = new ArrayList<>();
        for (CrosstoolSelectable selectableProvidingString : provides.get(provided)) {
            if (enabledActivatablesInOrder.contains(selectableProvidingString)) {
                conflicts.add(selectableProvidingString.getName());
            }
        }

        if (conflicts.size() > 1) {
            throw new CollidingProvidesException(String.format(CcToolchainFeatures.COLLIDING_PROVIDES_ERROR,
                    provided, Joiner.on(" ").join(conflicts)));
        }
    }

    ImmutableSet.Builder<String> enabledActionConfigNames = ImmutableSet.builder();
    for (ActionConfig actionConfig : enabledActionConfigsInOrder) {
        enabledActionConfigNames.add(actionConfig.getActionName());
    }

    return new FeatureConfiguration(enabledFeaturesInOrder, enabledActionConfigNames.build(),
            actionConfigsByActionName);
}

From source file:com.android.tools.idea.editors.theme.ThemesListModel.java

/**
 * Updates the themes list reloading all the themes from the resolver
 *///  ww  w.j  ava 2s  . c o m
private void updateThemes() {
    // We sort the themes, displaying the local project themes at the top sorted alphabetically. The non local themes are sorted
    // alphabetically right below the project themes.
    ImmutableList<String> editableThemes = ThemeEditorUtils
            .getModuleThemeQualifiedNamesList(myContext.getCurrentContextModule());

    ImmutableList.Builder<String> availableThemesListBuilder = ImmutableList.builder();
    ImmutableList.Builder<String> disabledThemesListBuilder = ImmutableList.builder();
    ThemeResolver themeResolver = myContext.getThemeResolver();

    for (String themeName : editableThemes) {
        if (themeResolver.getTheme(themeName) != null) {
            availableThemesListBuilder.add(themeName);
        } else {
            disabledThemesListBuilder.add(themeName);
        }
    }

    myAvailableProjectThemes = availableThemesListBuilder.build();
    ImmutableList<String> disabledProjectThemes = disabledThemesListBuilder.build();

    String selectedItem = getSelectedItem();
    if (selectedItem == null) {
        if (myDefaultThemeName != null && (editableThemes.contains(myDefaultThemeName)
                || themeResolver.getTheme(myDefaultThemeName) != null)) {
            selectedItem = myDefaultThemeName;
        } else if (!editableThemes.isEmpty()) {
            selectedItem = editableThemes.get(0);
        } else if (!myDefaultThemeNames.isEmpty()) {
            selectedItem = myDefaultThemeNames.get(0);
        }
    }

    myEditOptions.clear();
    buildEditOptionsList(selectedItem);

    myAllItems = new SeparatedList(mySeparator, group(myAvailableProjectThemes), group(disabledProjectThemes),
            group(myDefaultThemeNames, SHOW_ALL_THEMES), group(myEditOptions));

    // Set the default selection to the first element.
    setSelectedItem(selectedItem);
}