/** * @return a string representation of this value which is guaranteed to be * able to be parsed using * {@link #parseBytesSizeValue(String, ByteSizeValue, String)}. * Unlike {@link #toString()} this method will not output fractional * or rounded values so this method should be preferred when * serialising the value to JSON. */ public String getStringRep() { if (size <= 0) { return String.valueOf(size); } return size + unit.getSuffix(); }
public ByteSizeValue(long size, ByteSizeUnit unit) { if (size < -1 || (size == -1 && unit != ByteSizeUnit.BYTES)) { DEPRECATION_LOGGER.deprecated( "Values less than -1 bytes are deprecated and will not be supported in the next major version: [{}]", size + unit.getSuffix()); } if (size > Long.MAX_VALUE / unit.toBytes(1)) { throw new IllegalArgumentException( "Values greater than " + Long.MAX_VALUE + " bytes are not supported: " + size + unit.getSuffix()); } this.size = size; this.unit = unit; }
@Override public String toString() { long bytes = getBytes(); double value = bytes; String suffix = ByteSizeUnit.BYTES.getSuffix(); if (bytes >= ByteSizeUnit.C5) { value = getPbFrac(); suffix = ByteSizeUnit.PB.getSuffix(); } else if (bytes >= ByteSizeUnit.C4) { value = getTbFrac(); suffix = ByteSizeUnit.TB.getSuffix(); } else if (bytes >= ByteSizeUnit.C3) { value = getGbFrac(); suffix = ByteSizeUnit.GB.getSuffix(); } else if (bytes >= ByteSizeUnit.C2) { value = getMbFrac(); suffix = ByteSizeUnit.MB.getSuffix(); } else if (bytes >= ByteSizeUnit.C1) { value = getKbFrac(); suffix = ByteSizeUnit.KB.getSuffix(); } return Strings.format1Decimals(value, suffix); }
/** * @return a string representation of this value which is guaranteed to be * able to be parsed using * {@link #parseBytesSizeValue(String, ByteSizeValue, String)}. * Unlike {@link #toString()} this method will not output fractional * or rounded values so this method should be preferred when * serialising the value to JSON. */ public String getStringRep() { if (size <= 0) { return String.valueOf(size); } return size + unit.getSuffix(); }
/** * @return a string representation of this value which is guaranteed to be * able to be parsed using * {@link #parseBytesSizeValue(String, ByteSizeValue, String)}. * Unlike {@link #toString()} this method will not output fractional * or rounded values so this method should be preferred when * serialising the value to JSON. */ public String getStringRep() { if (size <= 0) { return String.valueOf(size); } return size + unit.getSuffix(); }
public ByteSizeValue(long size, ByteSizeUnit unit) { if (size < -1 || (size == -1 && unit != ByteSizeUnit.BYTES)) { DEPRECATION_LOGGER.deprecated( "Values less than -1 bytes are deprecated and will not be supported in the next major version: [{}]", size + unit.getSuffix()); } if (size > Long.MAX_VALUE / unit.toBytes(1)) { throw new IllegalArgumentException( "Values greater than " + Long.MAX_VALUE + " bytes are not supported: " + size + unit.getSuffix()); } this.size = size; this.unit = unit; }
public ByteSizeValue(long size, ByteSizeUnit unit) { if (size < -1 || (size == -1 && unit != ByteSizeUnit.BYTES)) { DEPRECATION_LOGGER.deprecated( "Values less than -1 bytes are deprecated and will not be supported in the next major version: [{}]", size + unit.getSuffix()); } if (size > Long.MAX_VALUE / unit.toBytes(1)) { throw new IllegalArgumentException( "Values greater than " + Long.MAX_VALUE + " bytes are not supported: " + size + unit.getSuffix()); } this.size = size; this.unit = unit; }
@Override public String toString() { long bytes = getBytes(); double value = bytes; String suffix = ByteSizeUnit.BYTES.getSuffix(); if (bytes >= ByteSizeUnit.C5) { value = getPbFrac(); suffix = ByteSizeUnit.PB.getSuffix(); } else if (bytes >= ByteSizeUnit.C4) { value = getTbFrac(); suffix = ByteSizeUnit.TB.getSuffix(); } else if (bytes >= ByteSizeUnit.C3) { value = getGbFrac(); suffix = ByteSizeUnit.GB.getSuffix(); } else if (bytes >= ByteSizeUnit.C2) { value = getMbFrac(); suffix = ByteSizeUnit.MB.getSuffix(); } else if (bytes >= ByteSizeUnit.C1) { value = getKbFrac(); suffix = ByteSizeUnit.KB.getSuffix(); } return Strings.format1Decimals(value, suffix); }
@Override public String toString() { long bytes = getBytes(); double value = bytes; String suffix = ByteSizeUnit.BYTES.getSuffix(); if (bytes >= ByteSizeUnit.C5) { value = getPbFrac(); suffix = ByteSizeUnit.PB.getSuffix(); } else if (bytes >= ByteSizeUnit.C4) { value = getTbFrac(); suffix = ByteSizeUnit.TB.getSuffix(); } else if (bytes >= ByteSizeUnit.C3) { value = getGbFrac(); suffix = ByteSizeUnit.GB.getSuffix(); } else if (bytes >= ByteSizeUnit.C2) { value = getMbFrac(); suffix = ByteSizeUnit.MB.getSuffix(); } else if (bytes >= ByteSizeUnit.C1) { value = getKbFrac(); suffix = ByteSizeUnit.KB.getSuffix(); } return Strings.format1Decimals(value, suffix); }