org.protempa.QueryResults Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of protempa-framework Show documentation
Show all versions of protempa-framework Show documentation
Protempa Framework is the core of Protempa.
/*
* #%L
* Protempa Framework
* %%
* Copyright (C) 2012 - 2013 Emory University
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* #L%
*/
package org.protempa;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.protempa.QueryResults.QueryResultsEntry;
import org.protempa.proposition.Proposition;
/**
*
* @author Andrew Post
*/
public final class QueryResults implements Iterable {
// public static QueryResults newInstance(QueryResultReader reader) {
//
// }
public static class QueryResultsEntry {
private String keyId;
private List propositions;
private QueryResultsEntry(String keyId, List propositions) {
this.keyId = keyId;
this.propositions = propositions;
}
public String getKeyId() {
return this.keyId;
}
public List getPropositions() {
return this.propositions;
}
}
public static class QueryResultsIterator implements Iterator {
private final Iterator>> itr;
private QueryResultsIterator(Map> results) {
this.itr = results.entrySet().iterator();
}
@Override
public boolean hasNext() {
return this.itr.hasNext();
}
@Override
public QueryResultsEntry next() {
Map.Entry> me = this.itr.next();
return new QueryResultsEntry(me.getKey(), me.getValue());
}
@Override
public void remove() {
throw new UnsupportedOperationException("Not supported yet.");
}
}
private Map> results;
QueryResults(Map> results) {
this.results = results;
}
public List get(String keyId) {
return Collections.unmodifiableList(this.results.get(keyId));
}
public Set getKeyIds() {
return this.results.keySet();
}
@Override
public Iterator iterator() {
return new QueryResultsIterator(this.results);
}
}