Code Review changes for HumanReadableSizeConversionFunction
package org.carlspring.strongbox.jtwig.extensions;
+import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import org.jtwig.functions.FunctionRequest;
import org.jtwig.functions.JtwigFunction;
-import com.google.common.collect.Lists;
-
/**
*
* @author ankit.tomar
@@ -25,7 +24,7 @@ public class HumanReadableSizeConversionFunction implements JtwigFunction
@Override
public Collection<String> aliases()
{
- return Collections.unmodifiableList(Lists.newArrayList("readableSize"));
+ return Collections.unmodifiableList(Arrays.asList("readableSize"));
}
@Override
@@ -49,7 +48,9 @@ public class HumanReadableSizeConversionFunction implements JtwigFunction
{
int unit = 1000;
if (bytes < unit)
+ {
return bytes + " B";
+ }
int exp = (int) (Math.log(bytes) / Math.log(unit));
String pre = "" + "KMGTPE".charAt(exp - 1);
return String.format("%.1f %sB", bytes / Math.pow(unit, exp), pre);
