Example usage for java.util ListIterator hasNext

List of usage examples for java.util ListIterator hasNext

Introduction

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

Prototype

boolean hasNext();

Source Link

Document

Returns true if this list iterator has more elements when traversing the list in the forward direction.

Usage

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

@Override
public int getGatedSelected(ImagePlus ip) {
    ArrayList<MicroObject> ImageGatedObjects = new ArrayList<MicroObject>();
    ArrayList<MicroObject> volumes = (ArrayList) plotvalues.get(1);
    try {/*w  ww  .ja va2  s.  co m*/
        ListIterator<MicroObject> itr = volumes.listIterator();
        while (itr.hasNext()) {
            MicroObject m = itr.next();
            int[] c = new int[2];
            c = m.getBoundsCenter();
            if (ip.getRoi().contains(c[0], c[1])) {
                ImageGatedObjects.add(m);
            }
        }
    } catch (NullPointerException e) {
        return 0;
    }

    Gate gate;
    ListIterator<Gate> gate_itr = gates.listIterator();
    ArrayList<MicroObject> result = new ArrayList<MicroObject>();

    while (gate_itr.hasNext()) {
        gate = gate_itr.next();
        if (gate.getSelected()) {
            Path2D path = gate.createPath2DInChartSpace();

            MicroObjectModel volume;
            double xValue = 0;
            double yValue = 0;

            ListIterator<MicroObject> it = ImageGatedObjects.listIterator();
            try {
                while (it.hasNext()) {
                    volume = it.next();
                    if (volume != null) {
                        xValue = ((Number) processPosition(currentX, (MicroObject) volume)).doubleValue();
                        yValue = ((Number) processPosition(currentY, (MicroObject) volume)).doubleValue();
                        if (path.contains(xValue, yValue)) {
                            result.add((MicroObject) volume);
                        }
                    }
                }
            } catch (NullPointerException e) {
                return 0;
            }
        }
    }
    return result.size();
}

From source file:com.projity.pm.graphic.model.cache.ViewNodeModelCache.java

public int getChildCount(Object obj) {
    ListIterator i = getIterator();
    GraphicNode node;/*from w ww .  j  a  va  2s . c om*/
    GraphicNode ref = null;
    if (obj == getRoot())
        ref = (GraphicNode) getRoot();
    else
        while (i.hasNext()) {
            node = (GraphicNode) i.next();
            if (node == obj) {
                ref = node;
                break;
            }
        }
    int count = 0;
    if (ref != null)
        while (i.hasNext()) {
            node = (GraphicNode) i.next();
            if (node.getLevel() <= ref.getLevel())
                break;
            else if (node.getLevel() == ref.getLevel() + 1)
                count++;
        }
    return count;
}

From source file:com.projity.pm.graphic.model.cache.ViewNodeModelCache.java

public boolean isLeaf(Object obj) {
    ListIterator i = getIterator();
    GraphicNode node;/* ww w  .j a  v a 2s .  c  o m*/
    GraphicNode ref = null;
    if (obj == getRoot())
        ref = (GraphicNode) getRoot();
    else
        while (i.hasNext()) {
            node = (GraphicNode) i.next();
            if (node == obj) {
                ref = node;
                break;
            }
        }
    if (ref == null)
        return true;
    if (i.hasNext()) {
        node = (GraphicNode) i.next();
        if (node.getLevel() > ref.getLevel())
            return false;
        else
            return true;
    }
    return true;
}

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

@Override
void buildBookingPassenger(BookingAirline bAir) {
    String passengerTypes = new String("");
    int costRefIndex = 0;
    MAmadeus pName = amadeusMap.get("passenger name");
    ArrayList<String> lines = (ArrayList<String>) sectionData.get(pName.getSection());
    //        System.out.println("Passenger " + lines.size());
    String ticketType = getField("ticket type");
    ListIterator<String> iterator = lines.listIterator();
    String line = null;//from w ww . j av a2 s .c  o  m
    BookingPassenger bp = null;
    while (iterator.hasNext()) {
        line = iterator.next();
        //            System.out.println("line-> " + line);
        String[] mline = line.split("\\r?\\n");

        String passengerName = getField("passenger name", mline[0]).trim();
        //            String passengerType = getField("passenger type", mline[0]);
        //            if (StringUtils.isEmpty(passengerType)
        //                    || !("ADT".equalsIgnoreCase(passengerType))
        //                    || !("CHD".equalsIgnoreCase(passengerType))
        //                    || !("INF".equalsIgnoreCase(passengerType))) {
        //                passengerType = "NON";
        //            }

        MAmadeus ticketNo1Ama = amadeusMap.get("ticket serial1");
        String section = ticketNo1Ama.getSection();
        String ticketLine = null;
        for (int i = 1; i < mline.length; i++) {
            if (mline[i].startsWith(section)) {
                ticketLine = mline[i];
                break;
            }
        }
        //            System.out.println("Ticket ->" + ticketLine);
        String ticketNo1 = getField("ticket serial1", ticketLine);
        String ticketNo2 = getField("ticket serial2", ticketLine);
        String ticketNo3 = getField("ticket serial3", ticketLine);

        //            System.out.println("passengerName " + passengerName);
        String[] splitName = passengerName.split("/");
        String lastName = splitName[0];
        String[] splitName2 = splitName[1].split(" ");
        // Using nameSeparatorIndex to handle case of blank space in first name.
        int nameSeparatorIndex = splitName[1].lastIndexOf(" ");
        String firstName = splitName[1].substring(0, nameSeparatorIndex);

        //            String firstName = splitName[1].substring(0, splitName[1].length() - 2);
        //            String initial = splitName[1].substring(splitName[1].length() - 2);
        String initial;
        String passengerType;
        if (!splitName2[1].contains("(")) {
            // plus 1 to exclude blankspace index.
            initial = splitName[1].substring(nameSeparatorIndex + 1);
            passengerType = "ADT";
        } else {
            int indexLess = splitName2[1].indexOf("(");
            int indexMore = splitName2[1].indexOf(")");
            initial = splitName2[1].substring(0, indexLess);
            passengerType = splitName2[1].substring(indexLess + 1, indexMore);
        }

        MAmadeus fareComAma = amadeusMap.get("fare commission");
        String fareSection = fareComAma.getSection();
        String fareLine = null;
        for (int i = 1; i < mline.length; i++) {
            if (mline[i].startsWith(fareSection)) {
                fareLine = mline[i];
                break;
            }
        }
        String fareCommission;
        if (fareLine == null) {
            fareCommission = "0";
        } else {
            fareCommission = getField("fare commission", fareLine).trim();
            fareCommission = fareCommission.replace("A", "");
        }
        String currency = getField("currency").trim();

        String ticket_fare = getTicketFare(currency);
        //            String ticket_fare = getField("ticket fare").trim();
        ticket_fare = stripNumberDecimalString(ticket_fare);
        String total_amount = getField("ticket total").trim();
        int tax = Integer.valueOf(total_amount) - Integer.valueOf(ticket_fare);
        if (tax < 0) {
            tax = tax * (-1);
        }

        //            System.out.println("lastname [" + lastName + "] ,firstname[" + firstName + "] ,initial[" + initial + "] passengerType[" + passengerType + "]");
        bp = new BookingPassenger();
        bp.setFirstName(firstName);
        bp.setLastName(lastName);
        bp.setInitialName(initial);
        bp.setPassengerType(passengerType);
        bp.setTicketType(ticketType);
        bp.setTicketnoS1(ticketNo1);//ticketNoS1);
        bp.setTicketnoS2(ticketNo2);
        bp.setTicketnoS3(ticketNo3);
        bp.setTicketFare(Integer.valueOf(ticket_fare));
        bp.setTicketTax(tax);
        bAir.getBookingPassengers().add(bp);
        bp.setBookingAirline(bAir);
        if (!passengerTypes.contains(passengerType)) {
            passengerTypes = passengerTypes + "," + passengerType;
            Integer cost;
            Integer price;
            if (isInternationalTicket(ticketType)) {
                String costS = getField("cost").trim();

                // No cost line. Set to ticket_fare.
                if ("0".equalsIgnoreCase(costS)) {
                    costS = ticket_fare;
                }
                cost = Integer.valueOf(costS);
                System.out.println("cost [" + cost + "]");
                price = cost + Integer.valueOf(fareCommission);
            } else {
                price = Integer.valueOf(ticket_fare);
                cost = (price * 95) / 100;
            }
            costRefIndex++;
            //Update cost,price,tax according to passengertype
            // Only first flight
            BookingFlight bf = (BookingFlight) bAir.getBookingFlights().iterator().next();
            //                BookingFlight bf = this.getMostEarlyFlight(bAir.getBookingPnr());
            if ("ADT".equalsIgnoreCase(passengerType)) {
                bf.setAdCost(cost);
                bf.setAdPrice(price);
                bf.setAdTax(tax);
            } else if ("CHD".equalsIgnoreCase(passengerType)) {
                bf.setChCost(cost);
                bf.setChPrice(price);
                bf.setChTax(tax);
            } else if ("INF".equalsIgnoreCase(passengerType)) {
                bf.setInCost(cost);
                bf.setInPrice(price);
                bf.setInTax(tax);
            } else {
                bf.setAdCost(cost);
                bf.setAdPrice(price);
                bf.setAdTax(tax);
            }
            //                }
        }

    }
}

From source file:com.polyvi.xface.extension.contact.XContactsExt.java

/**
 * JSONObjectchildren???Hash/*from w ww.ja v  a  2 s . c  om*/
 *
 * @param jsonObj
 *            ??json
 * @param contactData
 *            ??hash
 * @param logicParentField
 *            ??
 */
private void transferMultipleValueFields(JSONObject jsonObj, HashMap<String, Object> contactData,
        String logicParentField) {
    try {
        JSONArray childrenJson = jsonObj.optJSONArray(logicParentField);
        if (null == childrenJson) {
            return;
        }

        int len = childrenJson.length();
        for (int i = 0; i < len; i++) {
            JSONObject childJson = (JSONObject) childrenJson.get(i);

            ListIterator<String> logicSubFieldItor = mContactAccessor
                    .getLogicContactSubFieldsOf(logicParentField).listIterator();

            while (logicSubFieldItor.hasNext()) {
                String logicSubField = logicSubFieldItor.next();
                String key = mContactAccessor.generateSubFieldKey(logicParentField, i, logicSubField);
                putValueToMap(contactData, key, getJSONString(childJson, logicSubField));
            }

            // photosvalue
            if (XContactAccessor.LOGIC_FIELD_PHOTOS.equals(logicParentField)) {
                byte[] bytes = getPhotoBytes(getJSONString(jsonObj, XContactAccessor.LOGIC_FIELD_COMMON_VALUE));
                String key = mContactAccessor.generateSubFieldKey(logicParentField, i,
                        XContactAccessor.LOGIC_FIELD_COMMON_VALUE);
                contactData.put(key, bytes);
            }
        }

        String quantity = mContactAccessor.generateQuantityFieldOf(logicParentField);
        contactData.put(quantity, len);
    } catch (JSONException e) {
        e.printStackTrace();
        XLog.d(CLASS_NAME, "Could not read field [" + logicParentField + "] from json object");
    }
}

From source file:com.projity.pm.graphic.model.cache.ViewNodeModelCache.java

public Object getChild(Object obj, int index) {
    ListIterator i = getIterator();
    GraphicNode node;//  w ww  .ja v a 2 s  . c  o  m
    GraphicNode ref = null;
    if (obj == getRoot())
        ref = (GraphicNode) getRoot();
    else
        while (i.hasNext()) {
            node = (GraphicNode) i.next();
            if (node == obj) {
                ref = node;
                break;
            }
        }
    if (ref == null)
        return null;
    int count = 0;
    while (i.hasNext()) {
        node = (GraphicNode) i.next();
        if (node.getLevel() <= ref.getLevel())
            break;
        else if (node.getLevel() == ref.getLevel() + 1) {
            if (count == index)
                return node;
            count++;
        }
    }
    return null;
}

From source file:au.edu.ausstage.networks.LookupManager.java

/**
 * A method to take a group of collaborators and output XML encoded text
 *
 * @param collaborators the list of collaborators
 * @return              the HTML encoded string
 *///from ww  w  .  ja v  a  2s.c  om
private String createXMLOutput(java.util.LinkedList<Collaborator> collaborators) {

    // assume that all sorting and ordering has already been carried out
    // loop through the list of collaborators build the XML
    ListIterator iterator = collaborators.listIterator(0);

    // declare helper variables
    StringBuilder xmlMarkup = new StringBuilder("<?xml version=\"1.0\"?><collaborators>");
    Collaborator collaborator = null;
    int count = 0;

    while (iterator.hasNext()) {

        // get the collaborator
        collaborator = (Collaborator) iterator.next();

        xmlMarkup.append("<collaborator id=\"" + collaborator.getId() + "\">");

        xmlMarkup.append("<url>" + StringEscapeUtils.escapeXml(collaborator.getUrl()) + "</url>");
        xmlMarkup.append("<givenName>" + collaborator.getGivenName() + "</givenName>");
        xmlMarkup.append("<familyName>" + collaborator.getFamilyName() + "</familyName>");
        xmlMarkup.append("<name>" + collaborator.getName() + "</name>");
        xmlMarkup.append("<function>" + collaborator.getFunction() + "</function>");
        xmlMarkup.append("<firstDate>" + collaborator.getFirstDate() + "</firstDate>");
        xmlMarkup.append("<lastDate>" + collaborator.getLastDate() + "</lastDate>");
        xmlMarkup.append("<collaborations>" + collaborator.getCollaborations() + "</collaborations>");
        xmlMarkup.append("</collaborator>");

        // increment the count
        count++;
    }

    // add a comment
    xmlMarkup.append("<!-- Contributors listed: " + count + " -->");

    // end the table
    xmlMarkup.append("</collaborators>");

    return xmlMarkup.toString();

}

From source file:com.projity.pm.graphic.model.cache.ViewNodeModelCache.java

public int getIndexOfChild(Object parent, Object child) {
    ListIterator i = getIterator();
    GraphicNode node;//from  w  w w . j  a va2 s .c o  m
    GraphicNode ref = null;
    if (parent == getRoot())
        ref = (GraphicNode) getRoot();
    else
        while (i.hasNext()) {
            node = (GraphicNode) i.next();
            if (node == parent) {
                ref = node;
                break;
            }
        }
    if (ref == null)
        return -1;
    int count = 0;
    while (i.hasNext()) {
        node = (GraphicNode) i.next();
        if (node.getLevel() <= ref.getLevel())
            break;
        else if (node.getLevel() == ref.getLevel() + 1) {
            if (node == child)
                return count;
            count++;
        }
    }
    return -1;
}

From source file:com.net2plan.cli.tools.CLITrafficDesign.java

