private static DataUnit determineDataUnit(String suffix, @Nullable DataUnit defaultUnit) { DataUnit defaultUnitToUse = (defaultUnit != null ? defaultUnit : DataUnit.BYTES); return (StringUtils.hasLength(suffix) ? DataUnit.fromSuffix(suffix) : defaultUnitToUse); }
/** * Obtain a {@link DataSize} representing an amount in the specified {@link DataUnit}. * @param amount the amount of the size, measured in terms of the unit, * positive or negative * @return a corresponding {@link DataSize} */ public static DataSize of(long amount, DataUnit unit) { Assert.notNull(unit, "Unit must not be null"); return new DataSize(Math.multiplyExact(amount, unit.size().toBytes())); }
/** * Return the {@link DataUnit} matching the specified {@code suffix}. * @param suffix one of the standard suffix * @return the {@link DataUnit} matching the specified {@code suffix} * @throws IllegalArgumentException if the suffix does not match any * of this enum's constants */ public static DataUnit fromSuffix(String suffix) { for (DataUnit candidate : values()) { if (Objects.equals(candidate.suffix, suffix)) { return candidate; } } throw new IllegalArgumentException("Unknown unit '" + suffix + "'"); }
/** * Obtain a {@link DataSize} representing an amount in the specified {@link DataUnit}. * @param amount the amount of the size, measured in terms of the unit, * positive or negative * @return a corresponding {@link DataSize} */ public static DataSize of(long amount, DataUnit unit) { Assert.notNull(unit, "Unit must not be null"); return new DataSize(Math.multiplyExact(amount, unit.size().toBytes())); }
private static DataUnit determineDataUnit(String suffix, @Nullable DataUnit defaultUnit) { DataUnit defaultUnitToUse = (defaultUnit != null ? defaultUnit : DataUnit.BYTES); return (StringUtils.hasLength(suffix) ? DataUnit.fromSuffix(suffix) : defaultUnitToUse); }
/** * Return the {@link DataUnit} matching the specified {@code suffix}. * @param suffix one of the standard suffix * @return the {@link DataUnit} matching the specified {@code suffix} * @throws IllegalArgumentException if the suffix does not match any * of this enum's constants */ public static DataUnit fromSuffix(String suffix) { for (DataUnit candidate : values()) { if (Objects.equals(candidate.suffix, suffix)) { return candidate; } } throw new IllegalArgumentException("Unknown unit '" + suffix + "'"); }
/** * Obtain a {@link DataSize} representing an amount in the specified {@link DataUnit}. * @param amount the amount of the size, measured in terms of the unit, * positive or negative * @return a corresponding {@link DataSize} */ public static DataSize of(long amount, DataUnit unit) { Assert.notNull(unit, "Unit must not be null"); return new DataSize(Math.multiplyExact(amount, unit.size().toBytes())); }
private static DataUnit determineDataUnit(String suffix, @Nullable DataUnit defaultUnit) { DataUnit defaultUnitToUse = (defaultUnit != null ? defaultUnit : DataUnit.BYTES); return (StringUtils.hasLength(suffix) ? DataUnit.fromSuffix(suffix) : defaultUnitToUse); }
/** * Return the {@link DataUnit} matching the specified {@code suffix}. * @param suffix one of the standard suffix * @return the {@link DataUnit} matching the specified {@code suffix} * @throws IllegalArgumentException if the suffix does not match any * of this enum's constants */ public static DataUnit fromSuffix(String suffix) { for (DataUnit candidate : values()) { if (Objects.equals(candidate.suffix, suffix)) { return candidate; } } throw new IllegalArgumentException("Unknown unit '" + suffix + "'"); }
/** * Obtain a {@link DataSize} representing an amount in the specified {@link DataUnit}. * @param amount the amount of the size, measured in terms of the unit, * positive or negative * @return a corresponding {@link DataSize} */ public static DataSize of(long amount, DataUnit unit) { Assert.notNull(unit, "Unit must not be null"); return new DataSize(Math.multiplyExact(amount, unit.size().toBytes())); }
private static DataUnit determineDataUnit(String suffix, @Nullable DataUnit defaultUnit) { DataUnit defaultUnitToUse = (defaultUnit != null ? defaultUnit : DataUnit.BYTES); return (StringUtils.hasLength(suffix) ? DataUnit.fromSuffix(suffix) : defaultUnitToUse); }
/** * Return the {@link DataUnit} matching the specified {@code suffix}. * @param suffix one of the standard suffix * @return the {@link DataUnit} matching the specified {@code suffix} * @throws IllegalArgumentException if the suffix does not match any * of this enum's constants */ public static DataUnit fromSuffix(String suffix) { for (DataUnit candidate : values()) { if (Objects.equals(candidate.suffix, suffix)) { return candidate; } } throw new IllegalArgumentException("Unknown unit '" + suffix + "'"); }