List of usage examples for java.util ListIterator set
void set(E e);
From source file:de.tudarmstadt.ukp.dkpro.core.api.io.ResourceCollectionReaderBase.java
@Override public void initialize(UimaContext aContext) throws ResourceInitializationException { super.initialize(aContext); // if an ExternalResourceLocator providing a custom ResourcePatternResolver // has been specified, use it, by default use PathMatchingResourcePatternresolver // If there are no patterns, then look for a pattern in the location itself. // If the source location contains a wildcard, split it up into a base and a pattern if (patterns == null) { int asterisk = sourceLocation.indexOf('*'); if (asterisk != -1) { patterns = new String[] { INCLUDE_PREFIX + sourceLocation.substring(asterisk) }; sourceLocation = sourceLocation.substring(0, asterisk); }/*www .j ava 2 s . c om*/ } // Parse the patterns and inject them into the FileSet List<String> includes = new ArrayList<String>(); List<String> excludes = new ArrayList<String>(); if (patterns != null) { for (String pattern : patterns) { if (pattern.startsWith(INCLUDE_PREFIX)) { includes.add(pattern.substring(INCLUDE_PREFIX.length())); } else if (pattern.startsWith(EXCLUDE_PREFIX)) { excludes.add(pattern.substring(EXCLUDE_PREFIX.length())); } else if (pattern.matches("^\\[.\\].*")) { throw new ResourceInitializationException(new IllegalArgumentException( "Patterns have to start with " + INCLUDE_PREFIX + " or " + EXCLUDE_PREFIX + ".")); } else { includes.add(pattern); } } } // These should be the same as documented here: http://ant.apache.org/manual/dirtasks.html if (useDefaultExcludes) { excludes.add("**/*~"); excludes.add("**/#*#"); excludes.add("**/.#*"); excludes.add("**/%*%"); excludes.add("**/._*"); excludes.add("**/CVS"); excludes.add("**/CVS/**"); excludes.add("**/.cvsignore"); excludes.add("**/SCCS"); excludes.add("**/SCCS/**"); excludes.add("**/vssver.scc"); excludes.add("**/.svn"); excludes.add("**/.svn/**"); excludes.add("**/.DS_Store"); excludes.add("**/.git"); excludes.add("**/.git/**"); excludes.add("**/.gitattributes"); excludes.add("**/.gitignore"); excludes.add("**/.gitmodules"); excludes.add("**/.hg"); excludes.add("**/.hg/**"); excludes.add("**/.hgignore"); excludes.add("**/.hgsub"); excludes.add("**/.hgsubstate"); excludes.add("**/.hgtags"); excludes.add("**/.bzr"); excludes.add("**/.bzr/**"); excludes.add("**/.bzrignore"); } try { if (sourceLocation == null) { ListIterator<String> i = includes.listIterator(); while (i.hasNext()) { i.set(locationToUrl(i.next())); } i = excludes.listIterator(); while (i.hasNext()) { i.set(locationToUrl(i.next())); } } else { sourceLocation = locationToUrl(sourceLocation); } resources = scan(sourceLocation, includes, excludes); // Get the iterator that will be used to actually traverse the FileSet. resourceIterator = resources.iterator(); getLogger().info("Found [" + resources.size() + "] resources to be read"); } catch (IOException e) { throw new ResourceInitializationException(e); } }
From source file:com.digitalgeneralists.assurance.model.entities.ApplicationConfiguration.java
private List<String> transformStringPropertyToListProperty(String property, boolean removeExtensionPatterns) { StrTokenizer tokenizer = new StrTokenizer(property, ','); List<String> tokenizedList = tokenizer.getTokenList(); // NOTE: May want to reconsider the toLowercase conversion. ListIterator<String> iterator = tokenizedList.listIterator(); while (iterator.hasNext()) { String extension = iterator.next(); // NOTE: This is probably a bit overly-aggressive and less-sophisticated than it could be, // but it should handle 99% of the input that will be entered. if (removeExtensionPatterns) { extension = StringUtils.replace(extension, "*.", ""); extension = StringUtils.replace(extension, "*", ""); extension = StringUtils.replace(extension, ".", ""); }//from www. j a va 2 s. c o m iterator.set(extension.toLowerCase().trim()); } return tokenizedList; }
From source file:com.garyclayburg.persistence.repository.AccountMatcher.java
public User attachAccount(UserAccount scimAccount) { User matchedUser = matchAccount(scimAccount); User savedUser = null;//from ww w . j av a 2s . c o m if (matchedUser != null) { List<UserAccount> userAccounts = matchedUser.getUserAccounts(); if (userAccounts != null) { ListIterator<UserAccount> listIterator = userAccounts.listIterator(); boolean updatedAccount = false; while (listIterator.hasNext()) { UserAccount userAccount = listIterator.next(); String username = userAccount.getUsername(); String accountType = userAccount.getAccountType(); if (username != null && accountType != null) { if (username.equals(scimAccount.getUsername()) && accountType.equals(scimAccount.getAccountType())) { listIterator.set(scimAccount); updatedAccount = true; } } } if (!updatedAccount) { //add as new account for this matched user userAccounts.add(scimAccount); } } else { //user does not have any accounts yet. This will be his first. List<UserAccount> newAccounts = new ArrayList<>(); newAccounts.add(scimAccount); matchedUser.setUserAccounts(newAccounts); } savedUser = auditedUserRepo.save(matchedUser); } return savedUser; }
From source file:org.apache.qpid.amqp_1_0.client.Respond.java
private void respond(Message m) throws Sender.SenderCreationException { List<Section> sections = m.getPayload(); String replyTo = null;/* w ww . j a va 2 s. com*/ Object correlationId = null; for (Section section : sections) { if (section instanceof Properties) { replyTo = getResponseQueue() == null ? ((Properties) section).getReplyTo() : getResponseQueue(); correlationId = ((Properties) section).getMessageId(); break; } } if (replyTo != null) { Sender s = _senders.get(replyTo); if (s == null) { s = (isUseMultipleConnections() ? _session2 : _session).createSender(replyTo, getWindowSize()); _senders.put(replyTo, s); } List<Section> replySections = new ArrayList<Section>(sections); ListIterator<Section> sectionIterator = replySections.listIterator(); while (sectionIterator.hasNext()) { Section section = sectionIterator.next(); if (section instanceof Properties) { Properties newProps = new Properties(); newProps.setTo(replyTo); newProps.setCorrelationId(correlationId); newProps.setMessageId(_responseMsgId); _responseMsgId = _responseMsgId.add(UnsignedLong.ONE); sectionIterator.set(newProps); } } Message replyMessage = new Message(replySections); System.out.println("Sent Message: " + replySections); s.send(replyMessage, _txn); } _receiver.acknowledge(m.getDeliveryTag(), _txn); }
From source file:chat.viska.commons.pipelines.Pipeline.java
@SchedulerSupport(SchedulerSupport.IO) public Maybe<Pipe> replace(final String name, final Pipe newPipe) { Validate.notBlank(name);// www. j a va 2 s.co m return Maybe.fromCallable(() -> { pipeLock.writeLock().lockInterruptibly(); final Pipe oldPipe; try { final ListIterator<Map.Entry<String, Pipe>> iterator = getIteratorOf(name); if (iterator == null) { throw new NoSuchElementException(name); } oldPipe = iterator.next().getValue(); iterator.set(new AbstractMap.SimpleImmutableEntry<>(name, newPipe)); oldPipe.onRemovedFromPipeline(this); newPipe.onAddedToPipeline(this); } finally { pipeLock.writeLock().unlock(); } return oldPipe; }).subscribeOn(Schedulers.io()); }
From source file:edu.oregonstate.eecs.mcplan.sim.OptionSimulator.java
@Override public void takeAction(final JointAction<Option<S, A>> j) { action_count_ += 1;/* ww w. j a va2s .c o m*/ // System.out.println( "Setting option " + o + " for player " + turn_ ); // Find all options that terminated final ArrayList<Option<S, A>> term = new ArrayList<Option<S, A>>(); for (int i = 0; i < turn_.size(); ++i) { assert (active_.get(i) == null); term.add(terminated_.get(i)); terminated_.set(i, null); } pushFrame(turn_, term); // Activate new options for (int i = 0; i < turn_.size(); ++i) { assert (j.get(i) != null); final Option<S, A> o = j.get(i); active_.set(i, o); o.start(base_.state(), base_.t()); } assert (history_.size() == action_count_); // TODO: Debugging // Take actions according to active options until one or more // options terminates. final long told = base_.t(); final long tnew = told; while (true) { final S s = base_.state(); if (base_.isTerminalState()) { return; } // See if any options terminate final ListIterator<Option<S, A>> check_itr = active_.listIterator(); final TIntArrayList next_turn = new TIntArrayList(); while (check_itr.hasNext()) { final Option<S, A> ocheck = check_itr.next(); if (terminate(s, base_.t(), ocheck)) { // System.out.println( "! Option " + (check_itr.previousIndex()) + " terminated" ); check_itr.set(null); final int pidx = check_itr.previousIndex(); terminated_.set(pidx, ocheck); next_turn.add(pidx); } } // If they do, wait for new options if (!next_turn.isEmpty()) { turn_ = next_turn; return; } // Construct a JointAction over primitive actions and execute it final JointAction.Builder<A> ab = new JointAction.Builder<A>(Nplayers_); for (int i = 0; i < Nplayers_; ++i) { final Option<S, A> o = active_.get(i); assert (o != null); o.setState(s, base_.t()); ab.a(i, o.getAction()); } base_.takeAction(ab.finish()); // System.out.println( "Take action " + base_.getTurn() + " " + a ); history_.peek().steps += 1; // TODO: Give pi its reward // pi.actionResult( ??? ); } }
From source file:chat.viska.commons.pipelines.Pipeline.java
@SchedulerSupport(SchedulerSupport.IO) public Maybe<Pipe> replace(final Pipe oldPipe, final Pipe newPipe) { return Maybe.fromCallable(() -> { pipeLock.writeLock().lockInterruptibly(); try {/*from w ww . j a va 2 s.c o m*/ final ListIterator<Map.Entry<String, Pipe>> iterator = getIteratorOf(oldPipe); if (iterator == null) { throw new NoSuchElementException(); } Map.Entry<String, Pipe> oldEntry = iterator.next(); iterator.set(new AbstractMap.SimpleImmutableEntry<>(oldEntry.getKey(), newPipe)); oldPipe.onRemovedFromPipeline(this); newPipe.onAddedToPipeline(this); } finally { pipeLock.writeLock().unlock(); } return oldPipe; }).subscribeOn(Schedulers.io()); }
From source file:com.manydesigns.elements.options.DefaultSelectionProvider.java
public void ensureActive(Object... values) { Row row = null;// w w w.j a va 2s . c o m ListIterator<Row> iterator = rows.listIterator(); while (iterator.hasNext()) { Row current = iterator.next(); boolean found = true; for (int i = 0; i < fieldCount; i++) { if (!ObjectUtils.equals(values[i], current.getValues()[i])) { found = false; break; } } if (found) { row = new Row(values, current.getLabels(), true); iterator.set(row); break; } } if (row == null) { String[] labels = new String[fieldCount]; for (int i = 0; i < fieldCount; i++) { labels[i] = ObjectUtils.toString(values[i]); } row = new Row(values, labels, true); rows.add(row); } }
From source file:nl.eduvpn.app.adapter.ProfileAdapter.java
/** * Adds new items to this adapter.//w w w . j av a 2s .c o m * * @param profiles The list of profiles to add to the list of current items. */ public void addItemsIfNotAdded(List<Pair<Instance, Profile>> profiles) { synchronized (_profileListLock) { for (Pair<Instance, Profile> newPair : profiles) { ListIterator<Pair<Instance, Profile>> existingItemIterator = _profileList.listIterator(); boolean replacedItem = false; while (existingItemIterator.hasNext() && !replacedItem) { Pair<Instance, Profile> existingPair = existingItemIterator.next(); if (existingPair.first.getBaseURI().equals(newPair.first.getBaseURI()) && existingPair.second.getDisplayName().equals(newPair.second.getDisplayName())) { // Replace the item replacedItem = true; existingItemIterator.set(newPair); } } if (!replacedItem) { _profileList.add(newPair); } } } notifyDataSetChanged(); }
From source file:com.projity.pm.assignment.HasAssignmentsImpl.java
public void updateAssignment(Assignment modified) { ListIterator i = assignments.listIterator(); Assignment current = null;/*from w ww .j ava2s . com*/ while (i.hasNext()) { current = (Assignment) i.next(); if (current.getTask() == modified.getTask() && current.getResource() == modified.getResource()) { i.set(modified); // replace current with new one break; } } }