Update of /cvsroot/graphl/graphl/src/org/mediavirus/graphl/graph/filter
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4993/src/org/mediavirus/graphl/graph/filter
Added Files:
SourceFilter.java
Removed Files:
TestFilter.java
Log Message:
added SourceFilter that filters nodes depending on their origin
--- NEW FILE: SourceFilter.java ---
/*
* Created on 24.08.2005
*/
package org.mediavirus.graphl.graph.filter;
import java.util.Collection;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import org.mediavirus.graphl.graph.Edge;
import org.mediavirus.graphl.graph.Graph;
import org.mediavirus.graphl.graph.Node;
import org.mediavirus.graphl.vocabulary.NS;
/**
* @author flo
*/
public class SourceFilter implements GraphFilter {
protected List sources = new LinkedList();
protected boolean rejectSources = true;
protected boolean allMustMatch = true;
/**
* @see org.mediavirus.graphl.graph.filter.GraphFilter#acceptNode(org.mediavirus.graphl.graph.Node, org.mediavirus.graphl.graph.Graph)
*/
public boolean acceptNode(Node node, Graph graph) {
boolean result = rejectSources;
for (Iterator nodesI = node.getNeighbours(NS.graphl + "definedIn", true).iterator(); nodesI.hasNext();) {
Node source = (Node) nodesI.next();
boolean match = false;
for (Iterator sourcesI = sources.iterator(); sourcesI.hasNext();) {
String url = (String) sourcesI.next();
if (source.getId().equals(url)){
match = true;
break;
}
}
if (match) {
if (!allMustMatch) {
return !rejectSources;
}
else {
result = !rejectSources;
}
}
else {
if (allMustMatch) return rejectSources;
}
}
return result;
}
/**
* @see org.mediavirus.graphl.graph.filter.GraphFilter#acceptEdge(org.mediavirus.graphl.graph.Edge, org.mediavirus.graphl.graph.Graph)
*/
public boolean acceptEdge(Edge edge, Graph graph) {
boolean match = false;
for (Iterator sourcesI = sources.iterator(); sourcesI.hasNext();) {
String url = (String) sourcesI.next();
if (url.equals(edge.getSource())){
match = true;
break;
}
}
if (match) {
return !rejectSources;
}
else {
return rejectSources;
}
}
public boolean isRejectSources() {
return rejectSources;
}
public void setRejectSources(boolean rejectSources) {
this.rejectSources = rejectSources;
}
public void addSource(String url) {
sources.add(url);
}
public void removeSource(String url) {
sources.remove(url);
}
public Collection getSources() {
return sources;
}
}
--- TestFilter.java DELETED ---
|