add a new facade in front of DataStore
This is done in preparation for the proposal API. In order to compute proposals we need to consume the API of the DataStore, but the code does not need to be in the DataStore. Extracting the API allows us to separate these concerns.
This commit is contained in:
@@ -195,5 +195,4 @@ public class DataStore {
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
package org.lucares.pdb.datastore;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Path;
|
||||
import java.util.List;
|
||||
import java.util.SortedSet;
|
||||
|
||||
import org.lucares.pdb.api.Tags;
|
||||
|
||||
public class PdbDB {
|
||||
|
||||
private final DataStore dataStore;
|
||||
|
||||
public PdbDB(final Path dataDirectory) throws IOException {
|
||||
dataStore = new DataStore(dataDirectory);
|
||||
}
|
||||
|
||||
public List<Doc> search(final String query) {
|
||||
return dataStore.search(query);
|
||||
}
|
||||
|
||||
public Path createNewFile(final Tags tags) throws IOException {
|
||||
return dataStore.createNewFile(tags);
|
||||
}
|
||||
|
||||
public List<String> getAvailableFields() {
|
||||
return dataStore.getAvailableFields();
|
||||
}
|
||||
|
||||
public SortedSet<String> getAvailableValuesForKey(final String query, final String fieldName) {
|
||||
return dataStore.getAvailableValuesForKey(query, fieldName);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
package org.lucares.pdb.datastore;
|
||||
|
||||
public class Proposal implements Comparable<Proposal> {
|
||||
private final String proposedTag;
|
||||
|
||||
private final String proposedQuery;
|
||||
|
||||
private final long results;
|
||||
|
||||
public Proposal(final String proposedTag, final String proposedQuery, final long results) {
|
||||
super();
|
||||
this.proposedTag = proposedTag;
|
||||
this.proposedQuery = proposedQuery;
|
||||
this.results = results;
|
||||
}
|
||||
|
||||
public String getProposedTag() {
|
||||
return proposedTag;
|
||||
}
|
||||
|
||||
public String getProposedQuery() {
|
||||
return proposedQuery;
|
||||
}
|
||||
|
||||
public long getResults() {
|
||||
return results;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Proposal [proposedTag=" + proposedTag + ", proposedQuery=" + proposedQuery + ", results=" + results
|
||||
+ "]";
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + ((proposedQuery == null) ? 0 : proposedQuery.hashCode());
|
||||
result = prime * result + ((proposedTag == null) ? 0 : proposedTag.hashCode());
|
||||
result = prime * result + (int) (results ^ (results >>> 32));
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(final Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (obj == null)
|
||||
return false;
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
final Proposal other = (Proposal) obj;
|
||||
if (proposedQuery == null) {
|
||||
if (other.proposedQuery != null)
|
||||
return false;
|
||||
} else if (!proposedQuery.equals(other.proposedQuery))
|
||||
return false;
|
||||
if (proposedTag == null) {
|
||||
if (other.proposedTag != null)
|
||||
return false;
|
||||
} else if (!proposedTag.equals(other.proposedTag))
|
||||
return false;
|
||||
if (results != other.results)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(final Proposal o) {
|
||||
|
||||
if (results != o.results) {
|
||||
return results < o.results ? 1 : -1;
|
||||
}
|
||||
|
||||
return proposedTag.compareToIgnoreCase(o.proposedTag);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user