diff --git a/spring-core/src/main/java/org/springframework/util/unit/DataSize.java b/spring-core/src/main/java/org/springframework/util/unit/DataSize.java index 52b6cb5f81a..a3ca20e56b9 100644 --- a/spring-core/src/main/java/org/springframework/util/unit/DataSize.java +++ b/spring-core/src/main/java/org/springframework/util/unit/DataSize.java @@ -26,10 +26,27 @@ import org.springframework.util.StringUtils; /** * A data size, such as '12MB'. * - *

This class models a size in terms of bytes and is immutable and thread-safe. + *

This class models data size in terms of bytes and is immutable and thread-safe. + * + *

The terms and units used in this class are based on + * binary prefixes + * indicating multiplication by powers of 2. Consult the following table and + * the Javadoc for {@link DataUnit} for details. + * + *

+ * + * + * + * + * + * + * + *
TermData SizeSize in Bytes
byte1B1
kilobyte1KB1,024
megabyte1MB1,048,576
gigabyte1GB1,073,741,824
terabyte1TB1,099,511,627,776
* * @author Stephane Nicoll + * @author Sam Brannen * @since 5.1 + * @see DataUnit */ public final class DataSize implements Comparable { @@ -146,7 +163,7 @@ public final class DataSize implements Comparable { * the specified default {@link DataUnit} if no unit is specified. *

* The string starts with a number followed optionally by a unit matching one of the - * supported {@link DataUnit suffixes}. + * supported {@linkplain DataUnit suffixes}. *

* Examples: *

diff --git a/spring-core/src/main/java/org/springframework/util/unit/DataUnit.java b/spring-core/src/main/java/org/springframework/util/unit/DataUnit.java
index dc00e2ded28..3ade6a289b0 100644
--- a/spring-core/src/main/java/org/springframework/util/unit/DataUnit.java
+++ b/spring-core/src/main/java/org/springframework/util/unit/DataUnit.java
@@ -1,5 +1,5 @@
 /*
- * Copyright 2002-2018 the original author or authors.
+ * Copyright 2002-2019 the original author or authors.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -19,35 +19,52 @@ package org.springframework.util.unit;
 import java.util.Objects;
 
 /**
- * A standard set of data size units.
+ * A standard set of {@link DataSize} units.
+ *
+ * 

The unit prefixes used in this class are + * binary prefixes + * indicating multiplication by powers of 2. The following table displays the + * enum constants defined in this class and corresponding values. + * + *

+ * + * + * + * + * + * + * + *
ConstantData SizePower of 2Size in Bytes
{@link #BYTES}1B2^01
{@link #KILOBYTES}1KB2^101,024
{@link #MEGABYTES}1MB2^201,048,576
{@link #GIGABYTES}1GB2^301,073,741,824
{@link #TERABYTES}1TB2^401,099,511,627,776
* * @author Stephane Nicoll + * @author Sam Brannen * @since 5.1 + * @see DataSize */ public enum DataUnit { /** - * Bytes. + * Bytes, represented by suffix {@code B}. */ BYTES("B", DataSize.ofBytes(1)), /** - * Kilobytes. + * Kilobytes, represented by suffix {@code KB}. */ KILOBYTES("KB", DataSize.ofKilobytes(1)), /** - * Megabytes. + * Megabytes, represented by suffix {@code MB}. */ MEGABYTES("MB", DataSize.ofMegabytes(1)), /** - * Gigabytes. + * Gigabytes, represented by suffix {@code GB}. */ GIGABYTES("GB", DataSize.ofGigabytes(1)), /** - * Terabytes. + * Terabytes, represented by suffix {@code TB}. */ TERABYTES("TB", DataSize.ofTerabytes(1)); @@ -68,10 +85,10 @@ public enum DataUnit { /** * Return the {@link DataUnit} matching the specified {@code suffix}. - * @param suffix one of the standard suffix + * @param suffix one of the standard suffixes * @return the {@link DataUnit} matching the specified {@code suffix} - * @throws IllegalArgumentException if the suffix does not match any - * of this enum's constants + * @throws IllegalArgumentException if the suffix does not match the suffix + * of any of this enum's constants */ public static DataUnit fromSuffix(String suffix) { for (DataUnit candidate : values()) { @@ -79,7 +96,7 @@ public enum DataUnit { return candidate; } } - throw new IllegalArgumentException("Unknown unit '" + suffix + "'"); + throw new IllegalArgumentException("Unknown data unit suffix '" + suffix + "'"); } }