2 * SPDX-FileCopyrightText: The Storage-Units Authors
3 * SPDX-License-Identifier: 0BSD
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
;
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(@NotNull final BigInteger numberOfBytes
) {
27 * @param numberOfBytes The amount of bytes the Kilobyte contains.
28 * @return A new Kilobyte unit with the given value.
32 public static Kilobyte
valueOf(@NotNull final BigInteger numberOfBytes
) {
33 return new Kilobyte(numberOfBytes
);
37 * @param numberOfBytes The amount of bytes the Kilobyte contains.
38 * @return A new Kilobyte unit with the given value.
42 public static Kilobyte
valueOf(final long numberOfBytes
) {
43 return valueOf(BigInteger
.valueOf(numberOfBytes
));
47 * @param numberOfBytes The amount of bytes the Kilobyte contains.
48 * @return A new Kilobyte unit with the given value.
52 public static Kilobyte
valueOf(@NotNull final Long numberOfBytes
) {
53 return valueOf(numberOfBytes
.longValue());
59 public Kilobyte
add(final long bytesToAdd
) {
60 return add(BigInteger
.valueOf(bytesToAdd
));
66 public Kilobyte
add(@NotNull final BigInteger bytesToAdd
) {
67 return new Kilobyte(bytes
.add(bytesToAdd
));
73 public Kilobyte
add(@NotNull final StorageUnit
<?
> storageAmount
) {
74 return add(storageAmount
.bytes
);
80 public Kilobyte
divide(final long divisor
) {
81 return divide(BigInteger
.valueOf(divisor
));
87 public Kilobyte
divide(@NotNull final BigInteger divisor
) {
88 return new Kilobyte(bytes
.divide(divisor
));
94 public Kilobyte
multiply(final long factor
) {
95 return multiply(BigInteger
.valueOf(factor
));
101 public Kilobyte
multiply(@NotNull final BigInteger factor
) {
102 return new Kilobyte(bytes
.multiply(factor
));
108 public Kilobyte
subtract(final long bytesToSubtract
) {
109 return subtract(BigInteger
.valueOf(bytesToSubtract
));
115 public Kilobyte
subtract(@NotNull final BigInteger bytesToSubtract
) {
116 return new Kilobyte(bytes
.subtract(bytesToSubtract
));
122 public Kilobyte
subtract(final StorageUnit
<?
> storageAmount
) {
123 return subtract(storageAmount
.bytes
);
129 protected BigInteger
getNumberOfBytesPerUnit() {
130 return BYTES_IN_A_KILOBYTE
;
136 protected String
getSymbol() {
143 protected Function
<@NotNull BigInteger
, @NotNull StorageUnit
<?
>> converter() {
144 return StorageUnits
::decimalValueOf
;