com.emc.mongoose.api.common.supply.RangeDefinedLongFormattingSupplier Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of mongoose-api-common Show documentation
Show all versions of mongoose-api-common Show documentation
Mongoose is a high-load storage performance testing tool
package com.emc.mongoose.api.common.supply;
import java.io.IOException;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.util.List;
/**
Created by kurila on 07.03.17.
*/
public final class RangeDefinedLongFormattingSupplier
extends RangeDefinedLongSupplier
implements RangeDefinedSupplier {
private final NumberFormat format;
public RangeDefinedLongFormattingSupplier(
final long seed, final long min, final long max, final String formatStr
) {
super(seed, min, max);
this.format = formatStr == null || formatStr.isEmpty() ?
null : new DecimalFormat(formatStr);
}
@Override
public String get() {
return format == null ? Long.toString(getAsLong()) : format.format(getAsLong());
}
@Override
public int get(final List buffer, final int limit) {
final long numbers[] = new long[limit];
final int n = super.get(numbers, limit);
if(format == null) {
for(int i = 0; i < n; i ++) {
buffer.add(Long.toString(numbers[i]));
}
} else {
for(int i = 0; i < n; i ++) {
buffer.add(format.format(numbers[i]));
}
}
return n;
}
@Override
public Long value() {
return getAsLong();
}
@Override
public final void close()
throws IOException {
super.close();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy