cleanup and javadoc

This commit is contained in:
2019-08-31 16:52:13 +02:00
parent 0eee012798
commit f8e859fb6d
6 changed files with 216 additions and 89 deletions

View File

@@ -1,25 +1,43 @@
package org.lucares.pdb.api;
/**
* A {@link Tag} consists of a field and a value. In a query this is written as
* <em>field=value</em>, e.g., <em>name=Sam</em> where 'name' is the field and
* 'Sam' is the value.
*/
public class Tag implements Comparable<Tag> {
private final int key;
private final int field;
private final int value;
public Tag(final int key, final int value) {
this.key = key;
/**
* Create a new tag with field and value specified as int. See
* {@link Tags#STRING_COMPRESSOR} for the mapping between Strings and ints.
*
* @param field the field as int
* @param value the value as int
*/
public Tag(final int field, final int value) {
this.field = field;
this.value = value;
}
public Tag(final String key, final String value) {
this.key = key != null ? Tags.STRING_COMPRESSOR.getIfPresent(key) : -1;
/**
* Create a new {@link Tag} for the given field and value.
*
* @param field the field
* @param value the value
*/
public Tag(final String field, final String value) {
this.field = field != null ? Tags.STRING_COMPRESSOR.getIfPresent(field) : -1;
this.value = value != null ? Tags.STRING_COMPRESSOR.getIfPresent(value) : -1;
}
@Override
public int compareTo(final Tag o) {
if (key != o.key) {
return key - o.key;
if (field != o.field) {
return field - o.field;
} else if (value != o.value) {
return value - o.value;
}
@@ -28,11 +46,11 @@ public class Tag implements Comparable<Tag> {
}
public int getKey() {
return key;
return field;
}
public String getKeyAsString() {
return Tags.STRING_COMPRESSOR.get(key);
return Tags.STRING_COMPRESSOR.get(field);
}
public int getValue() {
@@ -45,14 +63,14 @@ public class Tag implements Comparable<Tag> {
@Override
public String toString() {
return Tags.STRING_COMPRESSOR.get(key) + "=" + Tags.STRING_COMPRESSOR.get(value);
return Tags.STRING_COMPRESSOR.get(field) + "=" + Tags.STRING_COMPRESSOR.get(value);
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + key;
result = prime * result + field;
result = prime * result + value;
return result;
}
@@ -66,7 +84,7 @@ public class Tag implements Comparable<Tag> {
if (getClass() != obj.getClass())
return false;
final Tag other = (Tag) obj;
if (key != other.key)
if (field != other.field)
return false;
if (value != other.value)
return false;