List of usage examples for java.util Set contains
boolean contains(Object o);
From source file:org.elasticsearch.client.RestClientTestCase.java
/** * Assert that the actual headers are the expected ones given the original default and request headers. Some headers can be ignored, * for instance in case the http client is adding its own automatically. * * @param defaultHeaders the default headers set to the REST client instance * @param requestHeaders the request headers sent with a particular request * @param actualHeaders the actual headers as a result of the provided default and request headers * @param ignoreHeaders header keys to be ignored as they are not part of default nor request headers, yet they * will be part of the actual ones *//*from w ww . j a va2 s . co m*/ protected static void assertHeaders(final Header[] defaultHeaders, final Header[] requestHeaders, final Header[] actualHeaders, final Set<String> ignoreHeaders) { final Map<String, List<String>> expectedHeaders = new HashMap<>(); final Set<String> requestHeaderKeys = new HashSet<>(); for (final Header header : requestHeaders) { final String name = header.getName(); addValueToListEntry(expectedHeaders, name, header.getValue()); requestHeaderKeys.add(name); } for (final Header defaultHeader : defaultHeaders) { final String name = defaultHeader.getName(); if (requestHeaderKeys.contains(name) == false) { addValueToListEntry(expectedHeaders, name, defaultHeader.getValue()); } } Set<String> actualIgnoredHeaders = new HashSet<>(); for (Header responseHeader : actualHeaders) { final String name = responseHeader.getName(); if (ignoreHeaders.contains(name)) { expectedHeaders.remove(name); actualIgnoredHeaders.add(name); continue; } final String value = responseHeader.getValue(); final List<String> values = expectedHeaders.get(name); assertNotNull("found response header [" + name + "] that wasn't originally sent: " + value, values); assertTrue("found incorrect response header [" + name + "]: " + value, values.remove(value)); if (values.isEmpty()) { expectedHeaders.remove(name); } } assertEquals("some headers meant to be ignored were not part of the actual headers", ignoreHeaders, actualIgnoredHeaders); assertTrue("some headers that were sent weren't returned " + expectedHeaders, expectedHeaders.isEmpty()); }
From source file:elaborate.editor.solr.ElaborateSolrIndexer.java
public static SolrInputDocument getSolrInputDocument(ProjectEntry projectEntry, boolean forPublication, Collection<String> facetsToSplit) { SolrInputDocument doc = new SolrInputDocument(); doc.addField(ID, projectEntry.getId()); doc.addField(NAME, projectEntry.getName()); Project project = projectEntry.getProject(); for (String field : project.getProjectEntryMetadataFieldnames()) { String facetName = SolrUtils.facetName(field); String value = projectEntry.getMetadataValue(field); doc.addField(facetName,/*from w w w .j a v a 2 s.c o m*/ StringUtils.defaultIfBlank(value, EMPTYVALUE_SYMBOL).replaceAll("\\r?\\n|\\r", "/"), 1.0f); if (forPublication) { // TODO: This is CNW/BoschDoc specific, refactoring needed handleCNWFacets(facetName, value, doc); if (facetsToSplit.contains(facetName)) { handleMultiValuedFields(facetName, value, doc); } } } Set<String> textLayersProcessed = Sets.newHashSet(); for (Transcription transcription : projectEntry.getTranscriptions()) { String tBody = convert(transcription.getBody()); String textLayer = SolrUtils.normalize(transcription.getTextLayer()); if (textLayersProcessed.contains(textLayer)) { Log.error("duplicate textlayer {} for entry {}", textLayer, projectEntry.getId()); } else { doc.addField(TEXTLAYER_PREFIX + textLayer, tBody); doc.addField(TEXTLAYERCS_PREFIX + textLayer, tBody); for (Annotation annotation : transcription.getAnnotations()) { String body = annotation.getBody(); if (body != null) { String aBody = convert(body); doc.addField(ANNOTATION_PREFIX + textLayer, aBody); doc.addField(ANNOTATIONCS_PREFIX + textLayer, aBody); } } textLayersProcessed.add(textLayer); } } if (!forPublication) { doc.addField(PUBLISHABLE, projectEntry.isPublishable(), 1.0f); doc.addField(PROJECT_ID, projectEntry.getProject().getId()); } Log.info("doc={}", doc); return doc; }
From source file:Main.java
public static List<Element> elements(Element element, Set<String> allowedTagNames) { if (element == null || !element.hasChildNodes()) { return Collections.emptyList(); }//w ww . j a v a 2 s . co m List<Element> elements = new ArrayList<Element>(); for (Node child = element.getFirstChild(); child != null; child = child.getNextSibling()) { if (child.getNodeType() == Node.ELEMENT_NODE) { Element childElement = (Element) child; if (allowedTagNames.contains(child.getLocalName())) { elements.add(childElement); } } } return elements; }
From source file:io.fabric8.maven.core.util.ClassUtil.java
public static <T> Class<T> classForName(String className, List<ClassLoader> additionalClassLoaders) { ClassLoader[] classLoaders = mergeClassLoaders(additionalClassLoaders); Set<ClassLoader> tried = new HashSet<>(); for (ClassLoader loader : classLoaders) { // Go up the classloader stack to eventually find the server class. Sometimes the WebAppClassLoader // hide the server classes loaded by the parent class loader. while (loader != null) { try { if (!tried.contains(loader)) { return (Class<T>) Class.forName(className, true, loader); }/*from w w w .j ava 2s . c o m*/ } catch (ClassNotFoundException ignored) { } tried.add(loader); loader = loader.getParent(); } } return null; }
From source file:com.splicemachine.db.impl.ast.FindHashJoinColumns.java
private static boolean fromResultSets(Set<ResultSetNode> resultSetNodeSet, ResultColumn resultColumn) { ValueNode v = resultColumn.getExpression(); if (v instanceof VirtualColumnNode) { ResultSetNode sourceResultSet = ((VirtualColumnNode) v).getSourceResultSet(); if (resultSetNodeSet.contains(sourceResultSet)) return true; }/* www. j av a2s .c o m*/ return false; }
From source file:io.wcm.caconfig.extensions.persistence.impl.PersistenceUtils.java
/** * Delete children that are no longer contained in list of collection items. * @param resource Parent resource//from w ww .ja v a2s.c o m * @param data List of collection items */ public static void deleteChildrenNotInCollection(Resource resource, ConfigurationCollectionPersistData data) { Set<String> collectionItemNames = data.getItems().stream().map(item -> item.getCollectionItemName()) .collect(Collectors.toSet()); for (Resource child : resource.getChildren()) { if (!collectionItemNames.contains(child.getName()) && !StringUtils.equals(JCR_CONTENT, child.getName())) { deletePageOrResource(child); } } }
From source file:com.bigdata.dastor.tools.SSTableExport.java
/** * Export specific rows from an SSTable and write the resulting JSON to a PrintStream. * //from ww w. j ava2s .c om * @param ssTableFile the SSTable to export the rows from * @param outs PrintStream to write the output to * @param keys the keys corresponding to the rows to export * @throws IOException on failure to read/write input/output */ public static void export(String ssTableFile, PrintStream outs, String[] keys, String[] excludes) throws IOException { SSTableReader reader = SSTableReader.open(ssTableFile); SSTableScanner scanner = reader.getScanner(INPUT_FILE_BUFFER_SIZE); IPartitioner<?> partitioner = DatabaseDescriptor.getPartitioner(); Set<String> excludeSet = new HashSet(); int i = 0; if (excludes != null) excludeSet = new HashSet<String>(Arrays.asList(excludes)); outs.println("{"); for (String key : keys) { if (excludeSet.contains(key)) continue; DecoratedKey<?> dk = partitioner.decorateKey(key); scanner.seekTo(dk); i++; if (scanner.hasNext()) { IteratingRow row = scanner.next(); try { String jsonOut = serializeRow(row); if (i != 1) outs.println(","); outs.print(" " + jsonOut); } catch (IOException ioexc) { System.err.println("WARNING: Corrupt row " + key + " (skipping)."); continue; } catch (OutOfMemoryError oom) { System.err.println("ERROR: Out of memory deserializing row " + key); continue; } } } outs.println("\n}"); outs.flush(); }
From source file:Main.java
static <E> Set<E> ungrowableSet(final Set<E> s) { return new Set<E>() { @Override/*from w w w .ja v a 2 s . co m*/ public int size() { return s.size(); } @Override public boolean isEmpty() { return s.isEmpty(); } @Override public boolean contains(Object o) { return s.contains(o); } @Override public Object[] toArray() { return s.toArray(); } @Override public <T> T[] toArray(T[] a) { return s.toArray(a); } @Override public String toString() { return s.toString(); } @Override public Iterator<E> iterator() { return s.iterator(); } @Override public boolean equals(Object o) { return s.equals(o); } @Override public int hashCode() { return s.hashCode(); } @Override public void clear() { s.clear(); } @Override public boolean remove(Object o) { return s.remove(o); } @Override public boolean containsAll(Collection<?> coll) { return s.containsAll(coll); } @Override public boolean removeAll(Collection<?> coll) { return s.removeAll(coll); } @Override public boolean retainAll(Collection<?> coll) { return s.retainAll(coll); } @Override public boolean add(E o) { throw new UnsupportedOperationException(); } @Override public boolean addAll(Collection<? extends E> coll) { throw new UnsupportedOperationException(); } }; }
From source file:com.github.stagirs.lingvo.syntax.disambiguity.MyStemTest.java
public static Set<Attr> getAttrs(String form) { Set<Attr> result = new HashSet<Attr>(); Set<String> formSet = new HashSet<String>(Arrays.asList(form.split(",|="))); for (Map.Entry<Attr, List<String>> entry : opencorpora2mystem.entrySet()) { if (formSet.containsAll(entry.getValue())) { if (entry.getKey() == Attr.acc2) { continue; }//from w ww. j av a2s .com result.add(entry.getKey()); } if (formSet.contains("ADVPRO")) { result.add(Attr.ADVB); } } return result; }
From source file:com.formtek.dashlets.sitetaskmgr.SiteWFUtil.java
/** * Determines if the current user can cancel/delete or edit the workflow * Starts with the Workflow path/* ww w . j a va 2 s . c o m*/ * * @param operation "edit" or "view" workflow * @param path The workflow path to check * @param site The name of the site the workflow should belong to * @param workflowService workflowService * @param nodeService nodeService * @param authenticationService authenticationService * @param authorityService authorityService * @return true if the user can change the workflow, false otherwise */ public static boolean canAccessWorkflow(String operation, WorkflowPath path, String site, WorkflowService workflowService, NodeService nodeService, AuthenticationService authenticationService, AuthorityService authorityService) { boolean canAccess = false; // Access Security check // Check to make sure that only members of the specified site have access String currentUser = authenticationService.getCurrentUserName(); logger.debug("Current User is: " + currentUser); Set<String> userAuthorities = authorityService.getAuthoritiesForUser(currentUser); if (operation == "view") { // If the user is not a site member or administrator, then return false if (!userAuthorities.contains("GROUP_site_" + site) && !userAuthorities.contains("GROUP_ALFRESCO_ADMINISTRATORS")) { logger.debug( "Exiting because user does not have authority or the workflow is not associated with the site."); } else { canAccess = true; logger.debug("User successfully authenticated for view"); } } else { // Get the current task of the path to see if it belongs to a site WorkflowTask workflowTask = getWorkflowTask(path, workflowService); // Query the initiator of the workflow logger.debug("Querying the initiator"); String initiator = getWorkflowInitiatorUsername(path, nodeService); // Testing for edit rights logger.debug("Is this user [" + currentUser + "] in the SiteManager group?: " + userAuthorities.contains("GROUP_site_" + site + "_SiteManager")); logger.debug("Is this user an administrator?: " + authorityService.hasAdminAuthority()); logger.debug("Is this user an administrator (via alfresco administrators group)?: " + userAuthorities.contains("GROUP_ALFRESCO_ADMINISTRATORS")); logger.debug("Is this user the initiator?: " + currentUser.equals(initiator)); logger.debug("Is this a site task?: " + isSiteTask(workflowTask, site, workflowService)); // If the user is not the site manager, an administrator or the initiator, then return false if (initiator == null || (!userAuthorities.contains("GROUP_site_" + site + "_SiteManager") && !userAuthorities.contains("GROUP_ALFRESCO_ADMINISTRATORS") && !currentUser.equals(initiator)) || !isSiteTask(workflowTask, site, workflowService)) { logger.debug("User does not have authority or the workflow is not associated with the site."); } else { canAccess = true; logger.debug("User successfully authenticated for change"); } } return canAccess; }