List of usage examples for java.util List listIterator
ListIterator<E> listIterator();
From source file:org.apache.axis2.jaxws.spi.migrator.ApplicationContextMigratorUtil.java
/** * @param contextMigratorListID/*w w w .j av a2 s . com*/ * @param responseContext * @param messageContext */ public static void performMigrationFromMessageContext(String contextMigratorListID, Map<String, Object> responseContext, MessageContext messageContext) { if (messageContext == null) { throw ExceptionFactory.makeWebServiceException(Messages.getMessage("nullMsgCtxErr")); } ServiceDescription sd = messageContext.getEndpointDescription().getServiceDescription(); if (sd != null) { ConfigurationContext configCtx = sd.getAxisConfigContext(); List<ApplicationContextMigrator> migratorList = (List<ApplicationContextMigrator>) configCtx .getProperty(contextMigratorListID); if (migratorList != null) { // Create copy to avoid using shared list List listCPM = null; // synchronize on non-null migratorList synchronized (migratorList) { listCPM = new ArrayList(migratorList); } ListIterator<ApplicationContextMigrator> itr = listCPM.listIterator(); // Iterate over non-shared list while (itr.hasNext()) { ApplicationContextMigrator cpm = itr.next(); if (log.isDebugEnabled()) { log.debug("migrator: " + cpm.getClass().getName() + ".migratePropertiesFromMessageContext"); } // TODO: Synchronizing here is expensive too. // If a cpm requires synchronization, it should provide it inside of its migratePropertiesFromMessageContext implementation. cpm.migratePropertiesFromMessageContext( new ApplicationPropertyMapWriter(responseContext, messageContext.getMEPContext()), messageContext); } } } }
From source file:com.cinchapi.concourse.lang.Parser.java
/** * Go through a list of symbols and group the expressions together in a * {@link Expression} object.// w w w.j av a2 s . c om * * @param symbols * @return the expression */ protected static List<Symbol> groupExpressions(List<Symbol> symbols) { // visible // for // testing try { List<Symbol> grouped = Lists.newArrayList(); ListIterator<Symbol> it = symbols.listIterator(); while (it.hasNext()) { Symbol symbol = it.next(); if (symbol instanceof KeySymbol) { // NOTE: We are assuming that the list of symbols is well // formed, and, as such, the next elements will be an // operator and one or more symbols. If this is not the // case, this method will throw a ClassCastException OperatorSymbol operator = (OperatorSymbol) it.next(); ValueSymbol value = (ValueSymbol) it.next(); Expression expression; if (operator.getOperator() == Operator.BETWEEN) { ValueSymbol value2 = (ValueSymbol) it.next(); expression = Expression.create((KeySymbol) symbol, operator, value, value2); } else { expression = Expression.create((KeySymbol) symbol, operator, value); } grouped.add(expression); } else if (symbol instanceof TimestampSymbol) { // Add the // timestamp to the // previously // generated // Expression ((Expression) Iterables.getLast(grouped)).setTimestamp((TimestampSymbol) symbol); } else { grouped.add(symbol); } } return grouped; } catch (ClassCastException e) { throw new SyntaxException(e.getMessage()); } }
From source file:com.ofalvai.bpinfo.api.bkkinfo.BkkInfoClient.java
/** * Alerts scheduled for the current day (and not yet started) appear in the current alerts list. * We need to find them and move to the future alerts list *//* w w w . jav a2s . c o m*/ private static void fixFutureAlertsInTodayList(List<Alert> alertsToday, List<Alert> alertsFuture) { // Avoiding ConcurrentModificationException when removing from alertsToday ListIterator<Alert> todayIterator = alertsToday.listIterator(); while (todayIterator.hasNext()) { Alert alert = todayIterator.next(); DateTime startTime = new DateTime(alert.getStart() * 1000L); if (startTime.isAfterNow()) { alertsFuture.add(alert); todayIterator.remove(); } } }
From source file:org.apache.hadoop.yarn.service.launcher.ServiceLauncher.java
/** * Extract the configuration arguments and apply them to the configuration, * building an array of processed arguments to hand down to the service. * * @param conf configuration to update/*from w ww. ja v a 2 s .c o m*/ * @param args main arguments. args[0] is assumed to be the service * classname and is skipped * @return the processed list. */ public static String[] extractConfigurationArgs(Configuration conf, List<String> args) { //convert args to a list int argCount = args.size(); if (argCount <= 1) { return new String[0]; } List<String> argsList = new ArrayList<String>(argCount); ListIterator<String> arguments = args.listIterator(); //skip that first entry arguments.next(); while (arguments.hasNext()) { String arg = arguments.next(); if (arg.equals(ARG_CONF)) { //the argument is a --conf file tuple: extract the path and load //it in as a configuration resource. //increment the loop iterator if (!arguments.hasNext()) { //overshot the end of the file exitWithMessage(EXIT_COMMAND_ARGUMENT_ERROR, ARG_CONF + ": missing configuration file after "); } File file = new File(arguments.next()); if (!file.exists()) { exitWithMessage(EXIT_COMMAND_ARGUMENT_ERROR, ARG_CONF + ": configuration file not found: " + file); } try { conf.addResource(file.toURI().toURL()); } catch (MalformedURLException e) { exitWithMessage(EXIT_COMMAND_ARGUMENT_ERROR, ARG_CONF + ": configuration file path invalid: " + file); } } else { argsList.add(arg); } } String[] processedArgs = new String[argsList.size()]; argsList.toArray(processedArgs); return processedArgs; }
From source file:org.apache.lens.cube.metadata.MetastoreUtil.java
public static List<Partition> filterPartitionsByNonTimeParts(List<Partition> partitions, Map<String, String> nonTimePartSpec, String latestPartCol) { ListIterator<Partition> iter = partitions.listIterator(); while (iter.hasNext()) { Partition part = iter.next();/*from w ww . j a va2 s . c om*/ boolean ignore = false; for (Map.Entry<String, String> entry1 : part.getSpec().entrySet()) { if ((nonTimePartSpec == null || !nonTimePartSpec.containsKey(entry1.getKey())) && !entry1.getKey().equals(latestPartCol)) { try { UpdatePeriod.valueOf(part.getParameters().get(PARTITION_UPDATE_PERIOD)).format() .parse(entry1.getValue()); } catch (ParseException e) { ignore = true; } } } if (ignore) { iter.remove(); } } return partitions; }
From source file:edu.harvard.mcz.imagecapture.PositionTemplate.java
public static List<PositionTemplate> getTemplates() { //TemplateLifeCycle tls = new TemplateLifeCycle(); //List<Template> templates = tls.findAll(); ArrayList<PositionTemplate> results = new ArrayList<PositionTemplate>(); List<String> templateIds = PositionTemplate.getTemplateIds(); ListIterator<String> i = templateIds.listIterator(); while (i.hasNext()) { try {/* ww w . jav a 2 s. c om*/ results.add(new PositionTemplate(i.next())); } catch (NoSuchTemplateException e) { // TODO Auto-generated catch block e.printStackTrace(); } } return results; }
From source file:base.Engine.java
public static Set<TreeSet<PatternInstance>> findCollisions(List<PatternInstance> instanceList, int caseThreshold) { Set<TreeSet<PatternInstance>> returnSet = new TreeSet<>(new TreeComparator()); if (instanceList.size() < 2) return returnSet; // Our base case if (instanceList.size() < caseThreshold) { PatternInstance currentInstance = null; for (ListIterator<PatternInstance> i = instanceList.listIterator(); i.hasNext();) { currentInstance = i.next();/* w w w .ja v a 2s . c o m*/ PatternInstance otherInstance = null; for (ListIterator<PatternInstance> j = instanceList.listIterator(i.nextIndex()); j.hasNext();) { otherInstance = j.next(); if (currentInstance != otherInstance && currentInstance.getRectangle().overlaps(otherInstance.getRectangle())) { returnSet = addPair(returnSet, currentInstance, otherInstance); } } } return returnSet; // Our other base case } Rectangle getRect = instanceList.get(0).getRectangle(); // Create a super-rectangle that encompasses all the objects PatternInstance currentInstance = null; for (ListIterator<PatternInstance> i = instanceList.listIterator(1); i.hasNext();) { currentInstance = i.next(); getRect = getRect.merge(currentInstance.getRectangle()); } List<PatternInstance> listQ1 = new LinkedList<>(); List<PatternInstance> listQ2 = new LinkedList<>(); List<PatternInstance> listQ3 = new LinkedList<>(); List<PatternInstance> listQ4 = new LinkedList<>(); Rectangle rectQ1 = new Rectangle(getRect.getX(), getRect.getY(), getRect.getWidth() / 2 + 1, getRect.getHeight() / 2 + 1); Rectangle rectQ2 = new Rectangle(getRect.getX(), getRect.getY() + getRect.getHeight() / 2 + 1, getRect.getWidth() / 2 + 1, getRect.getHeight() / 2 + 1); Rectangle rectQ3 = new Rectangle(getRect.getX() + getRect.getWidth() / 2 + 1, getRect.getY() + getRect.getHeight() / 2 + 1, getRect.getWidth() / 2 + 1, getRect.getHeight() / 2 + 1); Rectangle rectQ4 = new Rectangle(getRect.getX() + getRect.getWidth() / 2 + 1, getRect.getY(), getRect.getWidth() / 2 + 1, getRect.getHeight() / 2 + 1); for (ListIterator<PatternInstance> iter = instanceList.listIterator(); iter.hasNext();) { currentInstance = iter.next(); if (currentInstance.getRectangle().overlaps(rectQ1)) listQ1.add(currentInstance); if (currentInstance.getRectangle().overlaps(rectQ2)) listQ2.add(currentInstance); if (currentInstance.getRectangle().overlaps(rectQ3)) listQ3.add(currentInstance); if (currentInstance.getRectangle().overlaps(rectQ4)) listQ4.add(currentInstance); } for (TreeSet<PatternInstance> t1 : findCollisions(listQ1, caseThreshold * 2)) resolveTree(returnSet, t1); for (TreeSet<PatternInstance> t2 : findCollisions(listQ2, caseThreshold * 2)) resolveTree(returnSet, t2); for (TreeSet<PatternInstance> t3 : findCollisions(listQ3, caseThreshold * 2)) resolveTree(returnSet, t3); for (TreeSet<PatternInstance> t4 : findCollisions(listQ4, caseThreshold * 2)) resolveTree(returnSet, t4); return returnSet; }
From source file:ca.uhn.fhir.context.BaseRuntimeElementCompositeDefinition.java
private static int findIndex(List<BaseRuntimeChildDefinition> theChildren, String theName, boolean theDefaultAtEnd) { int index = theDefaultAtEnd ? theChildren.size() : -1; for (ListIterator<BaseRuntimeChildDefinition> iter = theChildren.listIterator(); iter.hasNext();) { if (iter.next().getElementName().equals(theName)) { index = iter.previousIndex(); break; }/* w w w.j a v a 2s . c o m*/ } return index; }
From source file:edu.harvard.mcz.imagecapture.PositionTemplate.java
/** Fetch the list of valid template names (including the no component parts template). * Use these names in the constructor PositionTemplate(String templateToUse); * // w w w . j a v a 2 s . c o m * @return a list of the identifiers of the currently available templates. */ public static List<String> getTemplateIds() { String[] templates = { TEMPLATE_TEST_1, TEMPLATE_DEFAULT, TEMPLATE_NO_COMPONENT_PARTS }; List<String> temp = Arrays.asList(templates); ArrayList<String> templateIdList = new ArrayList<String>(); for (int i = 0; i < temp.size(); i++) { templateIdList.add(temp.get(i)); } TemplateLifeCycle tls = new TemplateLifeCycle(); List<Template> persistentTemplates = tls.findAll(); if (persistentTemplates == null) { tls.cleanUpReferenceImage(); persistentTemplates = tls.findAll(); } ListIterator<Template> iter = persistentTemplates.listIterator(); while (iter.hasNext()) { templateIdList.add(iter.next().getTemplateId()); } return templateIdList; }
From source file:org.apache.axis2.jaxws.spi.migrator.ApplicationContextMigratorUtil.java
/** * Register a new ContextPropertyMigrator. * * @param configurationContext/*w w w . j a v a 2s.c o m*/ * @param contextMigratorListID The name of the property in the ConfigurationContext that * contains the list of migrators. * @param migrator */ public static void addApplicationContextMigrator(ConfigurationContext configurationContext, String contextMigratorListID, ApplicationContextMigrator migrator) { List<ApplicationContextMigrator> migratorList = (List<ApplicationContextMigrator>) configurationContext .getProperty(contextMigratorListID); if (migratorList == null) { migratorList = new LinkedList<ApplicationContextMigrator>(); configurationContext.setProperty(contextMigratorListID, migratorList); } synchronized (migratorList) { // Check to make sure we haven't already added this migrator to the // list. ListIterator<ApplicationContextMigrator> itr = migratorList.listIterator(); while (itr.hasNext()) { ApplicationContextMigrator m = itr.next(); if (m.getClass().equals(migrator.getClass())) { return; } } if (log.isDebugEnabled()) { log.debug("Adding ApplicationContextMigrator: " + migrator.getClass().getName()); } migratorList.add(migrator); } }