Example usage for java.util ListIterator next

List of usage examples for java.util ListIterator next

Introduction

In this page you can find the example usage for java.util ListIterator next.

Prototype

E next();

Source Link

Document

Returns the next element in the list and advances the cursor position.

Usage

From source file:com.amalto.core.history.accessor.record.DataRecordAccessor.java

@SuppressWarnings({ "unchecked", "rawtypes" })
@Override//from   w  w  w  .  j  ava  2  s. c  om
public void insert() {
    try {
        if (!exist()) {
            create();
        } else {
            DataRecord current = dataRecord;
            ListIterator<PathElement> elements = getPath(dataRecord, path).listIterator();
            PathElement pathElement = null;
            while (elements.hasNext()) {
                pathElement = elements.next();
                if (!elements.hasNext()) {
                    break;
                }
                if (pathElement.field instanceof ContainedTypeFieldMetadata) {
                    Object o = current.get(pathElement.field);
                    if (pathElement.field.isMany()) {
                        List list = (List) o;
                        current = (DataRecord) list.get(pathElement.index);
                    } else {
                        current = (DataRecord) o;
                    }
                }
            }
            if (pathElement != null && pathElement.field.isMany()) {
                List list = (List) current.get(pathElement.field);
                list.add(pathElement.index, null);
            }
        }
    } finally {
        cachedExist = true;
    }
}

From source file:com.smi.travel.monitor.MonitorGalileo.java

@Override
void buildBookingFlight(BookingAirline bAir) {
    MGalileo flightNumber = galileoMap.get("flight number");
    String section = flightNumber.getSection();
    MGalileo source = galileoMap.get("source");
    MGalileo destination = galileoMap.get("destination");
    MGalileo departureDate = galileoMap.get("departure date");
    MGalileo arrivalDate = galileoMap.get("arrive date");

    MGalileo ticketDate = galileoMap.get("ticket date");
    MGalileo deptTime = galileoMap.get("departure time");
    MGalileo arrvTime = galileoMap.get("arrive time");

    int lineNo = Integer.parseInt(ticketDate.getLine());
    String lineT = lineData.get(lineNo);
    String ticketDateS = lineT.substring(ticketDate.getStartlength() - 1,
            ticketDate.getStartlength() - 1 + ticketDate.getLength());
    String year = ticketDateS.substring(5);

    //Check how many rows there is.
    ArrayList<String> lines = (ArrayList<String>) sectionData.get(section);

    ListIterator<String> iterator = lines.listIterator();
    BookingFlight bf = null;//from   w w w .  j a  v  a2 s. co  m
    while (iterator.hasNext()) {
        String line = iterator.next();
        System.out.println("BookingFlingt input line[" + line + "]");
        String flightNo = bAir.getAirlineCode() + getField("flight number", line).trim();
        //            String flightNo = line.substring(flightNumber.getStartlength() - 1, flightNumber.getStartlength() - 1 + flightNumber.getLength());
        String sourceCode = line.substring(source.getStartlength() - 1,
                source.getStartlength() - 1 + source.getLength());
        String desCode = line.substring(destination.getStartlength() - 1,
                destination.getStartlength() - 1 + destination.getLength());
        String deptDateS = line.substring(departureDate.getStartlength() - 1,
                departureDate.getStartlength() - 1 + departureDate.getLength());
        String arrivalDateS = line.substring(arrivalDate.getStartlength() - 1,
                arrivalDate.getStartlength() - 1 + arrivalDate.getLength());
        //            String deptTimeS = line.substring(deptTime.getStartlength() - 1, deptTime.getStartlength() - 1 + deptTime.getLength());
        String deptTimeS = getField("departure time", line);
        String arrvTimeS = line.substring(arrvTime.getStartlength() - 1,
                arrvTime.getStartlength() - 1 + arrvTime.getLength());
        Date deptDate = convertStringToDate(deptDateS + year);
        Date arrvDate = convertStringToDate(deptDateS + year, Integer.parseInt(arrivalDateS));

        String flightClass = getField("flight class", line);
        bf = new BookingFlight(flightNo, sourceCode, desCode, deptDate, arrvDate, flightClass);
        bf.setDepartTime(deptTimeS);
        bf.setArriveTime(arrvTimeS);
        bf.setAdCost(0);
        bf.setAdPrice(0);
        bf.setAdTax(0);
        bf.setChCost(0);
        bf.setChPrice(0);
        bf.setChTax(0);
        bf.setInCost(0);
        bf.setInPrice(0);
        bf.setInTax(0);
        bf.setOtCost(0);
        bf.setOtPrice(0);
        bf.setOtTax(0);
        bAir.getBookingFlights().add(bf);
        bf.setBookingAirline(bAir);

        //            System.out.println("Build BookingFlight - " + bf.toString());
    }

    return;
}

