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.optim.linear;
018    
019    import java.util.Set;
020    import java.util.HashSet;
021    import java.util.Collection;
022    import java.util.Collections;
023    import org.apache.commons.math3.optim.OptimizationData;
024    
025    /**
026     * Class that represents a set of {@link LinearConstraint linear constraints}.
027     *
028     * @version $Id$
029     * @since 3.1
030     */
031    public class LinearConstraintSet implements OptimizationData {
032        /** Set of constraints. */
033        private final Set<LinearConstraint> linearConstraints
034            = new HashSet<LinearConstraint>();
035    
036        /**
037         * Creates a set containing the given constraints.
038         *
039         * @param constraints Constraints.
040         */
041        public LinearConstraintSet(LinearConstraint... constraints) {
042            for (LinearConstraint c : constraints) {
043                linearConstraints.add(c);
044            }
045        }
046    
047        /**
048         * Creates a set containing the given constraints.
049         *
050         * @param constraints Constraints.
051         */
052        public LinearConstraintSet(Collection<LinearConstraint> constraints) {
053            linearConstraints.addAll(constraints);
054        }
055    
056        /**
057         * Gets the set of linear constraints.
058         *
059         * @return the constraints.
060         */
061        public Collection<LinearConstraint> getConstraints() {
062            return Collections.unmodifiableSet(linearConstraints);
063        }
064    }