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

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

Introduction

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

Prototype

public static <T> Predicate<T> or(Predicate<? super T> first, Predicate<? super T> second) 

Source Link

Document

Returns a predicate that evaluates to true if either of its components evaluates to true .

Usage

From source file:org.eclipse.sirius.table.business.internal.dialect.TableContributionsFinder.java

private Set<EObject> getAllRepresentations(Iterable<EObject> from) {
    Set<EObject> result = Sets.newHashSet();
    for (EObject eObject : from) {
        Iterables.addAll(result,/*  w w w  .j  a v a2s. co  m*/
                Iterables.filter(AllContents.of(eObject, true),
                        Predicates.or(Predicates.instanceOf(RepresentationDescription.class),
                                Predicates.instanceOf(RepresentationExtensionDescription.class))));
    }
    return result;
}

From source file:com.ardorcraft.control.FlyControl.java

public void setupMouseTriggers(final LogicalLayer layer, final boolean dragOnly) {
    final FlyControl control = this;
    // Mouse look
    final Predicate<TwoInputStates> someMouseDown = Predicates.or(TriggerConditions.leftButtonDown(),
            Predicates.or(TriggerConditions.rightButtonDown(), TriggerConditions.middleButtonDown()));
    final Predicate<TwoInputStates> dragged = Predicates.and(TriggerConditions.mouseMoved(), someMouseDown);
    final TriggerAction dragAction = new TriggerAction() {

        // Test boolean to allow us to ignore first mouse event. First event
        // can wildly vary based on platform.
        private boolean firstPing = true;

        @Override/* w w  w  .j  a  va  2  s.co  m*/
        public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) {
            final MouseState mouse = inputStates.getCurrent().getMouseState();
            if (mouse.getDx() != 0 || mouse.getDy() != 0) {
                if (!firstPing) {
                    control.rotate(-mouse.getDx(), -mouse.getDy());
                } else {
                    firstPing = false;
                }
            }
        }
    };

    _mouseTrigger = new InputTrigger(dragOnly ? dragged : TriggerConditions.mouseMoved(), dragAction);
    layer.registerTrigger(_mouseTrigger);
}

From source file:org.eclipse.sirius.ui.tools.internal.views.common.modelingproject.manager.ModelingProjectManagerImpl.java

private void loadAndOpenRepresentationsFiles(final List<URI> representationsFilesURIs, boolean user) {
    // Add the specific sessions listener (if not already added).
    SessionManager.INSTANCE.addSessionsListener(sessionManagerListener);

    // List only the representations files that are not already loaded or
    // that are not currently in loading.
    Iterator<URI> representationsFilesURIsToLoadIterator = Iterators.filter(representationsFilesURIs.iterator(),
            Predicates.not(Predicates.or(Predicates.in(sessionFileLoading), isAlreadyLoadedPredicate)));
    if (!representationsFilesURIsToLoadIterator.hasNext()) {
        return;//from   w w w  . ja v a 2s . co m
    }

    // We add the representationsFilesURIs to the list of representations
    // files that are currently loading because the event
    // SessionListener.OPENING comes too late (after loading of the
    // representations file that can be very long).
    List<URI> tempRepresentationsFilesURIs = Lists.newArrayList(representationsFilesURIsToLoadIterator);
    sessionFileLoading.addAll(tempRepresentationsFilesURIs);
    // Launch the silently job to open the representations files
    for (URI representationsFilesURI : tempRepresentationsFilesURIs) {
        OpenRepresentationsFileJob.scheduleNewWhenPossible(representationsFilesURI, user);
    }
}

From source file:com.ardorcraft.control.WalkControl.java

