use of org.joda.time.MutableDateTime in project graylog2-server by Graylog2.
the class FieldHistogramResult method getResults.
@Override
public Map<Long, Map<String, Number>> getResults() {
if (result.getBuckets().isEmpty()) {
return Collections.emptyMap();
}
final Map<Long, Map<String, Number>> results = Maps.newTreeMap();
for (Histogram.Bucket b : result.getBuckets()) {
final ImmutableMap.Builder<String, Number> resultMap = ImmutableMap.builder();
resultMap.put("total_count", b.getDocCount());
final Stats stats = b.getAggregations().get(Searches.AGG_STATS);
resultMap.put("count", stats.getCount());
resultMap.put("min", stats.getMin());
resultMap.put("max", stats.getMax());
resultMap.put("total", stats.getSum());
resultMap.put("mean", stats.getAvg());
// cardinality is only calculated if it was explicitly requested, so this might be null
final Cardinality cardinality = b.getAggregations().get(Searches.AGG_CARDINALITY);
resultMap.put("cardinality", cardinality == null ? 0 : cardinality.getValue());
final DateTime keyAsDate = (DateTime) b.getKey();
final long timestamp = keyAsDate.getMillis() / 1000L;
results.put(timestamp, resultMap.build());
}
final long minTimestamp = Collections.min(results.keySet());
final long maxTimestamp = Collections.max(results.keySet());
final MutableDateTime currentTime = new MutableDateTime(minTimestamp, DateTimeZone.UTC);
while (currentTime.getMillis() < maxTimestamp) {
final Map<String, Number> entry = results.get(currentTime.getMillis());
// advance timestamp by the interval's seconds value
currentTime.add(interval.getPeriod());
if (entry == null) {
// synthesize a 0 value for this timestamp
results.put(currentTime.getMillis(), EMPTY_RESULT);
}
}
return results;
}
use of org.joda.time.MutableDateTime in project joda-time by JodaOrg.
the class TestTextFields method testWeekdayNames.
public void testWeekdayNames() {
DateTimeFormatter printer = DateTimeFormat.forPattern("EEEE");
for (int i = 0; i < ZONES.length; i++) {
MutableDateTime mdt = new MutableDateTime(2004, 1, 1, 1, 20, 30, 40, ZONES[i]);
for (int day = 1; day <= 366; day++) {
mdt.setDayOfYear(day);
int weekday = mdt.getDayOfWeek();
String weekdayText = printer.print(mdt);
assertEquals(WEEKDAYS[weekday], weekdayText);
}
}
}
use of org.joda.time.MutableDateTime in project joda-time by JodaOrg.
the class DateTimePerformance method checkJISOSetHour.
private void checkJISOSetHour() {
int COUNT = COUNT_VERY_FAST;
// Is it fair to use only MutableDateTime here? You decide.
MutableDateTime dt = new MutableDateTime();
for (int i = 0; i < AVERAGE; i++) {
start("JISO", "setHour");
for (int j = 0; j < COUNT; j++) {
dt.setHourOfDay(13);
if (dt == null) {
System.out.println("Anti optimise");
}
}
end(COUNT);
}
}
use of org.joda.time.MutableDateTime in project joda-time by JodaOrg.
the class DateTimePerformance method checkJISOSetGetYear.
private void checkJISOSetGetYear() {
int COUNT = COUNT_FAST;
// Is it fair to use only MutableDateTime here? You decide.
// MutableDateTime dt = new MutableDateTime();
// for (int i = 0; i < AVERAGE; i++) {
// start("JISO", "setGetYear");
// for (int j = 0; j < COUNT; j++) {
// dt.setYear(1972);
// int val = dt.getYear();
// if (val < 0) {System.out.println("Anti optimise");}
// }
// end(COUNT);
// }
DateTime dt = new DateTime();
for (int i = 0; i < AVERAGE; i++) {
start("JISO", "setGetYear");
for (int j = 0; j < COUNT; j++) {
dt = dt.year().setCopy(1972);
int val = dt.getYear();
if (val < 0) {
System.out.println("Anti optimise");
}
}
end(COUNT);
}
}
use of org.joda.time.MutableDateTime in project joda-time by JodaOrg.
the class DateTimePerformance method checkJodaSetGetYear.
// Set then get year
//------------------------------------------------------------------------
private void checkJodaSetGetYear() {
int COUNT = COUNT_FAST;
// Is it fair to use only MutableDateTime here? You decide.
// MutableDateTime dt = new MutableDateTime(GJChronology.getInstance());
// for (int i = 0; i < AVERAGE; i++) {
// start("Joda", "setGetYear");
// for (int j = 0; j < COUNT; j++) {
// dt.setYear(1972);
// int val = dt.getYear();
// if (val < 0) {System.out.println("Anti optimise");}
// }
// end(COUNT);
// }
DateTime dt = new DateTime(GJChronology.getInstance());
for (int i = 0; i < AVERAGE; i++) {
start("Joda", "setGetYear");
for (int j = 0; j < COUNT; j++) {
dt = dt.year().setCopy(1972);
int val = dt.getYear();
if (val < 0) {
System.out.println("Anti optimise");
}
}
end(COUNT);
}
}
Aggregations