From f26bab6a4a152868611499477502dc6f85fb1dd7 Mon Sep 17 00:00:00 2001 From: Luc Maisonobe <luc@orekit.org> Date: Tue, 20 Sep 2016 14:50:30 +0200 Subject: [PATCH] ConstantRefraction does not really need to implement Comparable. --- .../refraction/ConstantRefractionLayer.java | 29 ++----------------- .../rugged/refraction/MultiLayerModel.java | 10 ++++--- 2 files changed, 8 insertions(+), 31 deletions(-) diff --git a/src/main/java/org/orekit/rugged/refraction/ConstantRefractionLayer.java b/src/main/java/org/orekit/rugged/refraction/ConstantRefractionLayer.java index 3b0da0c8..b89f4cd3 100644 --- a/src/main/java/org/orekit/rugged/refraction/ConstantRefractionLayer.java +++ b/src/main/java/org/orekit/rugged/refraction/ConstantRefractionLayer.java @@ -19,8 +19,9 @@ package org.orekit.rugged.refraction; /** * Class that represents a constant refraction layer to be used with {@link MultiLayerModel}. * @author Sergio Esteves + * @since 2.0 */ -public class ConstantRefractionLayer implements Comparable<ConstantRefractionLayer> { +public class ConstantRefractionLayer { /** lowest altitude of this layer. */ private final Double lowestAltitude; @@ -45,30 +46,4 @@ public class ConstantRefractionLayer implements Comparable<ConstantRefractionLay return refractiveIndex; } - @Override - public int compareTo(final ConstantRefractionLayer o) { - return lowestAltitude.compareTo(o.lowestAltitude); - } - - @Override - public boolean equals(final Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - - final ConstantRefractionLayer that = (ConstantRefractionLayer) o; - - if (Double.compare(that.refractiveIndex, refractiveIndex) != 0) return false; - return lowestAltitude != null ? lowestAltitude.equals(that.lowestAltitude) : that.lowestAltitude == null; - - } - - @Override - public int hashCode() { - int result; - long temp; - result = lowestAltitude != null ? lowestAltitude.hashCode() : 0; - temp = Double.doubleToLongBits(refractiveIndex); - result = 31 * result + (int) (temp ^ (temp >>> 32)); - return result; - } } diff --git a/src/main/java/org/orekit/rugged/refraction/MultiLayerModel.java b/src/main/java/org/orekit/rugged/refraction/MultiLayerModel.java index 2d9065f9..87e9df4c 100644 --- a/src/main/java/org/orekit/rugged/refraction/MultiLayerModel.java +++ b/src/main/java/org/orekit/rugged/refraction/MultiLayerModel.java @@ -33,6 +33,7 @@ import java.util.List; /** * Multi layer model for atmospheric refraction. * @author Sergio Esteves, Luc Maisonobe + * @since 2.0 */ public class MultiLayerModel implements AtmosphericRefraction { @@ -73,13 +74,14 @@ public class MultiLayerModel implements AtmosphericRefraction { /** Simple constructor. * @param ellipsoid the ellipsoid to be used. - * @param refractionLayers the refraction layers to be used with this model. + * @param refractionLayers the refraction layers to be used with this model (layers can be in any order). */ public MultiLayerModel(final ExtendedEllipsoid ellipsoid, final List<ConstantRefractionLayer> refractionLayers) { this.ellipsoid = ellipsoid; - this.refractionLayers = refractionLayers; - Collections.sort(this.refractionLayers, Collections.<ConstantRefractionLayer>reverseOrder()); - atmosphereLowestAltitude = refractionLayers.get(refractionLayers.size() - 1).getLowestAltitude(); + this.refractionLayers = new ArrayList<>(refractionLayers); + Collections.sort(this.refractionLayers, + (l1, l2) -> Double.compare(l2.getLowestAltitude(), l1.getLowestAltitude())); + atmosphereLowestAltitude = this.refractionLayers.get(this.refractionLayers.size() - 1).getLowestAltitude(); } /** {@inheritDoc} */ -- GitLab