List of usage examples for java.util Set equals
boolean equals(Object o);
From source file:ddf.catalog.impl.operations.DeleteOperations.java
private boolean foundAllDeleteRequestMetacards(DeleteRequest deleteRequest, SourceResponse response) { Set<String> originalKeys = deleteRequest.getAttributeValues().stream().map(Object::toString) .collect(Collectors.toSet()); Set<String> responseKeys = response.getResults().stream().map(Result::getMetacard) .map(m -> m.getAttribute(deleteRequest.getAttributeName())).filter(Objects::nonNull) .map(Attribute::getValue).filter(Objects::nonNull).map(Object::toString) .collect(Collectors.toSet()); return originalKeys.equals(responseKeys); }
From source file:org.intermine.pathquery.LogicExpression.java
/** * Takes a List of collections of String variables and returns a List of the same length, * containing sections of the LogicExpression with those variables in. * * @param variables a List of Collections of String variable names * @return a List of LogicExpression objects * @throws IllegalArgumentException if the LogicExpression cannot be split up in this way, * or if there is an overlap in variables, or if there is an unrepresented variable, or if * there is an extra variable//from w w w . j a va 2 s .c o m */ public List<LogicExpression> split(List<? extends Collection<String>> variables) { Set<String> presentVariables = new HashSet<String>(); for (Collection<String> v : variables) { for (String var : v) { if (presentVariables.contains(var)) { throw new IllegalArgumentException("There is an overlap in variables"); } presentVariables.add(var); } } if (!presentVariables.equals(getVariableNames())) { throw new IllegalArgumentException("Variables in argument (" + presentVariables + ") do not match variables in expression (" + getVariableNames() + ")"); } if (root instanceof Variable) { return Collections.singletonList(this); } else if (root instanceof Or) { if (variables.size() == 1) { return Collections.singletonList(this); } else { throw new IllegalArgumentException("Cannot split OR constraint " + toString()); } } else { And and = (And) root; List<List<String>> buckets = new ArrayList<List<String>>(); for (int i = 0; i < variables.size(); i++) { buckets.add(new ArrayList<String>()); } for (Node node : and.getChildren()) { Set<String> hasVariables = new HashSet<String>(); getVariableNames(hasVariables, node); int bucketNo = -1; for (int i = 0; i < variables.size(); i++) { Collection<String> bucketVariables = variables.get(i); if (bucketVariables.containsAll(hasVariables)) { buckets.get(i).add(node.toString()); bucketNo = i; break; } } if (bucketNo == -1) { throw new IllegalArgumentException("Cannot split node " + node.toString()); } } List<LogicExpression> retval = new ArrayList<LogicExpression>(); for (List<String> bucket : buckets) { if (bucket.isEmpty()) { retval.add(null); } else { StringBuffer newExpression = new StringBuffer(); boolean needComma = false; for (String part : bucket) { if (needComma) { newExpression.append(" and "); } needComma = true; newExpression.append("(" + part + ")"); } retval.add(new LogicExpression(newExpression.toString())); } } return retval; } }
From source file:org.apache.whirr.ClusterSpec.java
public InstanceTemplate getInstanceTemplate(final Set<String> roles) { for (InstanceTemplate template : instanceTemplates) { if (roles.equals(template.getRoles())) { return template; }//from w ww . ja va 2 s.c om } return null; }
From source file:moe.johnny.tombstone.ui.PreventFragment.java
private void setNewAdapterIfNeeded(PreventActivity activity, boolean force) { Set<String> names; if (force || prevNames == null) { names = getPackageNames(activity); } else {/*from w ww . ja v a 2 s. c o m*/ names = prevNames; } if (force || mAdapter == null || !names.equals(prevNames)) { if (mAdapter != null) { setListAdapter(null); } mAdapter = new Adapter(activity, names, filter, showRunning()); setListAdapter(mAdapter); if (prevNames == null) { prevNames = new HashSet<String>(); } prevNames.clear(); prevNames.addAll(names); } else { mAdapter.notifyDataSetChanged(); Position position = getListPosition(); if (position != null) { getListView().setSelectionFromTop(position.pos, position.top); } } }
From source file:com.yahoo.elide.core.PersistentResource.java
/** * Filter a set of PersistentResources.//from w w w . j a v a 2 s. c o m * * @param <A> the type parameter * @param <T> the type parameter * @param permission the permission * @param resources the resources * @return Filtered set of resources */ protected static <A extends Annotation, T> Set<PersistentResource<T>> filter(Class<A> permission, Set<PersistentResource<T>> resources) { Set<PersistentResource<T>> filteredSet = new LinkedHashSet<>(); for (PersistentResource<T> resource : resources) { try { resource.checkFieldAwarePermissions(permission); filteredSet.add(resource); } catch (ForbiddenAccessException e) { // Do nothing. Filter from set. } } // keep original SingleElementSet if (resources instanceof SingleElementSet && resources.equals(filteredSet)) { return resources; } return filteredSet; }
From source file:org.jitsi.videobridge.Endpoint.java
/** * Notifies this {@code Endpoint} that a * {@code SelectedEndpointChangedEvent} has been received by the associated * {@code SctpConnection}.//from w ww .j a v a 2 s . c o m * * @param src the {@code WebRtcDataStream} by which {@code jsonObject} has * been received * @param jsonObject the JSON object with {@link Videobridge#COLIBRI_CLASS} * {@code SelectedEndpointChangedEvent} which has been received by the * associated {@code SctpConnection} */ private void onSelectedEndpointChangedEvent(WebRtcDataStream src, JSONObject jsonObject) { List<String> newSelectedEndpointIDs = readSelectedEndpointID(jsonObject); if (logger.isDebugEnabled()) { StringCompiler sc = new StringCompiler(); sc.bind("selectedIds", newSelectedEndpointIDs); sc.bind("this", this); logger.debug(sc .c("Endpoint {this.id} notified us that its big screen" + " displays endpoint {selectedId}.")); } Conference conference = weakConference.get(); Set<Endpoint> newSelectedEndpoints = new HashSet<>(); if (!newSelectedEndpointIDs.isEmpty() && conference != null) { for (String endpointId : newSelectedEndpointIDs) { Endpoint endpoint = conference.getEndpoint(endpointId); if (endpoint != null) { newSelectedEndpoints.add(endpoint); } } } boolean changed; Set<Endpoint> oldSelectedEndpoints = this.getSelectedEndpoints(); synchronized (selectedEndpointSyncRoot) { // Compare the collections changed = !(oldSelectedEndpoints.equals(newSelectedEndpoints)); if (changed) { updateWeakSelectedEndpoints(newSelectedEndpoints); } } // NOTE(gp) This won't guarantee that property change events are fired // in the correct order. We should probably call the // firePropertyChange() method from inside the synchronized _and_ the // underlying PropertyChangeNotifier should have a dedicated events // queue and a thread for firing PropertyChangeEvents from the queue. if (changed) { if (logger.isDebugEnabled()) { StringCompiler sc = new StringCompiler(); sc.bind("selected", newSelectedEndpoints); sc.bind("this", this); logger.debug(sc.c("Endpoint {this.id} selected {selected.id}.")); } firePropertyChange(SELECTED_ENDPOINT_PROPERTY_NAME, oldSelectedEndpoints, newSelectedEndpoints); } }
From source file:net.solarnetwork.node.power.sma.yasdi4j.SMAyasdi4jPowerDatumDataSource.java
private void setupChannelNamesToMonitor() { Set<String> s = new LinkedHashSet<String>(3); if (getPvWattsChannelNames() != null && getPvWattsChannelNames().size() > 0) { s.addAll(getPvWattsChannelNames()); } else {/* w w w . j a va 2s . co m*/ if (getPvVoltsChannelName() != null) { s.add(getPvVoltsChannelName()); } if (getPvAmpsChannelName() != null) { s.add(getPvAmpsChannelName()); } } s.add(getkWhChannelName()); if (otherChannelNames != null) { s.addAll(otherChannelNames); } if (!s.equals(this.getChannelNamesToMonitor())) { setChannelNamesToMonitor(s); } }
From source file:org.candlepin.policy.js.pool.PoolRules.java
private boolean checkForChangedProducts(Product incomingProduct, Set<Product> incomingProvided, Pool existingPool, Set<Product> changedProducts) { Product existingProduct = existingPool.getProduct(); Set<Product> currentProvided = existingPool.getProvidedProducts(); String pid = existingProduct.getId(); // TODO: ideally we would differentiate between these different product changes // a little, but in the end it probably doesn't matter: boolean productsChanged = (pid != null && !pid.equals(incomingProduct.getId())) || !currentProvided.equals(incomingProvided); // Check if the existing product is in the set of changed products if (!productsChanged && changedProducts != null && existingProduct.getId() != null) { for (Product product : changedProducts) { if (pid.equals(product.getId())) { // TODO: Should we maybe check if the products have actually changed, or is it // safe to assume their presence is enough? productsChanged = true;/* w w w. ja v a2 s .c o m*/ break; } } } if (productsChanged) { existingPool.setProduct(incomingProduct); existingPool.setProvidedProducts(incomingProvided); } return productsChanged; }
From source file:org.candlepin.policy.js.pool.PoolRules.java
private boolean checkForChangedDerivedProducts(Pool pool, Pool existingPool, Set<Product> changedProducts) { boolean productsChanged = false; if (pool.getDerivedProduct() != null) { productsChanged = !pool.getDerivedProduct().getId().equals(existingPool.getDerivedProduct().getId()); productsChanged = productsChanged || (changedProducts != null && changedProducts.contains(pool.getDerivedProduct())); }// w w w. j a v a 2 s .c o m // Build expected set of ProvidedProducts and compare: Set<Product> currentProvided = existingPool.getDerivedProvidedProducts(); Set<Product> incomingProvided = new HashSet<Product>(); if (pool.getDerivedProvidedProducts() != null) { for (Product p : pool.getDerivedProvidedProducts()) { incomingProvided.add(p); } } productsChanged = productsChanged || !currentProvided.equals(incomingProvided); if (productsChanged) { // 998317: NPE during refresh causes refresh to abort. // Above we check getDerivedProduct for null, but here // we ignore the fact that it may be null. So we will // now check for null to avoid blowing up. if (pool.getDerivedProduct() != null) { existingPool.setDerivedProduct(pool.getDerivedProduct()); } else { // subscription no longer has a derived product existingPool.setDerivedProduct(null); } existingPool.getDerivedProvidedProducts().clear(); if (incomingProvided != null && !incomingProvided.isEmpty()) { existingPool.getDerivedProvidedProducts().addAll(incomingProvided); } } return productsChanged; }
From source file:org.mifosplatform.portfolio.loanproduct.domain.LoanProduct.java
public boolean updateTaxes(final Collection<TaxMap> newProductTaxes) { if (newProductTaxes == null) { return false; }// w w w. j a v a 2 s. c o m boolean updated = false; if (this.taxes != null) { final Set<TaxMap> currentSetOfTaxes = new HashSet<TaxMap>(this.taxes); final Set<TaxMap> newSetOfTaxes = new HashSet<TaxMap>(newProductTaxes); if (!currentSetOfTaxes.equals(newSetOfTaxes)) { updated = true; this.taxes = newProductTaxes; } } else { updated = true; this.taxes = newProductTaxes; } return updated; }