001/*
002 *  Unit-Lib - Units of Measurement Library for Java
003 * Copyright (c) 2005-2016, Jean-Marie Dautelle, Werner Keil, V2COM.
004 *
005 * All rights reserved.
006 *
007 * Redistribution and use in source and binary forms, with or without modification,
008 * are permitted provided that the following conditions are met:
009 *
010 * 1. Redistributions of source code must retain the above copyright notice,
011 *    this list of conditions and the following disclaimer.
012 *
013 * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions
014 *    and the following disclaimer in the documentation and/or other materials provided with the distribution.
015 *
016 * 3. Neither the name of JSR-363 nor the names of its contributors may be used to endorse or promote products
017 *    derived from this software without specific prior written permission.
018 *
019 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
020 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
021 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
022 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
023 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
024 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
025 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
026 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
027 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
028 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
029 */
030package tec.uom.lib.common;
031
032import javax.measure.Quantity;
033import javax.measure.Unit;
034
035/**
036 * <p>
037 * This class provides support for common binary prefixes to be used by units.
038 * </p>
039 *
040 * @author <a href="mailto:units@catmedia.us">Werner Keil</a>
041 * @version 1.0, October 13, 2016
042 * @see <a href="https://en.wikipedia.org/wiki/Binary_prefix">Wikipedia: Binary
043 *      Prefix</a>
044 */
045public final class BinaryPrefix {
046
047    /**
048     * DefaultQuantityFactory constructor (private).
049     */
050    private BinaryPrefix() {
051        // Utility class no visible constructor.
052    }
053
054    /**
055     * Returns the specified unit multiplied by the factor <code>1024</code>
056     * (binary prefix).
057     * 
058     * @param unit
059     *            any unit.
060     * @return <code>unit.multiply(1024)</code>.
061     */
062    public static <Q extends Quantity<Q>> Unit<Q> KIBI(Unit<Q> unit) {
063        return unit.multiply(1024);
064    }
065
066    /**
067     * Returns the specified unit multiplied by the factor
068     * <code>1024<sup>2</sup></code> (binary prefix).
069     * 
070     * @param unit
071     *            any unit.
072     * @return <code>unit.multiply(1048576)</code>.
073     */
074    public static <Q extends Quantity<Q>> Unit<Q> MEBI(Unit<Q> unit) {
075        return unit.multiply(1048576);
076    }
077
078    /**
079     * Returns the specified unit multiplied by the factor
080     * <code>1024<sup>3</sup></code> (binary prefix).
081     * 
082     * @param unit
083     *            any unit.
084     * @return <code>unit.multiply(1073741824)</code>.
085     */
086    public static <Q extends Quantity<Q>> Unit<Q> GIBI(Unit<Q> unit) {
087        return unit.multiply(1073741824);
088    }
089
090    /**
091     * Returns the specified unit multiplied by the factor
092     * <code>1024<sup>4</sup></code> (binary prefix).
093     * 
094     * @param unit
095     *            any unit.
096     * @return <code>unit.multiply(1099511627776L)</code>.
097     */
098    public static <Q extends Quantity<Q>> Unit<Q> TEBI(Unit<Q> unit) {
099        return unit.multiply(1099511627776L);
100    }
101
102    /**
103     * Returns the specified unit multiplied by the factor
104     * <code>1024<sup>5</sup></code> (binary prefix).
105     * 
106     * @param unit
107     *            any unit.
108     * @return <code>unit.multiply(1125899906842624L)</code>.
109     */
110    public static <Q extends Quantity<Q>> Unit<Q> PEBI(Unit<Q> unit) {
111        return unit.multiply(1125899906842624L);
112    }
113
114    /**
115     * Returns the specified unit multiplied by the factor
116     * <code>1024<sup>6</sup></code> (binary prefix).
117     * 
118     * @param unit
119     *            any unit.
120     * @return <code>unit.multiply(1152921504606846976L)</code>.
121     */
122    public static <Q extends Quantity<Q>> Unit<Q> EXBI(Unit<Q> unit) {
123        return unit.multiply(1152921504606846976L);
124    }
125
126    /**
127     * Returns the specified unit multiplied by the factor
128     * <code>1024<sup>7</sup></code> (binary prefix).
129     * 
130     * @param unit
131     *            any unit.
132     * @return <code>unit.multiply(1152921504606846976d)</code>.
133     */
134    public static <Q extends Quantity<Q>> Unit<Q> ZEBI(Unit<Q> unit) {
135        return unit.multiply(1180591620717411303424d);
136    }
137
138    /**
139     * Returns the specified unit multiplied by the factor
140     * <code>1024<sup>8</sup></code> (binary prefix).
141     * 
142     * @param unit
143     *            any unit.
144     * @return <code>unit.multiply(1208925819614629174706176d)</code>.
145     */
146    public static <Q extends Quantity<Q>> Unit<Q> YOBI(Unit<Q> unit) {
147        return unit.multiply(1208925819614629174706176d);
148    }
149}