All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.joda.primitives.DoubleUtils Maven / Gradle / Ivy

The newest version!
/*
 *  Copyright 2001-2010 Stephen Colebourne
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */
package org.joda.primitives;

import java.util.Collection;
import java.util.Iterator;

import org.joda.primitives.collection.DoubleCollection;

/**
 * Provides utility methods and constants for double.
 * 
 * @author Stephen Colebourne
 * @author Jason Tiscione
 * @version CODE GENERATED
 * @since 1.0
 */
public class DoubleUtils {
    // This file is CODE GENERATED. Do not change manually.
    
    /**
     * Immutable empty array.
     */
    public static final double[] EMPTY_DOUBLE_ARRAY = new double[0];
    
    /**
     * Constructor that should not usually be used.
     */
    public DoubleUtils() {
        super();
    }

    /**
     * Wraps an double with an Object wrapper.
     * 
     * @param value  the primitive value
     * @return the Object wrapper
     */
    public static Double toObject(double value) {
        return new Double(value);
    }

    /**
     * Unwraps the Double to retrieve the primitive double.
     * 
     * @param value  the Object wrapper, must not be null
     * @return the primitive value
     * @throws NullPointerException if the value if null
     * @throws ClassCastException if the object is not Double
     */
    public static double toPrimitive(Object value) {
        return ((Double) value).doubleValue();
    }

    /**
     * Unwraps a Collection to retrieve the primitive double.
     * 
     * @param coll  the Collection of Double, must not be null
     * @return the primitive value array
     * @throws NullPointerException if the collection if null
     * @throws ClassCastException if any object is not Double
     */
    public static double[] toPrimitiveArray(Collection  coll) {
        if (coll instanceof DoubleCollection) {
            return ((DoubleCollection) coll).toDoubleArray();
        }
        double[] result = new double[coll.size()];
        int i = 0;
        for (Iterator it = coll.iterator(); it.hasNext(); i++) {
            Double value = (Double) it.next();
            result[i] = value.doubleValue();
        }
        return result;
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy