List of usage examples for java.util LinkedList contains
public boolean contains(Object o)
From source file:fr.univlorraine.mondossierweb.views.RechercheRapideView.java
private List<ResultatDeRecherche> quickSearch(String valueString) { List<ResultatDeRecherche> listeReponses = new LinkedList<ResultatDeRecherche>(); items.clear();/*from ww w . j a v a 2s . c o m*/ String value = valueString; if (StringUtils.hasText(value) && value.length() > 2) { /////////////////////////////////////////////////////// //appel elasticSearch /////////////////////////////////////////////////////// //transformation de la chaine recherche en fonction des besoins String valueselasticSearch = value; //valueselasticSearch = valueselasticSearch+"*"; List<Map<String, Object>> lobjresult = ElasticSearchService.findObj(valueselasticSearch, Utils.NB_MAX_RESULT_QUICK_SEARCH * 5, true); //Liste des types autoriss LinkedList<String> listeTypeAutorise = new LinkedList(); if (casesAcocherComposantes.getValue()) { listeTypeAutorise.add(Utils.CMP); } if (casesAcocherVet.getValue()) { listeTypeAutorise.add(Utils.VET); } if (casesAcocherElp.getValue()) { listeTypeAutorise.add(Utils.ELP); } if (casesAcocherEtudiant.getValue()) { listeTypeAutorise.add(Utils.ETU); } /////////////////////////////////////////////////////// // recuperation des obj ElasticSearch /////////////////////////////////////////////////////// if (lobjresult != null && listeTypeAutorise.size() > 0) { for (Map<String, Object> obj : lobjresult) { if (listeReponses.size() < Utils.NB_MAX_RESULT_QUICK_SEARCH) { if (obj != null) { if (listeTypeAutorise.contains((String) obj.get(Utils.ES_TYPE))) { if (listeReponses.size() > 0) { boolean triOk = true; int rang = 0; //On evite des doublons while (triOk && rang < listeReponses.size()) { //En quickSearch on prend la description et non pas le libelle ResultatDeRecherche r = (ResultatDeRecherche) listeReponses.get(rang); if ((r.lib.toUpperCase()) .equals((new ResultatDeRecherche(obj)).lib.toUpperCase())) { triOk = false; } rang++; } if (triOk) { //En quickSearch on prend la description et non pas le libelle listeReponses.add(new ResultatDeRecherche(obj)); items.add(new ResultatDeRecherche(obj)); } } else { //En quickSearch on prend la description et non pas le libelle listeReponses.add(new ResultatDeRecherche(obj)); items.add(new ResultatDeRecherche(obj)); } } } } } } } //return listeReponses; //return new ArrayList<Object>(listeReponses); return listeReponses; }
From source file:de.ovgu.featureide.featurehouse.FeatureHouseComposer.java
/** * @param configPath//from ww w. ja v a2 s.c o m * @param basePath * @param outputPath */ private void buildDefaultMetaProduct(final String configPath, final String basePath, final String outputPath) { new FeatureModelClassGenerator(featureProject); FSTGenComposerExtension.key = IFeatureProject.META_THEOREM_PROVING .equals(featureProject.getMetaProductGeneration()) || IFeatureProject.META_MODEL_CHECKING_BDD_JAVA_JML .equals(featureProject.getMetaProductGeneration()); composer = new FSTGenComposerExtension(); composer.addCompositionErrorListener(compositionErrorListener); FeatureModel featureModel = featureProject.getFeatureModel(); List<String> featureOrderList = featureModel.getFeatureOrderList(); // dead features should not be composed LinkedList<String> deadFeatures = new LinkedList<String>(); for (Feature deadFeature : featureModel.getAnalyser().getDeadFeatures()) { deadFeatures.add(deadFeature.getName()); } String[] features = new String[featureOrderList.size()]; int i = 0; for (String f : featureOrderList) { if (!deadFeatures.contains(f)) { features[i++] = f; } } try { String[] args = getArguments(configPath, basePath, outputPath, getContractParameter()); long start = System.currentTimeMillis(); FeatureModelInfo modelInfo = new FeatureIDEModelInfo(featureModel, !IFeatureProject.META_THEOREM_PROVING.equals(featureProject.getMetaProductGeneration())); ((FSTGenComposerExtension) composer).setModelInfo(modelInfo); ((FSTGenComposerExtension) composer).buildMetaProduct(args, features); long end = System.currentTimeMillis(); long duration = end - start; File file = new File("duration.txt"); try { FileWriter writer = new FileWriter(file, true); writer.write(String.valueOf(duration)); writer.write(System.getProperty("line.separator")); writer.flush(); writer.close(); } catch (IOException ex) { } } catch (TokenMgrError e) { } catch (Error e) { LOGGER.logError(e); } }
From source file:com.act.reachables.CladeTraversal.java
/** * This function traverses the reachables tree from the given start point using BFS, adds all the chemical's derivatives * to a file based on if they pass the mechanistic validator, and the derivatives' reaction pathway from the target * is also logged. Finally, for all the reactions that did not pass the mechanistic validator, we render those reactions * for furthur analysis into a directory. * * @param startPointId - The start point node id to traverse from * @param validatedInchisFileName - The file containing all the derivative inchis that pass the validator. * @param reactionPathwayFileName - The file containing the reaction pathway information from source to target. * @param renderedReactionDirName - The directory containing all the rendered chemical reactions that failed the * mechanistic validator. * @throws IOException/* w w w.j av a2s.c o m*/ */ private void traverseTreeFromStartPoint(Long startPointId, String validatedInchisFileName, String reactionPathwayFileName, String renderedReactionDirName) throws IOException { ReactionRenderer render = new ReactionRenderer(); PrintWriter validatedInchisWriter = new PrintWriter(validatedInchisFileName, "UTF-8"); PrintWriter reactionPathwayWriter = new PrintWriter(reactionPathwayFileName, "UTF-8"); LinkedList<Long> queue = new LinkedList<>(); queue.addAll(this.parentToChildren.get(startPointId)); while (!queue.isEmpty()) { Long candidateId = queue.pop(); validatedInchisWriter.println(db.readChemicalFromInKnowledgeGraph(candidateId).getInChI()); reactionPathwayWriter.println(formatPathFromSrcToDerivativeOfSrc(startPointId, candidateId)); Set<Long> children = this.parentToChildren.get(candidateId); if (children != null) { for (Long child : children) { for (Long rxnId : rxnIdsForEdge(candidateId, child)) { // In the case of a negative rxn id, this signifies the reaction is happening in reverse to what is // referenced in the DB. In order to get the correct db index, one has to transform this negative reaction // into its actual id. if (rxnId < 0) { rxnId = Reaction.reverseNegativeId(rxnId); } // Validate the reaction and only add its children to the queue if the reaction makes sense to our internal // ros and the child is not in the queue already. Map<Integer, List<Ero>> validatorResults = this.validator.validateOneReaction(rxnId); if (validatorResults != null && validatorResults.size() > 0 && !queue.contains(child)) { queue.add(child); } else { try { render.drawReaction(db.getReadDB(), rxnId, renderedReactionDirName, true); } catch (Exception e) { LOGGER.error( "Error caught when trying to draw and save reaction %d with error message: %s", rxnId, e.getMessage()); } } } } } } reactionPathwayWriter.close(); validatedInchisWriter.close(); }
From source file:es.emergya.ui.plugins.admin.aux1.SummaryAction.java
private void reorder(int inicio, int fin) { boolean sentido = inicio < fin; LinkedList<Object> aSubir = new LinkedList<Object>(); LinkedList<Object> resultado = new LinkedList<Object>(); for (Object o : right.getSelectedValues()) { aSubir.add(o);/*from w w w. j av a 2 s . c o m*/ } final DefaultListModel defaultListModel = (DefaultListModel) right.getModel(); if (log.isTraceEnabled()) { log.trace("Elementos seleccionados:"); for (Object o : aSubir) { log.trace(o + " " + o.getClass()); } } for (int i = inicio; (sentido ? i <= fin : fin <= i); i = (sentido ? i + 1 : i - 1)) { Object o = defaultListModel.get(i); if (aSubir.contains(o) && i != inicio) { Object siguiente = resultado.pollLast(); log.trace("Cambiamos " + o + " por " + siguiente); resultado.add(o); resultado.add(siguiente); } else { log.trace("Aadimos " + o); resultado.add(o); } } ((DefaultListModel) right.getModel()).removeAllElements(); log.trace("Nueva lista: "); int inicio2 = (sentido ? 0 : resultado.size() - 1); int fin2 = (sentido ? resultado.size() - 1 : 0); for (int i = inicio2; (sentido ? i <= fin2 : fin2 <= i); i = (sentido ? i + 1 : i - 1)) { Object o = resultado.get(i); log.trace("Nueva lista >" + o); ((DefaultListModel) right.getModel()).addElement(o); } int seleccion[] = new int[aSubir.size()]; int k = 0; for (Integer i = 0; i < right.getModel().getSize(); i++) { if (aSubir.contains(right.getModel().getElementAt(i))) { seleccion[k++] = i; } } right.setSelectedIndices(seleccion); right.updateUI(); }
From source file:org.commonjava.maven.ext.io.PomIO.java
private List<PomPeek> peekAtPomHierarchy(final File topPom) throws ManipulationException { final List<PomPeek> peeked = new ArrayList<>(); try {//from w w w . j ava 2 s.c o m final LinkedList<File> pendingPoms = new LinkedList<>(); pendingPoms.add(topPom.getCanonicalFile()); final String topDir = topPom.getAbsoluteFile().getParentFile().getCanonicalPath(); final Set<File> seen = new HashSet<>(); File topLevelParent = topPom; while (!pendingPoms.isEmpty()) { final File pom = pendingPoms.removeFirst(); seen.add(pom); logger.debug("PEEK: " + pom); final PomPeek peek = new PomPeek(pom); final ProjectVersionRef key = peek.getKey(); if (key != null) { peeked.add(peek); final File dir = pom.getParentFile(); final String relPath = peek.getParentRelativePath(); if (relPath != null) { logger.debug("Found parent relativePath: " + relPath + " in pom: " + pom); File parent = new File(dir, relPath); if (parent.isDirectory()) { parent = new File(parent, "pom.xml"); } parent = parent.getCanonicalFile(); if (parent.getParentFile().getCanonicalPath().startsWith(topDir) && parent.exists() && !seen.contains(parent) && !pendingPoms.contains(parent)) { topLevelParent = parent; logger.debug("Possible top level parent " + parent); pendingPoms.add(parent); } else { logger.debug("Skipping reference to non-existent parent relativePath: '" + relPath + "' in: " + pom); } } final Set<String> modules = peek.getModules(); if (modules != null && !modules.isEmpty()) { for (final String module : modules) { logger.debug("Found module: " + module + " in pom: " + pom); File modPom = new File(dir, module); if (modPom.isDirectory()) { modPom = new File(modPom, "pom.xml"); } if (modPom.exists() && !seen.contains(modPom) && !pendingPoms.contains(modPom)) { pendingPoms.addLast(modPom); } else { logger.debug( "Skipping reference to non-existent module: '" + module + "' in: " + pom); } } } } else { logger.debug("Skipping " + pom + " as its a template file."); } } final HashSet<ProjectVersionRef> projectrefs = new HashSet<>(); for (final PomPeek p : peeked) { projectrefs.add(p.getKey()); if (p.getPom().equals(topLevelParent)) { logger.debug("Setting top level parent to " + p.getPom() + " :: " + p.getKey()); p.setInheritanceRoot(true); } } for (final PomPeek p : peeked) { if (p.getParentKey() == null || !seenThisParent(projectrefs, p.getParentKey())) { logger.debug("Found a standalone pom " + p.getPom() + " :: " + p.getKey()); p.setInheritanceRoot(true); } } } catch (final IOException e) { throw new ManipulationException("Problem peeking at POMs.", e); } return peeked; }
From source file:com.bluros.updater.UpdatesSettings.java
private void updateLayout() { // Read existing Updates LinkedList<String> existingFiles = new LinkedList<String>(); mUpdateFolder = Utils.makeUpdateFolder(); File[] files = mUpdateFolder.listFiles(new UpdateFilter(".zip")); if (mUpdateFolder.exists() && mUpdateFolder.isDirectory() && files != null) { for (File file : files) { if (file.isFile()) { existingFiles.add(file.getName()); }// www .j a v a 2 s. com } } // Build list of updates LinkedList<UpdateInfo> availableUpdates = State.loadState(this); final LinkedList<UpdateInfo> updates = new LinkedList<UpdateInfo>(); for (String fileName : existingFiles) { updates.add(new UpdateInfo.Builder().setFileName(fileName).build()); } for (UpdateInfo update : availableUpdates) { // Only add updates to the list that are not already downloaded if (existingFiles.contains(update.getFileName())) { continue; } updates.add(update); } Collections.sort(updates, new Comparator<UpdateInfo>() { @Override public int compare(UpdateInfo lhs, UpdateInfo rhs) { // sort in descending 'UI name' order (newest first) return -lhs.getName().compareTo(rhs.getName()); } }); // Update the preference list refreshPreferences(updates); // Prune obsolete change log files new Thread() { @Override public void run() { File cacheDir = getCacheDir(); if (cacheDir == null) { return; } File[] files = cacheDir.listFiles(new UpdateFilter(UpdateInfo.CHANGELOG_EXTENSION)); if (files == null) { return; } for (File file : files) { boolean updateExists = false; for (UpdateInfo info : updates) { if (file.getName().startsWith(info.getFileName())) { updateExists = true; break; } } if (!updateExists) { file.delete(); } } } }.start(); }
From source file:com.redhat.rcm.version.mgr.VersionManager.java
protected List<PomPeek> peekAtPomHierarchy(final File topPom, final VersionManagerSession session) throws IOException { final LinkedList<File> pendingPoms = new LinkedList<File>(); pendingPoms.add(topPom.getCanonicalFile()); final String topDir = topPom.getParentFile().getCanonicalPath(); final Set<File> seen = new HashSet<File>(); final List<PomPeek> peeked = new ArrayList<PomPeek>(); while (!pendingPoms.isEmpty()) { final File pom = pendingPoms.removeFirst(); seen.add(pom);// w w w.j a va 2 s.c om logger.info("PEEK: " + pom); final PomPeek peek = new PomPeek(pom); final FullProjectKey key = peek.getKey(); if (key != null) { session.addPeekPom(key, pom); peeked.add(peek); final File dir = pom.getParentFile(); final String relPath = peek.getParentRelativePath(); if (relPath != null) { logger.info("Found parent relativePath: " + relPath + " in pom: " + pom); File parent = new File(dir, relPath); if (parent.isDirectory()) { parent = new File(parent, "pom.xml"); } logger.info("Looking for parent POM: " + parent); parent = parent.getCanonicalFile(); if (parent.getParentFile().getCanonicalPath().startsWith(topDir) && parent.exists() && !seen.contains(parent) && !pendingPoms.contains(parent)) { pendingPoms.add(parent); } else { logger.info("Skipping reference to non-existent parent relativePath: '" + relPath + "' in: " + pom); } } final Set<String> modules = peek.getModules(); if (modules != null && !modules.isEmpty()) { for (final String module : modules) { logger.info("Found module: " + module + " in pom: " + pom); File modPom = new File(dir, module); if (modPom.isDirectory()) { modPom = new File(modPom, "pom.xml"); } logger.info("Looking for module POM: " + modPom); if (modPom.getParentFile().getCanonicalPath().startsWith(topDir) && modPom.exists() && !seen.contains(modPom) && !pendingPoms.contains(modPom)) { pendingPoms.addLast(modPom); } else { logger.info("Skipping reference to non-existent module: '" + module + "' in: " + pom); } } } } else { logger.info("Skipping " + pom + " as its a template file."); } } return peeked; }
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/*from ww w. jav a 2 s. 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.nuxeo.ecm.core.storage.dbs.DBSSession.java
@Override public Document copy(Document source, Document parent, String name) throws DocumentException { transaction.save();//from w w w.j av a2s. co m if (name == null) { name = source.getName(); } name = findFreeName(parent, name); String sourceId = source.getUUID(); String parentId = parent.getUUID(); State sourceState = transaction.getStateForRead(sourceId); State parentState = transaction.getStateForRead(parentId); String oldParentId = (String) sourceState.get(KEY_PARENT_ID); Object[] parentAncestorIds = (Object[]) parentState.get(KEY_ANCESTOR_IDS); LinkedList<String> ancestorIds = new LinkedList<String>(); if (parentAncestorIds != null) { for (Object id : parentAncestorIds) { ancestorIds.add((String) id); } } ancestorIds.add(parentId); if (oldParentId != null && !oldParentId.equals(parentId)) { if (ancestorIds.contains(sourceId)) { throw new DocumentException( "Cannot copy a node under itself: " + parentId + " is under " + sourceId); } // checkNotUnder(parentId, sourceId, "copy"); } // do the copy String copyId = copyRecurse(sourceId, parentId, ancestorIds, name); DBSDocumentState copyState = transaction.getStateForUpdate(copyId); // version copy fixup if (source.isVersion()) { copyState.put(KEY_IS_VERSION, null); } // update read acls transaction.updateReadAcls(copyId); return getDocument(copyState); }
From source file:uk.ac.diamond.scisoft.analysis.rcp.inspector.InspectionTab.java
@Override protected void populateCombos() { Combo c = combos.get(0);//from w w w . j ava 2s . c o m c.removeAll(); c.add(CONSTANT); String name = dataset == null ? null : dataset.getName(); if (name == null || name.length() == 0) c.add(DATA); else c.add(name); c.setText(CONSTANT); if (paxes != null) { PlotAxisProperty p = paxes.get(0); p.setName(CONSTANT, false); } if (daxes != null && daxes.size() != 1) { super.populateCombos(); return; } int cSize = combos.size() - comboOffset; LinkedList<String> sAxes = getAllAxisNames(); int jmax = daxes.size(); for (int i = 0; i < cSize; i++) { c = combos.get(i + comboOffset); c.removeAll(); PlotAxisProperty p = paxes.get(i + comboOffset); String a; if (i < jmax) { a = daxes.get(i).getSelectedName(); if (!sAxes.contains(a)) { a = sAxes.getLast(); } } else { a = sAxes.getLast(); } p.clear(); int pmax = sAxes.size(); for (int j = 0; j < pmax; j++) { String n = sAxes.get(j); p.put(j, n); c.add(n); } c.setText(a); sAxes.remove(a); p.setName(a, false); p.setInSet(true); } }