prepare the addition of a date index
This commit is contained in:
@@ -1,8 +1,6 @@
|
||||
package org.lucares.pdb.api;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.time.OffsetDateTime;
|
||||
import java.time.ZoneOffset;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
|
||||
public class Entry {
|
||||
@@ -11,39 +9,22 @@ public class Entry {
|
||||
* A special {@link Entry} that can be used as poison object for
|
||||
* {@link BlockingQueueIterator}.
|
||||
*/
|
||||
public static final Entry POISON = new Entry(0, -1);
|
||||
|
||||
private final long epochMilli;
|
||||
public static final Entry POISON = new Entry(OffsetDateTime.MIN, -1, null);
|
||||
|
||||
private final long value;
|
||||
|
||||
private final Tags tags;
|
||||
|
||||
private final OffsetDateTime date;
|
||||
|
||||
public Entry(final OffsetDateTime date, final long value, final Tags tags) {
|
||||
this.date = date;
|
||||
this.tags = tags;
|
||||
this.epochMilli = date.toInstant().toEpochMilli();
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public Entry(final long epochMilli, final long value, final Tags tags) {
|
||||
if (value < 0) {
|
||||
throw new IllegalArgumentException("value must be between 0 and " + Long.MAX_VALUE + ", but was " + value);
|
||||
}
|
||||
|
||||
this.epochMilli = epochMilli;
|
||||
this.value = value;
|
||||
this.tags = tags;
|
||||
}
|
||||
|
||||
private Entry(final long epochMilli, final long value) {
|
||||
this.epochMilli = epochMilli;
|
||||
this.value = value;
|
||||
this.tags = null;
|
||||
}
|
||||
|
||||
public OffsetDateTime getDate() {
|
||||
final Instant instant = Instant.ofEpochMilli(epochMilli);
|
||||
return OffsetDateTime.ofInstant(instant, ZoneOffset.UTC);
|
||||
return date;
|
||||
}
|
||||
|
||||
public long getValue() {
|
||||
@@ -51,7 +32,7 @@ public class Entry {
|
||||
}
|
||||
|
||||
public long getEpochMilli() {
|
||||
return epochMilli;
|
||||
return date.toInstant().toEpochMilli();
|
||||
}
|
||||
|
||||
public Tags getTags() {
|
||||
@@ -72,7 +53,7 @@ public class Entry {
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + (int) (epochMilli ^ (epochMilli >>> 32));
|
||||
result = prime * result + ((date == null) ? 0 : date.hashCode());
|
||||
result = prime * result + ((tags == null) ? 0 : tags.hashCode());
|
||||
result = prime * result + (int) (value ^ (value >>> 32));
|
||||
return result;
|
||||
@@ -87,7 +68,10 @@ public class Entry {
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
final Entry other = (Entry) obj;
|
||||
if (epochMilli != other.epochMilli)
|
||||
if (date == null) {
|
||||
if (other.date != null)
|
||||
return false;
|
||||
} else if (!date.equals(other.date))
|
||||
return false;
|
||||
if (tags == null) {
|
||||
if (other.tags != null)
|
||||
@@ -98,4 +82,5 @@ public class Entry {
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package org.lucares.pdb.api;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
@@ -9,6 +10,7 @@ import java.util.Set;
|
||||
import java.util.SortedSet;
|
||||
import java.util.TreeSet;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.Function;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
@@ -162,6 +164,15 @@ public class Tags {
|
||||
}
|
||||
}
|
||||
|
||||
public Tags mapTags(final Function<Tag, Tag> tagMapFuntion) {
|
||||
final Set<Tag> tags = toTags();
|
||||
final Collection<Tag> mappedTags = new ArrayList<>(tags.size());
|
||||
for (final Tag tag : tags) {
|
||||
mappedTags.add(tagMapFuntion.apply(tag));
|
||||
}
|
||||
return Tags.create(mappedTags);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Tags [filename=" + serialize() + ", tags=" + toTags() + "]";
|
||||
|
||||
Reference in New Issue
Block a user