List of usage examples for com.google.common.base Predicates equalTo
public static <T> Predicate<T> equalTo(@Nullable T target)
From source file:org.apache.druid.segment.column.SimpleDictionaryEncodedColumn.java
@Override public HistoricalDimensionSelector makeDimensionSelector(final ReadableOffset offset, @Nullable final ExtractionFn extractionFn) { abstract class QueryableDimensionSelector implements HistoricalDimensionSelector, IdLookup { @Override// w w w . j a va 2s. c o m public int getValueCardinality() { return getCardinality(); } @Override public String lookupName(int id) { final String value = SimpleDictionaryEncodedColumn.this.lookupName(id); return extractionFn == null ? value : extractionFn.apply(value); } @Override public boolean nameLookupPossibleInAdvance() { return true; } @Nullable @Override public IdLookup idLookup() { return extractionFn == null ? this : null; } @Override public int lookupId(String name) { if (extractionFn != null) { throw new UnsupportedOperationException( "cannot perform lookup when applying an extraction function"); } return SimpleDictionaryEncodedColumn.this.lookupId(name); } } if (hasMultipleValues()) { class MultiValueDimensionSelector extends QueryableDimensionSelector { @Override public IndexedInts getRow() { return multiValueColumn.get(offset.getOffset()); } @Override public IndexedInts getRow(int offset) { return multiValueColumn.get(offset); } @Override public ValueMatcher makeValueMatcher(String value) { return DimensionSelectorUtils.makeValueMatcherGeneric(this, value); } @Override public ValueMatcher makeValueMatcher(Predicate<String> predicate) { return DimensionSelectorUtils.makeValueMatcherGeneric(this, predicate); } @Nullable @Override public Object getObject() { return defaultGetObject(); } @Override public Class classOfObject() { return Object.class; } @Override public void inspectRuntimeShape(RuntimeShapeInspector inspector) { inspector.visit("multiValueColumn", multiValueColumn); inspector.visit("offset", offset); inspector.visit("extractionFn", extractionFn); } } return new MultiValueDimensionSelector(); } else { class SingleValueQueryableDimensionSelector extends QueryableDimensionSelector implements SingleValueHistoricalDimensionSelector { private final SingleIndexedInt row = new SingleIndexedInt(); @Override public IndexedInts getRow() { row.setValue(getRowValue()); return row; } public int getRowValue() { return column.get(offset.getOffset()); } @Override public IndexedInts getRow(int offset) { row.setValue(getRowValue(offset)); return row; } @Override public int getRowValue(int offset) { return column.get(offset); } @Override public ValueMatcher makeValueMatcher(final String value) { if (extractionFn == null) { final int valueId = lookupId(value); if (valueId >= 0) { return new ValueMatcher() { @Override public boolean matches() { return getRowValue() == valueId; } @Override public void inspectRuntimeShape(RuntimeShapeInspector inspector) { inspector.visit("column", SimpleDictionaryEncodedColumn.this); } }; } else { return BooleanValueMatcher.of(false); } } else { // Employ caching BitSet optimization return makeValueMatcher(Predicates.equalTo(value)); } } @Override public ValueMatcher makeValueMatcher(final Predicate<String> predicate) { final BitSet checkedIds = new BitSet(getCardinality()); final BitSet matchingIds = new BitSet(getCardinality()); // Lazy matcher; only check an id if matches() is called. return new ValueMatcher() { @Override public boolean matches() { final int id = getRowValue(); if (checkedIds.get(id)) { return matchingIds.get(id); } else { final boolean matches = predicate.apply(lookupName(id)); checkedIds.set(id); if (matches) { matchingIds.set(id); } return matches; } } @Override public void inspectRuntimeShape(RuntimeShapeInspector inspector) { inspector.visit("column", SimpleDictionaryEncodedColumn.this); } }; } @Override public Object getObject() { return lookupName(getRowValue()); } @Override public Class classOfObject() { return String.class; } @Override public void inspectRuntimeShape(RuntimeShapeInspector inspector) { inspector.visit("column", column); inspector.visit("offset", offset); inspector.visit("extractionFn", extractionFn); } } return new SingleValueQueryableDimensionSelector(); } }
From source file:org.apache.kudu.client.KuduTable.java
/** * Retrieves a formatted representation of this table's range partitions. The * range partitions will be returned in sorted order by value, and will * contain no duplicates./*from w w w .j a va 2 s . co m*/ * * @param deadline the deadline of the operation * @return a list of the formatted range partitions */ @InterfaceAudience.LimitedPrivate("Impala") @InterfaceStability.Unstable public List<String> getFormattedRangePartitions(long deadline) throws Exception { List<String> rangePartitions = new ArrayList<>(); for (LocatedTablet tablet : getTabletsLocations(deadline)) { Partition partition = tablet.getPartition(); // Filter duplicate range partitions by taking only the tablets whose hash // partitions are all 0s. if (!Iterators.all(partition.getHashBuckets().iterator(), Predicates.equalTo(0))) { continue; } rangePartitions.add(partition.formatRangePartition(this)); } return rangePartitions; }
From source file:com.google.javascript.jscomp.graph.LinkedDirectedGraph.java
/** * DiGraphNode look ups can be expensive for a large graph operation, prefer the * version below that takes DiGraphNodes, if you have them available. *//*from ww w .j av a 2 s.com*/ @Override public boolean isConnectedInDirection(N n1, E edgeValue, N n2) { return isConnectedInDirection(n1, Predicates.equalTo(edgeValue), n2); }
From source file:org.apache.druid.segment.column.StringDictionaryEncodedColumn.java
@Override public HistoricalDimensionSelector makeDimensionSelector(final ReadableOffset offset, @Nullable final ExtractionFn extractionFn) { abstract class QueryableDimensionSelector extends AbstractDimensionSelector implements HistoricalDimensionSelector, IdLookup { @Override/* w w w. j a v a 2s.co m*/ public int getValueCardinality() { return getCardinality(); } @Override public String lookupName(int id) { final String value = StringDictionaryEncodedColumn.this.lookupName(id); return extractionFn == null ? value : extractionFn.apply(value); } @Override public boolean nameLookupPossibleInAdvance() { return true; } @Nullable @Override public IdLookup idLookup() { return extractionFn == null ? this : null; } @Override public int lookupId(String name) { if (extractionFn != null) { throw new UnsupportedOperationException( "cannot perform lookup when applying an extraction function"); } return StringDictionaryEncodedColumn.this.lookupId(name); } } if (hasMultipleValues()) { class MultiValueDimensionSelector extends QueryableDimensionSelector { @Override public IndexedInts getRow() { return multiValueColumn.get(offset.getOffset()); } @Override public IndexedInts getRow(int offset) { return multiValueColumn.get(offset); } @Override public ValueMatcher makeValueMatcher(@Nullable String value) { return DimensionSelectorUtils.makeValueMatcherGeneric(this, value); } @Override public ValueMatcher makeValueMatcher(Predicate<String> predicate) { return DimensionSelectorUtils.makeValueMatcherGeneric(this, predicate); } @Nullable @Override public Object getObject() { return defaultGetObject(); } @Override public Class classOfObject() { return Object.class; } @Override public void inspectRuntimeShape(RuntimeShapeInspector inspector) { inspector.visit("multiValueColumn", multiValueColumn); inspector.visit("offset", offset); inspector.visit("extractionFn", extractionFn); } } return new MultiValueDimensionSelector(); } else { class SingleValueQueryableDimensionSelector extends QueryableDimensionSelector implements SingleValueHistoricalDimensionSelector { private final SingleIndexedInt row = new SingleIndexedInt(); @Override public IndexedInts getRow() { row.setValue(getRowValue()); return row; } public int getRowValue() { return column.get(offset.getOffset()); } @Override public IndexedInts getRow(int offset) { row.setValue(getRowValue(offset)); return row; } @Override public int getRowValue(int offset) { return column.get(offset); } @Override public ValueMatcher makeValueMatcher(final @Nullable String value) { if (extractionFn == null) { final int valueId = lookupId(value); if (valueId >= 0) { return new ValueMatcher() { @Override public boolean matches() { return getRowValue() == valueId; } @Override public void inspectRuntimeShape(RuntimeShapeInspector inspector) { inspector.visit("column", StringDictionaryEncodedColumn.this); } }; } else { return BooleanValueMatcher.of(false); } } else { // Employ caching BitSet optimization return makeValueMatcher(Predicates.equalTo(value)); } } @Override public ValueMatcher makeValueMatcher(final Predicate<String> predicate) { final BitSet checkedIds = new BitSet(getCardinality()); final BitSet matchingIds = new BitSet(getCardinality()); // Lazy matcher; only check an id if matches() is called. return new ValueMatcher() { @Override public boolean matches() { final int id = getRowValue(); if (checkedIds.get(id)) { return matchingIds.get(id); } else { final boolean matches = predicate.apply(lookupName(id)); checkedIds.set(id); if (matches) { matchingIds.set(id); } return matches; } } @Override public void inspectRuntimeShape(RuntimeShapeInspector inspector) { inspector.visit("column", StringDictionaryEncodedColumn.this); } }; } @Override public Object getObject() { return lookupName(getRowValue()); } @Override public Class classOfObject() { return String.class; } @Override public void inspectRuntimeShape(RuntimeShapeInspector inspector) { inspector.visit("column", column); inspector.visit("offset", offset); inspector.visit("extractionFn", extractionFn); } } return new SingleValueQueryableDimensionSelector(); } }
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 w w w .j a v a 2 s . co 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:brooklyn.catalog.internal.BasicBrooklynCatalog.java
private String getDefaultVersion(String symbolicName) { Iterable<CatalogItem<Object, Object>> versions = getCatalogItems( CatalogPredicates.symbolicName(Predicates.equalTo(symbolicName))); Collection<CatalogItem<Object, Object>> orderedVersions = sortVersionsDesc(versions); if (!orderedVersions.isEmpty()) { return orderedVersions.iterator().next().getVersion(); } else {/* w w w. j a v a 2 s. c om*/ return null; } }
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 w w . j av a2s. c om*/ 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(); }//www .jav a 2 s . c om 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.linagora.linshare.core.domain.vo.UploadRequestVo.java
public static Predicate<? super UploadRequestVo> equalTo(String uuid) { UploadRequestVo test = new UploadRequestVo(); test.setUuid(uuid);/*from ww w . j a v a2 s.co m*/ return Predicates.equalTo(test); }
From source file:brooklyn.location.docker.DockerLocation.java
@Override public void release(MachineLocation machine) { if (provisioner == null) { throw new IllegalStateException("No provisioner available to release " + machine); }// w w w .j a va2s .c om String id = machine.getId(); Set<DockerHostLocation> set = Multimaps.filterValues(containers, Predicates.equalTo(id)).keySet(); if (set.isEmpty()) { throw new IllegalArgumentException( "Request to release " + machine + ", but this machine is not currently allocated"); } DockerHostLocation host = Iterables.getOnlyElement(set); if (LOG.isDebugEnabled()) { LOG.debug("Request to remove container mapping {} to {}", host, id); } host.release((DockerContainerLocation) machine); if (containers.remove(host, id)) { if (containers.get(host).isEmpty()) { if (LOG.isDebugEnabled()) { LOG.debug("Empty Docker host: {}", host); } // Remove hosts when it has no containers, except for the last one if (getOwner().config().get(DockerInfrastructure.REMOVE_EMPTY_DOCKER_HOSTS) && set.size() > 1) { LOG.info("Removing empty Docker host: {}", host); remove(host); } } } else { throw new IllegalArgumentException( "Request to release " + machine + ", but container mapping not found"); } }