    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    package org.apache.commons.math3.linear;
    018
    019    import org.apache.commons.math3.exception.NumberIsTooSmallException;
    020    import org.apache.commons.math3.exception.util.LocalizedFormats;
    021    import org.apache.commons.math3.exception.util.ExceptionContext;
    022
    023    /**
    024     * Exception to be thrown when a positive definite matrix is expected.
    025     *
    026     * @since 3.0
    027     * @version $Id: NonPositiveDefiniteMatrixException.java 1416643 2012-12-03 19:37:14Z tn $
    028     */
    029    public class NonPositiveDefiniteMatrixException extends NumberIsTooSmallException {
    030        /** Serializable version Id. */
    031        private static final long serialVersionUID = 1641613838113738061L;
    032        /** Index (diagonal element). */
    033        private final int index;
    034        /** Threshold. */
    035        private final double threshold;
    036
    037        /**
    038         * Construct an exception.
    039         *
    040         * @param wrong Value that fails the positivity check.
    041         * @param index Row (and column) index.
    042         * @param threshold Absolute positivity threshold.
    043         */
    044        public NonPositiveDefiniteMatrixException(double wrong,
    045                                                  int index,
    046                                                  double threshold) {
    047            super(wrong, threshold, false);
    048            this.index = index;
    049            this.threshold = threshold;
    050
    051            final ExceptionContext context = getContext();
    052            context.addMessage(LocalizedFormats.NOT_POSITIVE_DEFINITE_MATRIX);
    053            context.addMessage(LocalizedFormats.ARRAY_ELEMENT, wrong, index);
    054        }
    055
    056        /**
    057         * @return the row index.
    058         */
    059        public int getRow() {
    060            return index;
    061        }
    062        /**
    063         * @return the column index.
    064         */
    065        public int getColumn() {
    066            return index;
    067        }
    068        /**
    069         * @return the absolute positivity threshold.
    070         */
    071        public double getThreshold() {
    072            return threshold;
    073        }
    074    }