format & docs
[storage-units.git] / storage-units-model / src / main / java / wtf / metio / storageunits / model / Exbibyte.java
blobf6e456ac65bc9f3688f5ab4561c15c3b7889402f
1 /*
2 * SPDX-FileCopyrightText: The Storage-Units Authors
3 * SPDX-License-Identifier: 0BSD
4 */
5 package wtf.metio.storageunits.model;
7 import edu.umd.cs.findbugs.annotations.CheckReturnValue;
8 import org.jetbrains.annotations.NotNull;
10 import java.io.Serial;
11 import java.math.BigInteger;
12 import java.util.function.Function;
14 /**
15 * Exbibyte as specified in ISO IEC 80000-13:2008 (1 Exbibyte = 1 152 921 504 606 846 976 Byte).
17 public final class Exbibyte extends StorageUnit<Exbibyte> {
19 @Serial
20 private static final long serialVersionUID = 5993490571003918471L;
22 Exbibyte(@NotNull final BigInteger bytes) {
23 super(bytes);
26 /**
27 * @param numberOfBytes The amount of bytes the Exbibyte contains.
28 * @return A new Exbibyte unit with the given value.
30 @NotNull
31 @CheckReturnValue
32 public static Exbibyte valueOf(@NotNull final BigInteger numberOfBytes) {
33 return new Exbibyte(numberOfBytes);
36 /**
37 * @param numberOfBytes The amount of bytes the Exbibyte contains.
38 * @return A new Exbibyte unit with the given value.
40 @NotNull
41 @CheckReturnValue
42 public static Exbibyte valueOf(final long numberOfBytes) {
43 return valueOf(BigInteger.valueOf(numberOfBytes));
46 /**
47 * @param numberOfBytes The amount of bytes the Exbibyte contains.
48 * @return A new Exbibyte unit with the given value.
50 @NotNull
51 @CheckReturnValue
52 public static Exbibyte valueOf(@NotNull final Long numberOfBytes) {
53 return valueOf(numberOfBytes.longValue());
56 @Override
57 @NotNull
58 @CheckReturnValue
59 public Exbibyte add(final long bytesToAdd) {
60 return add(BigInteger.valueOf(bytesToAdd));
63 @Override
64 @NotNull
65 @CheckReturnValue
66 public Exbibyte add(@NotNull final BigInteger bytesToAdd) {
67 return new Exbibyte(bytes.add(bytesToAdd));
70 @Override
71 @NotNull
72 @CheckReturnValue
73 public Exbibyte add(@NotNull final StorageUnit<?> storageAmount) {
74 return add(storageAmount.bytes);
77 @Override
78 @NotNull
79 @CheckReturnValue
80 public Exbibyte divide(final long divisor) {
81 return divide(BigInteger.valueOf(divisor));
84 @Override
85 @NotNull
86 @CheckReturnValue
87 public Exbibyte divide(@NotNull final BigInteger divisor) {
88 return new Exbibyte(bytes.divide(divisor));
91 @Override
92 @NotNull
93 @CheckReturnValue
94 public Exbibyte multiply(final long factor) {
95 return new Exbibyte(bytes.multiply(BigInteger.valueOf(factor)));
98 @Override
99 @NotNull
100 @CheckReturnValue
101 public Exbibyte multiply(@NotNull final BigInteger factor) {
102 return new Exbibyte(bytes.multiply(factor));
105 @Override
106 @NotNull
107 @CheckReturnValue
108 public Exbibyte subtract(final long bytesToSubtract) {
109 return new Exbibyte(bytes.subtract(BigInteger.valueOf(bytesToSubtract)));
112 @Override
113 @NotNull
114 @CheckReturnValue
115 public Exbibyte subtract(@NotNull final BigInteger bytesToSubtract) {
116 return new Exbibyte(bytes.subtract(bytesToSubtract));
119 @Override
120 @NotNull
121 @CheckReturnValue
122 public Exbibyte subtract(@NotNull final StorageUnit<?> storageAmount) {
123 return new Exbibyte(bytes.subtract(storageAmount.bytes));
126 @Override
127 @NotNull
128 @CheckReturnValue
129 protected BigInteger getNumberOfBytesPerUnit() {
130 return StorageUnit.BYTES_IN_A_EXBIBYTE;
133 @Override
134 @NotNull
135 @CheckReturnValue
136 protected String getSymbol() {
137 return "EiB";
140 @Override
141 @NotNull
142 @CheckReturnValue
143 protected Function<@NotNull BigInteger, @NotNull StorageUnit<?>> converter() {
144 return StorageUnits::binaryValueOf;