List of usage examples for java.util LinkedHashSet contains
boolean contains(Object o);
From source file:Main.java
public static void main(String[] args) { LinkedHashSet<Integer> lhashSet = new LinkedHashSet<Integer>(); lhashSet.add(new Integer("1")); lhashSet.add(new Integer("2")); lhashSet.add(new Integer("3")); System.out.println(lhashSet.contains(new Integer("3"))); }
From source file:com.offbynull.coroutines.instrumenter.asm.TypeUtils.java
private static boolean isArrayElementTypeAssignableFrom(ClassInformationRepository repo, Type t, Type u) { Validate.notNull(repo);/*from w ww. ja va 2s .c om*/ Validate.notNull(t); Validate.notNull(u); Validate.isTrue(t.getSort() == Type.OBJECT); Validate.isTrue(u.getSort() == Type.OBJECT); ClassInformation ci = repo.getInformation(t.getInternalName()); Validate.isTrue(ci != null, "Unable to find class information for %s", t); LinkedHashSet<String> hierarchy = flattenHierarchy(repo, u.getInternalName()); return hierarchy.contains(t.getInternalName()); }
From source file:com.offbynull.coroutines.instrumenter.asm.TypeUtils.java
private static boolean isObjectTypeAssignableFrom(ClassInformationRepository repo, Type t, Type u) { Validate.notNull(repo);//from ww w . j a v a 2 s . co m Validate.notNull(t); Validate.notNull(u); Validate.isTrue(t.getSort() == Type.OBJECT); Validate.isTrue(u.getSort() == Type.OBJECT); ClassInformation ci = repo.getInformation(t.getInternalName()); Validate.isTrue(ci != null, "Unable to find class information for %s", t); if (ci.isInterface()) { // special logic found in original SimpleVerifier moved here t = Type.getType(Object.class); } LinkedHashSet<String> hierarchy = flattenHierarchy(repo, u.getInternalName()); return hierarchy.contains(t.getInternalName()); }
From source file:de.qaware.chronix.solr.type.metric.SolrDocumentBuilder.java
/** * Merges to sets of time series attributes. * The result is set for each key holding the values. * If the other value is a collection, than all values * of the collection are added instead of the collection object. * * @param merged the merged attributes * @param attributes the attributes of the other time series *//*from w w w.ja va 2 s.c o m*/ private static void merge(Map<String, Object> merged, Map<String, Object> attributes) { for (HashMap.Entry<String, Object> newEntry : attributes.entrySet()) { String key = newEntry.getKey(); //we ignore the version in the result if (key.equals("_version_")) { continue; } if (!merged.containsKey(key)) { merged.put(key, new LinkedHashSet()); } LinkedHashSet values = (LinkedHashSet) merged.get(key); Object value = newEntry.getValue(); //Check if the value is a collection. //If it is a collection we add all values instead of adding a collection object if (value instanceof Collection && !values.contains(value)) { values.addAll((Collection) value); } else if (!values.contains(value)) { //Otherwise we have a single value or an array. values.add(value); } //otherwise we ignore the value } }
From source file:de.qaware.chronix.solr.query.analysis.SolrDocumentBuilder.java
/** * Merges to sets of time series attributes. * The result is set for each key holding the values. * If the other value is a collection, than all values * of the collection are added instead of the collection object. * * @param merged the merged attributes * @param attributes the attributes of the other time series *//*from w w w. j av a 2s .c o m*/ private static void merge(Map<String, Object> merged, Map<String, Object> attributes) { for (HashMap.Entry<String, Object> newEntry : attributes.entrySet()) { String key = newEntry.getKey(); //we ignore the version in the result if (key.equals(ChronixQueryParams.SOLR_VERSION_FIELD)) { continue; } if (!merged.containsKey(key)) { merged.put(key, new LinkedHashSet()); } LinkedHashSet values = (LinkedHashSet) merged.get(key); Object value = newEntry.getValue(); //Check if the value is a collection. //If it is a collection we add all values instead of adding a collection object if (value instanceof Collection && !values.contains(value)) { values.addAll((Collection) value); } else if (!values.contains(value)) { //Otherwise we have a single value or an array. values.add(value); } //otherwise we ignore the value } }
From source file:azkaban.utils.PropsUtils.java
private static String resolveVariableReplacement(String value, Props props, LinkedHashSet<String> visitedVariables) { StringBuffer buffer = new StringBuffer(); int startIndex = 0; Matcher matcher = VARIABLE_REPLACEMENT_PATTERN.matcher(value); while (matcher.find(startIndex)) { if (startIndex < matcher.start()) { // Copy everything up front to the buffer buffer.append(value.substring(startIndex, matcher.start())); }/*from w ww.j a v a 2 s.c om*/ String subVariable = matcher.group(1); // Detected a cycle if (visitedVariables.contains(subVariable)) { throw new IllegalArgumentException( String.format("Circular variable substitution found: [%s] -> [%s]", StringUtils.join(visitedVariables, "->"), subVariable)); } else { // Add substitute variable and recurse. String replacement = props.get(subVariable); visitedVariables.add(subVariable); if (replacement == null) { throw new UndefinedPropertyException( String.format("Could not find variable substitution for variable(s) [%s]", StringUtils.join(visitedVariables, "->"))); } buffer.append(resolveVariableReplacement(replacement, props, visitedVariables)); visitedVariables.remove(subVariable); } startIndex = matcher.end(); } if (startIndex < value.length()) { buffer.append(value.substring(startIndex)); } return buffer.toString(); }
From source file:com.cenrise.test.azkaban.PropsUtils.java
private static String resolveVariableReplacement(final String value, final Props props, final LinkedHashSet<String> visitedVariables) { final StringBuffer buffer = new StringBuffer(); int startIndex = 0; final Matcher matcher = VARIABLE_REPLACEMENT_PATTERN.matcher(value); while (matcher.find(startIndex)) { if (startIndex < matcher.start()) { // Copy everything up front to the buffer buffer.append(value.substring(startIndex, matcher.start())); }//from ww w . jav a2 s . co m final String subVariable = matcher.group(1); // Detected a cycle if (visitedVariables.contains(subVariable)) { throw new IllegalArgumentException( String.format("Circular variable substitution found: [%s] -> [%s]", StringUtils.join(visitedVariables, "->"), subVariable)); } else { // Add substitute variable and recurse. final String replacement = props.get(subVariable); visitedVariables.add(subVariable); if (replacement == null) { throw new UndefinedPropertyException( String.format("Could not find variable substitution for variable(s) [%s]", StringUtils.join(visitedVariables, "->"))); } buffer.append(resolveVariableReplacement(replacement, props, visitedVariables)); visitedVariables.remove(subVariable); } startIndex = matcher.end(); } if (startIndex < value.length()) { buffer.append(value.substring(startIndex)); } return buffer.toString(); }
From source file:com.santander.serenity.devstack.springfox.config.itest.EnvironmentListenerIntegrationTests.java
/** * Checks that the property "security.ignored" has the correct values *//* w w w . ja v a2 s. com*/ @Test public void securityIgnoredPropertyValuesTest() { ConfigurableEnvironment environment = context.getEnvironment(); MutablePropertySources propertySources = environment.getPropertySources(); PropertySource<?> modifiedSecurityIgnoredPropertySource = propertySources .get("ModifiedSecurityIgnoredPropertySource"); Object securityIgnoredPropertyValues = modifiedSecurityIgnoredPropertySource .getProperty("security.ignored"); LinkedHashSet set = (LinkedHashSet) securityIgnoredPropertyValues; Assert.assertTrue("/webjars/** property is not in the security.ignored set", set.contains("/webjars/**")); Assert.assertTrue("/swagger-resources property is not in the security.ignored set", set.contains("/swagger-resources")); Assert.assertTrue("/v2/api-docs property is not in the security.ignored set", set.contains("/v2/api-docs")); Assert.assertTrue("/configuration/ui property is not in the security.ignored set", set.contains("/configuration/ui")); Assert.assertTrue("/configuration/security property is not in the security.ignored set", set.contains("/configuration/security")); Assert.assertTrue("/swagger-ui.html property is not in the security.ignored set", set.contains("/swagger-ui.html")); }
From source file:org.agiso.tempel.core.RecursiveTemplateVerifier.java
/** * Weryfikuje poprawno szablonu, szablonu nadrzdnego i rekurencyjne * sprawdza wszystkie szablony uywane. Kontroluje, czy drzewie wywoa * szablonw nie wystpuje zaptlenie.//from w ww . ja va 2s.co m * * @param template Szablon do weryfikacji. * @param templates Zbir identyfikatorw szablonw gazi. Wykorzystywany * do wykrywania zaptle wywoa. */ private void verifyTemplate(Template<?> template, LinkedHashSet<String> templates) { String id = template.getKey(); // Sprawdzanie, czy w gazi wywoa szablonw nie ma zaptlenia: if (templates.contains(id)) { // Wywietlanie gazi z zaptleniem i wyrzucanie wyjtku: Iterator<String> t = templates.iterator(); System.out.print(t.next()); while (t.hasNext()) { System.out.print("->" + t.next()); } System.out.println("->" + id); throw new IllegalStateException("Zaptlenie wywoa szablonu '" + id + "'"); } // Szablon OK. Dodawanie do zbioru szablonw gazi: templates.add(id); // // Sprawdzanie kadego z podszablonw szablonu: // if(template.getReferences() != null) { // for(TemplateReference reference : template.getReferences()) { // verifyTemplate(reference, templates); // } // } }
From source file:de._13ducks.cor.game.server.movement.SectorPathfinder.java
/** * Der Start und Zielknoten sind von weit mehr als nur den Knoten ihres Polygons erreichbar. * Dies muss bereits whrend der Basic-Berechnung beachtet werden, das kann die Pfadoptimierung nachtrglich nichtmehr leisten. * Also alle Nodes suchen, die ohne Hinderniss direkt erreichbar sind * @param from alle vollstndig im Mesh liegenden Kanten von hier zu Nachbarknoten suchen * @param basicPolygon Der Polygon, in dem der Node drinliegt. * @return alle direkt erreichbaren Knoten (natrlich sind die des basicPolygons auch dabei) *///from www . ja v a 2 s . c o m private static Node[] computeDirectReachable(Node from, FreePolygon basicPolygon) { // Das ist eine modifizierte Breitensuche: LinkedList<FreePolygon> open = new LinkedList<FreePolygon>(); // Queue fr zu untersuchende Polygone LinkedHashSet<FreePolygon> openContains = new LinkedHashSet<FreePolygon>(); // Welche Elemente die open enthlt (schnellerer Test) LinkedHashSet<FreePolygon> closed = new LinkedHashSet<FreePolygon>(); LinkedHashSet<Node> testedNodes = new LinkedHashSet<Node>(); LinkedList<Node> result = new LinkedList<Node>(); open.offer(basicPolygon); // Start-Polygon openContains.add(basicPolygon); while (!open.isEmpty()) { // Diesen hier bearbeiten wir jetzt FreePolygon poly = open.poll(); openContains.remove(poly); closed.add(poly); boolean containsreachableNodes = false; // Alle Nodes dieses Knotens untersuchen for (Node node : poly.getNodes()) { // Schon bekannt? if (result.contains(node)) { // Bekannt und ok containsreachableNodes = true; } else { if (testedNodes.contains(node)) { // Der geht nicht } else { // Testen! FreePolygon currentPoly = basicPolygon; // Testweise Kante zwischen from und node erstellen Edge edge = new Edge(from, node); // Im Folgenden wird untersucht, ob der neue Weg "edge" passierbar ist. // Damit wir beim Dreieckwechsel nicht wieder zurck gehen: Node lastNode = null; boolean routeAllowed = true; // Jetzt so lange weiter laufen, bis wir im Ziel-Polygon sind while (!node.getPolygons().contains(currentPoly)) { // Untersuchen, ob es eine Seite des currentPolygons gibt, die sich mit der alternativRoute schneidet List<Edge> edges = currentPoly.calcEdges(); Edge intersecting = null; SimplePosition intersection = null; for (Edge testedge : edges) { // Gibts da einen Schnitt? intersection = edge.intersectionWithEndsNotAllowed(testedge); if (intersection != null && !intersection.equals(lastNode)) { intersecting = testedge; break; } } // Kandidat fr den nchsten Polygon FreePolygon nextPoly = null; // Kante gefunden if (intersecting != null) { // Von dieser Kante die Enden suchen nextPoly = getOtherPoly(intersecting.getStart(), intersecting.getEnd(), currentPoly); } if (intersecting != null && nextPoly != null) { // Wir haben einen Schnittpunkt und eine Kante gefunden, sind jetzt also in einem neuen Polygon // Extra Node bentigt Node extraNode = intersection.toNode(); extraNode.addPolygon(nextPoly); extraNode.addPolygon(currentPoly); lastNode = extraNode; currentPoly = nextPoly; // Der nchste Schleifendurchlauf wird den nchsten Polygon untersuchen } else { // Es gab leider keinen betretbaren Polygon hier. // Das bedeutet, dass wir die Suche abbrechen knnen, es gibt hier keinen direkten Weg routeAllowed = false; break; } } // Wenn der neue Weg gltig war, einbauen. Sonst weiter mit dem nchsten Knoten if (routeAllowed) { // In die erlaubt-Liste: result.add(node); testedNodes.add(node); containsreachableNodes = true; } else { testedNodes.add(node); } } } } // Nur weiter in die Tiefe gehen, wenn mindestens einer erreichbar war if (containsreachableNodes) { // Alle Nachbarn untersuchen: for (FreePolygon n : poly.getNeighbors()) { // Schon bekannt/bearbeitet? if (!openContains.contains(n) && !closed.contains(n)) { // Nein, also auch zur Bearbeitung vorsehen open.add(n); openContains.add(n); } } } } return result.toArray(new Node[0]); }