List of usage examples for java.util List indexOf
int indexOf(Object o);
From source file:main.java.edu.isistan.genCom.gui.Principal.java
/** * Carga la seccin con el resumen de la generacin * // ww w .j a v a 2s.co m * @param generacion */ private void cargarGeneracion() { ConfiguracionAG conf = generacionCargada.getConfiguracion(); // Carga la tabla resumen DefaultTableModel dtm = (DefaultTableModel) tbResumen.getModel(); limpiarModelo(dtm); dtm.addRow(new String[] { String.valueOf(generacionCargada.getEjecuciones().size()), conf.getCruce().toString(), conf.getMutacion().toString(), conf.getSeleccion().toString(), conf.getModelo().toString(), String.valueOf(conf.getCorte()), generacionCargada.getConfiguracion().getFitness().toString(), String.valueOf(generacionCargada.getFitnessPromedio()), String.valueOf(generacionCargada.getFitnessDesviacion()) }); // Carga la tabla de ejecuciones DefaultTableModel dtmEjecucion = (DefaultTableModel) tbEjecuciones.getModel(); limpiarModelo(dtmEjecucion); List<Ejecucion> ejecuciones = generacionCargada.getEjecuciones(); for (Ejecucion ejecucion : ejecuciones) { dtmEjecucion.addRow(new String[] { String.valueOf(ejecuciones.indexOf(ejecucion)), String.valueOf(ejecucion.getFitness()), String.valueOf(ejecucion.getTiempo()) + " ms." }); } // Limpia la tabla de comision DefaultTableModel dtmComision = (DefaultTableModel) tbComision.getModel(); limpiarModelo(dtmComision); }
From source file:edu.hawaii.soest.hioos.storx.StorXDispatcher.java
/** * A method used to connect each of the StorXSource drivers to the * DataTurbine. There is a one driver for each sensor stated in the xml * configuration file, and the primary key for each sensor is the sensor * serial number.//from w w w . j a v a2 s . com */ protected boolean connect() { logger.debug("StorXDispatcher.execute() called."); if (isConnected()) { return true; } try { // Create a list of sensors from the properties file, and iterate // through // the list, creating an RBNB Source object for each sensor listed. // Store // these objects in a HashMap for later referral. this.sourceMap = new HashMap<String, Object>(); // the sensor properties to be pulled from each account's sensor // list. String loggerName = ""; String loggerSerialNumber = ""; String sourceName = ""; String sourceType = ""; String serialNumber = ""; String description = ""; String cacheSize = ""; String archiveSize = ""; String archiveChannel = ""; // iterate through each account List accountList = xmlConfiguration.getList("account.accountName"); for (Iterator aIterator = accountList.iterator(); aIterator.hasNext();) { int aIndex = accountList.indexOf(aIterator.next()); // evaluate each logger listed in the // email.account.properties.xml file List loggerList = xmlConfiguration.getList("account.logger.loggerName"); for (Iterator gIterator = loggerList.iterator(); gIterator.hasNext();) { int gIndex = loggerList.indexOf(gIterator.next()); loggerName = (String) this.xmlConfiguration .getProperty("account(" + aIndex + ").logger(" + gIndex + ").loggerName"); loggerSerialNumber = (String) this.xmlConfiguration .getProperty("account(" + aIndex + ").logger(" + gIndex + ").loggerSerialNumber"); // evaluate each logger listed in the // email.account.properties.xml file List sensorList = xmlConfiguration.getList("account.logger.sensor.name"); for (Iterator sIterator = sensorList.iterator(); sIterator.hasNext();) { // get each property value of the sensor int sIndex = sensorList.indexOf(sIterator.next()); sourceName = (String) this.xmlConfiguration.getProperty( "account(" + aIndex + ").logger(" + gIndex + ").sensor(" + sIndex + ").name"); sourceType = (String) this.xmlConfiguration.getProperty( "account(" + aIndex + ").logger(" + gIndex + ").sensor(" + sIndex + ").type"); serialNumber = (String) this.xmlConfiguration.getProperty("account(" + aIndex + ").logger(" + gIndex + ").sensor(" + sIndex + ").serialNumber"); description = (String) this.xmlConfiguration.getProperty("account(" + aIndex + ").logger(" + gIndex + ").sensor(" + sIndex + ").description"); cacheSize = (String) this.xmlConfiguration.getProperty( "account(" + aIndex + ").logger(" + gIndex + ").sensor(" + sIndex + ").cacheSize"); archiveSize = (String) this.xmlConfiguration.getProperty("account(" + aIndex + ").logger(" + gIndex + ").sensor(" + sIndex + ").archiveSize"); archiveChannel = (String) this.xmlConfiguration.getProperty("account(" + aIndex + ").logger(" + gIndex + ").sensor(" + sIndex + ").archiveChannel"); // test for all of the critical source information if (sourceName != null && sourceType != null && cacheSize != null && archiveSize != null && archiveChannel != null) { // test which type of source to create the RBNB // Source if (sourceType.equals("StorXSource")) { // given the properties, create a StorXSource // object StorXSource storXSource = new StorXSource(this.serverName, (new Integer(this.serverPort)).toString(), this.archiveMode, (new Integer(archiveSize).intValue()), (new Integer(cacheSize).intValue()), sourceName); storXSource.startConnection(); sourceMap.put(serialNumber, storXSource); } else if (sourceType.equals("CTDSource")) { // given the properties, create a CTDSource // object CTDSource ctdSource = new CTDSource(this.serverName, (new Integer(this.serverPort)).toString(), this.archiveMode, (new Integer(archiveSize).intValue()), (new Integer(cacheSize).intValue()), sourceName); ctdSource.startConnection(); sourceMap.put(serialNumber, ctdSource); } else if (sourceType.equals("ISUSSource")) { // given the properties, create an ISUSSource // object ISUSSource isusSource = new ISUSSource(this.serverName, (new Integer(this.serverPort)).toString(), this.archiveMode, (new Integer(archiveSize).intValue()), (new Integer(cacheSize).intValue()), sourceName); isusSource.startConnection(); sourceMap.put(serialNumber, isusSource); } // end if() } // end if() } // end for() } // end for() } // end for() logger.debug(this.sourceMap.toString()); return true; } catch (Exception e) { logger.debug("Failed to connect. Message: " + e.getMessage()); return false; } }
From source file:cgeo.geocaching.connector.gc.GCParser.java
private static void getExtraOnlineInfo(final Geocache cache, final String page, final CancellableHandler handler) { if (CancellableHandler.isCancelled(handler)) { return;// www .j av a2 s . com } //cache.setLogs(loadLogsFromDetails(page, cache, false)); if (Settings.isFriendLogsWanted()) { CancellableHandler.sendLoadProgressDetail(handler, R.string.cache_dialog_loading_details_status_logs); final List<LogEntry> allLogs = cache.getLogs(); final List<LogEntry> friendLogs = getLogsFromDetails(page, true); if (friendLogs != null) { for (final LogEntry log : friendLogs) { if (allLogs.contains(log)) { allLogs.get(allLogs.indexOf(log)).friend = true; } else { cache.getLogs().add(log); } } } } if (Settings.isRatingWanted()) { if (CancellableHandler.isCancelled(handler)) { return; } CancellableHandler.sendLoadProgressDetail(handler, R.string.cache_dialog_loading_details_status_gcvote); final GCVoteRating rating = GCVote.getRating(cache.getGuid(), cache.getGeocode()); if (rating != null) { cache.setRating(rating.getRating()); cache.setVotes(rating.getVotes()); cache.setMyVote(rating.getMyVote()); } } }
From source file:edu.hawaii.soest.kilonalu.adam.AdamDispatcher.java
/** * A method used to connect to the UDP port of the host that will have the * UDP stream of data packets, and that will also connect each of the AdamSource * drivers to the DataTurbine.// ww w . j av a2 s . co m */ protected boolean connect() { if (isConnected()) { return true; } try { // bind to the UDP socket this.datagramSocket = new DatagramSocket(getHostPort()); // Create a list of sensors from the properties file, and iterate through // the list, creating an RBNB Source object for each sensor listed. Store // these objects in a HashMap for later referral. this.sourceMap = new HashMap<String, AdamSource>(); List sensorList = this.xmlConfiguration.getList("sensor.address"); // declare the properties that will be pulled from the // sensor.properties.xml file String address = ""; String sourceName = ""; String cacheSize = ""; String archiveSize = ""; String archiveChannel = ""; // evaluate each sensor listed in the sensor.properties.xml file for (Iterator sIterator = sensorList.iterator(); sIterator.hasNext();) { // get each property value of the sensor int index = sensorList.indexOf(sIterator.next()); address = (String) this.xmlConfiguration.getProperty("sensor(" + index + ").address"); sourceName = (String) this.xmlConfiguration.getProperty("sensor(" + index + ").name"); cacheSize = (String) this.xmlConfiguration.getProperty("sensor(" + index + ").cacheSize"); archiveSize = (String) this.xmlConfiguration.getProperty("sensor(" + index + ").archiveSize"); // given the properties, create an RBNB Source object AdamSource adamSource = new AdamSource(this.serverName, (new Integer(this.serverPort)).toString(), this.archiveMode, (new Integer(archiveSize).intValue()), (new Integer(cacheSize).intValue()), sourceName); adamSource.startConnection(); sourceMap.put(address, adamSource); } connected = true; } catch (SocketException se) { System.err.println( "Failed to connect to the UDP data stream. " + "The error message was: " + se.getMessage()); } return connected; }
From source file:com.core.controller.AlgoritmoController.java
public static Solucion aEstrellaConNodos(Grafo g, String inicio, String fin) { Solucion result = new Solucion("Algoritmo de busqueda A*"); List<String> abiertos = new ArrayList<>(); List<String> padresAbiertos = new ArrayList<>(); List<Integer> valorFuncionAbiertos = new ArrayList<>(); List<String> cerrados = new ArrayList<>(); List<String> padresCerrados = new ArrayList<>(); List<String> sucesores; String mejorNodo;/*from w w w. ja va2 s.c o m*/ int index; //Algoritmo A* abiertos.add(inicio); padresAbiertos.add("#"); valorFuncionAbiertos.add(g.buscarNodo(inicio).getValor() + 0); while (true) { result.agregarPaso("PadresCerrados: " + padresCerrados); result.agregarPaso("Cerrados: " + cerrados); result.agregarPaso("Abiertos: " + abiertos); result.agregarPaso("ValorFun: " + valorFuncionAbiertos); int costoHastaNodoActual, heuristicaNodo, valorFun; String padre; //Si esta vacia devuelve error if (abiertos.isEmpty()) { result.agregarPaso("Error"); break; } //Obtengo el mejor nodo de abiertos if (abiertos.size() == 1) { mejorNodo = abiertos.get(0); } else { mejorNodo = getMejorNodo(abiertos, valorFuncionAbiertos); result.agregarPaso("Mejor nodo: " + mejorNodo); } //Pregunto si es el nodo final if (mejorNodo.equals(fin)) { result.agregarPaso("Nodo fin alcanzado"); //Mostrar camino cerrados.add(mejorNodo); padresCerrados.add(padresAbiertos.get(abiertos.indexOf(mejorNodo))); String nodo = mejorNodo; ArrayList<String> secuenciaResultado = new ArrayList<>(); //Mostrar el camino hasta la solucion while (true) { secuenciaResultado.add(nodo); nodo = padresCerrados.get(cerrados.indexOf(nodo)); if (nodo.equals("#")) { String[] r = new String[secuenciaResultado.size()]; for (int i = 0; i < r.length; i++) { r[i] = secuenciaResultado.get(i); } ArrayUtils.reverse(r); result.agregarPaso(Arrays.toString(r)); break; } } break; } index = abiertos.indexOf(mejorNodo); padre = padresAbiertos.get(index); //obtengo el costo hasta mejorNodo heuristicaNodo = g.buscarNodo(mejorNodo).getValor(); costoHastaNodoActual = (valorFuncionAbiertos.get(index) - heuristicaNodo); //remuevo el nodo a ser explotado abiertos.remove(index); padresAbiertos.remove(index); valorFuncionAbiertos.remove(index); //lo agrego en cerrados cerrados.add(mejorNodo); padresCerrados.add(padre); //obtenemos los sucesores de mejor nodo sucesores = g.nodosVecinos(mejorNodo); for (int i = 0; i < sucesores.size(); i++) { heuristicaNodo = g.buscarNodo(sucesores.get(i)).getValor(); valorFun = costoHastaNodoActual + (g.buscarArista(mejorNodo + "-" + sucesores.get(i))).getValor() + heuristicaNodo; //pregunto si ya existe el noso en abiertos if (abiertos.contains(sucesores.get(i))) { index = abiertos.indexOf(sucesores.get(i)); //Si ya existe pregunto si el nuevo nodo es mejor if (valorFuncionAbiertos.get(index) < valorFun) { valorFuncionAbiertos.set(index, valorFun); padresAbiertos.set(index, mejorNodo); } } else { //pregunto si esta en cerrados if (cerrados.contains(sucesores.get(i))) { //no hacer nada } else { abiertos.add(sucesores.get(i)); padresAbiertos.add(mejorNodo); valorFuncionAbiertos.add(valorFun); } } } //fin for } //fin while //Verifico la solucion y la guardo en Solucion if (result.getPasos().contains("Nodo fin alcanzado")) { String solucion = result.getPasos().split("Nodo fin alcanzado\n")[1]; String[] array = solucion.replaceAll("\\[", "").replaceAll("\\]", "").replaceAll(" ", "").split(","); // ArrayUtils.reverse(array); for (String nombreNodo : array) { System.out.println("--------------------------------------"); for (Map.Entry<String, Nodo> n : g.getNodos().entrySet()) { if (n.getKey().equals(nombreNodo)) { System.out.println("Son iguales! Agregando " + nombreNodo + " a la lista"); result.getNodos().add(n.getValue()); } } } System.out.println( "Nodos del resultado final en la lista: " + Arrays.toString(result.getNodos().toArray())); } return result; }
From source file:com.github.dozermapper.core.MappingProcessor.java
private Set<?> addToSet(Object srcObj, FieldMap fieldMap, Collection<?> srcCollectionValue, Object destObj) { // create a list here so we can keep track of which elements we have mapped, and remove all others if removeOrphans = true Set<Object> mappedElements = new HashSet<>(); LinkedHashSet<Object> result = new LinkedHashSet<>(); // don't want to create the set if it already exists. Object field = fieldMap.getDestValue(destObj); if (field != null) { result.addAll((Collection<?>) field); }/*from w w w . ja v a 2 s . c om*/ Object destValue; Class<?> destEntryType = null; Class<?> prevDestEntryType = null; for (Object srcValue : srcCollectionValue) { if (destEntryType == null || (fieldMap.getDestHintContainer() != null && fieldMap.getDestHintContainer().hasMoreThanOneHint())) { destEntryType = determineCollectionItemType(fieldMap, destObj, srcValue, prevDestEntryType); } CopyByReferenceContainer copyByReferences = globalConfiguration.getCopyByReferences(); if (srcValue != null && copyByReferences.contains(srcValue.getClass())) { destValue = srcValue; } else { destValue = mapOrRecurseObject(srcObj, srcValue, destEntryType, fieldMap, destObj); } prevDestEntryType = destEntryType; if (RelationshipType.NON_CUMULATIVE.equals(fieldMap.getRelationshipType()) && result.contains(destValue)) { List<Object> resultAsList = new ArrayList<>(result); int index = resultAsList.indexOf(destValue); // perform an update if complex type - can't map strings Object obj = resultAsList.get(index); // make sure it is not a String if (!obj.getClass().isAssignableFrom(String.class)) { mapToDestObject(null, srcValue, obj, false, fieldMap.getMapId()); mappedElements.add(obj); } } else { if (destValue != null || fieldMap.isDestMapNull()) { result.add(destValue); } mappedElements.add(destValue); } } // If remove orphans - we only want to keep the objects we've mapped from the src collection // so we'll clear result and replace all entries with the ones in mappedElements if (fieldMap.isRemoveOrphans()) { result.clear(); result.addAll(mappedElements); } if (field == null) { Class<? extends Set<?>> destSetType = (Class<? extends Set<?>>) fieldMap .getDestFieldType(destObj.getClass()); return CollectionUtils.createNewSet(destSetType, result); } else { // Bug #1822421 - Clear first so we don't end up with the removed orphans again ((Set) field).clear(); ((Set) field).addAll(result); return (Set<?>) field; } }
From source file:cn.guoyukun.spring.jpa.plugin.serivce.BaseTreeableService.java
/** * //from w w w . ja va 2 s .c o m * ? * * @param source ? * @param target * @param moveType ? */ public void move(M source, M target, String moveType) { if (source == null || target == null || source.isRoot()) { //? return; } // ?weight?? boolean isSibling = source.getParentId().equals(target.getParentId()); boolean isNextOrPrevMoveType = "next".equals(moveType) || "prev".equals(moveType); if (isSibling && isNextOrPrevMoveType && Math.abs(source.getWeight() - target.getWeight()) == 1) { // if ("next".equals(moveType) && source.getWeight() > target.getWeight()) { return; } if ("prev".equals(moveType) && source.getWeight() < target.getWeight()) { return; } int sourceWeight = source.getWeight(); source.setWeight(target.getWeight()); target.setWeight(sourceWeight); return; } //? if ("next".equals(moveType)) { List<M> siblings = findSelfAndNextSiblings(target.getParentIds(), target.getWeight()); siblings.remove(0);// if (siblings.size() == 0) { // ??? int nextWeight = nextWeight(target.getParentId()); updateSelftAndChild(source, target.getParentId(), target.getParentIds(), nextWeight); return; } else { moveType = "prev"; target = siblings.get(0); //??? } } //? if ("prev".equals(moveType)) { List<M> siblings = findSelfAndNextSiblings(target.getParentIds(), target.getWeight()); //?? if (siblings.contains(source)) { // 1 2 [3 source] 4 siblings = siblings.subList(0, siblings.indexOf(source) + 1); int firstWeight = siblings.get(0).getWeight(); for (int i = 0; i < siblings.size() - 1; i++) { siblings.get(i).setWeight(siblings.get(i + 1).getWeight()); } siblings.get(siblings.size() - 1).setWeight(firstWeight); } else { // 1 2 3 4 [5 new] int nextWeight = nextWeight(target.getParentId()); int firstWeight = siblings.get(0).getWeight(); for (int i = 0; i < siblings.size() - 1; i++) { siblings.get(i).setWeight(siblings.get(i + 1).getWeight()); } siblings.get(siblings.size() - 1).setWeight(nextWeight); source.setWeight(firstWeight); updateSelftAndChild(source, target.getParentId(), target.getParentIds(), source.getWeight()); } return; } //??? int nextWeight = nextWeight(target.getId()); updateSelftAndChild(source, target.getId(), target.makeSelfAsNewParentIds(), nextWeight); }
From source file:de.micromata.genome.gwiki.controls.GWikiEditPageActionBean.java
public Object onReorderChildsAsync() { elementToEdit = wikiContext.getWikiWeb().findElement(pageId); if (elementToEdit == null) { return noForward(); }//from w w w. j ava2 s . com checkAccess(); String page1 = getReqParam("p1"); String page2 = getReqParam("p2"); if (StringUtils.isEmpty(page1) == true || StringUtils.isEmpty(page2) == true) { return noForward(); } String prefix = "chid_"; if (page1.startsWith(prefix) == true) { page1 = page1.substring(prefix.length()); } if (page2.startsWith(prefix) == true) { page2 = page2.substring(prefix.length()); } GWikiElementInfo c1 = wikiContext.getWikiWeb().findElementInfo(page1); if (c1 == null) { GLog.note(GWikiLogCategory.Wiki, "Cannot find page: " + page1 + " for reordering"); return noForward(); } GWikiElementInfo c2 = wikiContext.getWikiWeb().findElementInfo(page2); if (c2 == null) { GLog.note(GWikiLogCategory.Wiki, "Cannot find page: " + page2 + " for reordering"); return noForward(); } if (StringUtils.equals(c1.getParentId(), pageId) == false || StringUtils.equals(c1.getParentId(), pageId) == false) { return noForward(); } List<String> ochildList = elementToEdit.getElementInfo().getProps().getStringList(GWikiPropKeys.CHILDORDER); List<String> childList = new ArrayList<String>(); if (ochildList != null) { childList.addAll(ochildList); } GLog.note(GWikiLogCategory.Wiki, "Reorder page " + page2 + " before " + page1); childList.remove(page2); int insPos = childList.indexOf(page1); if (insPos == -1) { childList.add(page2); childList.add(page1); } else { childList.add(insPos, page2); } elementToEdit.getElementInfo().getProps().setStringList(GWikiPropKeys.CHILDORDER, childList); wikiContext.getWikiWeb().saveElement(wikiContext, elementToEdit, false); return noForward(); }
From source file:beast.evolution.tree.ConstrainedClusterTree.java
/** * Collect all monophyletic constraints, through MRCAPRiors, MultiMonoPhyleticConstraints and MRCAPrior outputs of a Tree * /*from w w w .j a va2s. c o m*/ * @param taxaNames list of taxa names to use * @param tree (optional) if present, output MRCAPriors are collected as well * @param multiMonophyleticConstraint * @param MRCAPriors * @param constraints returns constraints encoded as boolean arrays * @param constraintsize returns constraint sizes corresponding to 'constraints' array * @return list of MRCAPriors so time calibrations can be taken care of * @throws Exception when taxa in constraint cannot be found in taxaNames */ public static List<MRCAPrior> collectCalibrations(List<String> taxaNames, Tree tree, MultiMonophyleticConstraint multiMonophyleticConstraint, List<MRCAPrior> MRCAPriors, List<boolean[]> constraints, List<Integer> constraintsize) { List<MRCAPrior> calibrations = new ArrayList<>(); int nrOfTaxa = taxaNames.size(); // collect all calibrations calibrations.addAll(MRCAPriors); // pick up constraints from calibrations on m_initial input if (tree != null) { for (final Object plugin : tree.getOutputs()) { if (plugin instanceof MRCAPrior && !calibrations.contains(plugin)) { calibrations.add((MRCAPrior) plugin); } } } for (MRCAPrior prior : calibrations) { final boolean[] bTaxa = new boolean[nrOfTaxa]; List<String> taxa = prior.taxonsetInput.get().asStringList(); if (taxa == null) { prior.taxonsetInput.get().initAndValidate(); taxa = prior.taxonsetInput.get().asStringList(); } int size = 0; for (final String sTaxonID : taxa) { final int iID = taxaNames.indexOf(sTaxonID); if (iID < 0) { throw new IllegalArgumentException( "Taxon <" + sTaxonID + "> could not be found in list of taxa. Choose one of " + taxaNames.toArray(new String[0])); } bTaxa[iID] = true; size++; } if (prior.isMonophyleticInput.get() && size > 1) { // add any monophyletic constraint constraints.add(bTaxa); constraintsize.add(size); } } final MultiMonophyleticConstraint mul = multiMonophyleticConstraint; List<List<String>> allc = mul.getConstraints(); for (List<String> c : allc) { final boolean[] bTaxa = new boolean[nrOfTaxa]; for (String sTaxonID : c) { final int iID = taxaNames.indexOf(sTaxonID); if (iID < 0) { throw new IllegalArgumentException( "Taxon <" + sTaxonID + "> could not be found in list of taxa. Choose one of " + taxaNames.toArray(new String[0])); } bTaxa[iID] = true; } constraints.add(bTaxa); constraintsize.add(c.size()); } return calibrations; }