Example usage for org.apache.commons.lang3 Range between

List of usage examples for org.apache.commons.lang3 Range between

Introduction

In this page you can find the example usage for org.apache.commons.lang3 Range between.

Prototype

public static <T extends Comparable<T>> Range<T> between(final T fromInclusive, final T toInclusive) 

Source Link

Document

Obtains a range with the specified minimum and maximum values (both inclusive).

The range uses the natural ordering of the elements to determine where values lie in the range.

The arguments may be passed in the order (min,max) or (max,min).

Usage

From source file:org.kalypso.model.wspm.pdb.internal.waterlevel2d.ProjectedWaterlevels.java

private IProfileObject buildWaterlevel2dPart(final LineString waterlevelLine)
        throws MGeometryException, MismatchedDimensionException, FactoryException, TransformException {
    /* prepare to extract original points involved in this waterlevel part */
    final Range<Double> widthRange = Range.between(waterlevelLine.getStartPoint().getX(),
            waterlevelLine.getEndPoint().getX());

    /* create generic part of 2d waterlevel */
    final GenericProfileHorizon waterlevel2D = new GenericProfileHorizon(
            IWspmTuhhConstants.OBJECT_TYPE_WATERLEVEL_SEGMENT);

    /* get description only from involved points */
    final AggregatedWaterlevel aggregator = new AggregatedWaterlevel(m_waterlevels, widthRange);
    final String description = aggregator.getDescription();
    waterlevel2D.setDescription(description);

    /* get discharge only from involved points */
    final BigDecimal discharge = aggregator.getDischarge();
    if (discharge != null)
        waterlevel2D.setValue(IGafConstants.METADATA_WATERLEVEL_DISCHARGE, discharge.toString());

    /* convert to points */
    final IProfileObjectRecords records = waterlevel2D.getRecords();

    final Coordinate[] coordinates = waterlevelLine.getCoordinates();
    for (final Coordinate coordinate : coordinates) {
        final double width = coordinate.x;
        final double height = coordinate.y;

        /* extract location at width from profile */
        final Coordinate location = m_profileLine.getCoordinateAtM(width);

        /* create record and add values */
        final IProfileObjectRecord record = records.addNewRecord();

        record.setBreite(width);//from   w  w w .  j  av  a 2s.c o  m
        record.setHoehe(height);
        record.setComment(null);

        // FIXME: extrapolate location if outside profile
        if (location != null) {
            record.setRechtswert(location.x);
            record.setHochwert(location.y);
        }

        // FIXME: WS is of kind W, not W2
        record.setCode(GafPointCode.WS.getKey());
    }

    return waterlevel2D;
}

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

