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.brooklyn.util.core.osgi.BundleMaker.java
/** create a copy of the given ZIP as a JAR with the given manifest, returning the new temp file */ public File copyAddingManifest(File f, Manifest mf) { File f2 = Os.newTempFile(f.getName(), "zip"); ZipOutputStream zout = null;//from w ww . j ava 2s .co m ZipFile zf = null; try { zout = new JarOutputStream(new FileOutputStream(f2), mf); writeZipEntriesFromFile(zout, f, Predicates.not(Predicates.equalTo(MANIFEST_PATH))); } catch (IOException e) { throw Exceptions.propagateAnnotated("Unable to read " + f + " when looking for manifest", e); } finally { Streams.closeQuietly(zf); Streams.closeQuietly(zout); } return f2; }
From source file:eu.numberfour.n4js.ui.containers.NfarStorageMapper.java
private void updateCache(IN4JSEclipseProject project) { Set<URI> libArchives = knownLibArchives.get(project.getLocation()); if (libArchives != null) { Map<URI, Set<URI>> filteredMap = Maps.filterKeys(knownLibArchives, Predicates.not(Predicates.equalTo(project.getLocation()))); Set<URI> remainingLibs = Sets.newHashSet(Iterables.concat(filteredMap.values())); for (URI archive : libArchives) { if (!remainingLibs.contains(archive)) { knownEntries.remove(archive); }// w w w.j av a 2 s .c om } } if (project.exists()) { libArchives = Sets.newHashSetWithExpectedSize(3); List<? extends IN4JSArchive> libraries = project.getLibraries(); for (IN4JSArchive archive : libraries) { URI location = archive.getLocation(); libArchives.add(location); if (!knownEntries.containsKey(location)) { Set<URI> entryURIs = Sets.newHashSet(); traverseArchive(archive, entryURIs); knownEntries.put(location, Collections.unmodifiableSet(entryURIs)); } } knownLibArchives.put(project.getLocation(), libArchives); } else { knownLibArchives.remove(project.getLocation()); } }
From source file:eu.stratosphere.sopremo.expressions.EvaluationExpression.java
/** * Removes all sub-trees in-place that are equal to the given expression.<br> * If expressions cannot be completely removed, they are replaced by {@link EvaluationExpression#VALUE}. * /* w ww .j a v a 2s . c o m*/ * @param expressionToRemove * the expression to compare to * @return this expression without removed sub-expressions */ public EvaluationExpression remove(final EvaluationExpression expressionToRemove) { return this.remove(Predicates.equalTo(expressionToRemove)); }
From source file:org.eclipse.sirius.diagram.sequence.business.internal.util.SubEventsHelper.java
private Collection<ISequenceEvent> getCarryingParents(AbstractFrame frame, Set<Lifeline> coveredLifelines) { Set<ISequenceEvent> coveredEvents = Sets.newLinkedHashSet(); for (Lifeline lifeline : coveredLifelines) { EventFinder localParentFinder = new EventFinder(lifeline); localParentFinder.setReparent(true); localParentFinder.setEventsToIgnore(Predicates.equalTo((ISequenceEvent) frame)); ISequenceEvent localParent = localParentFinder.findMostSpecificEvent(frame.getVerticalRange()); if (localParent != null) { coveredEvents.add(localParent); }/* w ww . j a v a 2 s . c om*/ } return coveredEvents; }
From source file:com.google.gerrit.pgm.RebuildNoteDb.java
@Override public int run() throws Exception { mustHaveValidSite();//ww w.jav a 2 s. c om dbInjector = createDbInjector(MULTI_USER); threads = ThreadLimiter.limitThreads(dbInjector, threads); LifecycleManager dbManager = new LifecycleManager(); dbManager.add(dbInjector); dbManager.start(); sysInjector = createSysInjector(); sysInjector.injectMembers(this); if (!notesMigration.enabled()) { throw die("NoteDb is not enabled."); } LifecycleManager sysManager = new LifecycleManager(); sysManager.add(sysInjector); sysManager.start(); ListeningExecutorService executor = newExecutor(); System.out.println("Rebuilding the NoteDb"); ImmutableListMultimap<Project.NameKey, Change.Id> changesByProject = getChangesByProject(); boolean ok; Stopwatch sw = Stopwatch.createStarted(); try (Repository allUsersRepo = repoManager.openRepository(allUsersName)) { deleteRefs(RefNames.REFS_DRAFT_COMMENTS, allUsersRepo); List<ListenableFuture<Boolean>> futures = new ArrayList<>(); List<Project.NameKey> projectNames = Ordering.usingToString().sortedCopy(changesByProject.keySet()); for (Project.NameKey project : projectNames) { ListenableFuture<Boolean> future = executor.submit(() -> { try (ReviewDb db = unwrapDb(schemaFactory.open())) { return rebuildProject(db, changesByProject, project, allUsersRepo); } catch (Exception e) { log.error("Error rebuilding project " + project, e); return false; } }); futures.add(future); } try { ok = Iterables.all(Futures.allAsList(futures).get(), Predicates.equalTo(true)); } catch (InterruptedException | ExecutionException e) { log.error("Error rebuilding projects", e); ok = false; } } double t = sw.elapsed(TimeUnit.MILLISECONDS) / 1000d; System.out.format("Rebuild %d changes in %.01fs (%.01f/s)\n", changesByProject.size(), t, changesByProject.size() / t); return ok ? 0 : 1; }
From source file:org.apache.brooklyn.entity.group.AbstractGroupImpl.java
/** * Adds the given entity as a member of this group <em>and</em> this group as one of the groups of the child */// w ww . j av a2s .co m @Override public boolean addMember(Entity member) { synchronized (members) { if (Entities.isNoLongerManaged(member)) { // Don't add dead entities, as they could never be removed (because addMember could be called in // concurrent thread as removeMember triggered by the unmanage). // Not using Entities.isManaged here, as could be called in entity.init() log.debug("Group {} ignoring new member {}, because it is no longer managed", this, member); return false; } // FIXME do not set sensors on members; possibly we don't need FIRST at all, just look at the first in MEMBERS, and take care to guarantee order there Entity first = getAttribute(FIRST); if (first == null) { ((EntityLocal) member).sensors().set(FIRST_MEMBER, true); ((EntityLocal) member).sensors().set(FIRST, member); sensors().set(FIRST, member); } else { if (first.equals(member) || first.equals(member.getAttribute(FIRST))) { // do nothing (rebinding) } else { ((EntityLocal) member).sensors().set(FIRST_MEMBER, false); ((EntityLocal) member).sensors().set(FIRST, first); } } member.addGroup((Group) getProxyIfAvailable()); boolean changed = addMemberInternal(member); if (changed) { log.debug("Group {} got new member {}", this, member); sensors().set(GROUP_SIZE, getCurrentSize()); sensors().set(GROUP_MEMBERS, getMembers()); // emit after the above so listeners can use getMembers() and getCurrentSize() sensors().emit(MEMBER_ADDED, member); if (Boolean.TRUE.equals(getConfig(MEMBER_DELEGATE_CHILDREN))) { log.warn("Use of deprecated ConfigKey {} in {} (as of 0.9.0)", MEMBER_DELEGATE_CHILDREN.getName(), this); Optional<Entity> result = Iterables.tryFind(getChildren(), Predicates.equalTo(member)); if (!result.isPresent()) { String nameFormat = Optional.fromNullable(getConfig(MEMBER_DELEGATE_NAME_FORMAT)).or("%s"); DelegateEntity child = addChild(EntitySpec.create(DelegateEntity.class) .configure(DelegateEntity.DELEGATE_ENTITY, member) .displayName(String.format(nameFormat, member.getDisplayName()))); } } getManagementSupport().getEntityChangeListener().onMembersChanged(); } return changed; } }
From source file:tile80.tile80.Tile80.java
/** * Self crunch with all tag it contains/*ww w. java2s .c om*/ * @param world * @param event * @return */ public Iterable<Tile80> crunch(World80 world, Set<String> event) { ImmutableSet.Builder<Tile80> ret = ImmutableSet.builder(); Tile80 newTile = this; for (Behavior80 tag : getBehavior()) { Iterable<Tile80> tileLst = tag.crunch(newTile, world, event); newTile = findSelf(tileLst); for (Tile80 tile : FluentIterable.from(tileLst).filter(Predicates.not(Predicates.equalTo(newTile)))) ret.add(tile); if (newTile.equals(nothing)) break; } return ret.add(newTile).build(); }
From source file:org.apache.brooklyn.test.EntityTestUtils.java
/** alternate version of {@link #assertAttributeChangesEventually(Entity, AttributeSensor)} not using subscriptions and * with simpler code, for comparison */ @Beta// w w w . j ava 2 s . c om public static <T> void assertAttributeChangesEventually2(final Entity entity, final AttributeSensor<T> attribute) { assertAttributeEventually(entity, attribute, Predicates.not(Predicates.equalTo(entity.getAttribute(attribute)))); }
From source file:brooklyn.entity.nosql.etcd.EtcdClusterImpl.java
protected void onServerPoolMemberChanged(Entity member) { synchronized (mutex) { log.debug("For {}, considering membership of {} which is in locations {}", new Object[] { this, member, member.getLocations() }); Map<Entity, String> nodes = getAttribute(ETCD_CLUSTER_NODES); if (belongsInServerPool(member)) { if (nodes == null) { nodes = Maps.newLinkedHashMap(); }//from w ww .j a v 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. Entity firstNode = getAttribute(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).setAttribute(EtcdNode.ETCD_NODE_HAS_JOINED_CLUSTER, Boolean.TRUE); } else { int retry = 3; // TODO use a configurable Repeater instead? while (retry-- > 0 && member.getAttribute(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 .attributeWhenReady(anyNodeInCluster.get(), Startable.SERVICE_UP)) .orSubmitAndBlock(this).andWaitForSuccess(); Entities.invokeEffectorWithArgs(this, anyNodeInCluster.get(), EtcdNode.JOIN_ETCD_CLUSTER, name, getNodeAddress(member)).blockUntilEnded(); nodes.put(member, name); recalculateClusterAddresses(nodes); log.info("Adding node {}: {}; {} to cluster", new Object[] { this, member, name }); ((EntityInternal) member).setAttribute(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).setAttribute(EtcdNode.ETCD_NODE_HAS_JOINED_CLUSTER, Boolean.FALSE); } } ServiceNotUpLogic.updateNotUpIndicatorRequiringNonEmptyMap(this, ETCD_CLUSTER_NODES); log.debug("Done {} checkEntity {}", this, member); } }
From source file:clocker.mesos.location.MesosLocation.java
@Override public void release(MachineLocation task) { String id = task.getId();/*from ww w . j av a2 s .c o m*/ Set<MachineProvisioningLocation> set = Multimaps.filterValues(tasks, Predicates.equalTo(id)).keySet(); if (set.isEmpty()) { throw new IllegalArgumentException("Request to release " + task + ", but not currently allocated"); } MachineProvisioningLocation framework = Iterables.getOnlyElement(set); LOG.debug("Request to remove task mapping {} to {}", framework, id); framework.release(task); tasks.remove(framework, id); }