001/*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements.  See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License.  You may obtain a copy of the License at
008 *
009 *      http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017
018package org.apache.commons.math3.optimization;
019
020import java.io.Serializable;
021
022import org.apache.commons.math3.util.Pair;
023
024/**
025 * This class holds a point and the vectorial value of an objective function at
026 * that point.
027 *
028 * @see PointValuePair
029 * @see org.apache.commons.math3.analysis.MultivariateVectorFunction
030 * @deprecated As of 3.1 (to be removed in 4.0).
031 * @since 3.0
032 */
033@Deprecated
034public class PointVectorValuePair extends Pair<double[], double[]> implements Serializable {
035
036    /** Serializable UID. */
037    private static final long serialVersionUID = 20120513L;
038
039    /**
040     * Builds a point/objective function value pair.
041     *
042     * @param point Point coordinates. This instance will store
043     * a copy of the array, not the array passed as argument.
044     * @param value Value of the objective function at the point.
045     */
046    public PointVectorValuePair(final double[] point,
047                                final double[] value) {
048        this(point, value, true);
049    }
050
051    /**
052     * Build a point/objective function value pair.
053     *
054     * @param point Point coordinates.
055     * @param value Value of the objective function at the point.
056     * @param copyArray if {@code true}, the input arrays will be copied,
057     * otherwise they will be referenced.
058     */
059    public PointVectorValuePair(final double[] point,
060                                final double[] value,
061                                final boolean copyArray) {
062        super(copyArray ?
063              ((point == null) ? null :
064               point.clone()) :
065              point,
066              copyArray ?
067              ((value == null) ? null :
068               value.clone()) :
069              value);
070    }
071
072    /**
073     * Gets the point.
074     *
075     * @return a copy of the stored point.
076     */
077    public double[] getPoint() {
078        final double[] p = getKey();
079        return p == null ? null : p.clone();
080    }
081
082    /**
083     * Gets a reference to the point.
084     *
085     * @return a reference to the internal array storing the point.
086     */
087    public double[] getPointRef() {
088        return getKey();
089    }
090
091    /**
092     * Gets the value of the objective function.
093     *
094     * @return a copy of the stored value of the objective function.
095     */
096    @Override
097    public double[] getValue() {
098        final double[] v = super.getValue();
099        return v == null ? null : v.clone();
100    }
101
102    /**
103     * Gets a reference to the value of the objective function.
104     *
105     * @return a reference to the internal array storing the value of
106     * the objective function.
107     */
108    public double[] getValueRef() {
109        return super.getValue();
110    }
111
112    /**
113     * Replace the instance with a data transfer object for serialization.
114     * @return data transfer object that will be serialized
115     */
116    private Object writeReplace() {
117        return new DataTransferObject(getKey(), getValue());
118    }
119
120    /** Internal class used only for serialization. */
121    private static class DataTransferObject implements Serializable {
122        /** Serializable UID. */
123        private static final long serialVersionUID = 20120513L;
124        /**
125         * Point coordinates.
126         * @Serial
127         */
128        private final double[] point;
129        /**
130         * Value of the objective function at the point.
131         * @Serial
132         */
133        private final double[] value;
134
135        /** Simple constructor.
136         * @param point Point coordinates.
137         * @param value Value of the objective function at the point.
138         */
139        public DataTransferObject(final double[] point, final double[] value) {
140            this.point = point.clone();
141            this.value = value.clone();
142        }
143
144        /** Replace the deserialized data transfer object with a {@link PointValuePair}.
145         * @return replacement {@link PointValuePair}
146         */
147        private Object readResolve() {
148            return new PointVectorValuePair(point, value, false);
149        }
150    }
151}