Example usage for com.google.common.collect Iterables removeIf

List of usage examples for com.google.common.collect Iterables removeIf

Introduction

In this page you can find the example usage for com.google.common.collect Iterables removeIf.

Prototype

public static <T> boolean removeIf(Iterable<T> removeFrom, Predicate<? super T> predicate) 

Source Link

Document

Removes, from an iterable, every element that satisfies the provided predicate.

Usage

From source file:org.zoumbox.mh_dla_notifier.profile.v1.ProfileProxyV1.java

public Map<String, String> fetchProperties(final Context context, UpdateRequestType updateRequest,
        List<String> requestedProperties) throws QuotaExceededException, MissingLoginPasswordException,
        PublicScriptException, NetworkUnavailableException {

    Log.i(TAG, "Fetching properties with updateRequest: " + updateRequest);
    SharedPreferences preferences = context.getSharedPreferences(PREFS_NAME, 0);

    Pair<String, String> idAndPassword = loadIdPassword(preferences);
    final String trollNumber = idAndPassword.left();

    // Iterate over requested properties to know which SP are concerned
    Set<PublicScript> scripts = new LinkedHashSet<PublicScript>();
    Log.i(TAG, "Requesting properties: " + requestedProperties);
    //        for (String property : requestedProperties) {
    //            PublicScript script = PublicScript.forProperty(property);
    //            scripts.add(script);
    //        }/*from   w  w  w. j a  v a2  s  . com*/
    //        scripts.add(PublicScript.ProfilPublic2);
    //        scripts.add(PublicScript.Profil2);
    //        scripts.add(PublicScript.Caract);

    // Maybe no update is requested, but needed because of missing property
    UpdateRequestType updateRequestType = updateRequest;
    if (!updateRequestType.needUpdate()) {
        for (String property : requestedProperties) {
            String value = preferences.getString(property, null);
            if (value == null) {
                updateRequestType = UpdateRequestType.FULL;
                Log.i(TAG, "updateRequestType changed from " + updateRequest + " to " + updateRequestType);
                break;
            }
        }
    }

    UpdateRequestType backgroundUpdate = UpdateRequestType.NONE;
    if (updateRequestType.needUpdate()) {

        if (UpdateRequestType.ONLY_NECESSARY.equals(updateRequestType)) {
            Predicate<PublicScript> noNeedToUpdatePredicate = noNeedToUpdate(context, trollNumber);
            Iterables.removeIf(scripts, noNeedToUpdatePredicate);
        }

        for (PublicScript script : scripts) {
            try {
                Map<String, String> propertiesFetched = PublicScriptsProxy.fetchProperties(context, script,
                        idAndPassword);
                saveProperties(preferences, propertiesFetched);
            } catch (HighUpdateRateException hure) {
                // Nothing to do
            }
        }
    } else {
        Predicate<PublicScript> noNeedToUpdatePredicate = noNeedToUpdate(context, trollNumber);
        Iterables.removeIf(scripts, noNeedToUpdatePredicate);

        //            if (!scripts.isEmpty()) {
        if (scripts.contains(PublicScript.Profil2)) { // Ask for update only if profil2 needs an update
            backgroundUpdate = UpdateRequestType.ONLY_NECESSARY;
        }
    }

    Map<String, String> result = new LinkedHashMap<String, String>();
    Log.i(TAG, "Background update needed ? " + backgroundUpdate);
    result.put("NEEDS_UPDATE", backgroundUpdate.name());

    String pvVariation = preferences.getString("PV_VARIATION", "0");
    result.put("PV_VARIATION", pvVariation);

    for (String property : requestedProperties) {
        String value = preferences.getString(property, null);
        result.put(property, value);
    }

    return result;
}

From source file:org.artifactory.build.BuildServiceImpl.java

@Override
public List<BuildRun> getAllPreviousBuilds(String buildName, String buildNumber, String buildStarted) {
    final BuildRun currentBuildRun = getTransactionalMe().getBuildRun(buildName, buildNumber, buildStarted);
    Set<BuildRun> buildRuns = searchBuildsByName(buildName);
    final Comparator<BuildRun> buildNumberComparator = BuildRunComparators.getBuildStartDateComparator();
    Iterables.removeIf(buildRuns, new Predicate<BuildRun>() {
        @Override/*w  w w .j  a v a2 s .  c o m*/
        public boolean apply(@Nullable BuildRun input) {
            // Remove all builds equals or after the current one
            return buildNumberComparator.compare(currentBuildRun, input) <= 0;
        }
    });

    List<BuildRun> buildRunsList = Lists.newArrayList(buildRuns);
    Comparator<BuildRun> reverseComparator = Collections.reverseOrder(buildNumberComparator);
    Collections.sort(buildRunsList, reverseComparator);

    return buildRunsList;
}

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

