List of usage examples for java.util List indexOf
int indexOf(Object o);
From source file:edu.northwestern.bioinformatics.studycalendar.service.StudySiteService.java
@SuppressWarnings({ "unchecked" }) public List<List<StudySite>> refreshStudySitesForStudies(final List<Study> studies) { if (studies == null) { throw new IllegalArgumentException(STUDY_IS_NULL); }/*from w w w. j a v a 2s . co m*/ List<List<StudySite>> refreshed = new ArrayList<List<StudySite>>(); final Map<String, List<Site>> sites = buildProvidedSiteMap(); List<List<StudySite>> allProvided = studySiteConsumer.refreshSites(studies); for (int i = 0; i < studies.size(); i++) { final Study study = studies.get(i); List<StudySite> provided = allProvided.get(i); if (provided == null) { provided = EMPTY_LIST; } Collection<StudySite> qualifying = CollectionUtils.select(provided, new Predicate() { public boolean evaluate(Object o) { StudySite potential = (StudySite) o; // Verify Study Provider and StudySite Provider Are Equal if (study.getProvider() == null || !study.getProvider().equals(potential.getProvider())) { return false; } // Verify Site Provider and StudySite Provider Are Equal (And Site Exists) List<Site> providerSpecific = sites.get(potential.getProvider()); if (providerSpecific == null || !providerSpecific.contains(potential.getSite())) { return false; } // Verify new study site Site site = providerSpecific.get(providerSpecific.indexOf(potential.getSite())); if (StudySite.findStudySite(study, site) != null) { return false; } return true; } }); logger.debug("Found " + qualifying.size() + " new study sites from the provider."); for (StudySite u : qualifying) { logger.debug("- " + u); } // StudySites returned from provider are proxied by CGLIB. This causes problems when saving, // so we want to create a fresh StudySite instance. Also, we want to populate the site with a // valid Site from SiteService. Collection<StudySite> enhanced = CollectionUtils.collect(qualifying, new Transformer() { public Object transform(Object o) { StudySite s = (StudySite) o; List<Site> providerSpecific = sites.get(s.getProvider()); Site site = providerSpecific.get(providerSpecific.indexOf(s.getSite())); StudySite e = new StudySite(study, site); e.getStudy().addStudySite(e); e.getSite().addStudySite(e); e.setProvider(s.getProvider()); e.setLastRefresh(s.getLastRefresh()); return e; } }); for (StudySite s : enhanced) { studySiteDao.save(s); } refreshed.add(study.getStudySites()); } return refreshed; }
From source file:com.naver.template.social.connect.DaoConnectionRepository.java
public MultiValueMap<String, Connection<?>> findConnectionsToUsers( MultiValueMap<String, String> providerUsers) { if (providerUsers == null || providerUsers.isEmpty()) { throw new IllegalArgumentException("Unable to execute find: no providerUsers provided"); }/*from ww w . java2s. com*/ // StringBuilder providerUsersCriteriaSql = new StringBuilder(); // MapSqlParameterSource parameters = new MapSqlParameterSource(); // parameters.addValue("userId", userId); // for (Iterator<Entry<String, List<String>>> it = providerUsers.entrySet().iterator(); it.hasNext();) { // Entry<String, List<String>> entry = it.next(); // String providerId = entry.getKey(); // providerUsersCriteriaSql.append("providerId = :providerId_").append(providerId).append(" and providerUserId in (:providerUserIds_").append(providerId).append(")"); // parameters.addValue("providerId_" + providerId, providerId); // parameters.addValue("providerUserIds_" + providerId, entry.getValue()); // if (it.hasNext()) { // providerUsersCriteriaSql.append(" or " ); // } // } //List<Connection<?>> resultList = new NamedParameterJdbcTemplate(jdbcTemplate).query(selectFromUserConnection() + " where userId = :userId and " + providerUsersCriteriaSql + " order by providerId, rank", parameters, connectionMapper); List<Connection<?>> resultList = userConnectionDAO.selectConnections(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:org.esa.snap.rcp.spectrum.SpectrumTopComponent.java
static DisplayableSpectrum[] createSpectraFromUngroupedBands(SpectrumBand[] ungroupedBands, int symbolIndex, int strokeIndex) { List<String> knownUnits = new ArrayList<>(); List<DisplayableSpectrum> displayableSpectrumList = new ArrayList<>(); DisplayableSpectrum defaultSpectrum = new DisplayableSpectrum("tbd", -1); for (SpectrumBand ungroupedBand : ungroupedBands) { final String unit = ungroupedBand.getOriginalBand().getUnit(); if (StringUtils.isNullOrEmpty(unit)) { defaultSpectrum.addBand(ungroupedBand); } else if (knownUnits.contains(unit)) { displayableSpectrumList.get(knownUnits.indexOf(unit)).addBand(ungroupedBand); } else {//from w ww . jav a 2 s. com knownUnits.add(unit); final DisplayableSpectrum spectrum = new DisplayableSpectrum("Bands measured in " + unit, symbolIndex++); spectrum.setLineStyle(SpectrumStrokeProvider.getStroke(strokeIndex++)); spectrum.addBand(ungroupedBand); displayableSpectrumList.add(spectrum); } } if (strokeIndex == 0) { defaultSpectrum.setName(DisplayableSpectrum.DEFAULT_SPECTRUM_NAME); } else { defaultSpectrum.setName(DisplayableSpectrum.REMAINING_BANDS_NAME); } defaultSpectrum.setSymbolIndex(symbolIndex); defaultSpectrum.setLineStyle(SpectrumStrokeProvider.getStroke(strokeIndex)); displayableSpectrumList.add(defaultSpectrum); return displayableSpectrumList.toArray(new DisplayableSpectrum[displayableSpectrumList.size()]); }
From source file:com.alfaariss.oa.sso.authentication.web.AuthenticationManager.java
private IAuthenticationMethod getAuthenticationMethod(List<IAuthenticationMethod> listMethods, IAuthenticationMethod currentMethod, String sAuthNProfile) throws SSOException { IAuthenticationMethod oMethod = null; int iCurrentMethod = 0; int iMax = listMethods.size(); if (iMax == 0) { _logger.error("No authentication methods available in pool: " + sAuthNProfile); throw new SSOException(SystemErrors.ERROR_INTERNAL); }//from www. j ava2 s . co m if (currentMethod != null) { iCurrentMethod = listMethods.indexOf(currentMethod); if (iCurrentMethod == -1) { _logger.error("Current authentication method unavailable: " + currentMethod.getID()); throw new SSOException(SystemErrors.ERROR_INTERNAL); } iCurrentMethod++; } if (iCurrentMethod < iMax) oMethod = listMethods.get(iCurrentMethod); return oMethod; }
From source file:com.google.gdt.eclipse.designer.model.widgets.panels.DockLayoutPanelInfo.java
private void ensureWidgetBeforeCenter(WidgetInfo widget) throws Exception { List<WidgetInfo> childrenWidgets = getChildrenWidgets(); // prepare CENTER widget WidgetInfo centerWidget = null;// www.j a v a 2 s . co m for (WidgetInfo childWidget : childrenWidgets) { String childEdge = getEdge(childWidget); if ("CENTER".equals(childEdge)) { centerWidget = childWidget; } } // move current widget before CENTER if (centerWidget != null && centerWidget != widget) { int widgetIndex = childrenWidgets.indexOf(widget); int centerIndex = childrenWidgets.indexOf(centerWidget); if (widgetIndex > centerIndex) { command_MOVE2(widget, centerWidget); } } }
From source file:org.powertac.tariffmarket.TariffMarketService.java
/** * Reads configuration parameters, registers for timeslot phase activation. *//* w w w .ja va2 s . c om*/ @SuppressWarnings("unchecked") @Override public String initialize(Competition competition, List<String> completedInits) { int index = completedInits.indexOf("AccountingService"); if (index == -1) { return null; } for (Class<?> messageType : Arrays.asList(TariffSpecification.class, TariffExpire.class, TariffRevoke.class, VariableRateUpdate.class, EconomicControlEvent.class, BalancingOrder.class)) { brokerProxyService.registerBrokerMessageListener(this, messageType); } subsequentPublication = false; registrations.clear(); publicationFee = null; revocationFee = null; super.init(); pendingSubscriptionEvents.clear(); pendingRevokedTariffs.clear(); pendingVrus.clear(); disabledBrokers.clear(); revokedTariffs = null; lastRevokeProcess = new Instant(0l); serverProps.configureMe(this); // Register the NewTariffListeners List<NewTariffListener> listeners = SpringApplicationContext.listBeansOfType(NewTariffListener.class); for (NewTariffListener listener : listeners) { registerNewTariffListener(listener); } // compute the fees RandomSeed random = randomSeedService.getRandomSeed("TariffMarket", 0l, "fees"); if (publicationFee == null) { // interest will be non-null in case it was overridden in the config publicationFee = (minPublicationFee + (random.nextDouble() * (maxPublicationFee - minPublicationFee))); log.info("set publication fee: " + publicationFee); } if (revocationFee == null) { // interest will be non-null in case it was overridden in the config revocationFee = (minRevocationFee + (random.nextDouble() * (maxRevocationFee - minRevocationFee))); log.info("set revocation fee: " + revocationFee); } serverProps.publishConfiguration(this); return "TariffMarket"; }
From source file:net.palacesoft.cngstation.client.StationActivity.java
public void setCountries(List<String> countriesList) { if (!countriesList.isEmpty()) { ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(this, simple_spinner_item, countriesList); dataAdapter.setDropDownViewResource(simple_spinner_dropdown_item); countries.setAdapter(dataAdapter); if (currentLocationAddress != null) { String country = currentLocationAddress.getCountryName(); int countryIndex = countriesList.indexOf(country); if (countryIndex > -1) { countries.setSelection(countryIndex); }//from w w w . j av a 2 s.c om } } else { showInfoMessage("Could not load country list"); } }
From source file:com.b2international.snowowl.snomed.importer.net4j.SnomedSubsetImportUtil.java
private boolean setSnomedCtColumnId(final String line, final int lineNumber, final SubsetEntry entry) { final List<String> idCandidates; if (StringUtils.isEmpty(entry.getFieldSeparator())) { idCandidates = Arrays.asList(new String[] { line }); } else {/*from w ww . j a v a2s. co m*/ idCandidates = Arrays.asList(line.split(entry.getFieldSeparator())); } for (final String idCandidate : idCandidates) { if (isConceptId(idCandidate)) { entry.setFirstConceptRowNumber(lineNumber); entry.setIdColumnNumber(idCandidates.indexOf(idCandidate)); return true; } } return false; }
From source file:com.seajas.search.codex.social.connection.InMemoryConnectionRepository.java
@Override public MultiValueMap<String, Connection<?>> findConnectionsToUsers( final MultiValueMap<String, String> providerUsers) { if (providerUsers == null || providerUsers.isEmpty()) { throw new IllegalArgumentException("Unable to execute find: no providerUsers provided"); }//from ww w .j a v a 2 s . co m Map<String, List<String>> providerUserIdsByProviderId = new HashMap<String, List<String>>(); for (Entry<String, List<String>> entry : providerUsers.entrySet()) { String providerId = entry.getKey(); providerUserIdsByProviderId.put(providerId, entry.getValue()); } List<ConnectionData> connectionDatas = new ArrayList<ConnectionData>(); for (Map.Entry<String, List<String>> entry : providerUserIdsByProviderId.entrySet()) { connectionDatas.addAll(getInMemoryProviderConnectionRepository(entry.getKey()) .findByProviderUserIdsOrderByProviderIdAndRank(entry.getValue())); } List<Connection<?>> resultList = createConnections(connectionDatas); 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:loci.formats.in.KLBReader.java
@Override protected void initFile(String id) throws FormatException, IOException { super.initFile(id); store = makeFilterMetadata();//ww w. j av a 2 s . c o m in = new RandomAccessInputStream(id); int sizeT = 0; int sizeC = 1; String basePrefix; String parent = new Location(id).getAbsoluteFile().getParent(); File folder = new File(parent); File[] listOfFiles = folder.listFiles(); if (isGroupFiles() && id.indexOf(CHANNEL_PREFIX) >= 0) { basePrefix = id.substring(id.lastIndexOf(File.separator) + 1, id.indexOf(CHANNEL_PREFIX)); for (int i = 0; i < listOfFiles.length; i++) { String fileName = listOfFiles[i].getName(); if (fileName.contains(basePrefix)) { int channelNum = DataTools.parseInteger(fileName.substring( fileName.indexOf(CHANNEL_PREFIX) + CHANNEL_PREFIX.length(), fileName.indexOf('.'))); if (!channels.contains(channelNum)) { channels.add(channelNum); } } } if (channels.size() > 0) { sizeC = channels.size(); Collections.sort(channels); } String topLevelFolder = new Location(parent).getAbsoluteFile().getParent(); folder = new File(topLevelFolder); listOfFiles = folder.listFiles(); basePrefix = parent.substring(parent.lastIndexOf(File.separator) + 1, parent.lastIndexOf('.')); for (int i = 0; i < listOfFiles.length; i++) { String fileName = listOfFiles[i].getName(); if (fileName.startsWith(basePrefix)) { sizeT++; } } } if (isGroupFiles() && sizeT > 0) { filelist.put(DEFAULT_SERIES, new String[sizeT][sizeC]); basePrefix = parent.substring(parent.lastIndexOf(File.separator) + 1, parent.lastIndexOf('.')); Arrays.sort(listOfFiles); for (int i = 0; i < listOfFiles.length; i++) { String fileName = listOfFiles[i].getName(); if (fileName.startsWith(basePrefix)) { String timepointString = fileName.substring( fileName.indexOf(TIME_PREFIX) + TIME_PREFIX.length(), fileName.indexOf(TIME_SUFFIX)); int currentTimepoint = DataTools.parseInteger(timepointString); File[] innerFileList = listOfFiles[i].listFiles(); Arrays.sort(innerFileList); for (int j = 0; j < innerFileList.length; j++) { String innerFileName = innerFileList[j].getName(); if (innerFileName .contains(PROJECTION_PREFIX.substring(0, PROJECTION_PREFIX.length() - 1))) { String channelNumString = innerFileName.substring( innerFileName.indexOf(CHANNEL_PREFIX) + CHANNEL_PREFIX.length(), innerFileName.indexOf('.')); int currentChannelNum = DataTools.parseInteger(channelNumString); int channelIndex = channels.indexOf(currentChannelNum); if (innerFileName.indexOf(PROJECTION_PREFIX) >= 0) { String projection = innerFileName.substring( innerFileName.indexOf(PROJECTION_PREFIX) + PROJECTION_PREFIX.length(), innerFileName.indexOf(PROJECTION_SUFFIX)); if (SERIES_PREFIXES.contains(projection)) { if (filelist.get(projection) == null) { filelist.put(projection, new String[sizeT][sizeC]); core.add(new CoreMetadata(this, 0)); } filelist.get(projection)[currentTimepoint][channelIndex] = innerFileList[j] .getAbsolutePath(); if (currentTimepoint == 0 && channelIndex == 0) { in.close(); in = new RandomAccessInputStream(innerFileList[j].getAbsolutePath()); List<String> stringsList = new ArrayList<>(filelist.keySet()); readHeader(core.get(stringsList.indexOf(projection))); } } } else { filelist.get(DEFAULT_SERIES)[currentTimepoint][channelIndex] = innerFileList[j] .getAbsolutePath(); if (currentTimepoint == 0 && channelIndex == 0) { in.close(); in = new RandomAccessInputStream(innerFileList[j].getAbsolutePath()); readHeader(core.get(0)); } } } } } } } else { //Dealing with a single file filelist.put(DEFAULT_SERIES, new String[1][1]); String absolutePath = new Location(id).getAbsolutePath(); filelist.get(DEFAULT_SERIES)[0][0] = absolutePath; in.close(); in = new RandomAccessInputStream(absolutePath); readHeader(core.get(0)); } MetadataTools.populatePixels(store, this); }