fix #23
[storage-units.git] / src / main / java / de / xn__ho_hia / utils / storage_unit / Tebibyte.java
blob924c97a6dabf3afd07549db5b3e3aeb8bd5e28fc
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.quality.null_analysis.Nullsafe.addNullsafe;
10 import static de.xn__ho_hia.quality.null_analysis.Nullsafe.asBigInteger;
11 import static de.xn__ho_hia.quality.null_analysis.Nullsafe.divideNullsafe;
12 import static de.xn__ho_hia.quality.null_analysis.Nullsafe.multiplyNullsafe;
13 import static de.xn__ho_hia.quality.null_analysis.Nullsafe.subtractNullsafe;
15 import java.math.BigInteger;
16 import java.util.function.Function;
18 import org.eclipse.jdt.annotation.NonNull;
20 /**
21 * Tebibyte as specified in ISO IEC 80000-13:2008 (1 Tebibyte = 1 099 511 627 776 Byte).
23 public final class Tebibyte extends StorageUnit<Tebibyte> {
25 /** Generated */
26 private static final long serialVersionUID = 3614537130129620881L;
28 Tebibyte(@NonNull final BigInteger bytes) {
29 super(bytes);
32 /**
33 * @param numberOfBytes
34 * The amount of bytes the Tebibyte contains.
35 * @return A new Tebibyte unit with the given value.
37 @NonNull
38 public static Tebibyte valueOf(@NonNull final BigInteger numberOfBytes) {
39 return new Tebibyte(numberOfBytes);
42 /**
43 * @param numberOfBytes
44 * The amount of bytes the Tebibyte contains.
45 * @return A new Tebibyte unit with the given value.
47 @NonNull
48 public static Tebibyte valueOf(final long numberOfBytes) {
49 return new Tebibyte(asBigInteger(numberOfBytes));
52 /**
53 * @param numberOfBytes
54 * The amount of bytes the Tebibyte contains.
55 * @return A new Tebibyte unit with the given value.
57 @NonNull
58 public static Tebibyte valueOf(@NonNull final Long numberOfBytes) {
59 return valueOf(numberOfBytes.longValue());
62 @Override
63 public Tebibyte add(final long bytesToAdd) {
64 return new Tebibyte(addNullsafe(bytes, asBigInteger(bytesToAdd)));
67 @Override
68 public Tebibyte add(final StorageUnit<?> storageAmount) {
69 return new Tebibyte(addNullsafe(bytes, storageAmount.bytes));
72 @Override
73 public Tebibyte divide(final long divisor) {
74 return new Tebibyte(divideNullsafe(bytes, asBigInteger(divisor)));
77 @Override
78 public Tebibyte multiply(final long factor) {
79 return new Tebibyte(multiplyNullsafe(bytes, asBigInteger(factor)));
82 @Override
83 public Tebibyte subtract(final long bytesToSubtract) {
84 return new Tebibyte(subtractNullsafe(bytes, asBigInteger(bytesToSubtract)));
87 @Override
88 public Tebibyte subtract(final StorageUnit<?> storageAmount) {
89 return new Tebibyte(subtractNullsafe(bytes, storageAmount.bytes));
92 @Override
93 protected BigInteger getNumberOfBytesPerUnit() {
94 return StorageUnit.BYTES_IN_A_TEBIBYTE;
97 @Override
98 protected String getSymbol() {
99 return "TiB"; //$NON-NLS-1$
102 @Override
103 protected Function<@NonNull BigInteger, @NonNull StorageUnit<?>> converter() {
104 return StorageUnits::binaryValueOf;