Example usage for java.util List listIterator

List of usage examples for java.util List listIterator

Introduction

In this page you can find the example usage for java.util List listIterator.

Prototype

ListIterator<E> listIterator();

Source Link

Document

Returns a list iterator over the elements in this list (in proper sequence).

Usage

From source file:org.apache.hadoop.conf.Configuration.java

private void toString(List resources, StringBuffer sb) {
    ListIterator i = resources.listIterator();
    while (i.hasNext()) {
        if (i.nextIndex() != 0) {
            sb.append(", ");
        }/*from w w w  .j a  v  a  2  s  .c  om*/
        sb.append(i.next());
    }
}

From source file:net.lightbody.bmp.proxy.jetty.http.HttpRequest.java

/**
 * Get the acceptable transfer encodings. The TE field is used to construct a list of acceptable
 * extension transfer codings in quality order. An empty list implies that only "chunked" is
 * acceptable. A null list implies that no transfer coding can be applied.
 * /*ww w  .j av  a  2s .co m*/
 * If the "trailer" coding is found in the TE field, then message trailers are enabled in any
 * linked response.
 * 
 * @return List of codings.
 */
public List getAcceptableTransferCodings() {
    if (_dotVersion < 1)
        return null;
    if (_te != null)
        return _te;

    // Decode any TE field
    Enumeration tenum = getFieldValues(HttpFields.__TE, HttpFields.__separators);

    if (tenum != null) {
        // Sort the list
        List te = HttpFields.qualityList(tenum);
        int size = te.size();
        // Process if something there
        if (size > 0) {
            Object acceptable = null;

            // remove trailer and chunked items.
            ListIterator iter = te.listIterator();
            while (iter.hasNext()) {
                String coding = StringUtil
                        .asciiToLowerCase(HttpFields.valueParameters(iter.next().toString(), null));

                if (!HttpFields.__Chunked.equalsIgnoreCase(coding)) {
                    acceptable = LazyList.ensureSize(acceptable, size);
                    acceptable = LazyList.add(acceptable, coding);
                }
            }
            _te = LazyList.getList(acceptable);
        } else
            _te = Collections.EMPTY_LIST;
    } else
        _te = Collections.EMPTY_LIST;

    return _te;
}

From source file:FastArrayList.java

/**
 * Compare the specified object with this list for equality.  This
 * implementation uses exactly the code that is used to define the
 * list equals function in the documentation for the
 * <code>List.equals</code> method.
 *
 * @param o Object to be compared to this list
 *//* w  w w.  ja  v a2 s  .  c o  m*/
public boolean equals(Object o) {

    // Simple tests that require no synchronization
    if (o == this)
        return (true);
    else if (!(o instanceof List))
        return (false);
    List lo = (List) o;

    // Compare the sets of elements for equality
    if (fast) {
        ListIterator li1 = list.listIterator();
        ListIterator li2 = lo.listIterator();
        while (li1.hasNext() && li2.hasNext()) {
            Object o1 = li1.next();
            Object o2 = li2.next();
            if (!(o1 == null ? o2 == null : o1.equals(o2)))
                return (false);
        }
        return (!(li1.hasNext() || li2.hasNext()));
    } else {
        synchronized (list) {
            ListIterator li1 = list.listIterator();
            ListIterator li2 = lo.listIterator();
            while (li1.hasNext() && li2.hasNext()) {
                Object o1 = li1.next();
                Object o2 = li2.next();
                if (!(o1 == null ? o2 == null : o1.equals(o2)))
                    return (false);
            }
            return (!(li1.hasNext() || li2.hasNext()));
        }
    }

}

From source file:com.amazonaws.services.kinesis.clientlibrary.lib.worker.WorkerTest.java

private void verifyAllRecordsWereConsumedExactlyOnce(List<Record> expectedRecords, List<Record> actualRecords) {
    //@formatter:on
    Assert.assertEquals(expectedRecords.size(), actualRecords.size());
    ListIterator<Record> expectedIter = expectedRecords.listIterator();
    ListIterator<Record> actualIter = actualRecords.listIterator();
    for (int i = 0; i < expectedRecords.size(); ++i) {
        Assert.assertEquals(expectedIter.next(), actualIter.next());
    }/*from   w  ww.j  av a 2  s . c  o  m*/
}