private ImmutableList<String> getToolchainFlags() {
    boolean fullyStatic = (linkStaticness == LinkStaticness.FULLY_STATIC);
    boolean mostlyStatic = (linkStaticness == LinkStaticness.MOSTLY_STATIC);
    boolean sharedLinkopts = linkTargetType == LinkTargetType.DYNAMIC_LIBRARY || linkopts.contains("-shared")
            || cppConfiguration.getLinkOptions().contains("-shared");

    List<String> toolchainFlags = new ArrayList<>();

    /*//from   w w  w  .  j  a v  a  2s  . c  o m
     * For backwards compatibility, linkopts come _after_ inputFiles.
     * This is needed to allow linkopts to contain libraries and
     * positional library-related options such as
     *    -Wl,--begin-group -lfoo -lbar -Wl,--end-group
     * or
     *    -Wl,--as-needed -lfoo -Wl,--no-as-needed
     *
     * As for the relative order of the three different flavours of linkopts
     * (global defaults, per-target linkopts, and command-line linkopts),
     * we have no idea what the right order should be, or if anyone cares.
     */
    toolchainFlags.addAll(linkopts);
    // Extra toolchain link options based on the output's link staticness.
    if (fullyStatic) {
        toolchainFlags.addAll(cppConfiguration.getFullyStaticLinkOptions(features, sharedLinkopts));
    } else if (mostlyStatic) {
        toolchainFlags.addAll(cppConfiguration.getMostlyStaticLinkOptions(features, sharedLinkopts));
    } else {
        toolchainFlags.addAll(cppConfiguration.getDynamicLinkOptions(features, sharedLinkopts));
    }

    // Extra test-specific link options.
    if (useTestOnlyFlags) {
        toolchainFlags.addAll(cppConfiguration.getTestOnlyLinkOptions());
    }

    toolchainFlags.addAll(cppConfiguration.getLinkOptions());

    // -pie is not compatible with shared and should be
    // removed when the latter is part of the link command. Should we need to further
    // distinguish between shared libraries and executables, we could add additional
    // command line / CROSSTOOL flags that distinguish them. But as long as this is
    // the only relevant use case we're just special-casing it here.
    if (linkTargetType == LinkTargetType.DYNAMIC_LIBRARY) {
        Iterables.removeIf(toolchainFlags, Predicates.equalTo("-pie"));
    }

    // Fission mode: debug info is in .dwo files instead of .o files. Inform the linker of this.
    if (linkTargetType.staticness() == Staticness.DYNAMIC && cppConfiguration.useFission()) {
        toolchainFlags.add("-Wl,--gdb-index");
    }

    return ImmutableList.copyOf(toolchainFlags);
}

From source file:org.opensaml.storage.AbstractMapBackedStorageService.java

/**
 * Locates and removes expired records from the input map.
 * // w  w w.ja  va  2s .  c om
 * <p>This method <strong>MUST</strong> be called while holding a write lock, if locking is required.</p>
 * 
 * @param dataMap       the map to reap
 * @param expiration    time at which to consider records expired
 * 
 * @return  true iff anything was purged
 */
protected boolean reapWithLock(@Nonnull @NonnullElements final Map<String, MutableStorageRecord> dataMap,
        final long expiration) {

    return Iterables.removeIf(dataMap.entrySet(), new Predicate<Entry<String, MutableStorageRecord>>() {
        public boolean apply(@Nullable final Entry<String, MutableStorageRecord> entry) {
            Long exp = entry.getValue().getExpiration();
            return exp != null && exp <= expiration;
        }
    });
}

From source file:org.gradle.execution.taskgraph.DefaultTaskExecutionPlan.java

private void removeShouldRunAfterSuccessorsIfTheyImposeACycle(
        final HashMultimap<TaskInfo, Integer> visitingNodes,
        final TaskInfoInVisitingSegment taskNodeWithVisitingSegment) {
    TaskInfo taskNode = taskNodeWithVisitingSegment.taskInfo;
    Iterables.removeIf(taskNode.getShouldSuccessors(), new Predicate<TaskInfo>() {
        public boolean apply(TaskInfo input) {
            return visitingNodes.containsEntry(input, taskNodeWithVisitingSegment.visitingSegment);
        }/*from   ww w .j av a  2  s .  c  o  m*/
    });
}

