Add number of bytes per unit to javadoc + test
[storage-units.git] / src / main / java / com / github / sebhoss / units / storage / Kibibyte.java
blob95b7a87e7c5c470224865cfbfd8a9e9064f17d69
1 /*
2 * This is free and unencumbered software released into the public domain.
4 * Anyone is free to copy, modify, publish, use, compile, sell, or
5 * distribute this software, either in source code form or as a compiled
6 * binary, for any purpose, commercial or non-commercial, and by any
7 * means.
9 * In jurisdictions that recognize copyright laws, the author or authors
10 * of this software dedicate any and all copyright interest in the
11 * software to the public domain. We make this dedication for the benefit
12 * of the public at large and to the detriment of our heirs and
13 * successors. We intend this dedication to be an overt act of
14 * relinquishment in perpetuity of all present and future rights to this
15 * software under copyright law.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
20 * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
21 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
22 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23 * OTHER DEALINGS IN THE SOFTWARE.
25 * For more information, please refer to <http://unlicense.org>
27 package com.github.sebhoss.units.storage;
29 import java.math.BigInteger;
31 /**
32 * Kibibyte as specified in ISO IEC 80000-13:2008 (1 Kibibyte = 1 024 Byte).
34 public final class Kibibyte extends StorageUnit<Kibibyte> {
36 private static final long serialVersionUID = 3798828851496657978L;
38 Kibibyte(final BigInteger bytes) {
39 super(bytes);
42 /**
43 * @param numberOfBytes
44 * The amount of bytes the kibibytes contains.
45 * @return A new Kibibyte unit with the given value.
47 public static Kibibyte valueOf(final BigInteger numberOfBytes) {
48 return new Kibibyte(numberOfBytes);
51 /**
52 * @param numberOfBytes
53 * The amount of bytes the kibibytes contains.
54 * @return A new Kibibyte unit with the given value.
56 public static Kibibyte valueOf(final long numberOfBytes) {
57 return valueOf(BigInteger.valueOf(numberOfBytes));
60 /**
61 * @param numberOfBytes
62 * The amount of bytes the kibibytes contains.
63 * @return A new Kibibyte unit with the given value.
65 public static Kibibyte valueOf(final Long numberOfBytes) {
66 return valueOf(numberOfBytes.longValue());
69 @Override
70 public Kibibyte add(final long bytesToAdd) {
71 return new Kibibyte(bytes.add(BigInteger.valueOf(bytesToAdd)));
74 @Override
75 public Kibibyte add(final StorageUnit<?> storageAmount) {
76 return new Kibibyte(bytes.add(storageAmount.bytes));
79 @Override
80 public Kibibyte divide(final long divisor) {
81 return new Kibibyte(bytes.divide(BigInteger.valueOf(divisor)));
84 @Override
85 public Kibibyte multiply(final long factor) {
86 return new Kibibyte(bytes.multiply(BigInteger.valueOf(factor)));
89 @Override
90 public Kibibyte subtract(final long bytesToSubtract) {
91 return new Kibibyte(bytes.subtract(BigInteger.valueOf(bytesToSubtract)));
94 @Override
95 public Kibibyte subtract(final StorageUnit<?> storageAmount) {
96 return new Kibibyte(bytes.subtract(storageAmount.bytes));
99 @Override
100 protected BigInteger getNumberOfBytesPerUnit() {
101 return StorageUnit.BYTES_IN_A_KIBIBYTE;
104 @Override
105 protected String getSymbol() {
106 return "KiB"; //$NON-NLS-1$