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 * Megabyte as specified in ISO IEC 80000-13:2008 (1 Megabyte = 1 000 000 Byte).
17 public final class Megabyte
extends StorageUnit
<Megabyte
> {
20 private static final long serialVersionUID
= 5901923092058760111L;
22 Megabyte(@NotNull final BigInteger bytes
) {
27 * @param numberOfBytes The amount of bytes the Megabyte contains.
28 * @return A new Megabyte unit with the given value.
32 public static Megabyte
valueOf(@NotNull final BigInteger numberOfBytes
) {
33 return new Megabyte(numberOfBytes
);
37 * @param numberOfBytes The amount of bytes the Megabyte contains.
38 * @return A new Megabyte unit with the given value.
42 public static Megabyte
valueOf(final long numberOfBytes
) {
43 return valueOf(BigInteger
.valueOf(numberOfBytes
));
47 * @param numberOfBytes The amount of bytes the Megabyte contains.
48 * @return A new Megabyte unit with the given value.
52 public static Megabyte
valueOf(@NotNull final Long numberOfBytes
) {
53 return valueOf(numberOfBytes
.longValue());
59 public Megabyte
add(final long bytesToAdd
) {
60 return add(BigInteger
.valueOf(bytesToAdd
));
66 public Megabyte
add(@NotNull final BigInteger bytesToAdd
) {
67 return new Megabyte(bytes
.add(bytesToAdd
));
73 public Megabyte
add(@NotNull final StorageUnit
<?
> storageAmount
) {
74 return add(storageAmount
.bytes
);
80 public Megabyte
divide(final long divisor
) {
81 return divide(BigInteger
.valueOf(divisor
));
87 public Megabyte
divide(@NotNull final BigInteger divisor
) {
88 return new Megabyte(bytes
.divide(divisor
));
94 public Megabyte
multiply(final long factor
) {
95 return multiply(BigInteger
.valueOf(factor
));
101 public Megabyte
multiply(@NotNull final BigInteger factor
) {
102 return new Megabyte(bytes
.multiply(factor
));
108 public Megabyte
subtract(final long bytesToSubtract
) {
109 return subtract(BigInteger
.valueOf(bytesToSubtract
));
115 public Megabyte
subtract(@NotNull final BigInteger bytesToSubtract
) {
116 return new Megabyte(bytes
.subtract(bytesToSubtract
));
122 public Megabyte
subtract(@NotNull final StorageUnit
<?
> storageAmount
) {
123 return subtract(storageAmount
.bytes
);
129 protected BigInteger
getNumberOfBytesPerUnit() {
130 return StorageUnit
.BYTES_IN_A_MEGABYTE
;
136 protected String
getSymbol() {
143 protected Function
<@NotNull BigInteger
, @NotNull StorageUnit
<?
>> converter() {
144 return StorageUnits
::decimalValueOf
;