fix #22
[storage-units.git] / storage-units / src / main / java / de / xn__ho_hia / storage_unit / Yobibyte.java
blob654f1f43b2bdb5febec1c954f0daf2c01d9f34bc
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.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 * Yobibyte as specified in ISO IEC 80000-13:2008 (1 Yobibyte = 1 208 925 819 614 629 174 706 176 Byte).
23 public final class Yobibyte extends StorageUnit<Yobibyte> {
25 /** Generated */
26 private static final long serialVersionUID = -5606322878020884194L;
28 Yobibyte(@NonNull final BigInteger bytes) {
29 super(bytes);
32 /**
33 * @param numberOfBytes
34 * The amount of bytes the Yobibyte contains.
35 * @return A new Yobibyte unit with the given value.
37 @NonNull
38 public static Yobibyte valueOf(@NonNull final BigInteger numberOfBytes) {
39 return new Yobibyte(numberOfBytes);
42 /**
43 * @param numberOfBytes
44 * The amount of bytes the Yobibyte contains.
45 * @return A new Yobibyte unit with the given value.
47 @NonNull
48 public static Yobibyte valueOf(final long numberOfBytes) {
49 return new Yobibyte(asBigInteger(numberOfBytes));
52 /**
53 * @param numberOfBytes
54 * The amount of bytes the Yobibyte contains.
55 * @return A new Yobibyte unit with the given value.
57 @NonNull
58 public static Yobibyte valueOf(@NonNull final Long numberOfBytes) {
59 return valueOf(numberOfBytes.longValue());
62 @Override
63 public Yobibyte add(final long bytesToAdd) {
64 return new Yobibyte(addNullsafe(bytes, asBigInteger(bytesToAdd)));
67 @Override
68 public Yobibyte add(final StorageUnit<?> storageAmount) {
69 return new Yobibyte(addNullsafe(bytes, storageAmount.bytes));
72 @Override
73 public Yobibyte divide(final long divisor) {
74 return new Yobibyte(divideNullsafe(bytes, asBigInteger(divisor)));
77 @Override
78 public Yobibyte multiply(final long factor) {
79 return new Yobibyte(multiplyNullsafe(bytes, asBigInteger(factor)));
82 @Override
83 public Yobibyte subtract(final long bytesToSubtract) {
84 return new Yobibyte(subtractNullsafe(bytes, asBigInteger(bytesToSubtract)));
87 @Override
88 public Yobibyte subtract(final StorageUnit<?> storageAmount) {
89 return new Yobibyte(subtractNullsafe(bytes, storageAmount.bytes));
92 @Override
93 protected BigInteger getNumberOfBytesPerUnit() {
94 return StorageUnit.BYTES_IN_A_YOBIBYTE;
97 @Override
98 protected String getSymbol() {
99 return "YiB"; //$NON-NLS-1$
102 @Override
103 protected Function<@NonNull BigInteger, @NonNull StorageUnit<?>> converter() {
104 return StorageUnits::binaryValueOf;