From source file:vteaexploration.plottools.panels.XYChartPanel.java

private double getMaximumOfData(ArrayList alVolumes, int x) {

    ListIterator litr = alVolumes.listIterator();

    //ArrayList<Number> al = new ArrayList<Number>();
    Number high = 0;/*from   w  w w. j a  v  a2s.  com*/

    while (litr.hasNext()) {
        try {
            MicroObjectModel volume = (MicroObjectModel) litr.next();
            Number Corrected = processPosition(x, volume);
            if (Corrected.floatValue() > high.floatValue()) {
                high = Corrected;
            }
        } catch (NullPointerException e) {
        }
    }
    return high.longValue();

}

From source file:ch.uzh.phys.ecn.oboma.agents.model.Agent.java

public String getNextWaypoint(String pCurrentNodeId) {
    ListIterator<Pair<String, Integer>> routeIterator = mRoute.listIterator();

    if (mRoute.isEmpty()) {
        return pCurrentNodeId;
    }//  ww  w.j a  v a  2  s. com

    if (pCurrentNodeId.contains("-")) {
        if (mRouteDirection.equals(RouteDirection.FORWARD)) {
            String[] keys = pCurrentNodeId.split("-");
            return keys[1];
        } else {
            // look for correct node to get previous node
            while (routeIterator.hasNext()) {
                String connectionKey = routeIterator.next().getKey();
                String[] keys = connectionKey.split("-");

                if (connectionKey.equals(pCurrentNodeId)) {
                    // get previous node with endId equals startId of pCurrentNodeId
                    ListIterator<Pair<String, Integer>> backwardsIterator = mRoute.listIterator();

                    while (backwardsIterator.hasNext()) {
                        String previousNodeId = backwardsIterator.next().getKey();
                        String[] previousKeys = previousNodeId.split("-");

                        if (previousKeys[1].equals(keys[0])) {
                            if (!routeIterator.hasNext()) {
                                mRouteDirection = RouteDirection.FORWARD;
                            }

                            return previousKeys[0];
                        }
                    }
                }
            }
        }
    } else {
        while (routeIterator.hasNext() && mRouteDirection.equals(RouteDirection.FORWARD)) {
            String connectionKey = routeIterator.next().getKey();
            String[] keys = connectionKey.split("-");

            if (keys[0].equals(pCurrentNodeId)) {
                // target node id
                return connectionKey;
            }
        }

        mRouteDirection = RouteDirection.BACKWARDS;

        // set iterator to start of list again
        routeIterator = mRoute.listIterator();
        while (routeIterator.hasNext() && mRouteDirection.equals(RouteDirection.BACKWARDS)) {
            String connectionKey = routeIterator.next().getKey();
            String[] keys = connectionKey.split("-");

            if (keys[1].equals(pCurrentNodeId)) {
                // source node id with currentNodeId as target
                // -> getNode with sourceNode as target, which represents node before
                ListIterator<Pair<String, Integer>> backwardsIterator = mRoute.listIterator();
                while (backwardsIterator.hasNext()) {
                    String previousNodeKey = backwardsIterator.next().getKey();
                    String[] prevKeys = previousNodeKey.split("-");

                    if (prevKeys[1].equals(keys[1])) {
                        if (!routeIterator.hasNext()) {
                            mRouteDirection = RouteDirection.FORWARD;
                        }

                        // return route with direction changed
                        return prevKeys[0] + "-" + prevKeys[1];
                    }
                }
            }
        }
    }

    LOGGER.warning("CurrentNodeId: " + pCurrentNodeId + ", Direction: " + mRouteDirection);

    throw new IllegalStateException("No route found for given nodeId " + pCurrentNodeId);
}

