update to latest parent & fix null issues
[storage-units.git] / src / main / java / de / xn__ho_hia / utils / storage_unit / Tebibyte.java
blob84edcb6cf05e889764f6bf909e06a05e3eedcaf1
1 /*
2 * This file is part of storage-units. It is subject to the license terms in the LICENSE file found in the top-level
3 * directory of this distribution and at http://creativecommons.org/publicdomain/zero/1.0/. No part of storage-units,
4 * including this file, may be copied, modified, propagated, or distributed except according to the terms contained
5 * in the LICENSE file.
6 */
7 package de.xn__ho_hia.utils.storage_unit;
9 import static de.xn__ho_hia.utils.storage_unit.NullsafeMath.addNullsafe;
10 import static de.xn__ho_hia.utils.storage_unit.NullsafeMath.asBigInteger;
11 import static de.xn__ho_hia.utils.storage_unit.NullsafeMath.divideNullsafe;
12 import static de.xn__ho_hia.utils.storage_unit.NullsafeMath.multiplyNullsafe;
13 import static de.xn__ho_hia.utils.storage_unit.NullsafeMath.subtractNullsafe;
15 import java.math.BigInteger;
17 /**
18 * Tebibyte as specified in ISO IEC 80000-13:2008 (1 Tebibyte = 1 099 511 627 776 Byte).
20 public final class Tebibyte extends StorageUnit<Tebibyte> {
22 /** Generated */
23 private static final long serialVersionUID = 3614537130129620881L;
25 Tebibyte(final BigInteger bytes) {
26 super(bytes);
29 /**
30 * @param numberOfBytes
31 * The amount of bytes the tebibyte contains.
32 * @return A new Tebibyte unit with the given value.
34 public static Tebibyte valueOf(final BigInteger numberOfBytes) {
35 return new Tebibyte(numberOfBytes);
38 /**
39 * @param numberOfBytes
40 * The amount of bytes the tebibytes contains.
41 * @return A new Tebibyte unit with the given value.
43 public static Tebibyte valueOf(final long numberOfBytes) {
44 return new Tebibyte(asBigInteger(numberOfBytes));
47 /**
48 * @param numberOfBytes
49 * The amount of bytes the tebibytes contains.
50 * @return A new Tebibyte unit with the given value.
52 public static Tebibyte valueOf(final Long numberOfBytes) {
53 return valueOf(numberOfBytes.longValue());
56 @Override
57 public Tebibyte add(final long bytesToAdd) {
58 return new Tebibyte(addNullsafe(bytes, asBigInteger(bytesToAdd)));
61 @Override
62 public Tebibyte add(final StorageUnit<?> storageAmount) {
63 return new Tebibyte(addNullsafe(bytes, storageAmount.bytes));
66 @Override
67 public Tebibyte divide(final long divisor) {
68 return new Tebibyte(divideNullsafe(bytes, asBigInteger(divisor)));
71 @Override
72 public Tebibyte multiply(final long factor) {
73 return new Tebibyte(multiplyNullsafe(bytes, asBigInteger(factor)));
76 @Override
77 public Tebibyte subtract(final long bytesToSubtract) {
78 return new Tebibyte(subtractNullsafe(bytes, asBigInteger(bytesToSubtract)));
81 @Override
82 public Tebibyte subtract(final StorageUnit<?> storageAmount) {
83 return new Tebibyte(subtractNullsafe(bytes, storageAmount.bytes));
86 @Override
87 protected BigInteger getNumberOfBytesPerUnit() {
88 return StorageUnit.BYTES_IN_A_TEBIBYTE;
91 @Override
92 protected String getSymbol() {
93 return "TiB"; //$NON-NLS-1$