Example usage for com.google.common.base Predicates not

List of usage examples for com.google.common.base Predicates not

Introduction

In this page you can find the example usage for com.google.common.base Predicates not.

Prototype

public static <T> Predicate<T> not(Predicate<T> predicate) 

Source Link

Document

Returns a predicate that evaluates to true if the given predicate evaluates to false .

Usage

From source file:eu.interedition.text.event.AnnotationEventSource.java

public void listen(final AnnotationEventListener listener, final int pageSize, final Text text,
        final Criterion criterion, final Set<Name> dataSet) throws IOException {
    textRepository.read(text, new TextConsumer() {

        public void read(Reader content, long contentLength) throws IOException {
            final SortedMap<Long, Set<Annotation>> starts = Maps.newTreeMap();
            final SortedMap<Long, Set<Annotation>> ends = Maps.newTreeMap();

            long offset = 0;
            long next = 0;
            long pageEnd = 0;

            listener.start();/*from  w w w  . j  a va 2  s . c  o  m*/

            final Set<Annotation> annotationData = Sets.newHashSet();
            while (true) {
                if ((offset % pageSize) == 0) {
                    pageEnd = Math.min(offset + pageSize, contentLength);
                    final Range pageRange = new Range(offset, pageEnd);
                    final Iterable<Annotation> pageAnnotations = annotationRepository
                            .find(and(criterion, text(text), rangeOverlap(pageRange)), dataSet);
                    for (Annotation a : pageAnnotations) {
                        final long start = a.getRange().getStart();
                        final long end = a.getRange().getEnd();
                        if (start >= offset) {
                            Set<Annotation> starting = starts.get(start);
                            if (starting == null) {
                                starts.put(start, starting = Sets.newHashSet());
                            }
                            starting.add(a);
                            annotationData.add(a);
                        }
                        if (end <= pageEnd) {
                            Set<Annotation> ending = ends.get(end);
                            if (ending == null) {
                                ends.put(end, ending = Sets.newHashSet());
                            }
                            ending.add(a);
                            annotationData.add(a);
                        }
                    }

                    next = Math.min(starts.isEmpty() ? contentLength : starts.firstKey(),
                            ends.isEmpty() ? contentLength : ends.firstKey());
                }

                if (offset == next) {
                    final Set<Annotation> startEvents = (!starts.isEmpty() && offset == starts.firstKey()
                            ? starts.remove(starts.firstKey())
                            : Sets.<Annotation>newHashSet());
                    final Set<Annotation> endEvents = (!ends.isEmpty() && offset == ends.firstKey()
                            ? ends.remove(ends.firstKey())
                            : Sets.<Annotation>newHashSet());

                    final Set<Annotation> terminating = Sets.filter(endEvents, Predicates.not(EMPTY));
                    if (!terminating.isEmpty())
                        listener.end(offset, filter(annotationData, terminating, true));

                    final Set<Annotation> empty = Sets.filter(startEvents, EMPTY);
                    if (!empty.isEmpty())
                        listener.empty(offset, filter(annotationData, empty, true));

                    final Set<Annotation> starting = Sets.filter(startEvents, Predicates.not(EMPTY));
                    if (!starting.isEmpty())
                        listener.start(offset, filter(annotationData, starting, false));

                    next = Math.min(starts.isEmpty() ? contentLength : starts.firstKey(),
                            ends.isEmpty() ? contentLength : ends.firstKey());
                }

                if (offset == contentLength) {
                    break;
                }

                final long readTo = Math.min(pageEnd, next);
                if (offset < readTo) {
                    final char[] currentText = new char[(int) (readTo - offset)];
                    int read = content.read(currentText);
                    if (read > 0) {
                        listener.text(new Range(offset, offset + read), new String(currentText, 0, read));
                        offset += read;
                    }
                }
            }

            listener.end();
        }
    });
}

From source file:org.jclouds.abiquo.compute.functions.VirtualMachineToNodeMetadata.java

@Override
public NodeMetadata apply(final VirtualMachine vm) {
    NodeMetadataBuilder builder = new NodeMetadataBuilder();
    builder.ids(vm.getId().toString());/* w w  w .ja  v  a2s. co m*/
    builder.uri(vm.getURI());
    builder.name(vm.getNameLabel());
    builder.group(vm.getVirtualAppliance().getName());

    // TODO: Node credentials still not present in Abiquo template metadata
    // Will be added in Abiquo 2.4:
    // http://jira.abiquo.com/browse/ABICLOUDPREMIUM-3647

    // Location details
    VirtualDatacenter vdc = vm.getVirtualDatacenter();
    builder.location(virtualDatacenterToLocation.apply(vdc));

    // Image details
    VirtualMachineTemplate template = vm.getTemplate();
    Image image = virtualMachineTemplateToImage.apply(template);
    builder.imageId(image.getId().toString());
    builder.operatingSystem(image.getOperatingSystem());

    // Hardware details
    Hardware defaultHardware = virtualMachineTemplateToHardware
            .apply(new VirtualMachineTemplateInVirtualDatacenter(template, vdc));

    Hardware hardware = HardwareBuilder.fromHardware(defaultHardware).ram(vm.getRam())
            .processors(Lists.newArrayList(new Processor(vm.getCpu(),
                    VirtualMachineTemplateInVirtualDatacenterToHardware.DEFAULT_CORE_SPEED))) //
            .build();

    builder.hardware(hardware);

    // Networking configuration
    Iterable<Ip<?, ?>> nics = vm.listAttachedNics();
    builder.privateAddresses(ips(filter(nics, Predicates.instanceOf(PrivateIp.class))));
    builder.publicAddresses(ips(filter(nics, Predicates.not(Predicates.instanceOf(PrivateIp.class)))));

    // Node state
    VirtualMachineState state = vm.getState();
    builder.status(virtualMachineStateToNodeState.apply(state));
    builder.backendStatus(state.name());

    return builder.build();
}

