Example usage for java.lang Double compare

List of usage examples for java.lang Double compare

Introduction

In this page you can find the example usage for java.lang Double compare.

Prototype

public static int compare(double d1, double d2) 

Source Link

Document

Compares the two specified double values.

Usage

From source file:org.apache.pig.builtin.Utf8StorageConverter.java

@Override
public Integer bytesToInteger(byte[] b) throws IOException {
    if (b == null || b.length == 0) {
        return null;
    }//from   w w w .j av  a  2 s  .c  o m

    String s = new String(b);
    s = s.trim();
    Integer ret = null;

    // See PIG-2835. Using exception handling to check if it's a double is very expensive.
    // So we write our sanity check.
    if (sanityCheckIntegerLong(s)) {
        try {
            ret = Integer.valueOf(s);
        } catch (NumberFormatException nfe) {
        }
    }
    if (ret == null) {
        // It's possible that this field can be interpreted as a double.
        // Unfortunately Java doesn't handle this in Integer.valueOf.  So
        // we need to try to convert it to a double and if that works then
        // go to an int.
        try {
            Double d = Double.valueOf(s);
            // Need to check for an overflow error
            if (Double.compare(d.doubleValue(), mMaxInt.doubleValue() + 1) >= 0
                    || Double.compare(d.doubleValue(), mMinInt.doubleValue() - 1) <= 0) {
                LogUtils.warn(this, "Value " + d + " too large for integer", PigWarning.TOO_LARGE_FOR_INT,
                        mLog);
                return null;
            }
            return Integer.valueOf(d.intValue());
        } catch (NumberFormatException nfe2) {
            LogUtils.warn(this,
                    "Unable to interpret value " + Arrays.toString(b) + " in field being "
                            + "converted to int, caught NumberFormatException <" + nfe2.getMessage()
                            + "> field discarded",
                    PigWarning.FIELD_DISCARDED_TYPE_CONVERSION_FAILED, mLog);
            return null;
        }
    }
    return ret;
}

From source file:com.likethecolor.alchemy.api.entity.DisambiguatedAlchemyEntity.java

@Override
public boolean equals(Object o) {
    if (this == o) {
        return true;
    }/*from  w w  w  . j a  v a 2s  .  c  o m*/
    if (o == null || getClass() != o.getClass()) {
        return false;
    }
    if (!super.equals(o)) {
        return false;
    }

    DisambiguatedAlchemyEntity entity = (DisambiguatedAlchemyEntity) o;

    if (census != null ? !census.equals(entity.census) : entity.census != null) {
        return false;
    }
    if (ciaFactbook != null ? !ciaFactbook.equals(entity.ciaFactbook) : entity.ciaFactbook != null) {
        return false;
    }
    if (crunchbase != null ? !crunchbase.equals(entity.crunchbase) : entity.crunchbase != null) {
        return false;
    }
    if (dbpedia != null ? !dbpedia.equals(entity.dbpedia) : entity.dbpedia != null) {
        return false;
    }
    if (freebase != null ? !freebase.equals(entity.freebase) : entity.freebase != null) {
        return false;
    }
    if (geo != null ? !geo.equals(entity.geo) : entity.geo != null) {
        return false;
    }

    if (Double.compare(entity.latitude, latitude) != 0) {
        return false;
    }
    if (Double.compare(entity.longitude, longitude) != 0) {
        return false;
    }
    if (geonames != null ? !geonames.equals(entity.geonames) : entity.geonames != null) {
        return false;
    }
    if (musicBrainz != null ? !musicBrainz.equals(entity.musicBrainz) : entity.musicBrainz != null) {
        return false;
    }
    if (name != null ? !name.equals(entity.name) : entity.name != null) {
        return false;
    }
    if (opencyc != null ? !opencyc.equals(entity.opencyc) : entity.opencyc != null) {
        return false;
    }
    if (semanticCrunchbase != null ? !semanticCrunchbase.equals(entity.semanticCrunchbase)
            : entity.semanticCrunchbase != null) {
        return false;
    }
    if (subtypes != null ? !subtypes.equals(entity.subtypes) : entity.subtypes != null) {
        return false;
    }
    if (umbel != null ? !umbel.equals(entity.umbel) : entity.umbel != null) {
        return false;
    }
    if (website != null ? !website.equals(entity.website) : entity.website != null) {
        return false;
    }
    if (yago != null ? !yago.equals(entity.yago) : entity.yago != null) {
        return false;
    }

    return true;
}

From source file:org.mskcc.cbio.portal.servlet.NetworkServlet.java

/**
 *
 * @param network/*w  ww  . j  a  va2 s .c o  m*/
 * @param n
 * @return
 */