public void setupMouseTriggers(final LogicalLayer layer, final boolean dragOnly) {
    final WalkControl control = this;
    // Mouse look
    final Predicate<TwoInputStates> someMouseDown = Predicates.or(TriggerConditions.leftButtonDown(),
            Predicates.or(TriggerConditions.rightButtonDown(), TriggerConditions.middleButtonDown()));
    final Predicate<TwoInputStates> dragged = Predicates.and(TriggerConditions.mouseMoved(), someMouseDown);
    final TriggerAction dragAction = new TriggerAction() {

        // Test boolean to allow us to ignore first mouse event. First event
        // can wildly vary based on platform.
        private boolean firstPing = true;

        @Override//ww w.  jav a  2  s. com
        public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) {
            final MouseState mouse = inputStates.getCurrent().getMouseState();
            if (mouse.getDx() != 0 || mouse.getDy() != 0) {
                if (!firstPing) {
                    control.rotate(-mouse.getDx(), -mouse.getDy());
                } else {
                    firstPing = false;
                }
            }
        }
    };

    _mouseTrigger = new InputTrigger(dragOnly ? dragged : TriggerConditions.mouseMoved(), dragAction);
    layer.registerTrigger(_mouseTrigger);
}

From source file:com.takin.emmet.concurrent.retry.RetryerBuilder.java

/**
 * Configures the retryer to retry if an exception satisfying the given predicate is
 * thrown by the call./* w w  w  . jav a 2s  .c  o  m*/
 *
 * @param exceptionPredicate the predicate which causes a retry if satisfied
 * @return <code>this</code>
 */
public RetryerBuilder<V> retryIfException(@Nonnull Predicate<Throwable> exceptionPredicate) {
    Preconditions.checkNotNull(exceptionPredicate, "exceptionPredicate may not be null");
    rejectionPredicate = Predicates.or(rejectionPredicate, new ExceptionPredicate<V>(exceptionPredicate));
    return this;
}

From source file:net.sourceforge.cilib.algorithm.AbstractAlgorithm.java

/**
 * Adds a stopping condition.//from  ww  w.  ja  va  2s.c  o  m
 * @param stoppingCondition A {@link net.sourceforge.cilib.stoppingcondition.StoppingCondition}
 *        to be added.
 */
@Override
public final void addStoppingCondition(StoppingCondition<Algorithm> stoppingCondition) {
    stoppingConditions.add(stoppingCondition);
    this.stoppingCondition = Predicates.or(this.stoppingCondition, stoppingCondition);
}

From source file:com.khs.sherpa.servlet.request.DefaultSherpaRequest.java

@SuppressWarnings("unchecked")
protected Object proccess() throws SherpaRuntimeException {
    if (!isRestful()) {
        requestProcessor = new DefaultRequestProcessor();
    } else {//  w w  w  .j  av  a 2s  .co  m
        requestProcessor = new RestfulRequestProcessor(applicationContext);
    }

    String endpoint = requestProcessor.getEndpoint(request);
    String action = requestProcessor.getAction(request);
    String httpMethod = request.getMethod();

    if (StringUtils.isEmpty(endpoint)) {
        if (action.equals(Constants.AUTHENTICATE_ACTION)) {
            return this.processAuthenication();
        } else if (action.equals(Constants.VALID)) {
            return this.processValid();
        }
    }

    Object target = null;
    Set<Method> methods = null;

    try {
        String userid = request.getHeader("userid");
        if (userid == null) {
            userid = request.getParameter("userid");
        }
        String token = request.getHeader("token");
        if (token == null) {
            token = request.getParameter("token");
        }

        this.hasPermission(applicationContext.getType(endpoint), userid, token);

        target = applicationContext.getManagedBean(endpoint);

        if (ApplicationContextAware.class.isAssignableFrom(target.getClass())) {
            ((ApplicationContextAware) target).setApplicationContext(applicationContext);
        }

        methods = Reflections.getAllMethods(applicationContext.getType(endpoint),
                Predicates.and(Predicates.not(SherpaPredicates.withAssignableFrom(Object.class)),
                        ReflectionUtils.withModifier(Modifier.PUBLIC),
                        Predicates.not(ReflectionUtils.withModifier(Modifier.ABSTRACT)),
                        Predicates.not(SherpaPredicates.withGeneric()),
                        Predicates.and(SherpaPredicates.withAssignableFrom(
                                Enhancer.isEnhanced(target.getClass()) ? target.getClass().getSuperclass()
                                        : target.getClass())),
                        Predicates.or(ReflectionUtils.withName(action),
                                Predicates.and(ReflectionUtils.withAnnotation(Action.class),
                                        SherpaPredicates.withActionAnnotationValueEqualTo(action)))));

        if (methods.size() == 0) {
            throw new SherpaActionNotFoundException(action);
        }

    } catch (NoSuchManagedBeanExcpetion e) {
        throw new SherpaRuntimeException(e);
    }

    return this.processEndpoint(target, methods.toArray(new Method[] {}), httpMethod);
}