From source file:org.sosy_lab.cpachecker.core.algorithm.counterexamplecheck.CounterexampleCheckAlgorithm.java

@Override
public AlgorithmStatus run(ReachedSet reached) throws CPAException, InterruptedException {
    AlgorithmStatus status = AlgorithmStatus.SOUND_AND_PRECISE;

    while (reached.hasWaitingState()) {
        status = status.update(algorithm.run(reached));
        assert ARGUtils.checkARG(reached);

        ARGState lastState = (ARGState) reached.getLastState();

        final List<ARGState> errorStates;
        if (lastState != null && lastState.isTarget()) {
            errorStates = checkedTargetStates.contains(lastState) ? ImmutableList.of()
                    : ImmutableList.of(lastState);
        } else {/*from  ww w  .j  a va 2  s .  co  m*/
            errorStates = from(reached).transform(AbstractStates.toState(ARGState.class))
                    .filter(AbstractStates.IS_TARGET_STATE)
                    .filter(Predicates.not(Predicates.in(checkedTargetStates))).toList();
        }

        if (errorStates.isEmpty()) {
            // no errors, so no analysis necessary
            break;
        }

        // check counterexample
        checkTime.start();
        try {
            List<ARGState> infeasibleErrorPaths = new ArrayList<>();
            boolean foundCounterexample = false;

            for (ARGState errorState : errorStates) {
                boolean counterexampleProvedFeasible = checkCounterexample(errorState, reached);
                if (counterexampleProvedFeasible) {
                    checkedTargetStates.add(errorState);
                    foundCounterexample = true;
                    status = status.withPrecise(true);
                } else {
                    infeasibleErrorPaths.add(errorState);
                    status = status.withSound(false);
                }
            }

            if (foundCounterexample) {
                break;
            } else {
                assert !infeasibleErrorPaths.isEmpty();
                throw new InfeasibleCounterexampleException(
                        "Error path found, but identified as infeasible by counterexample check with "
                                + checkerType + ".",
                        from(infeasibleErrorPaths).transform(ARGUtils::getOnePathTo).toList());
            }
        } finally {
            checkTime.stop();
        }
    }
    return status;
}

From source file:org.splevo.refactoring.FullyAutomatedVariabilityRefactoring.java

/**
 * Register a multi to one replacement. This means that multiple elements are replaced by a
 * single one. If the replacement is contained in the originals, the corresponding entry will be
 * ignored./*from  w  ww.j a v  a 2 s. co  m*/
 * 
 * @param originals
 *            The element that have been replaced.
 * @param replacement
 *            The element that replaced the originals.
 */
protected void registerReplacement(Iterable<? extends EObject> originals, EObject replacement) {
    Iterable<? extends EObject> filteredOriginals = Iterables.filter(originals,
            Predicates.not(Predicates.equalTo(replacement)));
    for (EObject original : filteredOriginals) {
        registerReplacement(original, replacement);
    }
}

From source file:tile80.tile80.Tile80.java

/**
 * mutator return a modified copy//w w w .ja  v  a2s  .  co m
 * @param tag the tag to remove
 * @return  new version of the object
 */
public Tile80 removeTag(String tag) {
    return new Tile80Eager(getPos(), getId(),
            FluentIterable.from(getTags()).filter(Predicates.not(Predicates.equalTo(tag))).toSet(),
            getBehavior(), getKeyspace());
}

From source file:com.google.template.soy.types.aggregate.UnionType.java

/** Returns a Soy type that is equivalent to this one but with 'null' removed. */
public SoyType removeNullability() {
    if (isNullable()) {
        return of(Collections2.filter(members, Predicates.not(IS_NULL)));
    }/* www.j  av  a  2s. c o  m*/
    return this;
}

From source file:org.eclipse.sirius.diagram.sequence.business.internal.ordering.RefreshOrderingHelper.java