From source file:org.generationcp.breeding.manager.crossingmanager.MakeCrossesTableComponent.java

/**
 * Crosses each item on first list with its counterpart (same index or position) 
 * on second list. Assumes that checking if list sizes are equal was done beforehand.
 * The generated crossings are then added to Crossings Table.
 * /*from  w ww .  j a v  a 2s  . co m*/
 * @param parents1 - list of GermplasmList entries as first parents
 * @param parents2 - list of GermplasmList entries as second parents
 * @param listnameMaleParent 
 * @param listnameFemaleParent 
 */
public void makeTopToBottomCrosses(List<GermplasmListEntry> parents1, List<GermplasmListEntry> parents2,
        Label listnameFemaleParent, Label listnameMaleParent) {

    ListIterator<GermplasmListEntry> iterator1 = parents1.listIterator();
    ListIterator<GermplasmListEntry> iterator2 = parents2.listIterator();

    tableCrossesMade
            .setVisibleColumns(new Object[] { PARENTAGE, FEMALE_PARENT_COLUMN, MALE_PARENT_COLUMN, SOURCE });

    while (iterator1.hasNext()) {
        GermplasmListEntry parent1 = iterator1.next();
        GermplasmListEntry parent2 = iterator2.next();
        String caption1 = parent1.getDesignation();
        String caption2 = parent2.getDesignation();
        String caption3 = listnameFemaleParent.getValue().toString() + ":" + parent1.getEntryId() + "/"
                + listnameMaleParent.getValue().toString() + ":" + parent2.getEntryId();

        CrossParents parents = new CrossParents(parent1, parent2);

        if (!crossAlreadyExists(parents)) {
            tableCrossesMade.addItem(
                    new Object[] { CrossingManagerUtil.generateFemaleandMaleCrossName(caption1, caption2),
                            caption1, caption2, caption3 },
                    parents);
        }
    }
    this.crossesMadeCountContainer.setCaption("Total Crosses: " + tableCrossesMade.size());

    tableCrossesMade.setVisibleColumns(new Object[] { PARENTAGE, FEMALE_PARENT_COLUMN, MALE_PARENT_COLUMN });
    tableCrossesMade.setPageLength(0);
    tableCrossesMade.requestRepaint();
}

From source file:com.projity.pm.graphic.model.transform.NodeCacheTransformer.java

private void groupList(List list, List destList, ListIterator groupIterator, Node parentGroup,
        NodeTransformer composition, boolean preserveHierarchy) {
    NodeGroup group = (NodeGroup) groupIterator.next();
    NodeSorter sorter = group.getSorter();
    GraphicNodeComparator gcomp = new GraphicNodeComparator(sorter, composition);
    sorter.sortList(list, gcomp, preserveHierarchy);
    GraphicNode last = null;/*from   w w  w. j  a  va2  s  .c  om*/
    List nodes = null;
    GraphicNode current;
    for (ListIterator i = list.listIterator(); i.hasNext();) {
        current = (GraphicNode) i.next();
        if (last == null) {
            nodes = new LinkedList();
        } else if (gcomp.compare(last, current) != 0) {
            handleGroup(destList, groupIterator, parentGroup, group, last, nodes, composition,
                    preserveHierarchy);
            nodes = new LinkedList();
        }
        nodes.add(current);
        last = current;
    }
    if (nodes != null && nodes.size() > 0) {
        handleGroup(destList, groupIterator, parentGroup, group, last, nodes, composition, preserveHierarchy);
    }
    groupIterator.previous();
}

From source file:com.projity.pm.assignment.HasAssignmentsImpl.java

public void updateAssignment(Assignment modified) {
    ListIterator i = assignments.listIterator();
    Assignment current = null;/*www  .j a  v a  2 s .  co m*/
    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;
        }
    }
}

From source file:chat.viska.commons.pipelines.Pipeline.java

/**
 * Removes a {@link Pipe}./*ww w.  ja va  2  s  .c  om*/
 */