private List<Node> getNodesToRemove(final Network network, final double diffusion, final int n) {
    final Map<Node, Double> mapDiffusion = getMapDiffusedTotalAlteredPercentage(network, diffusion);

    // keep track of the top nKeep
    PriorityQueue<Node> topAlteredNodes = new PriorityQueue<Node>(n, new Comparator<Node>() {
        public int compare(Node n1, Node n2) {
            int ret = mapDiffusion.get(n1).compareTo(mapDiffusion.get(n2));
            if (diffusion != 0 && ret == 0) { // if the same diffused perc, use own perc
                ret = Double.compare(getTotalAlteredPercentage(n1), getTotalAlteredPercentage(n2));
            }

            if (ret == 0) { // if the same, rank according to degree
                ret = network.getDegree(n1) - network.getDegree(n2);
            }

            return ret;
        }
    });

    List<Node> nodesToRemove = new ArrayList<Node>();
    for (Node node : network.getNodes()) {
        if (isInQuery(node) || node.getType().equals(NodeType.DRUG)) {
            continue;
        }

        if (topAlteredNodes.size() < n) {
            topAlteredNodes.add(node);
        } else {
            if (n == 0) {
                nodesToRemove.add(node);
            } else {
                if (mapDiffusion.get(node) > mapDiffusion.get(topAlteredNodes.peek())) {
                    nodesToRemove.add(topAlteredNodes.poll());
                    topAlteredNodes.add(node);
                } else {
                    nodesToRemove.add(node);
                }
            }
        }
    }

    return nodesToRemove;
}

From source file:ml.shifu.shifu.core.binning.EqualPopulationBinning.java

/**
 * Insert one @HistogramUnit node into the histogram.
 * Meanwhile it will try to keep the histogram as most @maxHistogramUnitCnt
 * So when inserting one node in, the method will try to find the place to insert as well as minimum interval
 * // w ww.j a  v a 2s .co  m
 * @param node
 *            current node
 */
private void insertWithTrim(LinkNode<HistogramUnit> node) {
    LinkNode<HistogramUnit> insertOpsUnit = null;
    LinkNode<HistogramUnit> minIntervalOpsUnit = null;
    Double minInterval = Double.MAX_VALUE;

    LinkNode<HistogramUnit> tmp = this.tail;
    while (tmp != null) {
        if (insertOpsUnit == null) {
            int res = Double.compare(tmp.data().getHval(), node.data().getHval());
            if (res > 0) {
                // do nothing
            } else if (res == 0) {
                tmp.data().setHcnt(tmp.data().getHcnt() + node.data().getHcnt());
                return;
            } else if (res < 0) {
                // find the right insert position to insert
                insertOpsUnit = tmp;

                double interval = node.data().getHval() - tmp.data().getHval();
                if (interval < minInterval) {
                    minInterval = interval;
                    minIntervalOpsUnit = tmp;
                }

                if (tmp.next() != null) {
                    interval = tmp.next().data().getHval() - node.data().getHval();
                    if (interval < minInterval) {
                        minInterval = interval;
                        minIntervalOpsUnit = node;
                    }
                }
            }
        }

        if (tmp.next() != null) {
            LinkNode<HistogramUnit> next = tmp.next();
            double interval = next.data().getHval() - tmp.data().getHval();

            if (interval < minInterval) {
                minInterval = interval;
                minIntervalOpsUnit = tmp;
            }
        }

        tmp = tmp.prev();
    }

    // insert node into linked list
    if (insertOpsUnit == null) { // insert as the first node
        if (this.header != null) {
            this.header.setPrev(node);
        }
        node.setNext(this.header);
        this.header = node;
        if (this.tail == null) {
            this.tail = node;
        }
    } else if (insertOpsUnit == this.tail) { // insert as the last node
        node.setPrev(insertOpsUnit);
        insertOpsUnit.setNext(node);
        this.tail = node;
    } else { // some intermediate node
        node.setNext(insertOpsUnit.next());
        node.setPrev(insertOpsUnit);
        insertOpsUnit.next().setPrev(node);
        insertOpsUnit.setNext(node);
    }

    // merge info into next node
    if (this.currentHistogramUnitCnt == this.maxHistogramUnitCnt) {
        LinkNode<HistogramUnit> nextNode = minIntervalOpsUnit.next();
        HistogramUnit chu = minIntervalOpsUnit.data();
        HistogramUnit nhu = nextNode.data();
        nhu.setHval((chu.getHval() * chu.getHcnt() + nhu.getHval() * nhu.getHcnt())
                / (chu.getHcnt() + nhu.getHcnt()));
        nhu.setHcnt(chu.getHcnt() + nhu.getHcnt());
        removeCurrentNode(minIntervalOpsUnit, nextNode);
    } else {
        this.currentHistogramUnitCnt++;
    }
}

From source file:com.opengamma.analytics.financial.credit.creditdefaultswap.pricing.vanilla.isdanew.ISDACompliantCurve.java

