update to latest parent & fix null issues
[storage-units.git] / src / main / java / de / xn__ho_hia / utils / storage_unit / Zettabyte.java
blob3040a0db51810aed077f8b3a331c88edad80e721
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.utils.storage_unit;
9 import static de.xn__ho_hia.utils.storage_unit.NullsafeMath.addNullsafe;
10 import static de.xn__ho_hia.utils.storage_unit.NullsafeMath.asBigInteger;
11 import static de.xn__ho_hia.utils.storage_unit.NullsafeMath.divideNullsafe;
12 import static de.xn__ho_hia.utils.storage_unit.NullsafeMath.multiplyNullsafe;
13 import static de.xn__ho_hia.utils.storage_unit.NullsafeMath.subtractNullsafe;
15 import java.math.BigInteger;
17 /**
18 * Zettabyte as specified in ISO IEC 80000-13:2008 (1 Zettabyte = 1 000 000 000 000 000 000 000 Byte).
20 public class Zettabyte extends StorageUnit<Zettabyte> {
22 private static final long serialVersionUID = 8849006574018911826L;
24 Zettabyte(final BigInteger bytes) {
25 super(bytes);
28 /**
29 * @param numberOfBytes
30 * The amount of bytes the zettabyte contains.
31 * @return A new Zettabyte unit with the given value.
33 public static Zettabyte valueOf(final BigInteger numberOfBytes) {
34 return new Zettabyte(numberOfBytes);
37 /**
38 * @param numberOfBytes
39 * The amount of bytes the zettabytes contains.
40 * @return A new Zettabyte unit with the given value.
42 public static Zettabyte valueOf(final long numberOfBytes) {
43 return new Zettabyte(asBigInteger(numberOfBytes));
46 /**
47 * @param numberOfBytes
48 * The amount of bytes the zettabytes contains.
49 * @return A new Zettabyte unit with the given value.
51 public static Zettabyte valueOf(final Long numberOfBytes) {
52 return valueOf(numberOfBytes.longValue());
55 @Override
56 public Zettabyte add(final long bytesToAdd) {
57 return new Zettabyte(addNullsafe(bytes, asBigInteger(bytesToAdd)));
60 @Override
61 public Zettabyte add(final StorageUnit<?> storageAmount) {
62 return new Zettabyte(addNullsafe(bytes, storageAmount.bytes));
65 @Override
66 public Zettabyte divide(final long divisor) {
67 return new Zettabyte(divideNullsafe(bytes, asBigInteger(divisor)));
70 @Override
71 public Zettabyte multiply(final long factor) {
72 return new Zettabyte(multiplyNullsafe(bytes, asBigInteger(factor)));
75 @Override
76 public Zettabyte subtract(final long bytesToSubtract) {
77 return new Zettabyte(subtractNullsafe(bytes, asBigInteger(bytesToSubtract)));
80 @Override
81 public Zettabyte subtract(final StorageUnit<?> storageAmount) {
82 return new Zettabyte(subtractNullsafe(bytes, storageAmount.bytes));
85 @Override
86 protected BigInteger getNumberOfBytesPerUnit() {
87 return StorageUnit.BYTES_IN_A_ZETTABYTE;
90 @Override
91 protected String getSymbol() {
92 return "ZB"; //$NON-NLS-1$