From source file:net.sf.jasperreports.engine.analytics.dataset.MultiAxisDataService.java

protected Object evaluateBucketValue(JRCalculator calculator, DataAxisLevel level)
        throws JRExpressionEvalException {
    DataLevelBucket bucket = level.getBucket();
    Object mainValue = calculator.evaluate(bucket.getExpression());

    JRExpression labelExpression = bucket.getLabelExpression();
    List<DataLevelBucketProperty> bucketProperties = bucket.getBucketProperties();
    Object bucketValue;/*w  w  w  . j  av a  2s . c  om*/
    if (labelExpression == null && (bucketProperties == null || bucketProperties.isEmpty())) {
        bucketValue = mainValue;
    } else {
        String label = labelExpression == null ? null : (String) calculator.evaluate(labelExpression);

        Object[] propertyValues;
        if (bucketProperties == null || bucketProperties.isEmpty()) {
            propertyValues = null;
        } else {
            // evaluate property values
            //FIXME avoid evaluating these for each record
            propertyValues = new Object[bucketProperties.size()];
            for (ListIterator<DataLevelBucketProperty> it = bucketProperties.listIterator(); it.hasNext();) {
                DataLevelBucketProperty bucketProperty = it.next();
                propertyValues[it.previousIndex()] = calculator.evaluate(bucketProperty.getExpression());
            }
        }

        // wrap the main value and property values together
        bucketValue = new ValuePropertiesWrapper(mainValue, label, propertyValues);
    }

    return bucketValue;
}

From source file:org.apache.ofbiz.shipment.thirdparty.usps.UspsServices.java

public static Map<String, Object> uspsRateInquire(DispatchContext dctx, Map<String, ? extends Object> context) {
    Delegator delegator = dctx.getDelegator();
    String shipmentGatewayConfigId = (String) context.get("shipmentGatewayConfigId");
    String resource = (String) context.get("configProps");
    Locale locale = (Locale) context.get("locale");

    // check for 0 weight
    BigDecimal shippableWeight = (BigDecimal) context.get("shippableWeight");
    if (shippableWeight.compareTo(BigDecimal.ZERO) == 0) {
        // TODO: should we return an error, or $0.00 ?
        return ServiceUtil.returnFailure(UtilProperties.getMessage(resourceError,
                "FacilityShipmentUspsShippableWeightMustGreaterThanZero", locale));
    }/*w w  w.  ja  va2  s . c o m*/

    // get the origination ZIP
    String originationZip = null;
    GenericValue productStore = ProductStoreWorker.getProductStore(((String) context.get("productStoreId")),
            delegator);
    if (productStore != null && productStore.get("inventoryFacilityId") != null) {
        GenericValue facilityContactMech = ContactMechWorker.getFacilityContactMechByPurpose(delegator,
                productStore.getString("inventoryFacilityId"),
                UtilMisc.toList("SHIP_ORIG_LOCATION", "PRIMARY_LOCATION"));
        if (facilityContactMech != null) {
            try {
                GenericValue shipFromAddress = EntityQuery.use(delegator).from("PostalAddress")
                        .where("contactMechId", facilityContactMech.getString("contactMechId")).queryOne();
                if (shipFromAddress != null) {
                    originationZip = shipFromAddress.getString("postalCode");
                }
            } catch (GenericEntityException e) {
                Debug.logError(e, module);
            }
        }
    }
    if (UtilValidate.isEmpty(originationZip)) {
        return ServiceUtil.returnError(UtilProperties.getMessage(resourceError,
                "FacilityShipmentUspsUnableDetermineOriginationZip", locale));
    }

    // get the destination ZIP
    String destinationZip = null;
    String shippingContactMechId = (String) context.get("shippingContactMechId");
    if (UtilValidate.isNotEmpty(shippingContactMechId)) {
        try {
            GenericValue shipToAddress = EntityQuery.use(delegator).from("PostalAddress")
                    .where("contactMechId", shippingContactMechId).queryOne();
            if (shipToAddress != null) {
                if (!domesticCountries.contains(shipToAddress.getString("countryGeoId"))) {
                    return ServiceUtil.returnError(UtilProperties.getMessage(resourceError,
                            "FacilityShipmentUspsRateInquiryOnlyInUsDestinations", locale));
                }
                destinationZip = shipToAddress.getString("postalCode");
            }
        } catch (GenericEntityException e) {
            Debug.logError(e, module);
        }
    }
    if (UtilValidate.isEmpty(destinationZip)) {
        return ServiceUtil.returnError(UtilProperties.getMessage(resourceError,
                "FacilityShipmentUspsUnableDetermineDestinationZip", locale));
    }

    // get the service code
    String serviceCode = null;
    try {
        GenericValue carrierShipmentMethod = EntityQuery.use(delegator).from("CarrierShipmentMethod")
                .where("shipmentMethodTypeId", (String) context.get("shipmentMethodTypeId"), "partyId",
                        (String) context.get("carrierPartyId"), "roleTypeId",
                        (String) context.get("carrierRoleTypeId"))
                .queryOne();
        if (carrierShipmentMethod != null) {
            serviceCode = carrierShipmentMethod.getString("carrierServiceCode").toUpperCase();
        }
    } catch (GenericEntityException e) {
        Debug.logError(e, module);
    }
    if (UtilValidate.isEmpty(serviceCode)) {
        return ServiceUtil.returnError(UtilProperties.getMessage(resourceError,
                "FacilityShipmentUspsUnableDetermineServiceCode", locale));
    }

    // create the request document
    Document requestDocument = createUspsRequestDocument("RateV2Request", true, delegator,
            shipmentGatewayConfigId, resource);

    // TODO: 70 lb max is valid for Express, Priority and Parcel only - handle other methods
    BigDecimal maxWeight = new BigDecimal("70");
    String maxWeightStr = getShipmentGatewayConfigValue(delegator, shipmentGatewayConfigId, "maxEstimateWeight",
            resource, "shipment.usps.max.estimate.weight", "70");
    try {
        maxWeight = new BigDecimal(maxWeightStr);
    } catch (NumberFormatException e) {
        Debug.logWarning(
                "Error parsing max estimate weight string [" + maxWeightStr + "], using default instead",
                module);
        maxWeight = new BigDecimal("70");
    }

    List<Map<String, Object>> shippableItemInfo = UtilGenerics.checkList(context.get("shippableItemInfo"));
    List<Map<String, BigDecimal>> packages = ShipmentWorker.getPackageSplit(dctx, shippableItemInfo, maxWeight);
    boolean isOnePackage = packages.size() == 1; // use shippableWeight if there's only one package
    // TODO: Up to 25 packages can be included per request - handle more than 25
    for (ListIterator<Map<String, BigDecimal>> li = packages.listIterator(); li.hasNext();) {
        Map<String, BigDecimal> packageMap = li.next();

        BigDecimal packageWeight = isOnePackage ? shippableWeight
                : ShipmentWorker.calcPackageWeight(dctx, packageMap, shippableItemInfo, BigDecimal.ZERO);
        if (packageWeight.compareTo(BigDecimal.ZERO) == 0) {
            continue;
        }

        Element packageElement = UtilXml.addChildElement(requestDocument.getDocumentElement(), "Package",
                requestDocument);
        packageElement.setAttribute("ID", String.valueOf(li.nextIndex() - 1)); // use zero-based index (see examples)

        UtilXml.addChildElementValue(packageElement, "Service", serviceCode, requestDocument);
        UtilXml.addChildElementValue(packageElement, "ZipOrigination",
                StringUtils.substring(originationZip, 0, 5), requestDocument);
        UtilXml.addChildElementValue(packageElement, "ZipDestination",
                StringUtils.substring(destinationZip, 0, 5), requestDocument);

        BigDecimal weightPounds = packageWeight.setScale(0, BigDecimal.ROUND_FLOOR);
        // for Parcel post, the weight must be at least 1 lb
        if ("PARCEL".equals(serviceCode.toUpperCase()) && (weightPounds.compareTo(BigDecimal.ONE) < 0)) {
            weightPounds = BigDecimal.ONE;
            packageWeight = BigDecimal.ZERO;
        }
        // (packageWeight % 1) * 16 (Rounded up to 0 dp)
        BigDecimal weightOunces = packageWeight.remainder(BigDecimal.ONE).multiply(new BigDecimal("16"))
                .setScale(0, BigDecimal.ROUND_CEILING);

        UtilXml.addChildElementValue(packageElement, "Pounds", weightPounds.toPlainString(), requestDocument);
        UtilXml.addChildElementValue(packageElement, "Ounces", weightOunces.toPlainString(), requestDocument);

        // TODO: handle other container types, package sizes, and machinable packages
        // IMPORTANT: Express or Priority Mail will fail if you supply a Container tag: you will get a message like
        // Invalid container type. Valid container types for Priority Mail are Flat Rate Envelope and Flat Rate Box.
        /* This is an official response from the United States Postal Service:
        The <Container> tag is used to specify the flat rate mailing options, or the type of large or oversized package being mailed.
        If you are wanting to get regular Express Mail rates, leave the <Container> tag empty, or do not include it in the request at all.
         */
        if ("Parcel".equalsIgnoreCase(serviceCode)) {
            UtilXml.addChildElementValue(packageElement, "Container", "None", requestDocument);
        }
        UtilXml.addChildElementValue(packageElement, "Size", "REGULAR", requestDocument);
        UtilXml.addChildElementValue(packageElement, "Machinable", "false", requestDocument);
    }

    // send the request
    Document responseDocument = null;
    try {
        responseDocument = sendUspsRequest("RateV2", requestDocument, delegator, shipmentGatewayConfigId,
                resource, locale);
    } catch (UspsRequestException e) {
        Debug.logInfo(e, module);
        return ServiceUtil.returnError(
                UtilProperties.getMessage(resourceError, "FacilityShipmentUspsRateDomesticSendingError",
                        UtilMisc.toMap("errorString", e.getMessage()), locale));
    }

    if (responseDocument == null) {
        return ServiceUtil.returnError(
                UtilProperties.getMessage(resourceError, "FacilityShipmentRateNotAvailable", locale));
    }

    List<? extends Element> rates = UtilXml.childElementList(responseDocument.getDocumentElement(), "Package");
    if (UtilValidate.isEmpty(rates)) {
        return ServiceUtil.returnError(
                UtilProperties.getMessage(resourceError, "FacilityShipmentRateNotAvailable", locale));
    }

    BigDecimal estimateAmount = BigDecimal.ZERO;
    for (Element packageElement : rates) {
        try {
            Element postageElement = UtilXml.firstChildElement(packageElement, "Postage");
            BigDecimal packageAmount = new BigDecimal(UtilXml.childElementValue(postageElement, "Rate"));
            estimateAmount = estimateAmount.add(packageAmount);
        } catch (NumberFormatException e) {
            Debug.logInfo(e, module);
        }
    }

    Map<String, Object> result = ServiceUtil.returnSuccess();
    result.put("shippingEstimateAmount", estimateAmount);
    return result;
}

From source file:com.mirth.connect.client.ui.editors.filter.FilterPane.java

/**
 * load( Filter f )/*from  w  w  w .jav  a 2s .  co m*/
 */
public boolean load(Connector c, Filter f, Transformer t, boolean channelHasBeenChanged) {
    if (alertUnsupportedRuleTypes(f)) {
        return false;
    }

    switchTab = false;
    lastSelectedIndex = 0;
    tabbedPane.setSelectedIndex(0);

    prevSelRow = -1;
    filter = f;
    transformer = t;
    connector = c;
    channel = PlatformUI.MIRTH_FRAME.channelEditPanel.currentChannel;

    // we need to clear all the old data before we load the new
    makeFilterTable();

    parent.setCurrentContentPage((JPanel) this);
    parent.setFocus(new JXTaskPane[] { viewTasks, filterTasks }, false, true);

    // add any existing rules to the model
    List<Rule> list = filter.getRules();
    ListIterator<Rule> li = list.listIterator();
    while (li.hasNext()) {
        Rule s = li.next();
        setRowData(s, s.getSequenceNumber(), false);
    }

    tabTemplatePanel.setFilterView();

    int rowCount = filterTableModel.getRowCount();
    // select the first row if there is one
    if (rowCount > 0) {
        filterTable.setRowSelectionInterval(0, 0);
        prevSelRow = 0;
    } else {
        filterTable.getSelectionModel().clearSelection();
        rulePanel.showCard(BLANK_TYPE);

        for (FilterRulePlugin plugin : LoadedExtensions.getInstance().getFilterRulePlugins().values()) {
            plugin.getPanel().setData(null);
        }

        loadData(-1);
    }

    if (connector.getMode() == Connector.Mode.SOURCE) {
        tabTemplatePanel.setSourceView();
        tabTemplatePanel.setIncomingDataType((String) PlatformUI.MIRTH_FRAME.dataTypeToDisplayName
                .get(channel.getSourceConnector().getTransformer().getInboundDataType()));
    } else if (connector.getMode() == Connector.Mode.DESTINATION) {
        tabTemplatePanel.setDestinationView(false);
        if (channel.getSourceConnector().getTransformer().getOutboundDataType() != null) {
            tabTemplatePanel.setIncomingDataType((String) PlatformUI.MIRTH_FRAME.dataTypeToDisplayName
                    .get(channel.getSourceConnector().getTransformer().getOutboundDataType()));
        } else {
            tabTemplatePanel.setIncomingDataType((String) PlatformUI.MIRTH_FRAME.dataTypeToDisplayName
                    .get(channel.getSourceConnector().getTransformer().getInboundDataType()));
        }
    }

    tabTemplatePanel.setDefaultComponent();

    tabTemplatePanel.setIncomingDataProperties(transformer.getInboundProperties());

    tabTemplatePanel.setIncomingMessage(transformer.getInboundTemplate());

    updateRuleNumbers();
    if (filterTableModel.getRowCount() > 0) {
        updateTaskPane((String) filterTableModel.getValueAt(0, RULE_TYPE_COL));
    }

    if (channelHasBeenChanged) {
        modified = true;
    } else {
        modified = false;
    }

    updateCodePanel(null);

    return true;
}

From source file:edu.iu.daal_nn.NNDaalCollectiveMapper.java

private Tensor getTensorHDFS(DaalContext daal_Context, Configuration conf, String inputFiles, int vectorSize,
        int numRows) throws IOException {
    Path inputFilePaths = new Path(inputFiles);
    List<String> inputFileList = new LinkedList<>();

    try {//from   w  ww  . ja v a 2  s.c o m
        FileSystem fs = inputFilePaths.getFileSystem(conf);
        RemoteIterator<LocatedFileStatus> iterator = fs.listFiles(inputFilePaths, true);

        while (iterator.hasNext()) {
            String name = iterator.next().getPath().toUri().toString();
            inputFileList.add(name);
        }

    } catch (IOException e) {
        LOG.error("Fail to get test files", e);
    }

    int dataSize = vectorSize * numRows;
    // float[] data = new float[dataSize];
    double[] data = new double[dataSize];
    long[] dims = { numRows, vectorSize };
    int index = 0;

    FSDataInputStream in = null;

    //loop over all the files in the list
    ListIterator<String> file_itr = inputFileList.listIterator();
    while (file_itr.hasNext()) {
        String file_name = file_itr.next();
        LOG.info("read in file name: " + file_name);

        Path file_path = new Path(file_name);
        try {

            FileSystem fs = file_path.getFileSystem(conf);
            in = fs.open(file_path);

        } catch (Exception e) {
            LOG.error("Fail to open file " + e.toString());
            return null;
        }

        //read file content
        while (true) {
            String line = in.readLine();
            if (line == null)
                break;

            String[] lineData = line.split(",");

            for (int t = 0; t < lineData.length; t++) {
                if (index < dataSize) {
                    // data[index] = Float.parseFloat(lineData[t]);
                    data[index] = Double.parseDouble(lineData[t]);
                    index++;
                } else {
                    LOG.error("Incorrect size of file: dataSize: " + dataSize + "; index val: " + index);
                    return null;
                }

            }
        }

        in.close();

    }

    if (index != dataSize) {
        LOG.error("Incorrect total size of file: dataSize: " + dataSize + "; index val: " + index);
        return null;
    }

    //debug check the vals of data
    // for(int p=0;p<60;p++)
    //     LOG.info("data at: " + p + " is: " + data[p]);

    Tensor predictionData = new HomogenTensor(daal_Context, dims, data);
    return predictionData;

}

From source file:playground.christoph.evacuation.analysis.EvacuationTimePictureWriter.java

