com.emc.mongoose.common.supply.RangeDefinedDateFormattingSupplier Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of mongoose-common Show documentation
Show all versions of mongoose-common Show documentation
Mongoose is a high-load storage performance testing tool
The newest version!
package com.emc.mongoose.common.supply;
import org.apache.commons.lang.time.FastDateFormat;
import java.text.Format;
import java.util.Date;
import java.util.List;
/**
Created by kurila on 07.03.17.
*/
public class RangeDefinedDateFormattingSupplier
extends RangeDefinedLongSupplier
implements RangeDefinedSupplier {
private Format format;
public RangeDefinedDateFormattingSupplier(
final long seed, final Date startDate, final Date endDate, final String formatStr
) {
super(seed, startDate.getTime(), endDate.getTime());
format = formatStr == null || formatStr.isEmpty() ?
null : FastDateFormat.getInstance(formatStr);
}
private static ThreadLocal DATE = new ThreadLocal() {
@Override
protected final Date initialValue() {
return new Date();
}
};
@Override
public final String get() {
final Date date = DATE.get();
date.setTime(getAsLong());
return format == null ? date.toString() : format.format(date);
}
@Override
public final int get(final List buffer, final int limit) {
final long numbers[] = new long[limit];
final int n = super.get(numbers, limit);
final Date date = DATE.get();
if(format == null) {
for(int i = 0; i < n; i ++) {
date.setTime(numbers[i]);
buffer.add(date.toString());
}
} else {
for(int i = 0; i < n; i ++) {
date.setTime(numbers[i]);
buffer.add(format.format(date));
}
}
return n;
}
@Override
public final Date value() {
return new Date(getAsLong());
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy