com.thaiopensource.relaxng.pattern.RequiredElementsOrAttributesFunction Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jing Show documentation
Show all versions of jing Show documentation
Jing - tool for validating RelaxNG - (OSGi-compatible version)
package com.thaiopensource.relaxng.pattern;
import com.thaiopensource.xml.util.Name;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
/**
* Common functionality between RequiredAttributesFunction and RequiredElementsFunction
*/
abstract class RequiredElementsOrAttributesFunction extends AbstractPatternFunction> {
public Set caseOther(Pattern p) {
return Collections.emptySet();
}
public Set caseChoice(ChoicePattern p) {
Set s1 = p.getOperand1().apply(this);
Set s2 = p.getOperand2().apply(this);
if (s1.isEmpty())
return s1;
if (s2.isEmpty())
return s2;
s1.retainAll(s2);
return s1;
}
protected Set caseNamed(NameClass nc) {
if (!(nc instanceof SimpleNameClass))
return Collections.emptySet();
Set s = new HashSet();
s.add(((SimpleNameClass)nc).getName());
return s;
}
protected Set union(BinaryPattern p) {
Set s1 = p.getOperand1().apply(this);
Set s2 = p.getOperand2().apply(this);
if (s1.isEmpty())
return s2;
if (s2.isEmpty())
return s1;
s1.addAll(s2);
return s1;
}
public Set caseInterleave(InterleavePattern p) {
return union(p);
}
public Set caseAfter(AfterPattern p) {
return p.getOperand1().apply(this);
}
public Set caseOneOrMore(OneOrMorePattern p) {
return p.getOperand().apply(this);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy