2 * SPDX-FileCopyrightText: The Storage-Units Authors
3 * SPDX-License-Identifier: 0BSD
5 package wtf
.metio
.storageunits
.model
;
7 import com
.google
.errorprone
.annotations
.CheckReturnValue
;
8 import org
.jetbrains
.annotations
.NotNull
;
10 import java
.io
.Serial
;
11 import java
.math
.BigInteger
;
12 import java
.util
.function
.Function
;
15 * Kilobyte as specified in ISO IEC 80000-13:2008 (1 Kilobyte = 1 000 Byte).
17 public final class Kilobyte
extends StorageUnit
<Kilobyte
> {
20 private static final long serialVersionUID
= 6952239416014811456L;
22 Kilobyte(final @NotNull BigInteger numberOfBytes
) {
27 * @param numberOfBytes The amount of bytes the Kilobyte contains.
28 * @return A new Kilobyte unit with the given value.
31 public static @NotNull Kilobyte
valueOf(final @NotNull BigInteger numberOfBytes
) {
32 return new Kilobyte(numberOfBytes
);
36 * @param numberOfBytes The amount of bytes the Kilobyte contains.
37 * @return A new Kilobyte unit with the given value.
40 public static @NotNull Kilobyte
valueOf(final long numberOfBytes
) {
41 return valueOf(BigInteger
.valueOf(numberOfBytes
));
45 * @param numberOfBytes The amount of bytes the Kilobyte contains.
46 * @return A new Kilobyte unit with the given value.
49 public static @NotNull Kilobyte
valueOf(final @NotNull Long numberOfBytes
) {
50 return valueOf(numberOfBytes
.longValue());
55 public @NotNull Kilobyte
add(final long bytesToAdd
) {
56 return add(BigInteger
.valueOf(bytesToAdd
));
61 public @NotNull Kilobyte
add(final @NotNull BigInteger bytesToAdd
) {
62 return new Kilobyte(bytes
.add(bytesToAdd
));
67 public @NotNull Kilobyte
add(final @NotNull StorageUnit
<?
> storageAmount
) {
68 return add(storageAmount
.bytes
);
73 public @NotNull Kilobyte
divide(final long divisor
) {
74 return divide(BigInteger
.valueOf(divisor
));
79 public @NotNull Kilobyte
divide(final @NotNull BigInteger divisor
) {
80 return new Kilobyte(bytes
.divide(divisor
));
85 public @NotNull Kilobyte
multiply(final long factor
) {
86 return multiply(BigInteger
.valueOf(factor
));
91 public @NotNull Kilobyte
multiply(final @NotNull BigInteger factor
) {
92 return new Kilobyte(bytes
.multiply(factor
));
97 public @NotNull Kilobyte
subtract(final long bytesToSubtract
) {
98 return subtract(BigInteger
.valueOf(bytesToSubtract
));
103 public @NotNull Kilobyte
subtract(final @NotNull BigInteger bytesToSubtract
) {
104 return new Kilobyte(bytes
.subtract(bytesToSubtract
));
109 public @NotNull Kilobyte
subtract(final @NotNull StorageUnit
<?
> storageAmount
) {
110 return subtract(storageAmount
.bytes
);
115 protected @NotNull BigInteger
getNumberOfBytesPerUnit() {
116 return BYTES_IN_A_KILOBYTE
;
121 protected @NotNull String
getSymbol() {
127 protected @NotNull Function
<@NotNull BigInteger
, @NotNull StorageUnit
<?
>> converter() {
128 return StorageUnits
::decimalValueOf
;