List of usage examples for com.google.common.base Predicates not
public static <T> Predicate<T> not(Predicate<T> predicate)
From source file:com.flaptor.indextank.storage.Segment.java
public static Iterable<Segment> iterateSegments(final LogRoot root, File parent, Boolean sortedOnly) { Iterable<Segment> segments = iterateSegments(root, parent); if (sortedOnly != null) { segments = Iterables.filter(segments, sortedOnly ? IS_SORTED : Predicates.not(IS_SORTED)); }// w ww . j a v a 2 s . c o m return segments; }
From source file:gg.uhc.uhc.modules.death.DeathStandsModule.java
@EventHandler public void on(PlayerArmorStandManipulateEvent event) { ArmorStand stand = event.getRightClicked(); if (!isProtectedArmourStand(stand)) return;/*from w w w .j a v a2 s. c o m*/ ItemStack players = event.getPlayerItem(); ItemStack stands = event.getArmorStandItem(); // if the player is holding something it will be a swap if (players == null || players.getType() != Material.AIR) return; // if the stand hasn't got something then the player is adding // items or nothing will happen if (stands == null || stands.getType() == Material.AIR) return; // they're removing an item from the armour stand. If there // is only 1 item on the stand then this is the final item // on the armour stand so kill it (fire optional) if (Maps.filterValues(getItems(stand), Predicates.not(EMPTY_ITEM)).values().size() == 1) { stand.remove(); } }
From source file:com.google.devtools.build.lib.skyframe.RecursiveDirectoryTraversalFunction.java
/** * Looks in the directory specified by {@code recursivePkgKey} for a package, does some work as * specified by {@link Visitor} if such a package exists, then recursively does work in each * non-excluded subdirectory as specified by {@link #getSkyKeyForSubdirectory}, and finally * aggregates the {@link Visitor} value along with values from each subdirectory as specified by * {@link #aggregateWithSubdirectorySkyValues}, and returns that aggregation. * * <p>Returns null if {@code env.valuesMissing()} is true, checked after each call to one of * {@link RecursiveDirectoryTraversalFunction}'s abstract methods that were given {@code env}. * (And after each of {@code visitDirectory}'s own uses of {@code env}, of course.) *///from ww w .ja va 2s. c o m TReturn visitDirectory(RecursivePkgKey recursivePkgKey, Environment env) throws InterruptedException { RootedPath rootedPath = recursivePkgKey.getRootedPath(); ProcessPackageDirectoryResult packageExistenceAndSubdirDeps = processPackageDirectory .getPackageExistenceAndSubdirDeps(rootedPath, recursivePkgKey.getRepository(), env, recursivePkgKey.getExcludedPaths()); if (env.valuesMissing()) { return null; } Iterable<SkyKey> childDeps = packageExistenceAndSubdirDeps.getChildDeps(); TVisitor visitor = getInitialVisitor(); Map<SkyKey, SkyValue> subdirectorySkyValues; if (packageExistenceAndSubdirDeps.packageExists()) { PathFragment rootRelativePath = rootedPath.getRelativePath(); SkyKey packageKey = PackageValue .key(PackageIdentifier.create(recursivePkgKey.getRepository(), rootRelativePath)); Map<SkyKey, ValueOrException<NoSuchPackageException>> dependentSkyValues = env.getValuesOrThrow( Iterables.concat(childDeps, ImmutableList.of(packageKey)), NoSuchPackageException.class); if (env.valuesMissing()) { return null; } Package pkg = null; try { PackageValue pkgValue = (PackageValue) dependentSkyValues.get(packageKey).get(); if (pkgValue == null) { return null; } pkg = pkgValue.getPackage(); if (pkg.containsErrors()) { env.getListener() .handle(Event.error("package contains errors: " + rootRelativePath.getPathString())); } } catch (NoSuchPackageException e) { // The package had errors, but don't fail-fast as there might be subpackages below the // current directory. env.getListener() .handle(Event.error("package contains errors: " + rootRelativePath.getPathString())); } if (pkg != null) { visitor.visitPackageValue(pkg, env); if (env.valuesMissing()) { return null; } } ImmutableMap.Builder<SkyKey, SkyValue> subdirectoryBuilder = ImmutableMap.builder(); for (Map.Entry<SkyKey, ValueOrException<NoSuchPackageException>> entry : Maps .filterKeys(dependentSkyValues, Predicates.not(Predicates.equalTo(packageKey))).entrySet()) { try { subdirectoryBuilder.put(entry.getKey(), entry.getValue().get()); } catch (NoSuchPackageException e) { // ignored. } } subdirectorySkyValues = subdirectoryBuilder.build(); } else { subdirectorySkyValues = env.getValues(childDeps); } if (env.valuesMissing()) { return null; } return aggregateWithSubdirectorySkyValues(visitor, subdirectorySkyValues); }
From source file:org.opentestsystem.authoring.testauth.service.impl.BlueprintElementServiceImpl.java
@Override public List<BlueprintElement> saveBlueprintElementList(final List<BlueprintElement> blueprintElements) { final List<BlueprintElement> savedBlueprintElements = Lists.newArrayList(); if (!CollectionUtils.isEmpty(blueprintElements)) { final String assessmentId = blueprintElements.get(0).getAssessmentId(); checkForLockedAssessment(assessmentId); final List<BlueprintElement> blueprintElementsToRemove = Lists .newArrayList(Iterables.filter(blueprintElements, BLUEPRINT_ELEMENT_FILTER_REMOVE)); final List<BlueprintElement> blueprintElementsToSave = Lists.newArrayList( Iterables.filter(blueprintElements, Predicates.not(BLUEPRINT_ELEMENT_FILTER_REMOVE))); try {//w ww . j av a 2 s . co m if (!CollectionUtils.isEmpty(blueprintElementsToRemove)) { this.blueprintElementRepository.delete(blueprintElementsToRemove); final List<String> bpReferenceIdsToDelete = Lists.transform(blueprintElementsToRemove, BP_ELEMENT_ID_TRANSFORMER); cleanupForRelatedData(assessmentId, bpReferenceIdsToDelete); } if (!CollectionUtils.isEmpty(blueprintElementsToSave)) { final List<String> bpReferenceIdsToDelete = Lists .transform( Lists.newArrayList(Iterables.filter(blueprintElementsToSave, BlueprintHelper.BP_ELEMENT_ID_INACTIVE_FILTER)), BP_ELEMENT_ID_TRANSFORMER); savedBlueprintElements.addAll(this.blueprintElementRepository.save(blueprintElementsToSave)); cleanupForRelatedData(assessmentId, bpReferenceIdsToDelete); } } catch (final DuplicateKeyException dke) { throw new LocalizedException("blueprintElement.listhasduplicates", dke); } } return savedBlueprintElements; }
From source file:clocker.docker.location.DockerContainerLocation.java
@Override public int execScript(Map<String, ?> props, String summaryForLogging, List<String> commands, Map<String, ?> env) { Iterable<String> filtered = Iterables.filter(commands, DockerCallbacks.FILTER); for (String commandString : filtered) { parseDockerCallback(commandString); }// w w w . ja va 2s .c o m boolean entitySsh = Boolean.TRUE.equals(entity.config().get(DockerContainer.DOCKER_USE_SSH)); boolean dockerSsh = Boolean.TRUE.equals(getOwner().config().get(DockerContainer.DOCKER_USE_SSH)); if (entitySsh && dockerSsh) { return super.execScript(props, summaryForLogging, commands, env); } else { Map<String, ?> nonPortProps = Maps.filterKeys(props, Predicates.not(Predicates.containsPattern("port"))); return hostMachine.execCommands(nonPortProps, summaryForLogging, getDockerExecCommand(commands, env)); } }
From source file:com.google.api.tools.framework.model.MessageType.java
/** * Returns all fields which are not repeated. *///from w ww. j a v a 2s .c om public Iterable<Field> getNonRepeatedFields() { return FluentIterable.from(fields).filter(Predicates.not(Field.IS_REPEATED)); }
From source file:co.cask.cdap.app.runtime.spark.submit.AbstractSparkSubmitter.java
/** * Creates the list of arguments that will be used for calling {@link SparkSubmit#main(String[])}. * * @param spec the {@link SparkSpecification} of the program * @param configs set of Spark configurations * @param resources list of resources that needs to be localized to Spark containers * @param jobJar the job jar file for Spark * @return a list of arguments/* w w w . j av a2s . c om*/ */ private List<String> createSubmitArguments(SparkSpecification spec, Map<String, String> configs, List<LocalizeResource> resources, File jobJar) { ImmutableList.Builder<String> builder = ImmutableList.builder(); builder.add("--master").add(getMaster(configs)); builder.add("--class").add(SparkMainWrapper.class.getName()); builder.add("--conf").add("spark.app.name=" + spec.getName()); for (Map.Entry<String, String> entry : configs.entrySet()) { builder.add("--conf").add(entry.getKey() + "=" + entry.getValue()); } for (Map.Entry<String, String> entry : getSubmitConf().entrySet()) { builder.add("--conf").add(entry.getKey() + "=" + entry.getValue()); } String archives = Joiner.on(',') .join(Iterables.transform(Iterables.filter(resources, ARCHIVE_FILTER), RESOURCE_TO_PATH)); String files = Joiner.on(',').join( Iterables.transform(Iterables.filter(resources, Predicates.not(ARCHIVE_FILTER)), RESOURCE_TO_PATH)); if (!archives.isEmpty()) { builder.add("--archives").add(archives); } if (!files.isEmpty()) { builder.add("--files").add(files); } return builder.add(jobJar.getAbsolutePath()) .add("--" + SparkMainWrapper.ARG_USER_CLASS() + "=" + spec.getMainClassName()).build(); }
From source file:com.dasasian.chok.client.Client.java
protected void addIndexForSearching(IndexMetaData indexMD) { final Set<Shard> shards = indexMD.getShards(); List<String> shardNames = Lists.newArrayList(); for (Shard shard : shards) { shardNames.add(shard.getName()); }//from w ww . j a va 2s. c o m for (final String shardName : shardNames) { List<String> nodes = protocol.registerChildListener(this, PathDef.SHARD_TO_NODES, shardName, new IAddRemoveListener() { @Override public void removed(String nodeName) { LOG.info("shard '" + shardName + "' removed from node " + nodeName + "'"); Iterable<String> shardNodes = Iterables.filter(selectionPolicy.getShardNodes(shardName), Predicates.not(Predicates.equalTo(nodeName))); selectionPolicy.update(shardName, shardNodes); } @Override public void added(String nodeName) { LOG.info("shard '" + shardName + "' added to node '" + nodeName + "'"); VersionedProtocol proxy = proxyManager.getProxy(nodeName, true); if (proxy != null) { Iterable<String> shardNodes = Iterables.concat( selectionPolicy.getShardNodes(shardName), ImmutableList.of(nodeName)); selectionPolicy.update(shardName, shardNodes); } } }); Collection<String> shardNodes = Lists.newArrayList(); for (String node : nodes) { VersionedProtocol proxy = proxyManager.getProxy(node, true); if (proxy != null) { shardNodes.add(node); } } selectionPolicy.update(shardName, shardNodes); } indexToShards.put(indexMD.getName(), shardNames); }
From source file:org.apache.brooklyn.entity.nosql.etcd.EtcdClusterImpl.java
protected void onServerPoolMemberChanged(Entity member) { synchronized (memberMutex) { log.debug("For {}, considering membership of {} which is in locations {}", new Object[] { this, member, member.getLocations() }); Map<Entity, String> nodes = sensors().get(ETCD_CLUSTER_NODES); if (belongsInServerPool(member)) { if (nodes == null) { nodes = Maps.newLinkedHashMap(); }/*w w w .j a va 2s. c o m*/ String name = Preconditions.checkNotNull(getNodeName(member)); // Wait until node has been installed DynamicTasks .queueIfPossible( DependentConfiguration.attributeWhenReady(member, EtcdNode.ETCD_NODE_INSTALLED)) .orSubmitAndBlock(this).andWaitForSuccess(); // Check for first node in the cluster. Duration timeout = config().get(BrooklynConfigKeys.START_TIMEOUT); Entity firstNode = sensors().get(DynamicCluster.FIRST); if (member.equals(firstNode)) { nodes.put(member, name); recalculateClusterAddresses(nodes); log.info("Adding first node {}: {}; {} to cluster", new Object[] { this, member, name }); ((EntityInternal) member).sensors().set(EtcdNode.ETCD_NODE_HAS_JOINED_CLUSTER, Boolean.TRUE); } else { int retry = 3; // TODO use a configurable Repeater instead? while (retry-- > 0 && member.sensors().get(EtcdNode.ETCD_NODE_HAS_JOINED_CLUSTER) == null && !nodes.containsKey(member)) { Optional<Entity> anyNodeInCluster = Iterables.tryFind(nodes.keySet(), Predicates.and(Predicates.instanceOf(EtcdNode.class), EntityPredicates .attributeEqualTo(EtcdNode.ETCD_NODE_HAS_JOINED_CLUSTER, Boolean.TRUE))); if (anyNodeInCluster.isPresent()) { DynamicTasks.queueIfPossible(DependentConfiguration.builder() .attributeWhenReady(anyNodeInCluster.get(), Startable.SERVICE_UP) .timeout(timeout).build()).orSubmitAndBlock(this).andWaitForSuccess(); Entities.invokeEffectorWithArgs(this, anyNodeInCluster.get(), EtcdNode.JOIN_ETCD_CLUSTER, name, getNodeAddress(member)) .blockUntilEnded(timeout); nodes.put(member, name); recalculateClusterAddresses(nodes); log.info("Adding node {}: {}; {} to cluster", new Object[] { this, member, name }); ((EntityInternal) member).sensors().set(EtcdNode.ETCD_NODE_HAS_JOINED_CLUSTER, Boolean.TRUE); } else { log.info("Waiting for first node in cluster {}", this); Time.sleep(Duration.seconds(15)); } } } } else { if (nodes != null && nodes.containsKey(member)) { Optional<Entity> anyNodeInCluster = Iterables.tryFind(nodes.keySet(), Predicates.and( Predicates.instanceOf(EtcdNode.class), EntityPredicates .attributeEqualTo(EtcdNode.ETCD_NODE_HAS_JOINED_CLUSTER, Boolean.TRUE), Predicates.not(Predicates.equalTo(member)))); if (anyNodeInCluster.isPresent()) { Entities.invokeEffectorWithArgs(this, anyNodeInCluster.get(), EtcdNode.LEAVE_ETCD_CLUSTER, getNodeName(member)).blockUntilEnded(); } nodes.remove(member); recalculateClusterAddresses(nodes); log.info("Removing node {}: {}; {} from cluster", new Object[] { this, member, getNodeName(member) }); ((EntityInternal) member).sensors().set(EtcdNode.ETCD_NODE_HAS_JOINED_CLUSTER, Boolean.FALSE); } } ServiceNotUpLogic.updateNotUpIndicatorRequiringNonEmptyMap(this, ETCD_CLUSTER_NODES); log.debug("Done {} checkEntity {}", this, member); } }
From source file:org.opentestsystem.authoring.testauth.service.impl.ItemServiceImpl.java
@Override public List<Item> saveItemList(final List<Item> items) { final List<Item> savedItems = Lists.newArrayList(); if (!CollectionUtils.isEmpty(items)) { checkForLockedAssessment(items.get(0).getAssessmentId()); final List<Item> itemsToRemove = Lists .newArrayList(Iterables.filter(items, ItemHelper.ITEM_ELEMENT_FILTER_REMOVE)); final List<Item> itemsToSave = Lists .newArrayList(Iterables.filter(items, Predicates.not(ItemHelper.ITEM_ELEMENT_FILTER_REMOVE))); try {// w w w . j ava 2 s. c o m if (!CollectionUtils.isEmpty(itemsToRemove)) { this.itemRepository.delete(itemsToRemove); } if (!CollectionUtils.isEmpty(itemsToSave)) { savedItems.addAll(this.itemRepository.save(itemsToSave)); } } catch (final DuplicateKeyException dke) { throw new LocalizedException("item.listhasduplicates", dke); } } return savedItems; }