private void init() throws GMLSchemaException, GM_Exception {
    if (m_triangleWorkspace != null || m_breaklinesWorkspace != null)
        return;//w  w w .j a  v  a  2  s.  co  m

    final Map<Double, Double> wspMap = BreakLinesHelper.createWspMap(m_result, m_componentStation,
            m_componentWaterlevel);
    if (m_segments.length == 0)
        return;

    m_triangleWorkspace = FeatureFactory
            .createGMLWorkspace(new QName(NS_WSPMCOMMONS, "TriangulatedSurfaceFeature"), null, null); //$NON-NLS-1$
    final String defaultCrs = KalypsoDeegreePlugin.getDefault().getCoordinateSystem();
    final GM_TriangulatedSurface surface = org.kalypsodeegree_impl.model.geometry.GeometryFactory
            .createGM_TriangulatedSurface(defaultCrs);
    final Feature triangleFeature = m_triangleWorkspace.getRootFeature();
    triangleFeature.setProperty(new QName(NS_WSPMCOMMONS, "triangulatedSurfaceMember"), surface); //$NON-NLS-1$
    // TODO: set tin name
    NamedFeatureHelper.setDescription(triangleFeature, Messages.getString("BreakLinesHelper.0")); //$NON-NLS-1$
    NamedFeatureHelper.setName(triangleFeature, Messages.getString("BreakLinesHelper.1")); //$NON-NLS-1$
    triangleFeature.setProperty(new QName(NS_WSPMCOMMONS, "unit"), "NN+m"); //$NON-NLS-1$ //$NON-NLS-2$
    triangleFeature.setProperty(new QName(NS_WSPMCOMMONS, "parameter"), "h"); //$NON-NLS-1$ //$NON-NLS-2$
    triangleFeature.setProperty(new QName(NS_WSPMCOMMONS, "date"), //$NON-NLS-1$
            DateUtilities.toXMLGregorianCalendar(new Date()));

    m_breaklinesWorkspace = FeatureFactory
            .createGMLWorkspace(new QName(NS_WSPM_BREAKLINE, "BreaklineCollection"), null, null); //$NON-NLS-1$
    final Feature rootFeature = m_breaklinesWorkspace.getRootFeature();

    final String gmlVersion = rootFeature.getFeatureType().getGMLSchema().getGMLVersion();

    // debug
    GM_Curve lastProfile = null;
    Range<Double> range = null;
    for (final TuhhReachProfileSegment reach : m_segments) {
        final GM_Curve geometry = reach.getGeometry();
        final BigDecimal station = reach.getStation();
        if (geometry == null) // ignore profiles without geometry
            continue;

        final Double wsp = wspMap.get(station.doubleValue());

        final GM_Curve thinProfile = thinnedOutClone(geometry, m_epsThinning, gmlVersion);
        if (wsp != null) {
            if (range == null)
                range = Range.is(wsp);
            else
                range = Range.between(Math.min(wsp, range.getMinimum()), Math.max(wsp, range.getMaximum()));

            // ignore profiles without result (no value in length section). This can occur if the
            // simulation does not cover the whole reach.
            final GM_Curve newProfile = GeometryUtilities.setValueZ(thinProfile.getAsLineString(), wsp);

            /* Triangulate two adjacent profiles */
            if (lastProfile != null) {
                final GM_Position[] polygonPosesClosed = GeometryUtilities.getPolygonfromCurves(lastProfile,
                        newProfile);

                // Write the curve as breakline into breakline file
                final GM_Curve polygoneRing = GeometryFactory.createGM_Curve(polygonPosesClosed, defaultCrs);
                final Feature ringFeature = FeatureHelper.addFeature(rootFeature,
                        new QName(NS_WSPM_BREAKLINE, "breaklineMember"), //$NON-NLS-1$
                        new QName(NS_WSPM_BREAKLINE, "Breakline")); //$NON-NLS-1$
                ringFeature.setProperty(new QName(NS_WSPM_BREAKLINE, "geometry"), polygoneRing); //$NON-NLS-1$
                ringFeature.setProperty(new QName(NS_WSPM_BREAKLINE, "station"), station); //$NON-NLS-1$
                ringFeature.setProperty(new QName(NS_WSPM_BREAKLINE, "wsp"), wsp); //$NON-NLS-1$

                // Interpolate triangles between two adjacent curves and add them to the triangulated surface
                final GM_Position[] polygonPosesOpen = ArrayUtils.remove(polygonPosesClosed,
                        polygonPosesClosed.length - 1);
                final GM_Position[][] triangles = GeometryUtilities.triangulateRing(polygonPosesOpen);
                for (final GM_Position[] triangle : triangles) {
                    final GM_Triangle gmTriangle = GeometryFactory.createGM_Triangle(triangle, defaultCrs);
                    surface.add(gmTriangle);
                }
            }

            lastProfile = newProfile;
        }
    }

    m_range = range;
}

From source file:org.kalypso.model.wspm.ui.action.selection.AbstractProfilePointSelectionWidget.java

private void updateSelection(final boolean shiftDown) {
    if (m_viewMode)
        return;/*from w  w  w. ja  v a 2 s  .  c  om*/

    if (Objects.isNull(getProfile()))
        return;

    try {
        final IProfile profile = getProfile().getProfile();
        final IRangeSelection selection = profile.getSelection();

        final Double cursor = selection.getCursor();
        if (Objects.isNull(cursor))
            return;

        if (shiftDown) {
            final double p0 = Profiles.getWidth(profile, m_p0);
            selection.setRange(Range.between(p0, cursor));
        } else {
            selection.setRange(Range.is(cursor));
        }
    } catch (final GM_Exception e) {
        e.printStackTrace();
    } catch (final IllegalStateException e) {
        // if point is not on line
    }
}

From source file:org.kalypso.model.wspm.ui.commands.UpdateProfileSelectionChartHandler.java

@SuppressWarnings("rawtypes")
@Override/*w  ww .  j a  v  a2s  .  c o m*/
public void mouseUp(final MouseEvent e) {
    final IProfilChartLayer theme = SelectionChartHandlerHelper.findProfileTheme(getChart());
    if (theme == null) {
        m_p0 = null;
        m_p1 = null;
        return;
    }
    final ICoordinateMapper mapper = theme.getCoordinateMapper();
    final IAxis domAxis = mapper.getDomainAxis();
    final IProfile profile = theme.getProfil();
    final boolean isClicked = m_p1 == null || Math.abs(m_p0 - m_p1) < 5;
    final Double x1 = domAxis.screenToNumeric(m_p0);
    final Double x2 = isClicked ? x1 : domAxis.screenToNumeric(m_p1);
    final IRangeSelection selection = profile.getSelection();

    if (isClicked) {
        selection.setRange(Range.is(x1));
    } else {
        selection.setRange(Range.between(x1, x2));
    }
    m_p0 = null;
    m_p1 = null;
}

