001 package nl.tudelft.tbm.eeni.owl2java.model.jmodel;
002
003 import nl.tudelft.tbm.eeni.owl2java.model.jmodel.utils.LogUtils;
004 import nl.tudelft.tbm.eeni.owl2java.utils.IReporting;
005 import org.apache.commons.logging.Log;
006 import org.apache.commons.logging.LogFactory;
007
008 import java.util.ArrayList;
009 import java.util.List;
010
011
012 public class JOtherRestriction extends JBaseRestriction implements IReporting {
013
014 @SuppressWarnings("unused")
015 private static Log log = LogFactory.getLog(JOtherRestriction.class);
016
017 public List<JClass> someValues = new ArrayList<JClass>();
018 public List<String> hasValues = new ArrayList<String>();
019
020 public JOtherRestriction(JClass onClass, JProperty onProperty) {
021 super(onClass, onProperty);
022 }
023
024 public boolean equals(Object other) {
025 if (!(other instanceof JOtherRestriction))
026 return false;
027 JOtherRestriction or = (JOtherRestriction) other;
028 if (!(isEmpty == or.isEmpty))
029 return false;
030 if (!(hasValues.equals(or.hasValues)))
031 return false;
032 if (!someValues.equals(or.someValues))
033 return false;
034 return true;
035 }
036
037 public boolean hasSomeValues() {
038 return (!someValues.isEmpty());
039 }
040
041 public boolean hasHasValues() {
042 return (!hasValues.isEmpty());
043 }
044
045 public List<JClass> listSomeValues() {
046 return someValues;
047 }
048
049 public List<String> listHasValues() {
050 return hasValues;
051 }
052
053 public void mergeParent(JOtherRestriction parent) {
054 // empty parent cardinality restrictions (aka no restrictions) are ignored
055 if (!parent.isEmpty) {
056 someValues.addAll(parent.listSomeValues());
057 hasValues.addAll(parent.listHasValues());
058 isEmpty = false;
059 }
060 }
061
062 public void addSomeValues(JClass cls) {
063 isEmpty = false;
064 someValues.add(cls);
065 }
066
067 public void addHasValue(String uri) {
068 isEmpty = false;
069 hasValues.add(uri);
070 }
071
072 public JOtherRestriction clone() {
073 JOtherRestriction r = new JOtherRestriction(onClass, onProperty);
074 r.isEmpty = isEmpty;
075 r.someValues.addAll(someValues);
076 r.hasValues.addAll(hasValues);
077 return r;
078 }
079
080 @Override
081 public String getJModelReport() {
082 String ret = LogUtils.toLogName(this) + ": ";
083 if (isEmpty)
084 return ret + "Empty other restriction";
085
086 ret += "SomeValues: ";
087 for (JClass cls : someValues) {
088 ret += LogUtils.toLogName(cls) + ", ";
089 }
090 ret += "; hasValue: ";
091 for (String uri : hasValues) {
092 ret += uri + ", ";
093 }
094 return ret;
095 }
096
097 }