List of usage examples for java.util LinkedHashSet contains
boolean contains(Object o);
From source file:org.opencb.opencga.storage.core.variant.VariantStoragePipeline.java
public static void checkAndUpdateStudyConfiguration(StudyConfiguration studyConfiguration, int fileId, VariantSource source, ObjectMap options) throws StorageEngineException { if (options.containsKey(Options.SAMPLE_IDS.key()) && !options.getAsStringList(Options.SAMPLE_IDS.key()).isEmpty()) { for (String sampleEntry : options.getAsStringList(Options.SAMPLE_IDS.key())) { String[] split = sampleEntry.split(":"); if (split.length != 2) { throw new StorageEngineException("Param " + sampleEntry + " is malformed"); }// w w w. jav a 2 s. c om String sampleName = split[0]; int sampleId; try { sampleId = Integer.parseInt(split[1]); } catch (NumberFormatException e) { throw new StorageEngineException("SampleId " + split[1] + " is not an integer", e); } if (!source.getSamplesPosition().containsKey(sampleName)) { //ERROR throw new StorageEngineException( "Given sampleName '" + sampleName + "' is not in the input file"); } else { if (!studyConfiguration.getSampleIds().containsKey(sampleName)) { //Add sample to StudyConfiguration studyConfiguration.getSampleIds().put(sampleName, sampleId); } else { if (studyConfiguration.getSampleIds().get(sampleName) != sampleId) { throw new StorageEngineException("Sample " + sampleName + ":" + sampleId + " was already present. It was in the StudyConfiguration with a different sampleId: " + studyConfiguration.getSampleIds().get(sampleName)); } } } } //Check that all samples has a sampleId List<String> missingSamples = new LinkedList<>(); for (String sampleName : source.getSamples()) { if (!studyConfiguration.getSampleIds().containsKey(sampleName)) { missingSamples.add(sampleName); } /*else { Integer sampleId = studyConfiguration.getSampleIds().get(sampleName); if (studyConfiguration.getIndexedSamples().contains(sampleId)) { logger.warn("Sample " + sampleName + ":" + sampleId + " was already loaded. It was in the StudyConfiguration.indexedSamples"); } }*/ } if (!missingSamples.isEmpty()) { throw new StorageEngineException( "Samples " + missingSamples.toString() + " has not assigned sampleId"); } } else { //Find the grader sample Id in the studyConfiguration, in order to add more sampleIds if necessary. int maxId = 0; for (Integer i : studyConfiguration.getSampleIds().values()) { if (i > maxId) { maxId = i; } } //Assign new sampleIds for (String sample : source.getSamples()) { if (!studyConfiguration.getSampleIds().containsKey(sample)) { //If the sample was not in the original studyId, a new SampleId is assigned. int sampleId; int samplesSize = studyConfiguration.getSampleIds().size(); Integer samplePosition = source.getSamplesPosition().get(sample); if (!studyConfiguration.getSampleIds().containsValue(samplePosition)) { //1- Use with the SamplePosition sampleId = samplePosition; } else if (!studyConfiguration.getSampleIds().containsValue(samplesSize)) { //2- Use the number of samples in the StudyConfiguration. sampleId = samplesSize; } else { //3- Use the maxId sampleId = maxId + 1; } studyConfiguration.getSampleIds().put(sample, sampleId); if (sampleId > maxId) { maxId = sampleId; } } } } if (studyConfiguration.getSamplesInFiles().containsKey(fileId)) { LinkedHashSet<Integer> sampleIds = studyConfiguration.getSamplesInFiles().get(fileId); List<String> missingSamples = new LinkedList<>(); for (String sampleName : source.getSamples()) { if (!sampleIds.contains(studyConfiguration.getSampleIds().get(sampleName))) { missingSamples.add(sampleName); } } if (!missingSamples.isEmpty()) { throw new StorageEngineException( "Samples " + missingSamples.toString() + " were not in file " + fileId); } if (sampleIds.size() != source.getSamples().size()) { throw new StorageEngineException("Incorrect number of samples in file " + fileId); } } else { LinkedHashSet<Integer> sampleIdsInFile = new LinkedHashSet<>(source.getSamples().size()); for (String sample : source.getSamples()) { sampleIdsInFile.add(studyConfiguration.getSampleIds().get(sample)); } studyConfiguration.getSamplesInFiles().put(fileId, sampleIdsInFile); } }
From source file:edu.emory.cci.aiw.cvrg.eureka.etl.ksb.PropositionDefinitionFinder.java
private void getNodesToLoad(Stack<String> processedStack, LinkedHashSet<String> nodesToLoad) { while (!processedStack.empty()) { String node = processedStack.pop(); if (!nodesToLoad.contains(node)) { if (defaultProps.contains(node)) { nodesToLoad.add(node);/*from w w w . j av a2 s .c o m*/ } else { List<PropositionDefinition> parents; synchronized (parentsCache) { parents = parentsCache.get(node); } if (parents != null) { for (PropositionDefinition parent : parents) { if (nodesToLoad.contains(parent.getId())) { nodesToLoad.add(node); break; } } } } } } }
From source file:com.janrain.backplane2.server.Scope.java
public boolean isMessageInScope(@NotNull BackplaneMessage message) { for (BackplaneMessage.Field scopeField : scopes.keySet()) { LinkedHashSet<String> scopeValues = scopes.get(scopeField); if (scopeValues == null || !scopeValues.contains(message.get(scopeField))) return false; }// w ww. java 2s .c o m return true; }
From source file:com.spotify.hamcrest.jackson.IsJsonObject.java
private void describeMismatches(final ObjectNode node, final Description mismatchDescription, final LinkedHashSet<String> mismatchedKeys) { checkArgument(!mismatchedKeys.isEmpty(), "mismatchKeys must not be empty"); String previousMismatchKey = null; String previousKey = null;//from w w w . j a v a2 s . co m mismatchDescription.appendText("{\n"); for (String key : entryMatchers.keySet()) { if (mismatchedKeys.contains(key)) { // If this is not the first key and the previous key was not a mismatch then add ellipsis if (previousKey != null && !Objects.equals(previousMismatchKey, previousKey)) { mismatchDescription.appendText(" ...\n"); } final Matcher<?> valueMatcher = entryMatchers.get(key); final JsonNode value = node.path(key); describeKey(key, mismatchDescription, d -> valueMatcher.describeMismatch(value, d)); previousMismatchKey = key; } previousKey = key; } // If the last element was not a mismatch then add ellipsis if (!Objects.equals(previousMismatchKey, previousKey)) { mismatchDescription.appendText(" ...\n"); } mismatchDescription.appendText("}"); }
From source file:org.openflexo.foundation.sg.implmodel.TechnologyModuleDefinition.java
private void fillRequiredModules(Map<Integer, LinkedHashSet<TechnologyModuleDefinition>> requiredModules, int level) { // Avoid infinite loop (module1 requires module2 and module2 requires module1) for (LinkedHashSet<TechnologyModuleDefinition> set : requiredModules.values()) { if (set.contains(this)) { return; }// www. ja va 2s . co m } LinkedHashSet<TechnologyModuleDefinition> set = requiredModules.get(level); if (set == null) { set = new LinkedHashSet<TechnologyModuleDefinition>(); requiredModules.put(level, set); } set.add(this); for (TechnologyModuleDefinition moduleDefinition : getRequiredModules()) { moduleDefinition.fillRequiredModules(requiredModules, level + 1); } }
From source file:de._13ducks.cor.game.server.movement.SubSectorPathfinder.java
/** * Sucht einen Weg auf Freiflchen (FreePolygon) um ein Hindernis herum. * Beachtet weitere Hindernisse auf der "Umleitung". * Sucht die Route nur bis zum nchsten Ziel. * Der Mover darf sich nicht bereits auf einer Umleitung befinden, * diese muss ggf vorher gelscht worden sein. * @param mover// ww w .ja v a 2s.c om * @param obstacle * @return */ static List<SubSectorEdge> searchDiversion(Moveable mover, Moveable obstacle, SimplePosition target) { // Vorberprfung: Ist das Ziel berhaupt noch frei? List<Moveable> moversAroundTarget = Server.getInnerServer().moveMan.moveMap .moversAroundPoint(target.toFPP(), mover.getRadius() + 5); moversAroundTarget.remove(mover); // Falls drin for (Moveable m : moversAroundTarget) { if (m.getPrecisePosition().getDistance(target.toFPP()) < m.getRadius() + mover.getRadius() + ServerBehaviourMove.MIN_DISTANCE) { System.out.println("No div, target blocked!"); return null; } } /** * Wegsuche in 2 Schritten: * 1. Aufbauen eines geeigneten Graphen, der das gesamte Problem enthlt. * 2. Suchen einer Route in diesem Graphen mittels A* (A-Star). */ // Aufbauen des Graphen: ArrayList<SubSectorObstacle> graph = new ArrayList<SubSectorObstacle>(); // Der Graph selber LinkedList<Moveable> openObstacles = new LinkedList<Moveable>(); // Die Liste mit noch zu untersuchenden Knoten ArrayList<Moveable> closedObstacles = new ArrayList<Moveable>(); // Bearbeitete Knoten openObstacles.add(obstacle); // Startpunkt des Graphen. closedObstacles.add(mover); // Wird im Graphen nicht mitbercksichtigt. double radius = mover.getRadius() + ServerBehaviourMove.MIN_DISTANCE; while (!openObstacles.isEmpty()) { // Neues Element aus der Liste holen und als bearbeitet markieren. Moveable work = openObstacles.poll(); closedObstacles.add(work); SubSectorObstacle next = new SubSectorObstacle(work.getPrecisePosition().x(), work.getPrecisePosition().y(), work.getRadius()); // Zuerst alle Punkte des Graphen lschen, die jetzt nichtmehr erreichbar sind: for (SubSectorObstacle obst : graph) { obst.removeNearNodes(next, radius); } // Mit Graph vernetzen for (SubSectorObstacle node : graph) { if (node.inColRange(next, radius)) { // Schnittpunkte suchen SubSectorNode[] intersections = node.calcIntersections(next, radius); for (SubSectorNode n2 : intersections) { boolean reachable = true; for (SubSectorObstacle o : graph) { if (o.equals(node)) { continue; // Um den gehts jetzt ja gerade, natrlich liegen wir auf diesem Kreis } if (o.moveCircleContains(n2, radius)) { reachable = false; break; } } if (reachable) { // Schnittpunkt einbauen next.addNode(n2); node.addNode(n2); } } } } // Bearbeitetes selbst in Graph einfgen graph.add(next); // Weitere Hindernisse suchen, die jetzt relevant sind. List<Moveable> moversAround = Server.getInnerServer().moveMan.moveMap.moversAround(work, (work.getRadius() + radius) * 2); for (Moveable pmove : moversAround) { if (!closedObstacles.contains(pmove) && !openObstacles.contains(pmove)) { openObstacles.add(pmove); } } } // Jetzt drber laufen und Graph aufbauen: for (SubSectorObstacle obst : graph) { // Vorgensweise: // In jedem Hinderniss die Linie entlanglaufen und Knoten mit Kanten verbinden. // Ein Knoten darf auf einem Kreis immer nur in eine Richtung gehen. // (das sollte mithilfe seiner beiden, bekannten hindernisse recht einfach sein) // Die Lnge des Kreissegments lsst sich einfach mithilfe des winkels ausrechnen (Math.atan2(y,x) // Dann darf der A*. Bzw. Dijkstra, A* ist hier schon fast Overkill. // Alle Knoten ihrem Bogenma nach sortieren. obst.sortNodes(); obst.interConnectNodes(radius); } // Start- und Zielknoten einbauen und mit dem Graph vernetzten. SubSectorNode startNode = new SubSectorNode(mover.getPrecisePosition().x(), mover.getPrecisePosition().y()); SubSectorNode targetNode = new SubSectorNode(target.x(), target.y()); double min = Double.POSITIVE_INFINITY; SubSectorObstacle minObstacle = null; for (SubSectorObstacle obst : graph) { double newdist = Math.sqrt((obst.getX() - startNode.getX()) * (obst.getX() - startNode.getX()) + (obst.getY() - startNode.getY()) * (obst.getY() - startNode.getY())); newdist -= obst.getRadius() + radius; // Es interessiert uns der nchstmgliche Kreis, nicht das nchste Hinderniss if (newdist < min) { min = newdist; minObstacle = obst; } } // Punkt auf Laufkreis finden Vector direct = new Vector(startNode.getX() - minObstacle.getX(), startNode.getY() - minObstacle.getY()); direct = direct.normalize().multiply(minObstacle.getRadius() + radius); SubSectorNode minNode = new SubSectorNode(minObstacle.getX() + direct.getX(), minObstacle.getY() + direct.getY(), minObstacle); // In das Hinderniss integrieren: minObstacle.lateIntegrateNode(minNode); SubSectorEdge startEdge = new SubSectorEdge(startNode, minNode, min); if (!startNode.equals(minNode)) { startNode.addEdge(startEdge); minNode.addEdge(startEdge); } else { // Wir stehen schon auf dem minNode. // Die Einsprungkante ist nicht notwendig. startNode = minNode; } double min2 = Double.POSITIVE_INFINITY; SubSectorObstacle minObstacle2 = null; for (SubSectorObstacle obst : graph) { double newdist = Math.sqrt((obst.getX() - targetNode.getX()) * (obst.getX() - targetNode.getX()) + (obst.getY() - targetNode.getY()) * (obst.getY() - targetNode.getY())); newdist -= obst.getRadius() + radius; // Es interessiert uns der nchstmgliche Kreis, nicht das nchste Hinderniss if (newdist < min2) { min2 = newdist; minObstacle2 = obst; } } // Punkt auf Laufkreis finden Vector direct2 = new Vector(targetNode.getX() - minObstacle2.getX(), targetNode.getY() - minObstacle2.getY()); direct2 = direct2.normalize().multiply(minObstacle2.getRadius() + radius); SubSectorNode minNode2 = new SubSectorNode(minObstacle2.getX() + direct2.getX(), minObstacle2.getY() + direct2.getY(), minObstacle2); // In das Hinderniss integrieren: minObstacle2.lateIntegrateNode(minNode2); SubSectorEdge targetEdge = new SubSectorEdge(minNode2, targetNode, min2); if (!targetNode.equals(minNode2)) { targetNode.addEdge(targetEdge); minNode2.addEdge(targetEdge); } else { // Das Ziel ist schon auf dem Laufkreis. // Die Aussprungkante ist nicht ntig. targetNode = minNode2; } /** * Hier jetzt einen Weg suchen von startNode nach targetNode. * Die Kanten sind in node.myEdges * Die Ziele bekommt man mit edge.getOther(startNode) * Die Lnge (Wegkosten) stehen in edge.length (vorsicht: double-Wert!) */ PriorityBuffer open = new PriorityBuffer(); // Liste fr entdeckte Knoten LinkedHashSet<SubSectorNode> containopen = new LinkedHashSet<SubSectorNode>(); // Auch fr entdeckte Knoten, hiermit kann viel schneller festgestellt werden, ob ein bestimmter Knoten schon enthalten ist. LinkedHashSet<SubSectorNode> closed = new LinkedHashSet<SubSectorNode>(); // Liste fr fertig bearbeitete Knoten double cost_t = 0; //Movement Kosten (gerade 5, diagonal 7, wird spter festgelegt) open.add(startNode); while (open.size() > 0) { SubSectorNode current = (SubSectorNode) open.remove(); containopen.remove(current); if (current.equals(targetNode)) { //Abbruch, weil Weg von Start nach Ziel gefunden wurde //targetNode.setParent(current.getParent()); //"Vorgngerfeld" von Ziel bekannt break; } // Aus der open wurde current bereits gelscht, jetzt in die closed verschieben closed.add(current); ArrayList<SubSectorEdge> neighbors = current.getMyEdges(); for (SubSectorEdge edge : neighbors) { SubSectorNode node = edge.getOther(current); if (closed.contains(node)) { continue; } // Kosten dort hin berechnen cost_t = edge.getLength(); if (containopen.contains(node)) { //Wenn sich der Knoten in der openlist befindet, muss berechnet werden, ob es einen krzeren Weg gibt if (current.getCost() + cost_t < node.getCost()) { //krzerer Weg gefunden? node.setCost(current.getCost() + cost_t); //-> Wegkosten neu berechnen //node.setValF(node.cost + node.getHeuristic()); //F-Wert, besteht aus Wegkosten vom Start + Luftlinie zum Ziel node.setParent(current); //aktuelles Feld wird zum Vorgngerfeld } } else { node.setCost(current.getCost() + cost_t); //node.setHeuristic(Math.sqrt(Math.pow(Math.abs((targetNode.getX() - node.getX())), 2) + Math.pow(Math.abs((targetNode.getY() - node.getY())), 2))); // geschtzte Distanz zum Ziel //Die Zahl am Ende der Berechnung ist der Aufwand der Wegsuche //5 ist schnell, 4 normal, 3 dauert lange node.setParent(current); // Parent ist die RogPosition, von dem der aktuelle entdeckt wurde //node.setValF(node.cost + node.getHeuristic()); //F-Wert, besteht aus Wegkosten vom Start aus + Luftlinie zum Ziel open.add(node); // in openlist hinzufgen containopen.add(node); } } } if (targetNode.getParent() == null) { //kein Weg gefunden return null; } ArrayList<SubSectorNode> pathrev = new ArrayList<SubSectorNode>(); //Pfad aus parents erstellen, von Ziel nach Start while (!targetNode.equals(startNode)) { pathrev.add(targetNode); targetNode = targetNode.getParent(); } pathrev.add(startNode); ArrayList<SubSectorNode> path = new ArrayList<SubSectorNode>(); //Pfad umkehren, sodass er von Start nach Ziel ist for (int k = pathrev.size() - 1; k >= 0; k--) { path.add(pathrev.get(k)); } // Nachbearbeitung: // Wir brauchen eine Kanten-Liste mit arc/direct Informationen ArrayList<SubSectorEdge> finalPath = new ArrayList<SubSectorEdge>(); for (int i = 0; i < path.size() - 1; i++) { SubSectorNode from = path.get(i); SubSectorNode to = path.get(i + 1); SubSectorEdge edge = shortestCommonEdge(from, to); if (edge != null) { finalPath.add(edge); } else { throw new RuntimeException("ERROR Cannot find edge from " + from + " to " + to + " but it is part of the calculated path!!!"); } } return finalPath; //Pfad zurckgeben }
From source file:org.grouplens.grapht.graph.DAGNode.java
/** * Helper mode for {@link #getSortedNodes()}, via {@link TopologicalSortSupplier}. This method * does a depth-first traversal of the nodes, adding each to the {@code visited} set when it is * left. This results in {@code visited} being a topological sort. * * @param visited The set of nodes seen so far. */// w w w.j ava2s .c o m private void sortVisit(LinkedHashSet<DAGNode<V, E>> visited) { if (!visited.contains(this)) { for (DAGEdge<V, E> nbr : outgoingEdges) { nbr.getTail().sortVisit(visited); } // neighbors won't have added this, or we have an impossible cycle assert !visited.contains(this); visited.add(this); } }
From source file:com.chaschev.install.InstallMojo.java
private String findPath() throws MojoFailureException { String path = Optional.fromNullable(System.getenv("path")).or(System.getenv("PATH")); ArrayList<String> pathEntries = newArrayList(path == null ? new String[0] : path.split(File.pathSeparator)); String javaHomeAbsPath = SystemUtils.getJavaHome().getParentFile().getAbsolutePath(); String mavenHomeAbsPath = getMavenHomeByClass(DefaultMaven.class).getAbsolutePath(); List<MatchingPath> matchingPaths = new ArrayList<MatchingPath>(); final LinkedHashSet<File> knownBinFolders = Sets.newLinkedHashSet( Lists.transform(Arrays.asList("/usr/local/bin", "/usr/local/sbin"), PATH_TO_FILE)); for (String pathEntry : pathEntries) { File entryFile = new File(pathEntry); String absPath = entryFile.getAbsolutePath(); boolean writable = isWritable(entryFile); getLog().debug(/*from w w w . j av a 2s . c o m*/ "testing " + entryFile.getAbsolutePath() + ": " + (writable ? "writable" : "not writable")); if (absPath.startsWith(javaHomeAbsPath)) { addMatching(matchingPaths, absPath, writable, 1); } else if (absPath.startsWith(mavenHomeAbsPath)) { addMatching(matchingPaths, absPath, writable, 2); } } if (IS_OS_UNIX && matchingPaths.isEmpty()) { getLog().warn("didn't find maven/jdk writable roots available on path, trying common unix paths: " + knownBinFolders); final LinkedHashSet<File> pathEntriesSet = Sets .newLinkedHashSet(Lists.transform(pathEntries, PATH_TO_FILE)); for (File knownBinFolder : knownBinFolders) { if (pathEntriesSet.contains(knownBinFolder)) { addMatching(matchingPaths, knownBinFolder.getAbsolutePath(), isWritable(knownBinFolder), 3); } } } Collections.sort(matchingPaths); if (matchingPaths.isEmpty()) { throw new MojoFailureException("Could not find a bin folder to write to. Tried: \n" + Joiner.on("\n").join(mavenHomeAbsPath, javaHomeAbsPath) + "\n" + (IS_OS_UNIX ? knownBinFolders + "\n" : "") + " but they don't appear on the path or are not writable. You may try running as administrator or specifying -DinstallTo=your-bin-dir-path parameter"); } return matchingPaths.get(0).path; }
From source file:cc.kave.commons.pointsto.evaluation.ContextSampler.java
public List<Context> sample(Path contextsDirectory, int number) throws IOException { Map<ZipArchive, Integer> registry = buildRegistry(contextsDirectory); try {/*from w w w . j a v a 2s .c om*/ int totalNumContexts = registry.values().stream().mapToInt(Integer::intValue).sum(); LinkedHashSet<Integer> contextIndices = new LinkedHashSet<>(); if (totalNumContexts < number) { for (int i = 0; i < totalNumContexts; ++i) { contextIndices.add(i); } } else { for (int i = 0; i < number; ++i) { int index; do { index = rndGenerator.nextInt(totalNumContexts); } while (contextIndices.contains(index)); contextIndices.add(index); } } List<Context> contexts = new ArrayList<>(number); for (Integer index : contextIndices) { Context ctxt = getContext(registry, index); if (ctxt == null) { ctxt = new Context(); } contexts.add(ctxt); } return contexts; } finally { closeRegistry(registry); } }
From source file:com.assemblade.opendj.Session.java
private List<Entry> internalSearch(String dn, boolean subTree, String filter, LinkedHashSet<String> attributes) throws StorageException { final List<Entry> result = new ArrayList<Entry>(); List<Control> controls = new ArrayList<Control>(); try {// w w w .j a v a2s . com if (attributes.contains("aclRights")) { controls.add(new GetEffectiveRightsRequestControl(false, null, new ArrayList<String>())); } InternalSearchOperation operation = connection.processSearch(dn, subTree ? SearchScope.WHOLE_SUBTREE : SearchScope.SINGLE_LEVEL, DereferencePolicy.NEVER_DEREF_ALIASES, 0, 0, false, filter, attributes, controls, new InternalSearchListener() { @SuppressWarnings("unchecked") public void handleInternalSearchEntry(InternalSearchOperation operation, SearchResultEntry entry) throws DirectoryException { result.add(entry); } public void handleInternalSearchReference(InternalSearchOperation operation, SearchResultReference reference) throws DirectoryException { } }); if (operation.getResultCode() != ResultCode.SUCCESS) { log.error("Failed to search under [" + dn + "] because: " + operation.getErrorMessage().toString()); throw new StorageException(AssembladeErrorCode.ASB_0010); } } catch (DirectoryException e) { log.error("Caught a directory exception trying to search under [" + dn + "]", e); throw new StorageException(AssembladeErrorCode.ASB_9999); } return result; }