From source file:org.kalypso.model.wspm.ui.view.chart.layer.wsp.WaterlevelRenderWorker.java

private WaterlevelRenderSegment buildSegment(final LineSegment segment, final Range<Double> restriction)
        throws Exception {
    final Range<Double> segmentRange = Range.between(segment.p0.x, segment.p1.x);
    if (restriction != null && !segmentRange.isOverlappedBy(restriction))
        return null;

    final Polygon area = buildSegmentArea(segment);

    return new WaterlevelRenderSegment(segment, area);
}

From source file:org.kalypso.model.wspm.ui.view.chart.layer.wsp.WaterlevelRenderWorker.java

private Range<Double> getRestriction() {
    final String markerType = WspmUiPreferences.getWaterlevelRestrictionMarker();
    final IProfilePointMarker[] markers = m_profile.getPointMarkerFor(markerType);

    if (ArrayUtils.isEmpty(markers))
        return null;

    final double leftLimit = findLimit(markers, 0);
    final double rightLimit = findLimit(markers, markers.length - 1);

    if (Double.isNaN(leftLimit) || Double.isNaN(rightLimit))
        return null;

    return Range.between(leftLimit, rightLimit);
}

From source file:org.kalypso.ui.rrm.internal.timeseries.view.imports.ValidateRuecksprungVisitor.java

@Override
public void visit(final IObservationValueContainer container) throws SensorException {
    final IAxis dateAxis = AxisUtils.findDateAxis(container.getAxes());
    final Date date = (Date) container.get(dateAxis);

    if (Objects.isNotNull(m_lastDate)) {
        if (date.before(m_lastDate)) {
            if (m_ptrRuecksprung == -1)
                m_ptrRuecksprung = container.getIndex();
        } else {//from  w w  w. j  a v a2 s.  c om
            if (m_ptrRuecksprung != -1) {
                m_rueckspruenge.add(Range.between(m_ptrRuecksprung, container.getIndex()));
                m_ptrRuecksprung = -1;

                final SimpleDateFormat sdf = new SimpleDateFormat(
                        Messages.getString(Messages.getString("ValidateRuecksprungVisitor.0"))); //$NON-NLS-1$
                final TimeZone timezone = MetadataHelper.getTimeZone(container.getMetaData(),
                        KalypsoCorePlugin.getDefault().getTimeZone().getID());
                sdf.setTimeZone(timezone);

                final String msg = String.format(Messages.getString("ValidateRuecksprungVisitor.1"), //$NON-NLS-1$
                        sdf.format(m_lastDate), sdf.format(date));
                m_stati.add(IStatus.WARNING, msg);
            }

            m_lastDate = date;
        }

    } else
        m_lastDate = date;

}

From source file:org.kalypsodeegree.model.elevation.ElevationUtilities.java

public static Range<Double> calculateRange(final ICoverage[] coverages) {
    // get min / max
    double min = Double.MAX_VALUE;
    double max = -Double.MAX_VALUE;

    for (final ICoverage coverage : coverages) {
        try {//w  w  w .j  a  v a  2 s  .  c om
            final IElevationModel model = toElevationModel(coverage);
            min = Math.min(min, model.getMinElevation());
            max = Math.max(max, model.getMaxElevation());

            // dispose it
            model.dispose();
        } catch (final Exception e) {
            e.printStackTrace();
        }
    }

    return Range.between(min, max);
}

From source file:org.kalypsodeegree_impl.model.geometry.GM_TriangulatedSurface_Impl.java

private void buildStatistics() throws ElevationException {
    if (m_hasStatistics)
        return;/*from  ww w  .  jav a  2  s.  co  m*/
    final MinMaxSurfacePatchVisitor<GM_Triangle> minMaxVisitor = new MinMaxSurfacePatchVisitor<>();
    final GM_Envelope maxBox = getEnvelope();
    try {
        acceptSurfacePatches(maxBox, minMaxVisitor, new NullProgressMonitor());
    } catch (final CoreException e) {
        throw new ElevationException(e.getStatus().getMessage(), e);
    }

    final BigDecimal min = minMaxVisitor.getMin();
    final BigDecimal max = minMaxVisitor.getMax();

    m_minMax = Range.between(min, max);
}

From source file:Utils.Distribution.ComparableDistribution.java

/**
 * Create a new distribution only containing objects between lower and upper
 * @param lower The lower object/*from w w  w . j  a  v  a2  s  .  c  om*/
 * @param upper The upper object
 * @return The new distribution
 */
public ComparableDistribution<V> limitTo(V lower, V upper) {
    Range<V> range = Range.between(lower, upper);
    CountMap<V> newmap = new CountMap<>();
    super.allCounts().filter(p -> range.contains(p.getLeft()))
            .forEach(p -> newmap.add(p.getLeft(), p.getRight()));
    return new ComparableDistribution<>(newmap);
}