Example usage for org.apache.commons.lang3 ArrayUtils toPrimitive

List of usage examples for org.apache.commons.lang3 ArrayUtils toPrimitive

Introduction

In this page you can find the example usage for org.apache.commons.lang3 ArrayUtils toPrimitive.

Prototype

public static boolean[] toPrimitive(final Boolean[] array) 

Source Link

Document

Converts an array of object Booleans to primitives.

This method returns null for a null input array.

Usage

From source file:org.kalypso.kalypsomodel1d2d.ui.map.util.UtilMap.java

public static int[][] getPointArrays(final Point currentPoint, final List<GM_Point> nodes,
        final GeoTransform projection) {
    final List<Integer> xArray = new ArrayList<>();
    final List<Integer> yArray = new ArrayList<>();

    if (nodes != null && projection != null) {
        for (final GM_Point point : nodes) {
            final int x = (int) projection.getDestX(point.getX());
            final int y = (int) projection.getDestY(point.getY());

            xArray.add(new Integer(x));
            yArray.add(new Integer(y));
        }//from  ww w. j a  va2s  .c  o m
    }

    if (currentPoint != null) {
        xArray.add(currentPoint.x);
        yArray.add(currentPoint.y);
    }

    final int[] xs = ArrayUtils.toPrimitive(xArray.toArray(new Integer[xArray.size()]));
    final int[] ys = ArrayUtils.toPrimitive(yArray.toArray(new Integer[yArray.size()]));

    return new int[][] { xs, ys };
}

From source file:org.kalypso.model.hydrology.internal.binding.cm.LinearSumGenerator.java

/**
 * @param catchmentFeatures//from  w w  w  . jav  a 2  s.  c o  m
 *          The catchment features will be taken from the generator itself, so they are not needed here. Leave them <code>null</code>.
 */
@Override
public IObservation[] createRainfall(final Feature[] catchmentFeatures, final IStringResolver variables,
        final ILog log, IProgressMonitor monitor) throws CoreException {
    /* Monitor. */
    if (monitor == null)
        monitor = new NullProgressMonitor();

    try {
        /* Get the date range. */
        final DateRange dateRange = getPeriod(variables);

        /* Get the catchments. */
        final List<ICatchment> catchments = getCatchments();

        /* HINT: Keep in mind, that the results must match the order of the catchments array. */
        final IObservation[] results = new IObservation[catchments.size()];

        /* Monitor. */
        monitor.beginTask(String.format(Messages.getString("LinearSumGenerator_0"), catchments.size()), //$NON-NLS-1$
                catchments.size() * 200);
        monitor.subTask(Messages.getString("LinearSumGenerator_1")); //$NON-NLS-1$

        /* A catchment with the already used hash needs not to be calculated anymore. */
        /* Because the result timeseries would be the same. */
        /* Also the link in the catchment to the result timeseries should be the same. */
        final List<String> usedHashes = new ArrayList<>();

        /* Generate one timeseries for each catchment. */
        for (int i = 0; i < catchments.size(); i++) {
            /* Get the catchment. */
            final ICatchment catchment = catchments.get(i);
            final Feature areaLink = catchment.getAreaLink();
            final String description = areaLink.getDescription();

            /* Generate the message 1. */
            final String message1 = String.format(Messages.getString("LinearSumGenerator_2"), i + 1, //$NON-NLS-1$
                    description);

            /* Monitor. */
            monitor.subTask(message1);

            /* Log. */
            if (log != null)
                log.log(new Status(IStatus.INFO, ModelNA.PLUGIN_ID, message1));

            /* Memory for the factors and the observations of the catchments. */
            final List<Double> factors = new ArrayList<>();
            final List<IObservation> observations = new ArrayList<>();

            /* Build the hash. */
            final String hash = CatchmentHelper.buildHash(catchment);

            /* Was the target timeseries already generated by a previous catchment with the same hash. */
            if (!usedHashes.contains(hash)) {
                /* Get the factorized timeseries. */
                for (final IFactorizedTimeseries factorizedTimeseries : catchment.getFactorizedTimeseries()) {
                    /* Get the factor. */
                    final BigDecimal factor = factorizedTimeseries.getFactor();

                    /* Get the timeseries link. */
                    final GMLXPath linkPath = new GMLXPath(IFactorizedTimeseries.PROPERTY_TIMESERIES_LINK);

                    /* Get the filters from the gml. */
                    final IZmlFilter[] filters = getFilters().toArray(new IZmlFilter[] {});

                    /* Load the observation. */
                    final IObservation observation = readObservation(factorizedTimeseries, linkPath, filters,
                            dateRange);

                    /* If the factor is valid, add the factor and its observation. */
                    if (factor != null && factor.intValue() > 0 && factor.intValue() <= 100) {
                        factors.add(new Double(factor.doubleValue() / 100));
                        observations.add(observation);
                    }
                }

                /* Store the hash. */
                usedHashes.add(hash);
            }

            /* Generate the message 2. */
            final String message2 = String.format(Messages.getString("LinearSumGenerator_3"), i + 1, //$NON-NLS-1$
                    description, factors.size());

            /* Monitor. */
            monitor.worked(100);
            monitor.subTask(message2);

            /* Log. */
            if (log != null)
                log.log(new Status(IStatus.INFO, ModelNA.PLUGIN_ID, message2));

            /* Set the resulting observation for this catchment. */
            final double[] factorDoubles = ArrayUtils.toPrimitive(factors.toArray(new Double[] {}));
            results[i] = RainfallGeneratorUtilities.combineObses(observations.toArray(new IObservation[] {}),
                    factorDoubles, "catchmentGenerator://linearSum"); //$NON-NLS-1$

            /* Monitor. */
            monitor.worked(100);
        }

        return results;
    } catch (final Exception ex) {
        /* Create the error status. */
        final IStatus status = new Status(IStatus.ERROR, ModelNA.PLUGIN_ID, ex.getLocalizedMessage(), ex);

        /* If there is a log, log to it. */
        if (log != null)
            log.log(status);

        throw new CoreException(status);
    } finally {
        /* Monitor. */
        monitor.done();
    }
}

From source file:org.kalypso.model.wspm.core.profil.sobek.utils.hw.HeightWidthResult.java

private double[] sampleHeights(final Coordinate[] coordinates) {
    final Set<Double> sortedSet = new TreeSet<>();

    // double lastY = Double.NaN;
    for (final Coordinate coordinate : coordinates) {
        final double y = coordinate.y;
        sortedSet.add(new Double(y));
        // lastY = y;
    }/*  w ww . j  a  va 2s. c o m*/

    // Double[] ySoFar = sortedSet.toArray( new Double[sortedSet.size()] );

    final Double[] result = sortedSet.toArray(new Double[sortedSet.size()]);
    return ArrayUtils.toPrimitive(result);
}

From source file:org.kalypso.model.wspm.tuhh.schema.simulation.PolynomeReader.java

public void read(final File polyFile) throws IOException {
    LineNumberReader reader = null;
    try {//from  w w  w.j ava  2s  .c  o  m
        reader = new LineNumberReader(new FileReader(polyFile));

        while (reader.ready()) {
            final String line = reader.readLine();
            if (line == null)
                break;

            final String trimmedLine = line.trim().replaceAll(" \\(h\\)", "\\(h\\)"); //$NON-NLS-1$ //$NON-NLS-2$
            final String[] tokens = trimmedLine.split(" +"); //$NON-NLS-1$
            if (tokens.length < 8)
                continue;

            /* Determine if this is a good line: good lines are lines whos first token is a number */
            final BigDecimal station;
            try {
                station = new BigDecimal(tokens[0]);
            } catch (final NumberFormatException nfe) {
                /* Just ignore this line */
                continue;
            }

            try {
                final String description = tokens[1];
                // final String whatIsN = tokens[2];
                final char type = tokens[3].charAt(0);

                final int order = Integer.parseInt(tokens[4]);
                final double rangeMin = Double.parseDouble(tokens[5].replace('D', 'E'));
                final double rangeMax = Double.parseDouble(tokens[6].replace('D', 'E'));

                if (tokens.length < 7 + order + 1) {
                    /* A good line but bad content. Give user a hint that something might be wrong. */
                    m_log.log(false,
                            Messages.getString(
                                    "org.kalypso.model.wspm.tuhh.schema.simulation.PolynomeProcessor.22"), //$NON-NLS-1$
                            polyFile.getName(), reader.getLineNumber());
                    continue;
                }

                final List<Double> coefficients = new ArrayList<>(order);
                for (int i = 7; i < 7 + order + 1; i++) {
                    final double coeff = Double.parseDouble(tokens[i].replace('D', 'E'));
                    coefficients.add(coeff);
                }

                final Double[] doubles = coefficients.toArray(new Double[coefficients.size()]);
                final double[] coeffDoubles = ArrayUtils.toPrimitive(doubles);

                final String domainId;
                final String rangeId = IWspmTuhhQIntervallConstants.DICT_PHENOMENON_WATERLEVEL;
                switch (type) {
                case 'Q':
                    domainId = IWspmTuhhQIntervallConstants.DICT_PHENOMENON_RUNOFF;
                    break;
                case 'A':
                    domainId = IWspmTuhhQIntervallConstants.DICT_PHENOMENON_AREA;
                    break;
                case 'a':
                    domainId = IWspmTuhhQIntervallConstants.DICT_PHENOMENON_ALPHA;
                    break;

                default:
                    m_log.log(false,
                            Messages.getString(
                                    "org.kalypso.model.wspm.tuhh.schema.simulation.PolynomeProcessor.23"), //$NON-NLS-1$
                            station);
                    continue;
                }

                /* find feature for station */
                final QIntervallResult qresult = m_intervalIndex.get(station);
                if (qresult == null)
                    m_log.log(false,
                            Messages.getString(
                                    "org.kalypso.model.wspm.tuhh.schema.simulation.PolynomeProcessor.24"), //$NON-NLS-1$
                            station, line);
                else {
                    /* create new polynome */
                    final IPolynomial1D poly1d = qresult.createPolynomial();

                    poly1d.setName(description);
                    poly1d.setDescription(description);
                    poly1d.setCoefficients(coeffDoubles);
                    poly1d.setRange(rangeMin, rangeMax);

                    poly1d.setDomainPhenomenon(domainId);
                    poly1d.setRangePhenomenon(rangeId);
                }
            } catch (final NumberFormatException nfe) {
                /* A good line but bad content. Give user a hint that something might be wrong. */
                m_log.log(false,
                        Messages.getString(
                                "org.kalypso.model.wspm.tuhh.schema.simulation.PolynomeProcessor.25"), //$NON-NLS-1$
                        polyFile.getName(), reader.getLineNumber(), nfe.getLocalizedMessage());
            } catch (final Exception e) {
                // should never happen
                m_log.log(e,
                        Messages.getString(
                                "org.kalypso.model.wspm.tuhh.schema.simulation.PolynomeProcessor.25"), //$NON-NLS-1$
                        polyFile.getName(), reader.getLineNumber(), e.getLocalizedMessage());
            }
        }
        reader.close();
    } finally {
        IOUtils.closeQuietly(reader);
    }
}

From source file:org.kalypso.model.wspm.ui.profil.wizard.createDivider.CreateDividerOperation.java

private double[] getIntersectionWidths(final IProfile profil, final Point[] intersectionPoints) {
    final Collection<Double> widthList = new ArrayList<>(intersectionPoints.length);
    for (final Point point : intersectionPoints) {
        try {/*w  w  w. j  a va2 s  .  c  o  m*/
            final GM_Point p = (GM_Point) JTSAdapter.wrap(point,
                    KalypsoDeegreePlugin.getDefault().getCoordinateSystem());
            final Double width = WspmProfileHelper.getWidthPosition(p, profil);
            if (width != null) {
                widthList.add(width);
            }
        } catch (final Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

    final Double[] widths = widthList.toArray(new Double[widthList.size()]);
    return ArrayUtils.toPrimitive(widths);
}

From source file:org.kalypso.ogc.gml.map.widgets.AbstractCreateGeometeryWidget.java

/**
 * @return all the x and y points as int[][] array including the current point
 *//* w  ww . j a  v  a  2  s .  c  o  m*/
private int[][] getXYArrayPixel() {
    final List<Integer> xArray = new ArrayList<>();
    final List<Integer> yArray = new ArrayList<>();
    for (int i = 0; i < m_points.size(); i++) {
        xArray.add(new Integer((int) getMapPanel().getProjection().getDestX(m_points.get(i).getX())));
        yArray.add(new Integer((int) getMapPanel().getProjection().getDestY(m_points.get(i).getY())));
    }
    if (m_currentPoint != null) {
        xArray.add(new Integer((int) getMapPanel().getProjection().getDestX(m_currentPoint.getX())));
        yArray.add(new Integer((int) getMapPanel().getProjection().getDestY(m_currentPoint.getY())));
    }
    final int[] xs = ArrayUtils.toPrimitive(xArray.toArray(new Integer[m_points.size()]));
    final int[] ys = ArrayUtils.toPrimitive(yArray.toArray(new Integer[m_points.size()]));
    return new int[][] { xs, ys };
}

From source file:org.kalypso.ogc.gml.map.widgets.builders.LineGeometryBuilder.java

private int[][] getPointArrays(final GeoTransform projection, final Point currentPoint) {
    final List<Integer> xArray = new ArrayList<>();
    final List<Integer> yArray = new ArrayList<>();

    for (int i = 0; i < m_points.size(); i++) {
        final GM_Point point = m_points.get(i);

        final int x = (int) projection.getDestX(point.getX());
        final int y = (int) projection.getDestY(point.getY());

        xArray.add(new Integer(x));
        yArray.add(new Integer(y));
    }/*from w  w w  .ja v a  2 s  .c om*/

    if (currentPoint != null) {
        xArray.add(currentPoint.x);
        yArray.add(currentPoint.y);
    }

    final int[] xs = ArrayUtils.toPrimitive(xArray.toArray(new Integer[xArray.size()]));
    final int[] ys = ArrayUtils.toPrimitive(yArray.toArray(new Integer[yArray.size()]));

    return new int[][] { xs, ys };
}

From source file:org.kalypso.ogc.gml.map.widgets.builders.RectangleGeometryBuilder.java

private int[][] getPointArrays(final GeoTransform projection, final Point currentPoint) {
    final List<Integer> xArray = new ArrayList<>();
    final List<Integer> yArray = new ArrayList<>();

    final int xStart = (int) projection.getDestX(m_startPoint.getX());
    final int yStart = (int) projection.getDestY(m_startPoint.getY());

    if (currentPoint != null) {
        xArray.add(new Integer(xStart));
        xArray.add(new Integer(xStart));
        xArray.add(currentPoint.x);//from  ww  w . j a va2s .com
        xArray.add(currentPoint.x);

        yArray.add(new Integer(yStart));
        yArray.add(currentPoint.y);
        yArray.add(currentPoint.y);
        yArray.add(new Integer(yStart));
    }

    final int[] xs = ArrayUtils.toPrimitive(xArray.toArray(new Integer[xArray.size()]));
    final int[] ys = ArrayUtils.toPrimitive(yArray.toArray(new Integer[yArray.size()]));

    return new int[][] { xs, ys };
}

From source file:org.kalypso.ogc.sensor.timeseries.wq.wechmann.WechmannSet.java

/**
 * @param W//from   www  .java2 s.  co m
 * @return the WechmannParams that are relevant for the given water level.
 */
public WechmannParams getForW(final double w) {
    final Double[] ds = m_mapW.keySet().toArray(new Double[0]);
    int i = Arrays.binarySearch(ArrayUtils.toPrimitive(ds), w);

    if (i < 0)
        i = -i - 1;

    if (i < ds.length)
        return m_mapW.get(ds[i]);

    // W was too big for current parameters, just use last branch of Wechmann-Set
    return m_mapW.get(ds[ds.length - 1]);
}

From source file:org.kalypso.ogc.sensor.timeseries.wq.wechmann.WechmannSet.java

/**
 * @param Q//from  w ww. ja  v  a  2s .  c  o m
 * @return the WechmannParams that are relevant for the given discharge.
 */
public WechmannParams getForQ(final double q) {
    final Double[] ds = m_mapQ.keySet().toArray(new Double[0]);
    int i = Arrays.binarySearch(ArrayUtils.toPrimitive(ds), q);

    if (i < 0)
        i = -i - 1;

    if (i >= ds.length)
        i = ds.length - 1;

    return m_mapQ.get(ds[i]);
}