@Override
public boolean equals(final Object o) {
    if (this == o) {
        return true;
    }//from  w ww.j ava  2s . c  o m
    if (o == null || getClass() != o.getClass()) {
        return false;
    }

    final ISDACompliantCurve that = (ISDACompliantCurve) o;

    if (_n != that._n) {
        return false;
    }
    if (Double.compare(that._offsetRT, _offsetRT) != 0) {
        return false;
    }
    if (Double.compare(that._offsetTime, _offsetTime) != 0) {
        return false;
    }
    if (!Arrays.equals(_df, that._df)) {
        return false;
    }
    if (!Arrays.equals(_r, that._r)) {
        return false;
    }
    if (!Arrays.equals(_rt, that._rt)) {
        return false;
    }
    if (!Arrays.equals(_t, that._t)) {
        return false;
    }

    return true;
}

From source file:org.esa.nest.dataio.ceos.radarsat.RadarsatProductDirectory.java

private void addAbstractedMetadataHeader(Product product, MetadataElement root) {

    final MetadataElement absRoot = AbstractMetadata.addAbstractedMetadataHeader(root);

    BinaryRecord mapProjRec = leaderFile.getMapProjRecord();
    if (mapProjRec == null)
        mapProjRec = trailerFile.getMapProjRecord();
    BinaryRecord sceneRec = leaderFile.getSceneRecord();
    if (sceneRec == null)
        sceneRec = trailerFile.getSceneRecord();
    final BinaryRecord radiometricRec = leaderFile.getRadiometricRecord();
    BinaryRecord facilityRec = leaderFile.getFacilityRecord();
    if (facilityRec == null)
        facilityRec = trailerFile.getFacilityRecord();
    BinaryRecord detProcRec = leaderFile.getDetailedProcessingRecord();
    if (detProcRec == null)
        detProcRec = trailerFile.getDetailedProcessingRecord();

    //mph/*from   w w  w.  j  ava2 s .  c  om*/
    AbstractMetadata.setAttribute(absRoot, AbstractMetadata.PRODUCT, getProductName());
    AbstractMetadata.setAttribute(absRoot, AbstractMetadata.PRODUCT_TYPE, getProductType());
    AbstractMetadata.setAttribute(absRoot, AbstractMetadata.SPH_DESCRIPTOR,
            sceneRec.getAttributeString("Product type descriptor"));
    AbstractMetadata.setAttribute(absRoot, AbstractMetadata.MISSION, "RS1");

    AbstractMetadata.setAttribute(absRoot, AbstractMetadata.PROC_TIME,
            getProcTime(volumeDirectoryFile.getVolumeDescriptorRecord()));

    final ProductData.UTC startTime = getUTCScanStartTime(sceneRec, detProcRec);
    final ProductData.UTC endTime = getUTCScanStopTime(sceneRec, detProcRec);
    AbstractMetadata.setAttribute(absRoot, AbstractMetadata.first_line_time, startTime);
    AbstractMetadata.setAttribute(absRoot, AbstractMetadata.last_line_time, endTime);

    if (mapProjRec != null) {
        AbstractMetadata.setAttribute(absRoot, AbstractMetadata.first_near_lat,
                mapProjRec.getAttributeDouble("1st line 1st pixel geodetic latitude"));
        AbstractMetadata.setAttribute(absRoot, AbstractMetadata.first_near_long,
                mapProjRec.getAttributeDouble("1st line 1st pixel geodetic longitude"));

        AbstractMetadata.setAttribute(absRoot, AbstractMetadata.first_far_lat,
                mapProjRec.getAttributeDouble("1st line last valid pixel geodetic latitude"));
        AbstractMetadata.setAttribute(absRoot, AbstractMetadata.first_far_long,
                mapProjRec.getAttributeDouble("1st line last valid pixel geodetic longitude"));

        AbstractMetadata.setAttribute(absRoot, AbstractMetadata.last_near_lat,
                mapProjRec.getAttributeDouble("Last line 1st pixel geodetic latitude"));
        AbstractMetadata.setAttribute(absRoot, AbstractMetadata.last_near_long,
                mapProjRec.getAttributeDouble("Last line 1st pixel geodetic longitude"));
        AbstractMetadata.setAttribute(absRoot, AbstractMetadata.last_far_lat,
                mapProjRec.getAttributeDouble("Last line last valid pixel geodetic latitude"));
        AbstractMetadata.setAttribute(absRoot, AbstractMetadata.last_far_long,
                mapProjRec.getAttributeDouble("Last line last valid pixel geodetic longitude"));

        AbstractMetadata.setAttribute(absRoot, AbstractMetadata.PASS, getPass(mapProjRec, sceneRec));
        AbstractMetadata.setAttribute(absRoot, AbstractMetadata.range_spacing,
                mapProjRec.getAttributeDouble("Nominal inter-pixel distance in output scene"));
        AbstractMetadata.setAttribute(absRoot, AbstractMetadata.azimuth_spacing,
                mapProjRec.getAttributeDouble("Nominal inter-line distance in output scene"));

        AbstractMetadata.setAttribute(absRoot, AbstractMetadata.srgr_flag, isGroundRange(mapProjRec));
        AbstractMetadata.setAttribute(absRoot, AbstractMetadata.map_projection, getMapProjection(mapProjRec));
        AbstractMetadata.setAttribute(absRoot, AbstractMetadata.geo_ref_system,
                mapProjRec.getAttributeString("Name of reference ellipsoid"));

    } else if (sceneRec != null) {
        AbstractMetadata.setAttribute(absRoot, AbstractMetadata.range_spacing,
                sceneRec.getAttributeDouble("Pixel spacing"));
        AbstractMetadata.setAttribute(absRoot, AbstractMetadata.azimuth_spacing,
                sceneRec.getAttributeDouble("Line spacing"));
        AbstractMetadata.setAttribute(absRoot, AbstractMetadata.PASS, getPass(mapProjRec, sceneRec));
    }

    //sph
    if (sceneRec != null) {
        final int absOrbit = Integer.parseInt(sceneRec.getAttributeString("Orbit number").trim());
        AbstractMetadata.setAttribute(absRoot, AbstractMetadata.ABS_ORBIT, absOrbit);

        AbstractMetadata.setAttribute(absRoot, AbstractMetadata.mds1_tx_rx_polar,
                SARReader.findPolarizationInBandName(
                        sceneRec.getAttributeString("Sensor ID and mode of operation for this channel")));

        AbstractMetadata.setAttribute(absRoot, AbstractMetadata.algorithm,
                sceneRec.getAttributeString("Processing algorithm identifier"));
        AbstractMetadata.setAttribute(absRoot, AbstractMetadata.azimuth_looks,
                sceneRec.getAttributeDouble("Nominal number of looks processed in azimuth"));
        AbstractMetadata.setAttribute(absRoot, AbstractMetadata.range_looks,
                sceneRec.getAttributeDouble("Nominal number of looks processed in range"));
        AbstractMetadata.setAttribute(absRoot, AbstractMetadata.pulse_repetition_frequency,
                sceneRec.getAttributeDouble("Pulse Repetition Frequency"));
        double radarFreq = sceneRec.getAttributeDouble("Radar frequency");
        if (Double.compare(radarFreq, 0.0) == 0) {
            final double radarWaveLength = sceneRec.getAttributeDouble("Radar wavelength"); // in m
            if (Double.compare(radarWaveLength, 0.0) != 0) {
                radarFreq = Constants.lightSpeed / radarWaveLength / Constants.oneMillion; // in MHz
            }
        }
        AbstractMetadata.setAttribute(absRoot, AbstractMetadata.radar_frequency, radarFreq);

        AbstractMetadata.setAttribute(absRoot, AbstractMetadata.range_sampling_rate,
                sceneRec.getAttributeDouble("Range sampling rate"));

        // add Range and Azimuth bandwidth
        final double rangeBW = sceneRec.getAttributeDouble("Total processor bandwidth in range"); // Hz
        final double azimuthBW = sceneRec.getAttributeDouble("Total processor bandwidth in azimuth"); // Hz

        AbstractMetadata.setAttribute(absRoot, AbstractMetadata.range_bandwidth,
                rangeBW / Constants.oneMillion);
        AbstractMetadata.setAttribute(absRoot, AbstractMetadata.azimuth_bandwidth, azimuthBW);
    }

    AbstractMetadata.setAttribute(absRoot, AbstractMetadata.SAMPLE_TYPE, getSampleType());
    AbstractMetadata.setAttribute(absRoot, AbstractMetadata.line_time_interval,
            ReaderUtils.getLineTimeInterval(startTime, endTime, sceneHeight));
    AbstractMetadata.setAttribute(absRoot, AbstractMetadata.num_output_lines, product.getSceneRasterHeight());
    AbstractMetadata.setAttribute(absRoot, AbstractMetadata.num_samples_per_line,
            product.getSceneRasterWidth());
    AbstractMetadata.setAttribute(absRoot, AbstractMetadata.TOT_SIZE, ReaderUtils.getTotalSize(product));

    if (facilityRec != null) {
        AbstractMetadata.setAttribute(absRoot, AbstractMetadata.STATE_VECTOR_TIME, AbstractMetadata.parseUTC(
                facilityRec.getAttributeString("Time of input state vector used to processed the image")));

        AbstractMetadata.setAttribute(absRoot, AbstractMetadata.ant_elev_corr_flag,
                facilityRec.getAttributeInt("Antenna pattern correction flag"));
        AbstractMetadata.setAttribute(absRoot, AbstractMetadata.range_spread_comp_flag,
                facilityRec.getAttributeInt("Range spreading loss compensation flag"));
        AbstractMetadata.setAttribute(absRoot, AbstractMetadata.replica_power_corr_flag, 0);
        AbstractMetadata.setAttribute(absRoot, AbstractMetadata.abs_calibration_flag, 0);
        AbstractMetadata.setAttribute(absRoot, AbstractMetadata.coregistered_stack, 0);
        AbstractMetadata.setAttribute(absRoot, AbstractMetadata.calibration_factor,
                facilityRec.getAttributeDouble("Absolute calibration constant K"));
    }

    if (radiometricRec != null) {
        AbstractMetadata.setAttribute(absRoot, AbstractMetadata.calibration_factor,
                radiometricRec.getAttributeDouble("Calibration constant"));
    }

    AbstractMetadata.setAttribute(absRoot, AbstractMetadata.replica_power_corr_flag, 0);
    AbstractMetadata.setAttribute(absRoot, AbstractMetadata.abs_calibration_flag, 0);

    addOrbitStateVectors(absRoot, leaderFile.getPlatformPositionRecord());
    if (facilityRec != null)
        addSRGRCoefficients(absRoot, facilityRec);
    else
        addSRGRCoefficients(absRoot, detProcRec);
}

