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 * @since 0.9 045 */ 046public final class BinaryPrefix { 047 048 /** 049 * DefaultQuantityFactory constructor (private). 050 */ 051 private BinaryPrefix() { 052 // Utility class no visible constructor. 053 } 054 055 /** 056 * Returns the specified unit multiplied by the factor <code>1024</code> 057 * (binary prefix). 058 * 059 * @param unit 060 * any unit. 061 * @return <code>unit.multiply(1024)</code>. 062 */ 063 public static <Q extends Quantity<Q>> Unit<Q> KIBI(Unit<Q> unit) { 064 return unit.multiply(1024); 065 } 066 067 /** 068 * Returns the specified unit multiplied by the factor 069 * <code>1024<sup>2</sup></code> (binary prefix). 070 * 071 * @param unit 072 * any unit. 073 * @return <code>unit.multiply(1048576)</code>. 074 */ 075 public static <Q extends Quantity<Q>> Unit<Q> MEBI(Unit<Q> unit) { 076 return unit.multiply(1048576); 077 } 078 079 /** 080 * Returns the specified unit multiplied by the factor 081 * <code>1024<sup>3</sup></code> (binary prefix). 082 * 083 * @param unit 084 * any unit. 085 * @return <code>unit.multiply(1073741824)</code>. 086 */ 087 public static <Q extends Quantity<Q>> Unit<Q> GIBI(Unit<Q> unit) { 088 return unit.multiply(1073741824); 089 } 090 091 /** 092 * Returns the specified unit multiplied by the factor 093 * <code>1024<sup>4</sup></code> (binary prefix). 094 * 095 * @param unit 096 * any unit. 097 * @return <code>unit.multiply(1099511627776L)</code>. 098 */ 099 public static <Q extends Quantity<Q>> Unit<Q> TEBI(Unit<Q> unit) { 100 return unit.multiply(1099511627776L); 101 } 102 103 /** 104 * Returns the specified unit multiplied by the factor 105 * <code>1024<sup>5</sup></code> (binary prefix). 106 * 107 * @param unit 108 * any unit. 109 * @return <code>unit.multiply(1125899906842624L)</code>. 110 */ 111 public static <Q extends Quantity<Q>> Unit<Q> PEBI(Unit<Q> unit) { 112 return unit.multiply(1125899906842624L); 113 } 114 115 /** 116 * Returns the specified unit multiplied by the factor 117 * <code>1024<sup>6</sup></code> (binary prefix). 118 * 119 * @param unit 120 * any unit. 121 * @return <code>unit.multiply(1152921504606846976L)</code>. 122 */ 123 public static <Q extends Quantity<Q>> Unit<Q> EXBI(Unit<Q> unit) { 124 return unit.multiply(1152921504606846976L); 125 } 126 127 /** 128 * Returns the specified unit multiplied by the factor 129 * <code>1024<sup>7</sup></code> (binary prefix). 130 * 131 * @param unit 132 * any unit. 133 * @return <code>unit.multiply(1152921504606846976d)</code>. 134 */ 135 public static <Q extends Quantity<Q>> Unit<Q> ZEBI(Unit<Q> unit) { 136 return unit.multiply(1180591620717411303424d); 137 } 138 139 /** 140 * Returns the specified unit multiplied by the factor 141 * <code>1024<sup>8</sup></code> (binary prefix). 142 * 143 * @param unit 144 * any unit. 145 * @return <code>unit.multiply(1208925819614629174706176d)</code>. 146 */ 147 public static <Q extends Quantity<Q>> Unit<Q> YOBI(Unit<Q> unit) { 148 return unit.multiply(1208925819614629174706176d); 149 } 150}