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

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

Introduction

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

Prototype

public static <T extends Comparable<T>> Range<T> is(final T element) 

Source Link

Document

Obtains a range using the specified element as both the minimum and maximum in this range.

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

Usage

From source file:enumsupport.reverselookupmapfactory.DeduplicatdeNumberSetFactoryTest.java

/**
 * Test of makeSet method, of class DeduplicatdeNumberSetFactory.
 *//*from ww w.ja v  a 2  s .co  m*/
@Test
public void testMakeSet2() {
    LOG.info("makeSet");
    DeduplicatdeNumberSetFactory<Integer> instance = new DeduplicatdeNumberSetFactory<>();
    Set<Integer> expResult = new HashSet<>();
    expResult.add(10);
    Set<Integer> result = instance.makeSet(Range.is(10), 10);
    assertEquals(expResult, result);
}

From source file:enumsupport.reverselookupmapfactory.DeduplicatdeNumberSetFactoryTest.java

/**
 * Test of makeSet method, of class DeduplicatdeNumberSetFactory.
 *//*  w ww.j av  a 2s  .  co  m*/
@Test
@ExpectedExceptionMessage("?null???????")
public void testMakeSet3() {
    LOG.info("makeSet");
    DeduplicatdeNumberSetFactory<Integer> instance = new DeduplicatdeNumberSetFactory<>();
    Set<Integer> result = instance.makeSet(Range.is(10), null, 10);
}

From source file:org.apache.metron.profiler.client.stellar.IntervalPredicate.java

/**
 * Determine if x is in the set of intervals in O(log*n) time.
 * @param x// w  w  w  .  j  a  v a  2  s.  co  m
 * @return true if in the set of intervals and false otherwise.
 */
@Override
public boolean test(T x) {
    long ts = timestampTransformer.apply(x);
    int pos = Collections.binarySearch(intervals, Range.is(ts), INTERVAL_COMPARATOR);
    if (pos < 0) {
        pos = -pos - 1;
    }

    Optional<Range<Long>> right = pos >= 0 && pos < intervals.size() ? Optional.of(intervals.get(pos))
            : Optional.empty();
    Optional<Range<Long>> left = pos - 1 >= 0 && pos - 1 < intervals.size()
            ? Optional.of(intervals.get(pos - 1))
            : Optional.empty();
    return (right.isPresent() ? containsInclusive(right.get(), ts) : false)
            || (left.isPresent() ? containsInclusive(left.get(), ts) : false);
}

From source file:org.kalypso.model.wspm.core.profil.impl.RangeSelection.java

@Override
public void setActivePoints(final IProfileRecord... points) {
    if (ArrayUtils.getLength(points) == 1) {
        final IProfileRecord point = points[0];
        final Double width = point.getBreite();
        if (Objects.isNull(width))
            return;
        setRange(Range.is(width));

        setActivePointsInternal(point);//from  w w w. j  a va  2  s  .  c  o  m
    } else {
        setActivePointsInternal(points);

        final FindMinMaxVisitor visitor = new FindMinMaxVisitor(IWspmConstants.POINT_PROPERTY_BREITE);
        ProfileVisitors.visit(visitor, points);

        final Double min = visitor.getMinimum().getBreite();
        final Double max = visitor.getMaximum().getBreite();
        if (Objects.allNull(min, max))
            return;
        else if (Objects.isNull(min, max))
            setRange(Range.is(Objects.firstNonNull(min, max)));
        else
            setRange(Range.between(min, max));
    }
}

From source file:org.kalypso.model.wspm.core.profil.wrappers.ProfileRecord.java

@Override
public Range<Double> getBreiteAsRange() {
    return Range.is(getBreite());
}

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;//from w w  w. j  a  v a 2  s . com

    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;/*  ww w .  j  a  v  a2  s  .  co m*/

    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//  ww  w.ja va 2 s  .  co 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;
}