From source file:Main.java

/**
 * Finds the first occurrence in an array from specified given position and upto given length.
 *//*  w ww  .  j  a  v a2  s .  c  o  m*/
public static int indexOf(double[] array, double[] sub, int startIndex, int endIndex) {
    int sublen = sub.length;
    if (sublen == 0) {
        return startIndex;
    }
    int total = endIndex - sublen + 1;
    double c = sub[0];
    mainloop: for (int i = startIndex; i < total; i++) {
        if (Double.compare(array[i], c) != 0) {
            continue;
        }
        int j = 1;
        int k = i + 1;
        while (j < sublen) {
            if (Double.compare(sub[j], array[k]) != 0) {
                continue mainloop;
            }
            j++;
            k++;
        }
        return i;
    }
    return -1;
}

From source file:org.esa.nest.dataio.ceos.basic.BasicCeosProductDirectory.java

private void addAbstractedMetadataHeader(Product product, MetadataElement root) {

    final MetadataElement absRoot = AbstractMetadata.addAbstractedMetadataHeader(root);

    BinaryRecord mapProjRec = leaderFile.getMapProjRecord();
    if (mapProjRec == null)
        mapProjRec = trailerFile.getMapProjRecord();
    BinaryRecord sceneRec = leaderFile.getSceneRecord();
    if (sceneRec == null)
        sceneRec = trailerFile.getSceneRecord();
    final BinaryRecord radiometricRec = leaderFile.getRadiometricRecord();
    BinaryRecord facilityRec = leaderFile.getFacilityRecord();
    if (facilityRec == null)
        facilityRec = trailerFile.getFacilityRecord();
    BinaryRecord detProcRec = leaderFile.getDetailedProcessingRecord();
    if (detProcRec == null)
        detProcRec = trailerFile.getDetailedProcessingRecord();

    //mph/*from  w  w w. j a  va 2 s  .  c om*/
    AbstractMetadata.setAttribute(absRoot, AbstractMetadata.PRODUCT, getProductName());
    AbstractMetadata.setAttribute(absRoot, AbstractMetadata.PRODUCT_TYPE, getProductType());
    AbstractMetadata.setAttribute(absRoot, AbstractMetadata.SPH_DESCRIPTOR,
            sceneRec.getAttributeString("Product type descriptor"));
    AbstractMetadata.setAttribute(absRoot, AbstractMetadata.MISSION, "RS1");

    AbstractMetadata.setAttribute(absRoot, AbstractMetadata.PROC_TIME,
            getProcTime(volumeDirectoryFile.getVolumeDescriptorRecord()));

    final ProductData.UTC startTime = getUTCScanStartTime(sceneRec, detProcRec);
    final ProductData.UTC endTime = getUTCScanStopTime(sceneRec, detProcRec);
    AbstractMetadata.setAttribute(absRoot, AbstractMetadata.first_line_time, startTime);
    AbstractMetadata.setAttribute(absRoot, AbstractMetadata.last_line_time, endTime);

    if (mapProjRec != null) {
        AbstractMetadata.setAttribute(absRoot, AbstractMetadata.first_near_lat,
                mapProjRec.getAttributeDouble("1st line 1st pixel geodetic latitude"));
        AbstractMetadata.setAttribute(absRoot, AbstractMetadata.first_near_long,
                mapProjRec.getAttributeDouble("1st line 1st pixel geodetic longitude"));

        AbstractMetadata.setAttribute(absRoot, AbstractMetadata.first_far_lat,
                mapProjRec.getAttributeDouble("1st line last valid pixel geodetic latitude"));
        AbstractMetadata.setAttribute(absRoot, AbstractMetadata.first_far_long,
                mapProjRec.getAttributeDouble("1st line last valid pixel geodetic longitude"));

        AbstractMetadata.setAttribute(absRoot, AbstractMetadata.last_near_lat,
                mapProjRec.getAttributeDouble("Last line 1st pixel geodetic latitude"));
        AbstractMetadata.setAttribute(absRoot, AbstractMetadata.last_near_long,
                mapProjRec.getAttributeDouble("Last line 1st pixel geodetic longitude"));
        AbstractMetadata.setAttribute(absRoot, AbstractMetadata.last_far_lat,
                mapProjRec.getAttributeDouble("Last line last valid pixel geodetic latitude"));
        AbstractMetadata.setAttribute(absRoot, AbstractMetadata.last_far_long,
                mapProjRec.getAttributeDouble("Last line last valid pixel geodetic longitude"));

        AbstractMetadata.setAttribute(absRoot, AbstractMetadata.PASS, getPass(mapProjRec, sceneRec));
        AbstractMetadata.setAttribute(absRoot, AbstractMetadata.range_spacing,
                mapProjRec.getAttributeDouble("Nominal inter-pixel distance in output scene"));
        AbstractMetadata.setAttribute(absRoot, AbstractMetadata.azimuth_spacing,
                mapProjRec.getAttributeDouble("Nominal inter-line distance in output scene"));

        AbstractMetadata.setAttribute(absRoot, AbstractMetadata.srgr_flag, isGroundRange(mapProjRec));
        AbstractMetadata.setAttribute(absRoot, AbstractMetadata.map_projection, getMapProjection(mapProjRec));
        AbstractMetadata.setAttribute(absRoot, AbstractMetadata.geo_ref_system,
                mapProjRec.getAttributeString("Name of reference ellipsoid"));

    } else if (sceneRec != null) {
        AbstractMetadata.setAttribute(absRoot, AbstractMetadata.range_spacing,
                sceneRec.getAttributeDouble("Pixel spacing"));
        AbstractMetadata.setAttribute(absRoot, AbstractMetadata.azimuth_spacing,
                sceneRec.getAttributeDouble("Line spacing"));
        AbstractMetadata.setAttribute(absRoot, AbstractMetadata.PASS, getPass(mapProjRec, sceneRec));
    }

    //sph
    if (sceneRec != null) {
        final String absOrbit = sceneRec.getAttributeString("Orbit number").trim();
        if (absOrbit != null && !absOrbit.isEmpty()) {
            AbstractMetadata.setAttribute(absRoot, AbstractMetadata.ABS_ORBIT, Integer.parseInt(absOrbit));
        }
        AbstractMetadata.setAttribute(absRoot, AbstractMetadata.mds1_tx_rx_polar,
                SARReader.findPolarizationInBandName(
                        sceneRec.getAttributeString("Sensor ID and mode of operation for this channel")));

        AbstractMetadata.setAttribute(absRoot, AbstractMetadata.algorithm,
                sceneRec.getAttributeString("Processing algorithm identifier"));
        AbstractMetadata.setAttribute(absRoot, AbstractMetadata.azimuth_looks,
                sceneRec.getAttributeDouble("Nominal number of looks processed in azimuth"));
        AbstractMetadata.setAttribute(absRoot, AbstractMetadata.range_looks,
                sceneRec.getAttributeDouble("Nominal number of looks processed in range"));
        AbstractMetadata.setAttribute(absRoot, AbstractMetadata.pulse_repetition_frequency,
                sceneRec.getAttributeDouble("Pulse Repetition Frequency"));
        double radarFreq = sceneRec.getAttributeDouble("Radar frequency");
        if (Double.compare(radarFreq, 0.0) == 0) {
            final double radarWaveLength = sceneRec.getAttributeDouble("Radar wavelength"); // in m
            if (Double.compare(radarWaveLength, 0.0) != 0) {
                radarFreq = Constants.lightSpeed / radarWaveLength / Constants.oneMillion; // in MHz
            }
        }
        AbstractMetadata.setAttribute(absRoot, AbstractMetadata.radar_frequency, radarFreq);

        AbstractMetadata.setAttribute(absRoot, AbstractMetadata.range_sampling_rate,
                sceneRec.getAttributeDouble("Range sampling rate"));

        // add Range and Azimuth bandwidth
        final double rangeBW = sceneRec.getAttributeDouble("Total processor bandwidth in range"); // Hz
        final double azimuthBW = sceneRec.getAttributeDouble("Total processor bandwidth in azimuth"); // Hz

        AbstractMetadata.setAttribute(absRoot, AbstractMetadata.range_bandwidth,
                rangeBW / Constants.oneMillion);
        AbstractMetadata.setAttribute(absRoot, AbstractMetadata.azimuth_bandwidth, azimuthBW);
    }

    AbstractMetadata.setAttribute(absRoot, AbstractMetadata.SAMPLE_TYPE, getSampleType());
    AbstractMetadata.setAttribute(absRoot, AbstractMetadata.line_time_interval,
            ReaderUtils.getLineTimeInterval(startTime, endTime, sceneHeight));
    AbstractMetadata.setAttribute(absRoot, AbstractMetadata.num_output_lines, product.getSceneRasterHeight());
    AbstractMetadata.setAttribute(absRoot, AbstractMetadata.num_samples_per_line,
            product.getSceneRasterWidth());
    AbstractMetadata.setAttribute(absRoot, AbstractMetadata.TOT_SIZE, ReaderUtils.getTotalSize(product));

    if (facilityRec != null) {
        AbstractMetadata.setAttribute(absRoot, AbstractMetadata.STATE_VECTOR_TIME, AbstractMetadata.parseUTC(
                facilityRec.getAttributeString("Time of input state vector used to processed the image")));

        AbstractMetadata.setAttribute(absRoot, AbstractMetadata.ant_elev_corr_flag,
                facilityRec.getAttributeInt("Antenna pattern correction flag"));
        AbstractMetadata.setAttribute(absRoot, AbstractMetadata.range_spread_comp_flag,
                facilityRec.getAttributeInt("Range spreading loss compensation flag"));
        AbstractMetadata.setAttribute(absRoot, AbstractMetadata.replica_power_corr_flag, 0);
        AbstractMetadata.setAttribute(absRoot, AbstractMetadata.abs_calibration_flag, 0);
        AbstractMetadata.setAttribute(absRoot, AbstractMetadata.coregistered_stack, 0);
        AbstractMetadata.setAttribute(absRoot, AbstractMetadata.calibration_factor,
                facilityRec.getAttributeDouble("Absolute calibration constant K"));
    }

    if (radiometricRec != null) {
        AbstractMetadata.setAttribute(absRoot, AbstractMetadata.calibration_factor,
                radiometricRec.getAttributeDouble("Calibration constant"));
    }

    AbstractMetadata.setAttribute(absRoot, AbstractMetadata.replica_power_corr_flag, 0);
    AbstractMetadata.setAttribute(absRoot, AbstractMetadata.abs_calibration_flag, 0);

    addOrbitStateVectors(absRoot, leaderFile.getPlatformPositionRecord());
    if (facilityRec != null)
        addSRGRCoefficients(absRoot, facilityRec);
    else
        addSRGRCoefficients(absRoot, detProcRec);
}

From source file:qa.aligner.SRLToAligner.java

private List<ProcessFrame> constructProcessFrame(ProcessFrame frame,
        HashMap<String, ArrayList<RoleSpan>> roleRoleSpanPair) {
    final Comparator<RoleSpan> comp = (r1, r2) -> Double.compare(r1.getRoleScore(), r2.getRoleScore());
    ArrayList<ProcessFrame> res = new ArrayList<ProcessFrame>();
    List<List<RoleSpan>> roleSpanCombination = new ArrayList<List<RoleSpan>>();

    if (roleRoleSpanPair.keySet().size() == 0)
        return res;

    roleSpanCombination = getRoleSpanCombination(roleRoleSpanPair);
    for (int i = 0; i < roleSpanCombination.size(); i++) {
        List<RoleSpan> spans = roleSpanCombination.get(i);
        ProcessFrame newFrame = new ProcessFrame();
        newFrame.setProcessName(frame.getProcessName());
        newFrame.setRawText(frame.getRawText());
        newFrame.setTokenizedText(frame.getTokenizedText());

        for (int j = 0; j < spans.size(); j++) {
            if (spans.get(j).getRoleType().equals(GlobalV.A0)) {
                newFrame.setUnderGoer(spans.get(j).getTextSpan());
                newFrame.setScores(GlobalV.AO_IDX, spans.get(j).getScores());
            }/*from   ww  w  .jav  a2s  .  c  o m*/
            if (spans.get(j).getRoleType().equals(GlobalV.A1)) {
                newFrame.setEnabler(spans.get(j).getTextSpan());
                newFrame.setScores(GlobalV.A1_IDX, spans.get(j).getScores());
            }
            if (spans.get(j).getRoleType().equals(GlobalV.T)) {
                newFrame.setTrigger(spans.get(j).getTextSpan());
                newFrame.setScores(GlobalV.T_IDX, spans.get(j).getScores());
            }
            if (spans.get(j).getRoleType().equals(GlobalV.A2)) {
                newFrame.setResult(spans.get(j).getTextSpan());
                newFrame.setScores(GlobalV.A2_IDX, spans.get(j).getScores());
            }
        }
        res.add(newFrame);
    }

    return res;
}

From source file:org.tinygroup.jspengine.compiler.TagLibraryInfoImpl.java

private TagInfo createTagInfo(TreeNode elem, String jspVersion) throws JasperException {
    String tagName = null;/*from w  ww  . j  av a  2  s .c  o  m*/
    String tagClassName = null;
    String teiClassName = null;

    /*
     * Default body content for JSP 1.2 tag handlers (<body-content> has
     * become mandatory in JSP 2.0, because the default would be invalid
     * for simple tag handlers)
     */
    String bodycontent = "JSP";

    String info = null;
    String displayName = null;
    String smallIcon = null;
    String largeIcon = null;
    boolean dynamicAttributes = false;

    Vector attributeVector = new Vector();
    Vector variableVector = new Vector();
    Iterator list = elem.findChildren();
    while (list.hasNext()) {
        TreeNode element = (TreeNode) list.next();
        String tname = element.getName();

        if ("name".equals(tname)) {
            tagName = element.getBody();
        } else if ("tagclass".equals(tname) || "tag-class".equals(tname)) {
            tagClassName = element.getBody();
        } else if ("teiclass".equals(tname) || "tei-class".equals(tname)) {
            teiClassName = element.getBody();
        } else if ("bodycontent".equals(tname) || "body-content".equals(tname)) {
            bodycontent = element.getBody();
        } else if ("display-name".equals(tname)) {
            displayName = element.getBody();
        } else if ("small-icon".equals(tname)) {
            smallIcon = element.getBody();
        } else if ("large-icon".equals(tname)) {
            largeIcon = element.getBody();
        } else if ("icon".equals(tname)) {
            TreeNode icon = element.findChild("small-icon");
            if (icon != null) {
                smallIcon = icon.getBody();
            }
            icon = element.findChild("large-icon");
            if (icon != null) {
                largeIcon = icon.getBody();
            }
        } else if ("info".equals(tname) || "description".equals(tname)) {
            info = element.getBody();
        } else if ("variable".equals(tname)) {
            variableVector.addElement(createVariable(element));
        } else if ("attribute".equals(tname)) {
            attributeVector.addElement(createAttribute(element, jspVersion));
        } else if ("dynamic-attributes".equals(tname)) {
            dynamicAttributes = JspUtil.booleanValue(element.getBody());
        } else if ("example".equals(tname)) {
            // Ignored elements
        } else if ("tag-extension".equals(tname)) {
            // Ignored
        } else {
            err.jspError("jsp.error.unknown.element.in.tag", tname);
        }
    }

    // JSP 2.0 removed the capital versions of TAGDEPENDENT, EMPTY, and
    // SCRIPTLESS enumerations in body-contentType, see JSP.E.2 ("Changes
    // between JSP 2.0 PFD2 and JSP 2.0 PFD3"), section "Changes to Tag
    // Library Descriptor (TLD)". Enforce that from JSP 2.0 and up, only
    // "JSP", "tagdependent", "empty", and "scriptless" may be specified
    // as body-content values.
    Double jspVersionDouble = Double.valueOf(jspversion);
    if (Double.compare(jspVersionDouble, Constants.JSP_VERSION_2_0) >= 0) {
        if (!bodycontent.equals(TagInfo.BODY_CONTENT_JSP) && !bodycontent.equals(TagInfo.BODY_CONTENT_EMPTY)
                && !bodycontent.equals(TagInfo.BODY_CONTENT_TAG_DEPENDENT)
                && !bodycontent.equals(TagInfo.BODY_CONTENT_SCRIPTLESS)) {
            err.jspError("jsp.error.tld.badbodycontent", bodycontent, tagName);
        }
    }

    TagExtraInfo tei = null;
    if (teiClassName != null && !teiClassName.equals("")) {
        try {
            Class teiClass = ctxt.getClassLoader().loadClass(teiClassName);
            tei = (TagExtraInfo) teiClass.newInstance();
        } catch (Exception e) {
            err.jspError("jsp.error.teiclass.instantiation", teiClassName, e);
        }
    }

    TagAttributeInfo[] tagAttributeInfo = new TagAttributeInfo[attributeVector.size()];
    attributeVector.copyInto(tagAttributeInfo);

    TagVariableInfo[] tagVariableInfos = new TagVariableInfo[variableVector.size()];
    variableVector.copyInto(tagVariableInfos);

    TagInfo taginfo = new TagInfo(tagName, tagClassName, bodycontent, info, this, tei, tagAttributeInfo,
            displayName, smallIcon, largeIcon, tagVariableInfos, dynamicAttributes);
    return taginfo;
}