From source file:org.gradle.execution.plan.DefaultExecutionPlan.java

private void removeShouldRunAfterSuccessorsIfTheyImposeACycle(final HashMultimap<Node, Integer> visitingNodes,
        final NodeInVisitingSegment nodeWithVisitingSegment) {
    Node node = nodeWithVisitingSegment.node;
    if (!(node instanceof TaskNode)) {
        return;/*w  ww.j a va2s.  c om*/
    }
    Iterables.removeIf(((TaskNode) node).getShouldSuccessors(), new Predicate<Node>() {
        @Override
        @SuppressWarnings("NullableProblems")
        public boolean apply(Node input) {
            return visitingNodes.containsEntry(input, nodeWithVisitingSegment.visitingSegment);
        }
    });
}

From source file:org.eclipse.rcptt.launching.rap.RcpttRapLaunchDelegate.java

@Override
public String[] getVMArguments(ILaunchConfiguration config) throws CoreException {
    CachedInfo info = LaunchInfoCache.getInfo(config);
    if (info.vmArgs != null) {
        return info.vmArgs;
    }/*  w  ww. j av  a  2 s  . c  o  m*/

    List<String> args = new ArrayList<String>();
    // ORDER IS CRUCIAL HERE:
    // Override VM arguments that are specified manually with the values
    // necessary for the RAP launcher
    args.add("-Declipse.ignoreApp=true");
    args.add("-Dosgi.noShutdown=true");
    args.addAll(Arrays.asList(super.getVMArguments(config)));
    args.addAll(getRAPVMArguments());

    // Filter some PDE parameters
    Iterables.removeIf(args, new Predicate<String>() {
        public boolean apply(String input) {
            if (input.contains("-Declipse.pde.launch=true")) {
                return true;
            }
            return false;
        }
    });

    args.add("-Dq7id=" + launch.getAttribute(IQ7Launch.ATTR_AUT_ID));
    args.add("-Dq7EclPort=" + AutEventManager.INSTANCE.getPort());

    TargetPlatformHelper target = (TargetPlatformHelper) ((ITargetPlatformHelper) info.target);

    IPluginModelBase hook = target.getWeavingHook();
    if (hook == null) {
        throw new CoreException(Q7ExtLaunchingPlugin.status("No " + AJConstants.HOOK + " plugin")); //$NON-NLS-1$ //$NON-NLS-2$
    }

    // Append all other properties from original config file
    OriginalOrderProperties properties = target.getConfigIniProperties();

    args = UpdateVMArgs.addHook(args, hook, properties.getProperty(OSGI_FRAMEWORK_EXTENSIONS));

    args.add("-Declipse.vmargs=" + Joiner.on("\n").join(args) + "\n");

    info.vmArgs = args.toArray(new String[args.size()]);
    return info.vmArgs;
}

From source file:org.jclouds.abiquo.domain.cloud.VirtualMachine.java

public VirtualMachineTask detachHardDisks(final HardDisk... hardDisks) {
    List<HardDisk> expected = Lists.newArrayList(listAttachedHardDisks());
    Iterables.removeIf(expected, hardDiskIdIn(hardDisks));

    HardDisk[] disks = new HardDisk[expected.size()];
    return setHardDisks(expected.toArray(disks));
}

From source file:org.jclouds.abiquo.domain.cloud.VirtualMachine.java

public VirtualMachineTask detachVolumes(final Volume... volumes) {
    List<Volume> expected = Lists.newArrayList(listAttachedVolumes());
    Iterables.removeIf(expected, volumeIdIn(volumes));

    Volume[] vols = new Volume[expected.size()];
    return setVolumes(true, expected.toArray(vols));
}

From source file:com.tinspx.util.net.Headers.java

/**
 * Removes all headers mapped to {@code name} that satisfy
 * {@code valuePredicate}./*w w  w .  j a  v a2s  . c  o  m*/
 */
public Headers remove(@Nullable String name, @NonNull Predicate<? super String> valuePredicate) {
    if (name == null) {
        return this;
    }
    for (final String header : canons().get(canonicalize(name))) {
        final List<String> values = headers.get(header);
        if (values.isEmpty()) {
            continue;
        }
        if (Iterables.removeIf(values, valuePredicate)) {
            rebuildHeaders = true;
        }
    }
    return this;
}