From source file:com.android.builder.internal.packaging.IncrementalPackager.java

/**
 * Updates files in the archive.//from  w  w  w . j a  v a2s .c o  m
 *
 * @param updates the updates to perform
 * @throws IOException failed to update the archive
 */
private void updateFiles(@NonNull Set<PackagedFileUpdate> updates) throws IOException {
    Preconditions.checkNotNull(mApkCreator, "mApkCreator == null");

    Iterable<String> deletedPaths = Iterables
            .transform(
                    Iterables
                            .filter(updates,
                                    Predicates.compose(Predicates.equalTo(FileStatus.REMOVED),
                                            PackagedFileUpdate.EXTRACT_STATUS)),
                    PackagedFileUpdate.EXTRACT_NAME);

    for (String deletedPath : deletedPaths) {
        mApkCreator.deleteFile(deletedPath);
    }

    Predicate<PackagedFileUpdate> isNewOrChanged = Predicates.compose(
            Predicates.or(Predicates.equalTo(FileStatus.NEW), Predicates.equalTo(FileStatus.CHANGED)),
            PackagedFileUpdate.EXTRACT_STATUS);

    Function<PackagedFileUpdate, File> extractBaseFile = Functions.compose(RelativeFile.EXTRACT_BASE,
            PackagedFileUpdate.EXTRACT_SOURCE);

    Iterable<PackagedFileUpdate> newOrChangedNonArchiveFiles = Iterables.filter(updates,
            Predicates.and(isNewOrChanged, Predicates.compose(Files.isDirectory(), extractBaseFile)));

    for (PackagedFileUpdate rf : newOrChangedNonArchiveFiles) {
        mApkCreator.writeFile(rf.getSource().getFile(), rf.getName());
    }

    Iterable<PackagedFileUpdate> newOrChangedArchiveFiles = Iterables.filter(updates,
            Predicates.and(isNewOrChanged, Predicates.compose(Files.isFile(), extractBaseFile)));

    Iterable<File> archives = Iterables.transform(newOrChangedArchiveFiles, extractBaseFile);
    Set<String> names = Sets
            .newHashSet(Iterables.transform(newOrChangedArchiveFiles, PackagedFileUpdate.EXTRACT_NAME));

    /*
     * Build the name map. The name of the file in the filesystem (or zip file) may not
     * match the name we want to package it as. See PackagedFileUpdate for more information.
     */
    Map<String, String> pathNameMap = Maps.newHashMap();
    for (PackagedFileUpdate archiveUpdate : newOrChangedArchiveFiles) {
        pathNameMap.put(archiveUpdate.getSource().getOsIndependentRelativePath(), archiveUpdate.getName());
    }

    for (File arch : Sets.newHashSet(archives)) {
        mApkCreator.writeZip(arch, pathNameMap::get, name -> !names.contains(name));
    }
}

From source file:com.ardor3d.example.app.RotatingCubeGame.java

