2
* Licensed to the Apache Software Foundation (ASF) under one or more
3
* contributor license agreements. See the NOTICE file distributed with
4
* this work for additional information regarding copyright ownership.
5
* The ASF licenses this file to You under the Apache License, Version 2.0
6
* (the "License"); you may not use this file except in compliance with
7
* the License. You may obtain a copy of the License at
9
* http://www.apache.org/licenses/LICENSE-2.0
11
* Unless required by applicable law or agreed to in writing, software
12
* distributed under the License is distributed on an "AS IS" BASIS,
13
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
* See the License for the specific language governing permissions and
15
* limitations under the License.
17
package org.apache.commons.math.stat.descriptive.rank;
19
import java.io.Serializable;
21
import org.apache.commons.math.stat.descriptive.AbstractStorelessUnivariateStatistic;
24
* Returns the maximum of the available values.
27
* <li>The result is <code>NaN</code> iff all values are <code>NaN</code>
28
* (i.e. <code>NaN</code> values have no impact on the value of the statistic).</li>
29
* <li>If any of the values equals <code>Double.POSITIVE_INFINITY</code>,
30
* the result is <code>Double.POSITIVE_INFINITY.</code></li>
33
* <strong>Note that this implementation is not synchronized.</strong> If
34
* multiple threads access an instance of this class concurrently, and at least
35
* one of the threads invokes the <code>increment()</code> or
36
* <code>clear()</code> method, it must be synchronized externally.</p>
38
* @version $Revision: 780541 $ $Date: 2009-05-31 20:47:02 -0400 (Sun, 31 May 2009) $
40
public class Max extends AbstractStorelessUnivariateStatistic implements Serializable {
42
/** Serializable version identifier */
43
private static final long serialVersionUID = -5593383832225844641L;
45
/** Number of values that have been added */
48
/** Current value of the statistic */
52
* Create a Max instance
60
* Copy constructor, creates a new {@code Max} identical
61
* to the {@code original}
63
* @param original the {@code Max} instance to copy
65
public Max(Max original) {
73
public void increment(final double d) {
74
if (d > value || Double.isNaN(value)) {
93
public double getResult() {
105
* Returns the maximum of the entries in the specified portion of
106
* the input array, or <code>Double.NaN</code> if the designated subarray
109
* Throws <code>IllegalArgumentException</code> if the array is null or
110
* the array index parameters are not valid.</p>
113
* <li>The result is <code>NaN</code> iff all values are <code>NaN</code>
114
* (i.e. <code>NaN</code> values have no impact on the value of the statistic).</li>
115
* <li>If any of the values equals <code>Double.POSITIVE_INFINITY</code>,
116
* the result is <code>Double.POSITIVE_INFINITY.</code></li>
119
* @param values the input array
120
* @param begin index of the first array element to include
121
* @param length the number of elements to include
122
* @return the maximum of the values or Double.NaN if length = 0
123
* @throws IllegalArgumentException if the array is null or the array index
124
* parameters are not valid
127
public double evaluate(final double[] values, final int begin, final int length) {
128
double max = Double.NaN;
129
if (test(values, begin, length)) {
131
for (int i = begin; i < begin + length; i++) {
132
if (!Double.isNaN(values[i])) {
133
max = (max > values[i]) ? max : values[i];
145
Max result = new Max();
151
* Copies source to dest.
152
* <p>Neither source nor dest can be null.</p>
154
* @param source Max to copy
155
* @param dest Max to copy to
156
* @throws NullPointerException if either source or dest is null
158
public static void copy(Max source, Max dest) {
160
dest.value = source.value;