List of usage examples for java.util List indexOf
int indexOf(Object o);
From source file:at.ac.tuwien.qse.sepm.gui.controller.impl.HighlightsViewControllerImpl.java
private void handlePlaceSelected(Place place) { LOGGER.debug("selected place {}", place); List<Place> places = journeyPlaceList.getPlacesForJourney(journeyPlaceList.getSelectedJourney()); if (place == null) { // draw journey for all places wikipediaInfoPane.setVisible(false); drawJourney(places, true);//from w w w .j a v a 2 s. c om } else { List<Place> placesUntil = places.subList(0, places.indexOf(place) + 1); // draw journey until place drawJourney(placesUntil, false); wikipediaInfoPane.showDefaultWikiInfo(place); wikipediaInfoPane.setVisible(true); } setGoodPhotos(place); setMostUsedTagsWithPhotos(place); }
From source file:edu.umn.msi.tropix.proteomics.itraqquantitation.impl.Variance.java
static double[][] createVarianceMatrix(final List<ITraqLabel> labels, final Map<ITraqLabel, double[]> intensities, final double[] ds, final int binSize) { final int n = intensities.values().iterator().next().length; final double[] reference = new double[n]; for (int i = 0; i < n; i++) { double intensitiesProduct = 1.0d; for (final ITraqLabel label : labels) { final double intensity = intensities.get(label)[i]; intensitiesProduct *= intensity; }/* ww w. j a va2 s . c o m*/ reference[i] = MathUtils.log(2.0, intensitiesProduct); } // final double[] sortedReference = Arrays.copyOf(reference, reference.length); final double[] sortedReference = new double[reference.length]; for (int i = 0; i < reference.length; i++) { sortedReference[i] = reference[i]; } Arrays.sort(sortedReference); final List<ITraqRatio> ratios = ITraqLabels.buildRatios(labels); final int numRatios = ratios.size(); final int numRows = numRatios * n; // Precompute ratios final double[] actualRatios = new double[numRatios]; final double[][] numerators = new double[numRatios][]; final double[][] denominators = new double[numRatios][]; for (int ratioIndex = 0; ratioIndex < numRatios; ratioIndex++) { final ITraqRatio ratio = ratios.get(ratioIndex); final int numeratorIndex = labels.indexOf(ratio.getNumerator()); final int denominatorIndex = labels.indexOf(ratio.getDenominator()); numerators[ratioIndex] = intensities.get(ratio.getNumerator()); denominators[ratioIndex] = intensities.get(ratio.getDenominator()); actualRatios[ratioIndex] = MathUtils.log(2.0, ds[numeratorIndex] / ds[denominatorIndex]); } final double[][] samplePoints = new double[numRows][2]; for (int sortedReferenceIndex = 0; sortedReferenceIndex < n; sortedReferenceIndex++) { final double referenceValue = sortedReference[sortedReferenceIndex]; final int referenceIndex = indexOf(referenceValue, reference); final int rowOffset = sortedReferenceIndex * numRatios; for (int ratioIndex = 0; ratioIndex < numRatios; ratioIndex++) { final double actualRatio = actualRatios[ratioIndex]; final double estimatedRatio = MathUtils.log(2.0, numerators[ratioIndex][referenceIndex] / denominators[ratioIndex][referenceIndex]); final double diff = (estimatedRatio - actualRatio); samplePoints[rowOffset + ratioIndex][0] = referenceValue; samplePoints[rowOffset + ratioIndex][1] = diff * diff; } } final int numBins = numRows / binSize; final double[][] matrixXV = new double[numBins][2]; double maxV = Double.MIN_VALUE; double sumX = 0.0, sumV = 0.0; int curBin = 0; for (int i = 0; i < numRows; i++) { sumX += samplePoints[i][0]; sumV += samplePoints[i][1]; if ((i + 1) % binSize == 0) { final double x = sumX / binSize; final double v = sumV / binSize; final double binWeight = 1 / v; if (!Double.isInfinite(binWeight)) { maxV = Math.max(binWeight, maxV); } matrixXV[curBin][0] = x; matrixXV[curBin][1] = binWeight; curBin++; sumX = 0.0; sumV = 0.0; } } for (int i = 0; i < numBins; i++) { if (Double.isInfinite(matrixXV[i][1])) { matrixXV[i][1] = maxV; } } for (int i = 0; i < numBins - 1; i++) { matrixXV[i][0] = (matrixXV[i][0] + matrixXV[i + 1][0]) / 2.0; } return matrixXV; }
From source file:com.alibaba.napoli.metamorphosis.client.consumer.DefaultLoadBalanceStrategy.java
@Override public List<String> getPartitions(final String topic, final String consumerId, final List<String> curConsumers, final List<String> curPartitions) { // ??partition final int nPartsPerConsumer = curPartitions.size() / curConsumers.size(); // ?partitionconsumer final int nConsumersWithExtraPart = curPartitions.size() % curConsumers.size(); log.info("Consumer " + consumerId + " rebalancing the following partitions: " + curPartitions + " for topic " + topic + " with consumers: " + curConsumers); final int myConsumerPosition = curConsumers.indexOf(consumerId); if (myConsumerPosition < 0) { log.warn("No broker partions consumed by consumer " + consumerId + " for topic " + topic); return Collections.emptyList(); }// w w w. j a v a2 s. c om assert myConsumerPosition >= 0; // final int startPart = nPartsPerConsumer * myConsumerPosition + Math.min(myConsumerPosition, nConsumersWithExtraPart); final int nParts = nPartsPerConsumer + (myConsumerPosition + 1 > nConsumersWithExtraPart ? 0 : 1); if (nParts <= 0) { log.warn("No broker partions consumed by consumer " + consumerId + " for topic " + topic); return Collections.emptyList(); } final List<String> rt = new ArrayList<String>(); for (int i = startPart; i < startPart + nParts; i++) { final String partition = curPartitions.get(i); rt.add(partition); } return rt; }
From source file:com.core.controller.AlgoritmoController.java
public static Solucion busquedaAmplitud(Grafo g, String nodoInicioNombre, String nodoFinNombre) { //funcionna bien Solucion result = new Solucion(); result.setPasos("Algoritmo de Busqueda Primero en Amplitud"); result.agregarPaso("Cantidad de nodos: " + g.getNodos().size()); result.agregarPaso("Cantidad de aristas: " + g.getAristas().size()); Queue<String> cola = new LinkedList<>(); Queue<String> padresCola = new LinkedList<>(); List<String> explorados = new ArrayList<>(); //LISTA-NODOS List<String> padresExplorados = new ArrayList<>(); String nodoActual, nodoPadre; cola.add(nodoInicioNombre);/*from w ww .j av a 2 s . c o m*/ padresCola.add("#"); while (true) { System.out.println(cola); if (cola.isEmpty()) { result.agregarPaso("No se encontro el nodo destino"); break; } nodoActual = cola.poll(); nodoPadre = padresCola.poll(); explorados.add(nodoActual); padresExplorados.add(nodoPadre); if (nodoActual.equals(nodoFinNombre)) { result.agregarPaso("Nodo fin alcanzado"); //Mostrar camino String nodo = nodoActual; String secuenciaResultado = ""; while (nodo != "#") { secuenciaResultado = nodo + " " + secuenciaResultado; nodo = padresExplorados.get(explorados.indexOf(nodo)); } result.agregarPaso("Camino solucion: " + secuenciaResultado); break; } List<String> vecinos = g.nodosVecinos(nodoActual); Iterator<String> i = vecinos.iterator(); while (i.hasNext()) { String a = i.next(); if (!explorados.contains(a) && !cola.contains(a)) { cola.add(a); padresCola.add(nodoActual); } } } //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.split(" "); // ArrayUtils.reverse(array); for (String nombreNodo : array) { System.out.println("--------------------------------------"); for (Map.Entry<String, Nodo> n : g.getNodos().entrySet()) { System.out.println("Comparando " + n.getKey() + " con " + nombreNodo); 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.krawler.esp.servlets.deskeramob.java
public static String insertSmiley(String msg, String serverAdd) { String result = ""; String[] smileyStore = { ":)", ":(", ";)", ":D", ";;)", ">:D<", ":-/", ":x", ":>>", ":P", ":-*", "=((", ":-O", "X(", ":>", "B-)", ":-S", "#:-S", ">:)", ":((", ":))", ":|", "/:)", "=))", "O:-)", ":-B", "=;", ":-c" }; java.util.List smileyListArry = java.util.Arrays.asList(smileyStore); String smileyRegx = "(:\\(\\()|(:\\)\\))|(:\\))|(:x)|(:\\()|(:P)|(:D)|(;\\))|(;;\\))|(>:D<)|(:-\\/)|(:>>)|(:-\\*)|(=\\(\\()|(:-O)|(X\\()|(:>)|(B-\\))|(:-S)|(#:-S)|(>:\\))|(:\\|)|(\\/:\\))|(=\\)\\))|(O:-\\))|(:-B)|(=;)|(:-c)"; java.util.regex.Pattern myPattern = java.util.regex.Pattern.compile(smileyRegx); java.util.regex.Matcher myMatcher = myPattern.matcher(msg); int no = 0;/* w ww . j a va 2 s.co m*/ String replaceString = ""; try { while (myMatcher.find()) { no = smileyListArry.indexOf(myMatcher.group()) + 1; replaceString = "<img src=\"" + serverAdd + "/images/smiley" + no + ".gif\" style=display:inline;vertical-align:text-top;></img>"; msg = StringUtils.replaceOnce(msg, myMatcher.group(), replaceString); } } catch (Exception e) { System.out.print(e); } return msg; //return result; }
From source file:net.nifheim.beelzebu.coins.common.utils.FileManager.java
private void updateMessages() { try {//from w w w . j av a 2 s .c om List<String> lines = FileUtils.readLines(messagesFiles.get("default"), Charsets.UTF_8); int index; if (core.getMessages("").getInt("version") == 6) { index = lines.indexOf("version: 6"); lines.set(index, "version: 7"); index = lines.indexOf("Multipliers:"); lines.remove(index); index = lines.indexOf(" Menu:"); lines.add(index, "Multipliers:"); core.log("Updated messages.yml file to v7"); } if (core.getMessages("").getInt("version") == 7) { index = lines.indexOf("version: 7"); lines.set(index, "version: 8"); index = lines.indexOf(" Menu:") + 2; lines.addAll(index, Arrays.asList(" Confirm:", " Title: '&8Are you sure?'", " Accept: '&aYES!'", " Decline: '&cNope'", " Multipliers:", " Name: '&6Multiplier &cx%amount%'", " Lore:", " - ''", " - '&7Amount: &c%amount%'", " - '&7Server: &c%server%'", " - '&7Minutes: &c%minutes%'", " - ''", " - '&7ID: &c#%id%'", " No Multipliers:", " Name: '&cYou don''t have any multiplier :('", " Lore:", " - ''", " - '&7You can buy multipliers in our store'", " - '&6&nstore.servername.net'")); core.log("Updated messages.yml file to v8"); } if (core.getMessages("").getInt("version") == 8) { index = lines.indexOf("version: 8"); lines.set(index, "version: 9"); lines.removeAll(Arrays.asList("# Coins messages file.", "# If you need support or find a bug open a issuse in", "# the official github repo https://github.com/Beelzebu/Coins/issuses/", "", "# The version of this file, don't edit!")); lines.addAll(0, Arrays.asList("# Coins messages file.", "# If you need support or find a bug open a issuse in", "# the official github repo https://github.com/Beelzebu/Coins/issuses/", "", "# The version of this file, is used to auto update this file, don't change it", "# unless you know what you do.")); core.log("Updated messages.yml file to v9"); } if (core.getMessages("").getInt("version") == 9) { index = lines.indexOf("version: 9"); lines.set(index, "version: 10"); index = lines.indexOf( " Multiplier Create: '" + core.getMessages("").getString("Help.Multiplier Create") + "'") + 1; lines.add(index, " Multiplier Set: '%prefix% &cPlease use &f/coins multiplier set <amount> <enabler> <minutes> (server)'"); lines.addAll(Arrays.asList(" Set:", " - '%prefix% A multiplier with the following data was set for %server%'", " - ' &7Enabler: &c%enabler%'", " - ' &7Amount: &c%amount%'", " - ' &7Minutes: &c%minutes%'")); core.log("Updated messages.yml file to v10"); } FileUtils.writeLines(messagesFiles.get("default"), lines); } catch (IOException ex) { core.log("An unexpected error occurred while updating the messages.yml file."); core.debug(ex.getMessage()); } try { List<String> lines = FileUtils.readLines(messagesFiles.get("es"), Charsets.UTF_8); int index; if (core.getMessages("es").getInt("version") == 6) { index = lines.indexOf("version: 6"); lines.set(index, "version: 7"); index = lines.indexOf("Multipliers:"); lines.remove(index); index = lines.indexOf(" Menu:"); lines.add(index, "Multipliers:"); core.log("Updated messages_es.yml file to v7"); } if (core.getMessages("es").getInt("version") == 7) { index = lines.indexOf("version: 7"); lines.set(index, "version: 8"); index = lines.indexOf(" Menu:") + 2; lines.addAll(index, Arrays.asList(" Confirm:", " Title: '&8Ests seguro?'", " Accept: '&aSI!'", " Decline: '&cNo'", " Multipliers:", " Name: '&6Multiplicador &cx%amount%'", " Lore:", " - ''", " - '&7Cantidad: &c%amount%'", " - '&7Servidor: &c%server%'", " - '&7Minutos: &c%minutes%'", " - ''", " - '&7ID: &c#%id%'", " No Multipliers:", " Name: '&cNo tienes ningn multiplicador :('", " Lore:", " - ''", " - '&7Puedes comprar multiplicadores en nuestra tienda'", " - '&6&nstore.servername.net'")); core.log("Updated messages_es.yml file to v8"); } index = lines.indexOf(" - '&6&nstore.servername.net'\""); if (index != -1) { lines.set(index, " - '&6&nstore.servername.net'"); } if (core.getMessages("es").getInt("version") == 8) { index = lines.indexOf("version: 8"); lines.set(index, "version: 9"); lines.removeAll(Arrays.asList("# Coins messages file.", "# If you need support or find a bug open a issuse in", "# the official github repo https://github.com/Beelzebu/Coins/issuses/", "", "# The version of this file, don't edit!")); lines.addAll(0, Arrays.asList("# Coins messages file.", "# Si necesitas soporte o encuentras un error por favor abre un ticket en el", "# repositorio oficial de github https://github.com/Beelzebu/Coins/issuses/", "", "# La versin de este archivo, es usado para actualizarlo automticamente, no lo cambies", "# a menos que sepas lo que haces.")); core.log("Updated messages_es.yml file to v9"); } if (core.getMessages("es").getInt("version") == 9) { index = lines.indexOf("version: 9"); lines.set(index, "version: 10"); index = lines.indexOf( " Multiplier Create: '" + core.getMessages("es").getString("Help.Multiplier Create") + "'") + 1; lines.add(index, " Multiplier Set: '%prefix% &cPor favor usa &f/coins multiplier set <cantidad> <activador> <minutos> (server)'"); lines.addAll(Arrays.asList(" Set:", " - '%prefix% Un multiplicador con la siguiente informacin fue establecido en %server%'", " - ' &7Activador: &c%enabler%'", " - ' &7Cantidad: &c%amount%'", " - ' &7Minutos: &c%minutes%'")); core.log("Updated messages_es.yml file to v10"); } if (lines.get(0).startsWith(" Multiplier Set:")) { lines.remove(0); index = lines.indexOf( " Multiplier Create: '" + core.getMessages("es").getString("Help.Multiplier Create") + "'") + 1; lines.add(index, " Multiplier Set: '%prefix% &cPor favor usa &f/coins multiplier set <cantidad> <activador> <minutos> (server)'"); } FileUtils.writeLines(messagesFiles.get("es"), lines); } catch (IOException ex) { core.log("An unexpected error occurred while updating the messages_es.yml file."); core.debug(ex.getMessage()); } }
From source file:com.nextep.datadesigner.dbgm.gui.IndexEditorGUI.java
private void indexColumnDown(IIndex index, IBasicColumn c) { final IReference columnRef = c.getReference(); final List<IReference> colRef = index.getIndexedColumnsRef(); int colIndex = colRef.indexOf(columnRef); if (colIndex < colRef.size() - 1) { final IBasicColumn swappedCol = index.getColumns().get(colIndex + 1); Collections.swap(colRef, colIndex, colIndex + 1); index.notifyListeners(ChangeEvent.MODEL_CHANGED, c); c.notifyListeners(ChangeEvent.MODEL_CHANGED, null); swappedCol.notifyListeners(ChangeEvent.MODEL_CHANGED, null); }//from ww w . j a v a2 s .co m }
From source file:com.nextep.datadesigner.dbgm.gui.IndexEditorGUI.java
private void indexColumnUp(IIndex index, IBasicColumn column) { final IReference columnRef = column.getReference(); final List<IReference> colRefs = index.getIndexedColumnsRef(); int colIndex = colRefs.indexOf(columnRef); if (colIndex > 0) { final IBasicColumn swappedCol = index.getColumns().get(colIndex - 1); Collections.swap(colRefs, colIndex, colIndex - 1); index.notifyListeners(ChangeEvent.MODEL_CHANGED, column); column.notifyListeners(ChangeEvent.MODEL_CHANGED, null); swappedCol.notifyListeners(ChangeEvent.MODEL_CHANGED, null); }// ww w . j av a2s.c om }
From source file:com.haulmont.cuba.gui.data.impl.DsContextImpl.java
@SuppressWarnings("unchecked") protected void repairReferences(Entity entity, Entity contextEntity) { MetaClass metaClass = metadata.getClassNN(entity.getClass()); MetaClass contextEntityMetaClass = metadata.getClassNN(contextEntity.getClass()); for (MetaProperty property : metaClass.getProperties()) { if (!property.getRange().isClass() || !property.getRange().asClass().equals(contextEntityMetaClass) || !PersistenceHelper.isLoaded(entity, property.getName())) continue; Object value = entity.getValue(property.getName()); if (value != null) { if (property.getRange().getCardinality().isMany()) { Collection collection = (Collection) value; for (Object item : new ArrayList(collection)) { if (contextEntity.equals(item) && contextEntity != item) { if (collection instanceof List) { List list = (List) collection; list.set(list.indexOf(item), contextEntity); } else { collection.remove(item); collection.add(contextEntity); }// w ww . ja va2s .c o m } } } else { if (contextEntity.equals(value) && contextEntity != value) { entity.setValue(property.getName(), contextEntity); } } } } }
From source file:com.boxedfolder.carrot.service.impl.AnalyticsServiceImpl.java
@Override public List<AnalyticsTransfer> eventsTriggered(DateTime from, DateTime to) { List<AnalyticsTransfer> output = new ArrayList<>(); List<AnalyticsLog> logs = findAll(from, to); for (AnalyticsLog log : logs) { Event event = log.getOccuredEvent(); AnalyticsTransfer transfer = new AnalyticsTransfer(); transfer.setId(event.getId());//from w w w .ja va2 s .c o m transfer.setName(event.getName()); if (!output.contains(transfer)) { output.add(transfer); } else { transfer = output.get(output.indexOf(transfer)); } Integer value = transfer.getCount(); value++; transfer.setCount(value); } return output; }