List of usage examples for org.apache.commons.lang3 Range between
public static <T extends Comparable<T>> Range<T> between(final T fromInclusive, final T toInclusive)
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).
From source file:org.kalypso.gml.processes.tin.TinLoadJob.java
@Override protected IStatus run(final IProgressMonitor monitor) { final URL dataLocation = m_triangulatedSurfaceTin.getDataLocation(); final String mimeType = m_triangulatedSurfaceTin.getMimeType(); try {/*from ww w .j a v a 2s . c o m*/ Assert.isTrue("application/gml+xml".equals(mimeType)); //$NON-NLS-1$ final GMLWorkspace workspace = GmlSerializer.createGMLWorkspace(dataLocation, null, monitor); m_surface = (TriangulatedSurfaceFeature) workspace.getRootFeature(); /* Determine min/max */ final GM_TriangulatedSurface triangulatedSurface = m_surface.getTriangulatedSurface(); final MinMaxSurfacePatchVisitor<GM_Triangle> minMaxVisitor = new MinMaxSurfacePatchVisitor<>(); final GM_Envelope surfaceEnvelope = m_surface.getEnvelope(); triangulatedSurface.acceptSurfacePatches(surfaceEnvelope, minMaxVisitor, new NullProgressMonitor()); final BigDecimal min = minMaxVisitor.getMin(); final BigDecimal max = minMaxVisitor.getMax(); m_minMax = Range.between(min, max); return Status.OK_STATUS; } catch (final Exception e) { final String message = String.format(Messages.getString("TinLoadJob_0"), dataLocation); //$NON-NLS-1$ return new Status(IStatus.ERROR, KalypsoGmlProcessesPlugin.PLUGIN_ID, message, e); } }
From source file:org.kalypso.grid.GeoGridUtilities.java
public static Range<BigDecimal> calculateRange(final ICoverage[] coverages) { // get min / max BigDecimal min = new BigDecimal(Double.MAX_VALUE); BigDecimal max = new BigDecimal(-Double.MAX_VALUE); for (final ICoverage coverage : coverages) { try {/*from w w w .j a v a2 s . c om*/ final IGeoGrid geoGrid = GeoGridUtilities.toGrid(coverage); min = min.min(geoGrid.getMin()); max = max.max(geoGrid.getMax()); // dispose it geoGrid.dispose(); } catch (final Exception e) { e.printStackTrace(); } } final BigDecimal rangeMin = min; final BigDecimal rangeMax = max; return Range.between(rangeMin, rangeMax); }
From source file:org.kalypso.kalypsosimulationmodel.core.terrainmodel.HMOTerrainElevationModel.java
private final void parseFile(final URL hmoFileURL) throws CoreException, GM_Exception { final String sourceSrs = m_crs; // TODO: It does not transform anything. The read data will be in the source coordinate system. final HmoTriangulatedSurfaceConverter converter = new HmoTriangulatedSurfaceConverter(sourceSrs); m_surface = converter.convert(hmoFileURL, new NullProgressMonitor()); /* Determine min/max */ final MinMaxSurfacePatchVisitor<GM_Triangle> minMaxVisitor = new MinMaxSurfacePatchVisitor<>(); final GM_Envelope maxBox = m_surface.getEnvelope(); m_surface.acceptSurfacePatches(maxBox, minMaxVisitor, new NullProgressMonitor()); final BigDecimal min = minMaxVisitor.getMin(); final BigDecimal max = minMaxVisitor.getMax(); m_minMax = Range.between(min, max); }
From source file:org.kalypso.model.flood.ui.map.GenerateColorMapAction.java
static Range<BigDecimal> computeTinRange(final ITinReference[] tins) { // get min / max of the selected runoff event // REMARK: use min/max == Double.MAX_VALUE because the range does not support null values BigDecimal event_min = new BigDecimal(Double.MAX_VALUE); BigDecimal event_max = new BigDecimal(-Double.MAX_VALUE); for (final ITinReference tin : tins) { final BigDecimal min = tin.getMin(); if (min != null && min.compareTo(event_min) == -1) { event_min = min;/*from ww w. j av a2 s. co m*/ } final BigDecimal max = tin.getMax(); if (max != null && max.compareTo(event_max) == 1) { event_max = max; } } return Range.between(event_min, event_max); }
From source file:org.kalypso.model.wspm.core.profil.impl.AbstractProfile.java
@Override public void accept(final IProfileRecordVisitor visitor, final Double p1, final Double pn, final boolean includeVertexPoints, final int direction) { accept(visitor, Range.between(p1, pn), includeVertexPoints, direction); }
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));/*from w w w .j av a2 s . c om*/ setActivePointsInternal(point); } 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.visitors.FindPointsBetweenVisitor.java
public FindPointsBetweenVisitor(final double p0, final double pn, final boolean includeVertexPoints) { this(Range.between(p0, pn), includeVertexPoints); }
From source file:org.kalypso.model.wspm.core.profil.visitors.FindPointVisior.java
public FindPointVisior(final double width, final double fuzziness) { m_range = Range.between(width - fuzziness, width + fuzziness); }
From source file:org.kalypso.model.wspm.core.profil.visitors.ProfileVisitors.java
public static IProfileRecord[] findPointsBetween(final IProfile profile, final double p0, final double pn, final boolean includeVertexPoints) { return findPointsBetween(profile, Range.between(p0, pn), includeVertexPoints); }
From source file:org.kalypso.model.wspm.pdb.internal.waterlevel2d.ProjectedWaterlevels.java
/** * Calculate min/max x value of coordinates.<br/> * The returned range is extended in both directions by the width of the real range. *//*from w ww .ja v a2 s . c o m*/ private Range<Double> calculateExtendedWidthRange(final Coordinate[] profileCoordinates) { /* calculate min/max */ double min = Double.MAX_VALUE; double max = -Double.MAX_VALUE; for (final Coordinate coordinate : profileCoordinates) { final double value = coordinate.x; min = Math.min(min, value); max = Math.max(max, value); } /* extend range */ final double distance = max - min; return Range.between(min - distance, max + distance); }