Update of /cvsroot/commonjava/commonjava-projects/commonjava-util/src/java/org/commonjava/util
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv7824/src/java/org/commonjava/util
Modified Files:
FileSizeConstants.java
Log Message:
added formatting methods to FileSizeConstants class.
Index: FileSizeConstants.java
===================================================================
RCS file: /cvsroot/commonjava/commonjava-projects/commonjava-util/src/java/org/commonjava/util/FileSizeConstants.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- FileSizeConstants.java 18 Sep 2003 06:28:59 -0000 1.1
+++ FileSizeConstants.java 10 Mar 2004 21:47:40 -0000 1.2
@@ -21,4 +21,52 @@
private FileSizeConstants(){
}
+ /** Simply return a double, rounded to the thousandths, for the long value sent in, divided by
+ * 2^20. This in effect calculates the number of megabytes, to the thousandths, of a memory size.
+ *
+ * @param memory The number of memory bytes to transform.
+ * @return The amount of memory represented as megabytes rounded to the nearest thousandth.
+ */
+ public static double getMemorySizeInMb(long memory, int decimals){
+ double mb = (double)(memory)/FileSizeConstants.ONE_MEGABYTE;
+ int multiplier = (int)Math.pow(10, decimals);
+ mb = mb * multiplier;
+ mb = Math.round(mb);
+ mb = (double)mb / multiplier;
+
+ return mb;
+ }
+
+ /** Simply return a double, rounded to the thousandths, for the long value sent in, divided by
+ * 2^10. This in effect calculates the number of kilobytes, to the thousandths, of a memory size.
+ *
+ * @param memory The number of memory bytes to transform.
+ * @return The amount of memory represented as gigabytes rounded to the nearest thousandth.
+ */
+ public static double getMemorySizeInKb(long memory, int decimals){
+ double mb = (double)(memory)/FileSizeConstants.ONE_KILOBYTE;
+ int multiplier = (int)Math.pow(10, decimals);
+ mb = mb * multiplier;
+ mb = Math.round(mb);
+ mb = (double)mb / multiplier;
+
+ return mb;
+ }
+
+ /** Simply return a double, rounded to the thousandths, for the long value sent in, divided by
+ * 2^30. This in effect calculates the number of gigabytes, to the thousandths, of a memory size.
+ *
+ * @param memory The number of memory bytes to transform.
+ * @return The amount of memory represented as gigabytes rounded to the nearest thousandth.
+ */
+ public static double getMemorySizeInGb(long memory, int decimals){
+ double mb = (double)(memory)/FileSizeConstants.ONE_GIGABYTE;
+ int multiplier = (int)Math.pow(10, decimals);
+ mb = mb * multiplier;
+ mb = Math.round(mb);
+ mb = (double)mb / multiplier;
+
+ return mb;
+ }
+
}
|