List of usage examples for java.util List indexOf
int indexOf(Object o);
From source file:com.haulmont.cuba.core.sys.AppComponents.java
/** * @param componentIds identifiers of components to be used * @param block current application block (core, web, etc.) *//* ww w . ja v a 2s . c o m*/ public AppComponents(List<String> componentIds, String block) { this(block); for (String compId : componentIds) { AppComponent component = get(compId); if (component == null) { component = new AppComponent(compId); load(component); } if (!components.contains(component)) components.add(component); } components.sort((c1, c2) -> { int res = c1.compareTo(c2); if (res != 0) return res; else return componentIds.indexOf(c1.getId()) - componentIds.indexOf(c2.getId()); }); log.info("Using app components: {}", components); }
From source file:es.udc.gii.common.eaf.algorithm.operator.reproduction.mutation.de.mutationStrategy.NRandDEMutationStrategy.java
@Override public Individual getMutatedIndividual(EvolutionaryAlgorithm algorithm, Individual target) { int basePos;/*from w w w . j ava 2s .c o m*/ double[] base; List<Individual> individuals; List<Individual> listInd; List<Integer> index_list; int randomPos; double auxGeneValue, x1, x2; double F; IndividualChooser chooser = new ClosestIndividual(); F = this.getFPlugin().get(algorithm); individuals = algorithm.getPopulation().getIndividuals(); //Select the "base" individual based on the chooser, in this case ClosestIndividual: Individual closest = (Individual) chooser.get(algorithm, individuals, target); base = closest.getChromosomeAt(0); basePos = individuals.indexOf(closest); index_list = new ArrayList<>(); index_list.add(basePos); //se eligen los vectores diferenciales: listInd = new ArrayList<>(); for (int i = 0; i < this.getDiffVector() * 2; i++) { do { randomPos = (int) EAFRandom.nextInt(individuals.size()); } while (index_list.contains(randomPos)); index_list.add(randomPos); listInd.add(individuals.get(randomPos)); } if (base != null) { //Recorremos el numero de genes: for (int i = 0; i < base.length; i++) { auxGeneValue = base[i]; for (int j = 0; j < this.getDiffVector(); j += 2) { x1 = listInd.get(j).getChromosomeAt(0)[i]; x2 = listInd.get(j + 1).getChromosomeAt(0)[i]; auxGeneValue += F * (x1 - x2); } base[i] = auxGeneValue; } } Individual mutatedIndividual = new Individual(); mutatedIndividual.setChromosomeAt(0, base); return mutatedIndividual; }
From source file:com.google.android.apps.dashclock.ExtensionManager.java
public List<ExtensionWithData> getInternalActiveExtensionsWithData() { // Extract the data from the all active extension cache List<ComponentName> internalActiveExtensions = getInternalActiveExtensionNames(); ArrayList<ExtensionWithData> activeExtensions = new ArrayList<>( Arrays.asList(new ExtensionWithData[internalActiveExtensions.size()])); synchronized (mActiveExtensions) { for (ExtensionWithData ewd : mActiveExtensions) { int pos = internalActiveExtensions.indexOf(ewd.listing.componentName()); if (pos >= 0) { activeExtensions.set(pos, ewd); }// w w w. j ava2 s. c o m } } // Clean any null/unset data int count = activeExtensions.size(); for (int i = count - 1; i >= 0; i--) { if (activeExtensions.get(i) == null) { activeExtensions.remove(i); } } return activeExtensions; }
From source file:org.drools.planner.benchmark.SolverBenchmarkSuite.java
private void determineRankings() { List<SolverBenchmark> sortedSolverBenchmarkList = new ArrayList<SolverBenchmark>(solverBenchmarkList); Collections.sort(sortedSolverBenchmarkList, solverBenchmarkComparator); Collections.reverse(sortedSolverBenchmarkList); // Best results first, worst results last for (SolverBenchmark solverBenchmark : solverBenchmarkList) { solverBenchmark.setRanking(sortedSolverBenchmarkList.indexOf(solverBenchmark)); }// www . ja v a 2 s .c om }
From source file:com.opengamma.financial.analytics.model.pnl.YieldCurveNodePnLFunction.java
private DoubleTimeSeries<?> getPnLSeries(final InterpolatedYieldCurveSpecificationWithSecurities spec, final DoubleLabelledMatrix1D curveSensitivities, final HistoricalTimeSeriesBundle timeSeriesBundle, final LocalDate[] schedule, final TimeSeriesSamplingFunction samplingFunction) { DoubleTimeSeries<?> pnlSeries = null; final int n = curveSensitivities.size(); final Object[] labels = curveSensitivities.getLabels(); final List<Object> labelsList = Arrays.asList(labels); final double[] values = curveSensitivities.getValues(); final Set<FixedIncomeStripWithSecurity> strips = spec.getStrips(); final List<StripInstrumentType> stripList = new ArrayList<StripInstrumentType>(n); for (final FixedIncomeStripWithSecurity strip : strips) { final int index = labelsList.indexOf(strip.getSecurityIdentifier()); if (index < 0) { throw new OpenGammaRuntimeException("Could not get index for " + strip); }//from ww w. ja va 2s.c o m stripList.add(index, strip.getInstrumentType()); } for (int i = 0; i < n; i++) { final ExternalId id = (ExternalId) labels[i]; double sensitivity = values[i]; if (stripList.get(i) == StripInstrumentType.FUTURE) { // TODO Temporary fix as sensitivity is to rate, but historical time series is to price (= 1 - rate) sensitivity *= -1; } final HistoricalTimeSeries dbNodeTimeSeries = timeSeriesBundle .get(MarketDataRequirementNames.MARKET_VALUE, id); if (dbNodeTimeSeries == null) { throw new OpenGammaRuntimeException("Could not identifier / price series pair for " + id); } DoubleTimeSeries<?> nodeTimeSeries = samplingFunction .getSampledTimeSeries(dbNodeTimeSeries.getTimeSeries(), schedule); nodeTimeSeries = DIFFERENCE.evaluate(nodeTimeSeries); if (pnlSeries == null) { pnlSeries = nodeTimeSeries.multiply(sensitivity); } else { pnlSeries = pnlSeries.add(nodeTimeSeries.multiply(sensitivity)); } } return pnlSeries; }
From source file:com.funambol.server.engine.EngineHelper.java
/** * Remove from the given items the items already used in the operations. If isItemA is true, * we check if the items are used as itemA, otherwise we check itemB * @param items SyncItem[]//from w ww . java 2 s. com * @param operations List * @return SyncItem[] */ public static SyncItem[] removeItemsInOperations(SyncItem[] items, List operations, boolean isItemA) { if (operations == null || operations.isEmpty()) { return items; } List itemsList = new ArrayList(Arrays.asList(items)); SyncOperation operation = null; SyncItem item = null; Iterator itOperations = operations.iterator(); while (itOperations.hasNext()) { operation = (SyncOperation) itOperations.next(); if (isItemA) { item = operation.getSyncItemA(); } else { item = operation.getSyncItemB(); } if (itemsList.indexOf(item) != -1) { if (log.isTraceEnabled()) { log.trace("The item " + item + " is already used in an operation as " + (isItemA ? "itemA" : "itemB") + ". Removing it from the changed items list"); } itemsList.remove(item); } } return (SyncItem[]) itemsList.toArray(new SyncItem[itemsList.size()]); }
From source file:com.faujnet.mongo.repository.MongoConnectionRepository.java
/** * Find the connections the current user has to the given provider users. */// w w w . j a v a2 s. c o m @Override public MultiValueMap<String, Connection<?>> findConnectionsToUsers( MultiValueMap<String, String> providerUsers) { if (providerUsers == null || providerUsers.isEmpty()) { throw new IllegalArgumentException("Unable to execute find: no providerUsers provided"); } List<Connection<?>> resultList = connService.getConnections(userId, providerUsers); MultiValueMap<String, Connection<?>> connectionsForUsers = new LinkedMultiValueMap<String, Connection<?>>(); for (Connection<?> connection : resultList) { String providerId = connection.getKey().getProviderId(); List<String> userIds = providerUsers.get(providerId); List<Connection<?>> connections = connectionsForUsers.get(providerId); if (connections == null) { connections = new ArrayList<Connection<?>>(userIds.size()); for (int i = 0; i < userIds.size(); i++) { connections.add(null); } connectionsForUsers.put(providerId, connections); } String providerUserId = connection.getKey().getProviderUserId(); int connectionIndex = userIds.indexOf(providerUserId); connections.set(connectionIndex, connection); } return connectionsForUsers; }
From source file:com.novartis.opensource.yada.format.DelimitedResponse.java
/** * Skeletal override of method, calls {@link #append(Object)} * @throws YADAQueryConfigurationException * @see com.novartis.opensource.yada.format.AbstractResponse#compose(com.novartis.opensource.yada.YADAQueryResult[]) *///from w w w. j av a 2 s. c o m @SuppressWarnings("unchecked") @Override public Response compose(YADAQueryResult[] yqrs) throws YADAResponseException, YADAConverterException, YADAQueryConfigurationException { setYADAQueryResults(yqrs); String colsep = YADARequest.DEFAULT_DELIMITER; String recsep = YADARequest.DEFAULT_ROW_DELIMITER; for (YADAQueryResult yqr : yqrs) { setYADAQueryResult(yqr); colsep = this.yqr.getYADAQueryParamValue(YADARequest.PS_DELIMITER); recsep = this.yqr.getYADAQueryParamValue(YADARequest.PS_ROW_DELIMITER); for (Object result : yqr.getResults()) { // stores all results in yqr.convertedResults List this.append(result); } } // process converted headers into unique ordered Set Set<String> globalHeader = new LinkedHashSet<>(); for (YADAQueryResult yqr : getYadaQueryResults()) { // iterate over results and stitch together in StringBuffer for (String hdr : yqr.getConvertedHeader()) { globalHeader.add(hdr); } } // put header line into buffer int colCount = globalHeader.size(), g = 0; for (String hdr : globalHeader) { this.buffer.append(hdr); if (++g < colCount) this.buffer.append(colsep); } this.buffer.append(recsep); // keys: // if 'join' (ij) spec = true, then inner, using matching keys from local converted headers // if 'join' (ij) spec is list, then inner, using designated keys from local converted headers // if 'leftjoin' (lj) spec = true, then outer, using matching keys // if 'leftjoin' (lj) spec is list, then outer, using designated keys // each yqr is a list of results from one or more executions of a single query // each result is a list of indexed values boolean join = this.yqr.hasJoin(); // boolean outer = this.yqr.hasOuterJoin(); if (join) { Joiner joiner = new Joiner(getYadaQueryResults()); this.buffer.append((StringBuffer) joiner.join()); } // END JOIN else { // process converted data and add to buffer for (YADAQueryResult yqr : getYadaQueryResults()) { List<String> localHeader = yqr.getConvertedHeader(); List<Object> convertedResults = yqr.getConvertedResults(); for (int i = 0; i < convertedResults.size(); i++) { List<List<String>> convertedResult = (List<List<String>>) convertedResults.get(i); for (List<String> row : convertedResult) { int j = 0; for (String globalHdr : globalHeader) { String val = ""; int localHdrIdx = localHeader.indexOf(globalHdr); if (localHdrIdx > -1) { val = row.get(localHdrIdx); } this.buffer.append(val); if (++j < colCount) { this.buffer.append(colsep); } } this.buffer.append(recsep); } } } } return this; }
From source file:com.haulmont.cuba.web.gui.components.WebCalendar.java
@Override public Map<DayOfWeek, String> getDayNames() { List<String> days = Arrays.asList(component.getDayNamesShort().clone()); int shift = Math.abs(component.getFirstDayOfWeek() - java.util.Calendar.MONDAY) + 1; Collections.rotate(days, -shift); return days.stream().collect(Collectors.toMap((String d) -> DayOfWeek.of(days.indexOf(d) + 1), d -> d)); }
From source file:com.alvermont.terraj.stargen.dole.DoleAccrete.java
/** * Let's see who 'p' will run into, if anyone. * * @param star The star for the solar system * @param p The planet being considered//from w w w. j a v a2s . c o m */ void checkCoalesence(Primary star, DolePlanetRecord p) { boolean merged = true; while (merged) { merged = false; final List<Planet> planets = star.getPlanets(); int index = planets.indexOf(p); if (index < 0) { throw new AssertionError("Did not find the planet in the list"); } int pindex = index - 1; while (pindex >= 0) { final DolePlanetRecord p1 = (DolePlanetRecord) planets.get(pindex); if (p1.getRMax() >= p.getRMin()) { planets.set(pindex, mergePlanets(p1, p)); planets.remove(pindex + 1); --pindex; merged = true; } else { pindex = -1; } } if (merged) { // then this could have changed index = planets.indexOf(p); } pindex = index + 1; while (pindex < planets.size()) { final DolePlanetRecord p1 = (DolePlanetRecord) planets.get(pindex); if (p1.getRMin() <= p.getRMax()) { planets.set(pindex, mergePlanets(p1, p)); planets.remove(pindex - 1); ++pindex; merged = true; } else { pindex = Integer.MAX_VALUE; } } if (merged) { evolvePlanet(star, p); } } }