Add number of bytes per unit to javadoc + test
[storage-units.git] / src / main / java / com / github / sebhoss / units / storage / Tebibyte.java
blob577059ff9eb947a9780ea2edf11b7a2f2b2a5a84
1 /*
2 * This is free and unencumbered software released into the public domain.
4 * Anyone is free to copy, modify, publish, use, compile, sell, or
5 * distribute this software, either in source code form or as a compiled
6 * binary, for any purpose, commercial or non-commercial, and by any
7 * means.
9 * In jurisdictions that recognize copyright laws, the author or authors
10 * of this software dedicate any and all copyright interest in the
11 * software to the public domain. We make this dedication for the benefit
12 * of the public at large and to the detriment of our heirs and
13 * successors. We intend this dedication to be an overt act of
14 * relinquishment in perpetuity of all present and future rights to this
15 * software under copyright law.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
20 * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
21 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
22 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23 * OTHER DEALINGS IN THE SOFTWARE.
25 * For more information, please refer to <http://unlicense.org>
27 package com.github.sebhoss.units.storage;
29 import java.math.BigInteger;
31 /**
32 * Tebibyte as specified in ISO IEC 80000-13:2008 (1 Tebibyte = 1 099 511 627 776 Byte).
34 public final class Tebibyte extends StorageUnit<Tebibyte> {
36 /** Generated */
37 private static final long serialVersionUID = 3614537130129620881L;
39 Tebibyte(final BigInteger bytes) {
40 super(bytes);
43 /**
44 * @param numberOfBytes
45 * The amount of bytes the tebibyte contains.
46 * @return A new Tebibyte unit with the given value.
48 public static Tebibyte valueOf(final BigInteger numberOfBytes) {
49 return new Tebibyte(numberOfBytes);
52 /**
53 * @param numberOfBytes
54 * The amount of bytes the tebibytes contains.
55 * @return A new Tebibyte unit with the given value.
57 public static Tebibyte valueOf(final long numberOfBytes) {
58 return new Tebibyte(BigInteger.valueOf(numberOfBytes));
61 /**
62 * @param numberOfBytes
63 * The amount of bytes the tebibytes contains.
64 * @return A new Tebibyte unit with the given value.
66 public static Tebibyte valueOf(final Long numberOfBytes) {
67 return valueOf(numberOfBytes.longValue());
70 @Override
71 public Tebibyte add(final long bytesToAdd) {
72 return new Tebibyte(bytes.add(BigInteger.valueOf(bytesToAdd)));
75 @Override
76 public Tebibyte add(final StorageUnit<?> storageAmount) {
77 return new Tebibyte(bytes.add(storageAmount.bytes));
80 @Override
81 public Tebibyte divide(final long divisor) {
82 return new Tebibyte(bytes.divide(BigInteger.valueOf(divisor)));
85 @Override
86 public Tebibyte multiply(final long factor) {
87 return new Tebibyte(bytes.multiply(BigInteger.valueOf(factor)));
90 @Override
91 public Tebibyte subtract(final long bytesToSubtract) {
92 return new Tebibyte(bytes.subtract(BigInteger.valueOf(bytesToSubtract)));
95 @Override
96 public Tebibyte subtract(final StorageUnit<?> storageAmount) {
97 return new Tebibyte(bytes.subtract(storageAmount.bytes));
100 @Override
101 protected BigInteger getNumberOfBytesPerUnit() {
102 return StorageUnit.BYTES_IN_A_TEBIBYTE;
105 @Override
106 protected String getSymbol() {
107 return "TiB"; //$NON-NLS-1$