package org.simantics.xml.sax; import org.w3._2001.xmlschema.Any; import org.w3._2001.xmlschema.Element; import org.w3._2001.xmlschema.Group; class MultiplicityRestriction { long min; long max; public MultiplicityRestriction(Element element) { long min = 1; if (element.getMinOccurs() != null) min = element.getMinOccurs().longValue(); String element_maxS = element.getMaxOccurs(); max = 1; if ("unbounded".equals(element_maxS)) { max = -1; } else if (element_maxS != null) { max = Long.parseLong(element_maxS); max = Math.max(min, max); } } public MultiplicityRestriction(Group element) { long min = 1; if (element.getMinOccurs() != null) min = element.getMinOccurs().longValue(); String element_maxS = element.getMaxOccurs(); max = 1; if ("unbounded".equals(element_maxS)) { max = -1; } else if (element_maxS != null) { max = Long.parseLong(element_maxS); max = Math.max(min, max); } } public MultiplicityRestriction(Any element) { long min = 1; if (element.getMinOccurs() != null) min = element.getMinOccurs().longValue(); String element_maxS = element.getMaxOccurs(); max = 1; if ("unbounded".equals(element_maxS)) { max = -1; } else if (element_maxS != null) { max = Long.parseLong(element_maxS); max = Math.max(min, max); } } public long getMin() { return min; } public long getMax() { return max; } public boolean many() { return max != 1; } public boolean single() { return max == 1; } public boolean singleOptional() { return max == 1 && min == 0; } public boolean singleRequired() { return max == 1 && min == 1; } @Override public boolean equals(Object obj) { if (obj == null) return false; if (!getClass().equals(obj.getClass())) return false; MultiplicityRestriction other = (MultiplicityRestriction)obj; return (min == other.min && max == other.max); } @Override public int hashCode() { return Long.hashCode(min) + Long.hashCode(max); } }