SSJ API Documentation
Stochastic Simulation in Java
Loading...
Searching...
No Matches
DoubleArrayComparator.java
1/*
2 * Class: DoubleArrayComparator
3 * Description: Compares two double's arrays
4 * Environment: Java
5 * Software: SSJ
6 * Copyright (C) 2001 Pierre L'Ecuyer and Universite de Montreal
7 * Organization: DIRO, Universite de Montreal
8 * @author
9 * @since
10 *
11 *
12 * Licensed under the Apache License, Version 2.0 (the "License");
13 * you may not use this file except in compliance with the License.
14 * You may obtain a copy of the License at
15 *
16 * http://www.apache.org/licenses/LICENSE-2.0
17 *
18 * Unless required by applicable law or agreed to in writing, software
19 * distributed under the License is distributed on an "AS IS" BASIS,
20 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21 * See the License for the specific language governing permissions and
22 * limitations under the License.
23 *
24 */
25package umontreal.ssj.util.multidimsort;
26
27import java.util.Comparator;
28
40public class DoubleArrayComparator implements Comparator<double[]> {
41 private int j;
42
49 public DoubleArrayComparator(int j) {
50 this.j = j;
51 }
52
60 public int compare(double[] d1, double[] d2) {
61 if (j >= d1.length || j >= d2.length)
62 throw new IllegalArgumentException("Comparing in a" + "dimension larger than array dimension");
63 return (d1[j] < d2[j] ? -1 : (d1[j] > d2[j] ? 1 : 0));
64 }
65
66}
DoubleArrayComparator(int j)
Constructs a comparator, where j is the coordinate used for the comparisons.
int compare(double[] d1, double[] d2)
Returns , , or depending on whether d1[j] is less than, equal to, or greater than d2[j].