private static void minimizeEventEnds(List<EventEnd> result,
        Multimap<EObject, SingleEventEnd> semanticEndToSingleEventEnds) {
    for (EObject semanticEnd : semanticEndToSingleEventEnds.keySet()) {
        Collection<SingleEventEnd> sees = semanticEndToSingleEventEnds.get(semanticEnd);
        if (sees.isEmpty()) {
            continue;
        }//www .  jav  a  2  s  .  c  o m

        if (sees.size() == 1) {
            result.add(sees.iterator().next());
        } else {
            CompoundEventEnd cee = OrderingFactory.eINSTANCE.createCompoundEventEnd();
            cee.setSemanticEnd(semanticEnd);

            if (sees.size() == 2 && RefreshOrderingHelper.countEvents(sees) == 1) {
                // start first
                Iterables.addAll(cee.getEventEnds(), Iterables.filter(sees, EventEndHelper.IS_START));
                Iterables.addAll(cee.getEventEnds(),
                        Iterables.filter(sees, Predicates.not(EventEndHelper.IS_START)));
            } else {
                // end first
                Iterables.addAll(cee.getEventEnds(),
                        Iterables.filter(sees, Predicates.not(EventEndHelper.IS_START)));
                Iterables.addAll(cee.getEventEnds(), Iterables.filter(sees, EventEndHelper.IS_START));
            }
            result.add(cee);
        }
    }
}

From source file:org.eclipse.viatra.query.tooling.ui.queryexplorer.util.QueryExplorerPatternRegistry.java

/**
 * Unregisters the given pattern from the registry.
 *
 * @param specification/*  ww  w  .  jav  a 2  s . c o  m*/
 *            the pattern instance to be unregistered
 */
public List<IQuerySpecification<?>> unregisterPattern(IQuerySpecification<?> specification) {
    List<IQuerySpecification<?>> removedSpecifications = Lists.newArrayList();
    removedSpecifications.add(specification);
    patternNameMap.remove(specification.getFullyQualifiedName());
    Set<IQuerySpecification<?>> forgottenSpecifications = builder
            .forgetSpecificationTransitively(specification);
    for (IQuerySpecification<?> other : Iterables.filter(forgottenSpecifications,
            Predicates.not(Predicates.<IQuerySpecification<?>>equalTo(specification)))) {
        removedSpecifications.addAll(unregisterPattern(other));
    }
    return removedSpecifications;
}

From source file:de.iteratec.iteraplan.elasticeam.operator.filter.predicate.FilterPredicates.java

/**
 * Creates an AND/OR/NOT predicate./*w  w  w.j  a v a 2 s. co  m*/
 * 
 * @param operation
 *    The operation of choice.
 * @param subPredicates
 *    A list with sub-predicates. In case of NOT, the list should contain only one element.
 * @return
 *    The compiled predicate which can later be used to evaluate universal model expressions.
 */
public static Predicate<UniversalModelExpression> buildCompositePredicate(
        final CompositePredicateOperation operation,
        final List<Predicate<UniversalModelExpression>> subPredicates) {
    return new Predicate<UniversalModelExpression>() {
        public boolean apply(UniversalModelExpression modelExpression) {
            if (operation.equals(CompositePredicateOperation.AND)) {
                return Predicates.and(subPredicates).apply(modelExpression);
            } else if (operation.equals(CompositePredicateOperation.OR)) {
                return Predicates.or(subPredicates).apply(modelExpression);
            } else {
                return Predicates.not(subPredicates.get(0)).apply(modelExpression);
            }
        }

        public String toString() {
            return operation.getValue() + "(" + subPredicates + ")";
        }

        @SuppressWarnings("unused")
        @ConfigParameter
        public CompositePredicateOperation getOperation() {
            return operation;
        }

        @SuppressWarnings("unused")
        @ConfigParameter
        public List<Predicate<UniversalModelExpression>> getSubPredicates() {
            return Collections.unmodifiableList(subPredicates);
        }
    };
}

From source file:org.simmetrics.example.StringDistanceBuilderExample.java

/**
 * Tokens can be filtered to avoid comparing strings on common but otherwise
 * low information words. Tokens can be filtered after any tokenization step
 * and filters can be applied repeatedly.
 * /*from  w w  w .j av  a  2s.com*/
 * A filter can be implemented by implementing a the {@link Predicate}
 * interface. By chaining predicates more complicated filters can be build.
 * */
public static float example05() {
    Set<String> commonWords = Sets.newHashSet("it", "is");
    Set<String> otherCommonWords = Sets.newHashSet("a");

    String a = "A quirky thing it is. This is a sentence.";
    String b = "This sentence is similar; a quirky thing it is.";

    StringDistance metric = with(new EuclideanDistance<String>()).simplify(Simplifiers.toLowerCase())
            .simplify(Simplifiers.removeNonWord()).tokenize(Tokenizers.whitespace())
            .filter(Predicates.not(in(commonWords))).filter(Predicates.not(in(otherCommonWords)))
            .tokenize(Tokenizers.qGram(3)).build();

    return metric.distance(a, b); // 4.6904
}