@Override
public void executeFromCommandLine(String[] args) throws ParseException {
    long init = System.nanoTime();

    final CommandLineParser parser = new CommandLineParser();
    final CommandLine cli = parser.parse(OPTIONS, args);

    int numNodes;
    NetPlan netPlan;//from  w  ww. ja  v  a 2s . com

    if (cli.hasOption("num-nodes") && cli.hasOption("input-file"))
        throw new ParseException("'num-nodes' and 'input-file' are mutually exclusive");

    if (cli.hasOption("num-nodes")) {
        numNodes = ((Number) cli.getParsedOptionValue("num-nodes")).intValue();
        if (numNodes < 2)
            throw new Net2PlanException("Traffic matrix requires at least 2 nodes");

        netPlan = new NetPlan();
        for (int n = 0; n < numNodes; n++)
            netPlan.addNode(0, 0, null, null);
    } else {
        netPlan = new NetPlan((File) cli.getParsedOptionValue("input-file"));
        numNodes = netPlan.getNumberOfNodes();
    }

    int numMatrices = 1;
    String trafficPattern = null;

    DoubleMatrix2D[] trafficMatrices;
    if (cli.hasOption("variation-pattern")) {
        if (!cli.hasOption("num-matrices"))
            throw new Net2PlanException("'num-matrices' parameters must be specified");

        numMatrices = ((Number) cli.getParsedOptionValue("num-matrices")).intValue();
        if (numMatrices < 1)
            throw new Net2PlanException("Number of traffic matrices must be positive");

        DoubleMatrix2D trafficMatrix = netPlan.getMatrixNode2NodeOfferedTraffic();
        List<DoubleMatrix2D> newMatrices;
        String variationPattern = (String) cli.getParsedOptionValue("variation-pattern");
        switch (variationPattern) {
        case "cagr": {
            double cagr = ((Number) cli.getParsedOptionValue("variation-pattern-cagr")).doubleValue();
            if (cagr <= 0)
                throw new Net2PlanException("Compound annual growth rate must be greater than zero");
            newMatrices = TrafficMatrixGenerationModels.computeMatricesCAGR(trafficMatrix, cagr, numMatrices);

            break;
        }

        case "randomGaussian": {
            double cv = ((Number) cli.getParsedOptionValue("variation-pattern-cv")).doubleValue();
            double maxRelativeVariation = ((Number) cli
                    .getParsedOptionValue("variation-pattern-maxRelativeVariation")).doubleValue();
            if (cv <= 0)
                throw new Net2PlanException("Coefficient of variation must be greater than zero");
            if (maxRelativeVariation <= 0)
                throw new Net2PlanException("Maximum relative variation must be greater than zero");
            newMatrices = TrafficMatrixGenerationModels.computeMatricesRandomGaussianVariation(trafficMatrix,
                    cv, maxRelativeVariation, numMatrices);

            break;
        }

        case "randomUniform": {
            double maxRelativeVariation = ((Number) cli
                    .getParsedOptionValue("variation-pattern-maxRelativeVariation")).doubleValue();
            if (maxRelativeVariation <= 0)
                throw new Net2PlanException("Maximum relative variation must be greater than zero");
            newMatrices = TrafficMatrixGenerationModels.computeMatricesRandomUniformVariation(trafficMatrix,
                    maxRelativeVariation, numMatrices);

            break;
        }

        default:
            throw new RuntimeException("Bad - Unknown variation pattern '" + variationPattern + "'");
        }

        trafficMatrices = new DoubleMatrix2D[numMatrices];
        int i = 0;
        for (DoubleMatrix2D trafficMatrix1 : newMatrices)
            trafficMatrices[i++] = trafficMatrix1;
    } else {
        if (cli.hasOption("traffic-pattern")) {
            trafficPattern = cli.getOptionValue("traffic-pattern");
            if (!TRAFFIC_PATTERNS.containsKey(trafficPattern))
                throw new Net2PlanException("Unknown traffic pattern");

            if (cli.hasOption("num-matrices")) {
                numMatrices = ((Number) cli.getParsedOptionValue("num-matrices")).intValue();
                if (numMatrices < 1)
                    throw new Net2PlanException("Number of traffic matrices must be positive");
            }
        }

        trafficMatrices = new DoubleMatrix2D[numMatrices];
        if (trafficPattern != null) {
            switch (trafficPattern) {
            case "uniform-random-10":
                for (int tmId = 0; tmId < numMatrices; tmId++)
                    trafficMatrices[tmId] = TrafficMatrixGenerationModels.uniformRandom(numNodes, 0, 10);
                break;

            case "uniform-random-100":
                for (int tmId = 0; tmId < numMatrices; tmId++)
                    trafficMatrices[tmId] = TrafficMatrixGenerationModels.uniformRandom(numNodes, 0, 100);
                break;

            case "uniform-random-bimodal-50-50":
                for (int tmId = 0; tmId < numMatrices; tmId++)
                    trafficMatrices[tmId] = TrafficMatrixGenerationModels.bimodalUniformRandom(numNodes, 0.5, 0,
                            100, 0, 10);
                break;

            case "uniform-random-bimodal-25-75":
                for (int tmId = 0; tmId < numMatrices; tmId++)
                    trafficMatrices[tmId] = TrafficMatrixGenerationModels.bimodalUniformRandom(numNodes, 0.25,
                            0, 100, 0, 10);
                break;

            case "population-distance-model":
                double randomFactor = 0;
                double populationOffset = 0;
                double populationPower = 1;
                double distanceOffset = 0;
                double distancePower = 1;
                boolean normalizePopulation = true;
                boolean normalizeDistance = true;

                if (cli.hasOption("random-factor"))
                    randomFactor = ((Number) cli.getParsedOptionValue("random-factor")).doubleValue();
                if (cli.hasOption("population-offset"))
                    populationOffset = ((Number) cli.getParsedOptionValue("population-offset")).doubleValue();
                if (cli.hasOption("population-power"))
                    populationPower = ((Number) cli.getParsedOptionValue("population-power")).doubleValue();
                if (cli.hasOption("distance-offset"))
                    distanceOffset = ((Number) cli.getParsedOptionValue("distance-offset")).doubleValue();
                if (cli.hasOption("distance-power"))
                    distancePower = ((Number) cli.getParsedOptionValue("distance-power")).doubleValue();
                if (cli.hasOption("normalize-population"))
                    normalizePopulation = Boolean.parseBoolean(cli.getOptionValue("normalize-population"));
                if (cli.hasOption("normalize-distance"))
                    normalizeDistance = Boolean.parseBoolean(cli.getOptionValue("normalize-distance"));

                if (!cli.hasOption("level-matrix-file"))
                    throw new Net2PlanException("The level-matrix file is required");
                DoubleMatrix2D levelMatrix = DoubleUtils
                        .read2DMatrixFromFile((File) cli.getParsedOptionValue("level-matrix-file"));

                DoubleMatrix2D distanceMatrix = netPlan.getMatrixNode2NodeEuclideanDistance();
                int[] populationVector = StringUtils
                        .toIntArray(netPlan.getAttributes(netPlan.getNodes(), "population").values(), 0);
                int[] levelVector = StringUtils
                        .toIntArray(netPlan.getAttributes(netPlan.getNodes(), "level").values(), 1);

                for (int tmId = 0; tmId < numMatrices; tmId++)
                    trafficMatrices[tmId] = TrafficMatrixGenerationModels.populationDistanceModel(
                            distanceMatrix, populationVector, levelVector, levelMatrix, randomFactor,
                            populationOffset, populationPower, distanceOffset, distancePower,
                            normalizePopulation, normalizeDistance);

                break;

            case "gravity-model":
                if (cli.hasOption("gravity-model-file")) {
                    File gravityModelFile = (File) cli.getParsedOptionValue("gravity-model-file");
                    DoubleMatrix2D gravityModelMatrix = DoubleUtils.read2DMatrixFromFile(gravityModelFile);

                    if (gravityModelMatrix.rows() != numNodes || gravityModelMatrix.columns() != 2)
                        throw new Net2PlanException(
                                "'gravity-model-file' requires " + numNodes + " rows and two columns");

                    numMatrices = 1;
                    trafficMatrices[0] = TrafficMatrixGenerationModels.gravityModel(
                            gravityModelMatrix.viewColumn(0).toArray(),
                            gravityModelMatrix.viewColumn(1).toArray());
                } else {
                    throw new Net2PlanException("Parameter 'gravity-model-file' should be specified");
                }

                break;

            default:
                throw new RuntimeException("Bad - Unknown traffic pattern '" + trafficPattern + "'");
            }
        } else {
            trafficMatrices[0] = netPlan.getMatrixNode2NodeOfferedTraffic();
        }

        if (cli.hasOption("normalization-pattern")) {
            String normalizationPattern = (String) cli.getParsedOptionValue("normalization-pattern");
            switch (normalizationPattern) {
            case "total-normalization":
            case "row-normalization":
            case "column-normalization":
                if (cli.hasOption("normalization-pattern-file")) {
                    double[] normalizationPatternVector;
                    int patternId;

                    File normalizationPatternFile = (File) cli
                            .getParsedOptionValue("normalization-pattern-file");
                    DoubleMatrix2D normalizationPatternMatrix = DoubleUtils
                            .read2DMatrixFromFile(normalizationPatternFile);
                    if (normalizationPatternMatrix.rows() == 1 && normalizationPatternMatrix.columns() == 1) {
                        patternId = 0;
                        normalizationPatternVector = new double[] { normalizationPatternMatrix.getQuick(0, 0) };
                    } else if (normalizationPatternMatrix.rows() == 1
                            && normalizationPatternMatrix.columns() > 1) {
                        patternId = 1;
                        normalizationPatternVector = normalizationPatternMatrix.viewRow(0).toArray();
                    } else if (normalizationPatternMatrix.rows() > 1
                            && normalizationPatternMatrix.columns() == 1) {
                        patternId = 2;
                        normalizationPatternVector = normalizationPatternMatrix.viewColumn(0).toArray();
                    } else {
                        throw new Net2PlanException(
                                "Bad normalization pattern - Neither a scalar (for total normalization), nor row vector (for row normalization) nor a column vector (for column normalization) was provided");
                    }

                    for (int tmId = 0; tmId < numMatrices; tmId++) {
                        switch (patternId) {
                        case 0:
                            trafficMatrices[tmId] = TrafficMatrixGenerationModels
                                    .normalizationPattern_totalTraffic(trafficMatrices[tmId],
                                            normalizationPatternVector[0]);
                            break;

                        case 1:
                            trafficMatrices[tmId] = TrafficMatrixGenerationModels
                                    .normalizationPattern_incomingTraffic(trafficMatrices[tmId],
                                            normalizationPatternVector);
                            break;

                        case 2:
                            trafficMatrices[tmId] = TrafficMatrixGenerationModels
                                    .normalizationPattern_outgoingTraffic(trafficMatrices[tmId],
                                            normalizationPatternVector);
                            break;

                        default:
                            throw new RuntimeException("Bad");
                        }
                    }
                } else {
                    throw new Net2PlanException("Parameter 'normalization-pattern-file' should be specified");
                }

                break;

            case "max-traffic-estimated-minHop":
                for (int tmId = 0; tmId < numMatrices; tmId++) {
                    netPlan.setTrafficMatrix(trafficMatrices[tmId]);
                    netPlan.setVectorDemandOfferedTraffic(
                            TrafficMatrixGenerationModels.normalizeTraffic_networkCapacity(netPlan));
                    trafficMatrices[tmId] = netPlan.getMatrixNode2NodeOfferedTraffic();
                }
                break;

            case "max-traffic-exact":
                String solverName = Configuration.getOption("defaultILPSolver");
                String solverLibraryName = Configuration.getDefaultSolverLibraryName(solverName);
                //                        if (solverName.equalsIgnoreCase("glpk")) solverLibraryName = Configuration.getOption("glpkSolverLibraryName");
                //                        else if (solverName.equalsIgnoreCase("ipopt")) solverLibraryName = Configuration.getOption("ipoptSolverLibraryName");
                //                        else if (solverName.equalsIgnoreCase("cplex")) solverLibraryName = Configuration.getOption("cplexSolverLibraryName");
                //                        else if (solverName.equalsIgnoreCase("xpress")) solverLibraryName = Configuration.getOption("xpressSolverLicenseFileName");
                //
                for (int tmId = 0; tmId < numMatrices; tmId++) {
                    netPlan.setTrafficMatrix(trafficMatrices[tmId]);
                    netPlan.setVectorDemandOfferedTraffic(TrafficMatrixGenerationModels
                            .normalizeTraffic_linkCapacity_xde(netPlan, solverName, solverLibraryName));
                    trafficMatrices[tmId] = netPlan.getMatrixNode2NodeOfferedTraffic();
                }
                break;

            default:
                throw new RuntimeException(
                        "Bad - Unknown normalization pattern '" + normalizationPattern + "'");
            }
        }
    }

    List<NetPlan> outputDemandSets = new LinkedList<NetPlan>();
    for (int tmId = 0; tmId < numMatrices; tmId++) {
        NetPlan aux = new NetPlan();

        aux.setTrafficMatrix(trafficMatrices[tmId]);
        outputDemandSets.add(aux);

        trafficMatrices[tmId] = null;
    }

    File outputFile = (File) cli.getParsedOptionValue("output-file");

    if (outputDemandSets.size() == 1) {
        outputDemandSets.get(0).saveToFile(outputFile);
    } else {
        String templateFileName = outputFile.getAbsoluteFile().toString();
        if (templateFileName.endsWith(".n2p"))
            templateFileName = templateFileName.substring(0, templateFileName.lastIndexOf('.'));

        ListIterator<NetPlan> netPlanIt = outputDemandSets.listIterator();
        while (netPlanIt.hasNext())
            netPlanIt.next().saveToFile(new File(templateFileName + "_tm" + netPlanIt.nextIndex() + ".n2p"));
    }

    long end = System.nanoTime();

    System.out.println(String.format("%n%nTraffic matrix generation finished successfully in %f seconds",
            (end - init) / 1e9));
}

From source file:edu.umd.cfar.lamp.viper.geometry.BoundingBox.java

/**
 * Call this after changing the rectangle in any way. It removes rectangles
 * of size less than 1, and it also converts "composed" rectangles with
 * only one rectangle to uncomposed; it also updates the polygon.
 *///from  www. j a  v a 2  s  . c om
private void simplify() {
    boolean startedComposed = composed;
    if (composed) {
        if (pieces.size() == 0) {
            pieces = null;
            composed = false;
            rect = new Rectangle();
        } else if (pieces.size() == 1) {
            BoundingBox child = (BoundingBox) pieces.getFirst();
            composed = false;
            if (child != null)
                setTo(child);
            else
                pieces.clear();
        } else if (pieces.size() > 1) {
            boolean changed = false;
            ListIterator iter = pieces.listIterator(0);
            while (iter.hasNext())
                if (!(((BoundingBox) iter.next()).area()).greaterThan(0)) {
                    iter.remove();
                    changed = true;
                }
            if (changed)
                simplify();
        }
    }
    if (startedComposed && !composed)
        initPoly();
}