@SchedulerSupport(SchedulerSupport.IO)
public Maybe<Pipe> remove(final String name) {
    Validate.notBlank(name);
    return Maybe.fromCallable((Callable<@Nullable Pipe>) () -> {
        final Pipe pipe;
        pipeLock.writeLock().lockInterruptibly();
        try {
            final ListIterator<Map.Entry<String, Pipe>> iterator = getIteratorOf(name);
            if (iterator == null) {
                return null;
            }
            pipe = iterator.next().getValue();
            iterator.remove();
            pipe.onRemovedFromPipeline(this);
        } finally {
            pipeLock.writeLock().unlock();
        }
        return pipe;
    }).subscribeOn(Schedulers.io());
}

From source file:br.com.ingenieux.mojo.beanstalk.env.ReplaceEnvironmentMojo.java

/**
 * Prior to Launching a New Environment, lets look and copy the most we can
 *
 * @param curEnv current environment/*from   w  w w  .j a  va2  s. co  m*/
 */
private void copyOptionSettings(EnvironmentDescription curEnv) throws Exception {
    /**
     * Skip if we don't have anything
     */
    if (null != this.optionSettings && this.optionSettings.length > 0) {
        return;
    }

    DescribeConfigurationSettingsResult configSettings = getService()
            .describeConfigurationSettings(new DescribeConfigurationSettingsRequest()
                    .withApplicationName(applicationName).withEnvironmentName(curEnv.getEnvironmentName()));

    List<ConfigurationOptionSetting> newOptionSettings = new ArrayList<ConfigurationOptionSetting>(
            configSettings.getConfigurationSettings().get(0).getOptionSettings());

    ListIterator<ConfigurationOptionSetting> listIterator = newOptionSettings.listIterator();

    while (listIterator.hasNext()) {
        ConfigurationOptionSetting curOptionSetting = listIterator.next();

        boolean bInvalid = harmfulOptionSettingP(curEnv.getEnvironmentId(), curOptionSetting);

        if (bInvalid) {
            getLog().info(format("Excluding Option Setting: %s:%s['%s']", curOptionSetting.getNamespace(),
                    curOptionSetting.getOptionName(), CredentialsUtil.redact(curOptionSetting.getValue())));
            listIterator.remove();
        } else {
            getLog().info(format("Including Option Setting: %s:%s['%s']", curOptionSetting.getNamespace(),
                    curOptionSetting.getOptionName(), CredentialsUtil.redact(curOptionSetting.getValue())));
        }
    }

    Object __secGroups = project.getProperties().get("beanstalk.securityGroups");

    if (null != __secGroups) {
        String securityGroups = StringUtils.defaultString(__secGroups.toString());

        if (!StringUtils.isBlank(securityGroups)) {
            ConfigurationOptionSetting newOptionSetting = new ConfigurationOptionSetting(
                    "aws:autoscaling:launchconfiguration", "SecurityGroups", securityGroups);
            newOptionSettings.add(newOptionSetting);
            getLog().info(format("Including Option Setting: %s:%s['%s']", newOptionSetting.getNamespace(),
                    newOptionSetting.getOptionName(), newOptionSetting.getValue()));
        }
    }

    /*
     * Then copy it back
     */
    this.optionSettings = newOptionSettings.toArray(new ConfigurationOptionSetting[newOptionSettings.size()]);
}

From source file:com.adobe.acs.commons.httpcache.engine.impl.HttpCacheEngineImpl.java

@Activate
protected void activate(Map<String, Object> configs) {

    // PIDs of global cache handling rules.
    globalCacheHandlingRulesPid = new ArrayList<String>(Arrays.asList(
            PropertiesUtil.toStringArray(configs.get(PROP_GLOBAL_CACHE_HANDLING_RULES_PID), new String[] {})));
    ListIterator<String> listIterator = globalCacheHandlingRulesPid.listIterator();
    while (listIterator.hasNext()) {
        String value = listIterator.next();
        if (StringUtils.isBlank(value)) {
            listIterator.remove();/*from   w  w  w.j  av  a  2  s . c  om*/
        }
    }
    log.info("HttpCacheEngineImpl activated.");
}