private void registerInputTriggers() {
    logicalLayer.registerTrigger(new InputTrigger(new KeyHeldCondition(Key.W), new TriggerAction() {
        public void perform(final Canvas source, final InputState inputState, final double tpf) {
            moveForward(source, tpf);/*  w w  w  . j av  a 2 s  .  c o  m*/
        }
    }));
    logicalLayer.registerTrigger(new InputTrigger(new KeyHeldCondition(Key.S), new TriggerAction() {
        public void perform(final Canvas source, final InputState inputState, final double tpf) {
            moveBack(source, tpf);
        }
    }));
    logicalLayer.registerTrigger(new InputTrigger(new KeyHeldCondition(Key.A), new TriggerAction() {
        public void perform(final Canvas source, final InputState inputState, final double tpf) {
            turnLeft(source, tpf);
        }
    }));
    logicalLayer.registerTrigger(new InputTrigger(new KeyHeldCondition(Key.D), new TriggerAction() {
        public void perform(final Canvas source, final InputState inputState, final double tpf) {
            turnRight(source, tpf);
        }
    }));
    logicalLayer.registerTrigger(new InputTrigger(new KeyHeldCondition(Key.Q), new TriggerAction() {
        public void perform(final Canvas source, final InputState inputState, final double tpf) {
            moveLeft(source, tpf);
        }
    }));
    logicalLayer.registerTrigger(new InputTrigger(new KeyHeldCondition(Key.E), new TriggerAction() {
        public void perform(final Canvas source, final InputState inputState, final double tpf) {
            moveRight(source, tpf);
        }
    }));

    logicalLayer.registerTrigger(new InputTrigger(new KeyPressedCondition(Key.ESCAPE), new TriggerAction() {
        public void perform(final Canvas source, final InputState inputState, final double tpf) {
            exit.exit();
        }
    }));

    logicalLayer
            .registerTrigger(new InputTrigger(new KeyPressedCondition(toggleRotationKey), new TriggerAction() {
                public void perform(final Canvas source, final InputState inputState, final double tpf) {
                    toggleRotation();
                }
            }));
    logicalLayer.registerTrigger(new InputTrigger(new KeyReleasedCondition(Key.U), new TriggerAction() {
        public void perform(final Canvas source, final InputState inputState, final double tpf) {
            toggleRotation();
        }
    }));

    logicalLayer.registerTrigger(new InputTrigger(new KeyPressedCondition(Key.ZERO), new TriggerAction() {
        public void perform(final Canvas source, final InputState inputState, final double tpf) {
            resetCamera(source);
        }
    }));
    logicalLayer.registerTrigger(new InputTrigger(new KeyPressedCondition(Key.NINE), new TriggerAction() {
        public void perform(final Canvas source, final InputState inputState, final double tpf) {
            lookAtZero(source);
        }
    }));

    final Predicate<TwoInputStates> mouseMovedAndOneButtonPressed = Predicates.and(
            TriggerConditions.mouseMoved(),
            Predicates.or(TriggerConditions.leftButtonDown(), TriggerConditions.rightButtonDown()));

    logicalLayer.registerTrigger(new InputTrigger(mouseMovedAndOneButtonPressed, new TriggerAction() {
        public void perform(final Canvas source, final InputState inputState, final double tpf) {
            final MouseState mouseState = inputState.getMouseState();

            turn(source, mouseState.getDx() * tpf * -MOUSE_TURN_SPEED);
            rotateUpDown(source, mouseState.getDy() * tpf * -MOUSE_TURN_SPEED);
        }
    }));
    logicalLayer.registerTrigger(new InputTrigger(
            new MouseButtonCondition(ButtonState.DOWN, ButtonState.DOWN, ButtonState.UNDEFINED),
            new TriggerAction() {
                public void perform(final Canvas source, final InputState inputState, final double tpf) {
                    moveForward(source, tpf);
                }
            }));

}

From source file:com.takin.emmet.concurrent.retry.RetryerBuilder.java

/**
 * Configures the retryer to retry if the result satisfies the given predicate.
 *
 * @param resultPredicate a predicate applied to the result, and which causes the retryer
 *                        to retry if the predicate is satisfied
 * @return <code>this</code>
 *//*  w ww  . j a v a2s.  c o m*/
public RetryerBuilder<V> retryIfResult(@Nonnull Predicate<V> resultPredicate) {
    Preconditions.checkNotNull(resultPredicate, "resultPredicate may not be null");
    rejectionPredicate = Predicates.or(rejectionPredicate, new ResultPredicate<V>(resultPredicate));
    return this;
}