public FolderType getLinkFolder(String transportMode, Map<Id, BasicLocation> locations,
        Map<Id, Double> evacuationTimes) throws IOException {

    calcMaxEvacuationTime(evacuationTimes);

    /*/*w w w. j  a va 2  s  .  c  o m*/
     * create Folders and connect them
     */
    FolderType mainFolder = this.kmlObjectFactory.createFolderType();
    FolderType linkFolder = this.kmlObjectFactory.createFolderType();
    FolderType facilityFolder = this.kmlObjectFactory.createFolderType();
    FolderType linkFolderA = this.kmlObjectFactory.createFolderType(); // 0 .. 10 valid Trips
    FolderType linkFolderB = this.kmlObjectFactory.createFolderType(); // 10 .. 100 valid Trips
    FolderType linkFolderC = this.kmlObjectFactory.createFolderType(); // 100 .. 1000 valid Trips
    FolderType linkFolderD = this.kmlObjectFactory.createFolderType(); // 1000 and more valid Trips
    FolderType facilityFolderA = this.kmlObjectFactory.createFolderType(); // 0 .. 10 valid Trips
    FolderType facilityFolderB = this.kmlObjectFactory.createFolderType(); // 10 .. 100 valid Trips
    FolderType facilityFolderC = this.kmlObjectFactory.createFolderType(); // 100 .. 1000 valid Trips
    FolderType facilityFolderD = this.kmlObjectFactory.createFolderType(); // 1000 and more valid Trips

    mainFolder.setName("Evacuation Times " + transportMode);
    linkFolder.setName("Links");
    facilityFolder.setName("Facilities");
    linkFolderA.setName("Links with 0..9 valid Trips");
    linkFolderB.setName("Links with 10..99 valid Trips");
    linkFolderC.setName("Links with 100..9 valid Trips");
    linkFolderD.setName("Links with 1000 and more valid Trips");
    facilityFolderA.setName("Facilities with 0..9 valid Trips");
    facilityFolderB.setName("Facilities with 10..99 valid Trips");
    facilityFolderC.setName("Facilities with 100..9 valid Trips");
    facilityFolderD.setName("Facilities with 1000 and more valid Trips");

    mainFolder.getAbstractFeatureGroup().add(this.kmlObjectFactory.createFolder(linkFolder));
    mainFolder.getAbstractFeatureGroup().add(this.kmlObjectFactory.createFolder(facilityFolder));
    linkFolder.getAbstractFeatureGroup().add(this.kmlObjectFactory.createFolder(linkFolderA));
    linkFolder.getAbstractFeatureGroup().add(this.kmlObjectFactory.createFolder(linkFolderB));
    linkFolder.getAbstractFeatureGroup().add(this.kmlObjectFactory.createFolder(linkFolderC));
    linkFolder.getAbstractFeatureGroup().add(this.kmlObjectFactory.createFolder(linkFolderD));
    facilityFolder.getAbstractFeatureGroup().add(this.kmlObjectFactory.createFolder(facilityFolderA));
    facilityFolder.getAbstractFeatureGroup().add(this.kmlObjectFactory.createFolder(facilityFolderB));
    facilityFolder.getAbstractFeatureGroup().add(this.kmlObjectFactory.createFolder(facilityFolderC));
    facilityFolder.getAbstractFeatureGroup().add(this.kmlObjectFactory.createFolder(facilityFolderD));

    /*
     * create overall histogram and add it to the kmz file
     */
    ScreenOverlayType histogram = createHistogram(transportMode, evacuationTimes);
    mainFolder.getAbstractFeatureGroup().add(kmlObjectFactory.createScreenOverlay(histogram));

    /*
     * create legend and add it to the kmz file
     */
    ScreenOverlayType legend = createLegend(transportMode);
    mainFolder.getAbstractFeatureGroup().add(kmlObjectFactory.createScreenOverlay(legend));

    Map<BasicLocation, List<Double>> locationMap = new HashMap<BasicLocation, List<Double>>();

    for (Entry<Id, BasicLocation> entry : locations.entrySet()) {
        Id id = entry.getKey();
        BasicLocation location = entry.getValue();

        List<Double> list = locationMap.get(location);
        if (list == null) {
            list = new ArrayList<Double>();
            locationMap.put(location, list);
        }

        Double value = evacuationTimes.get(id);
        if (value == null)
            value = Double.NaN;
        list.add(value);
    }

    log.info("Number of different start locations found: " + locationMap.size());

    if (doClustering) {
        EvacuationTimeClusterer clusterer = new EvacuationTimeClusterer(scenario.getNetwork(), locationMap,
                scenario.getConfig().global().getNumberOfThreads());
        int numClusters = (int) Math.ceil(locationMap.size() / clusterFactor);
        locationMap = clusterer.buildCluster(numClusters, clusterIterations);
    }

    for (Entry<BasicLocation, List<Double>> entry : locationMap.entrySet()) {
        BasicLocation location = entry.getKey();
        List<Double> list = entry.getValue();

        int valid = 0;
        int invalid = 0;

        /*
         * Remove NaN entries from the List
         */
        List<Double> listWithoutNaN = new ArrayList<Double>();
        for (Double d : list) {
            if (d.isNaN()) {
                invalid++;
            } else
                listWithoutNaN.add(d);
        }

        /*
         * If trip with significant to high evacuation times should be cut off
         */
        if (limitMaxEvacuationTime) {
            double cutOffValue = meanEvacuationTime + standardDeviation * evacuationTimeCutOffFactor;
            ListIterator<Double> iter = listWithoutNaN.listIterator();
            while (iter.hasNext()) {
                double value = iter.next();
                if (value > cutOffValue) {
                    iter.remove();
                    invalid++;
                }
            }
        }
        valid = list.size() - invalid;

        double mean = 0.0;
        for (Double d : list) {
            mean = mean + d;
        }
        mean = mean / list.size();

        // if at least one valid entry found - otherwise it would result in a divide by zero error
        if (listWithoutNaN.size() == 0)
            continue;
        //         if (invalid < list.size()) mean = mean / (list.size() - invalid);
        //         else continue;

        int index = getColorIndex(mean);

        StyleType styleType = colorBarStyles[index];

        PlacemarkType placemark = createPlacemark(transportMode, location, mean, valid, invalid);
        placemark.setStyleUrl(styleType.getId());
        if (location instanceof Facility) {
            if (valid < 10)
                facilityFolderA.getAbstractFeatureGroup().add(this.kmlObjectFactory.createPlacemark(placemark));
            else if (valid < 100)
                facilityFolderB.getAbstractFeatureGroup().add(this.kmlObjectFactory.createPlacemark(placemark));
            else if (valid < 1000)
                facilityFolderC.getAbstractFeatureGroup().add(this.kmlObjectFactory.createPlacemark(placemark));
            else
                facilityFolderD.getAbstractFeatureGroup().add(this.kmlObjectFactory.createPlacemark(placemark));

        } else if (location instanceof Link) {
            if (valid < 10)
                linkFolderA.getAbstractFeatureGroup().add(this.kmlObjectFactory.createPlacemark(placemark));
            else if (valid < 100)
                linkFolderB.getAbstractFeatureGroup().add(this.kmlObjectFactory.createPlacemark(placemark));
            else if (valid < 1000)
                linkFolderC.getAbstractFeatureGroup().add(this.kmlObjectFactory.createPlacemark(placemark));
            else
                linkFolderD.getAbstractFeatureGroup().add(this.kmlObjectFactory.createPlacemark(placemark));
        } else {
            mainFolder.getAbstractFeatureGroup().add(this.kmlObjectFactory.createPlacemark(placemark));
        }

        histogramToKMZ(transportMode, location, listWithoutNaN);
        boxplotToKMZ(transportMode, location, listWithoutNaN);
    }

    return mainFolder;
}

From source file:annis.dao.SpringAnnisDao.java

@Override
public List<AnnisBinaryMetaData> getBinaryMeta(String toplevelCorpusName, String corpusName) {
    List<AnnisBinaryMetaData> metaData = getJdbcTemplate().query(MetaByteHelper.SQL,
            metaByteHelper.getArgs(toplevelCorpusName, corpusName), MetaByteHelper.getArgTypes(),
            metaByteHelper);/*from   w ww .j  a  v a 2 s .  c o  m*/

    // get the file size from the real file
    ListIterator<AnnisBinaryMetaData> it = metaData.listIterator();
    while (it.hasNext()) {
        AnnisBinaryMetaData singleEntry = it.next();
        File f = new File(getRealDataDir(), singleEntry.getLocalFileName());
        singleEntry.setLength((int) f.length());
    }
    return metaData;
}