public boolean equals(Object o) { if (!(o instanceof DocumentType)) return false; DocumentType other = (DocumentType) o; // Ignore whether one of them have added inheritance to super Document.0 type if (super.equals(o) && headerType.equals(other.headerType) && bodyType.equals(other.bodyType)) { if ((inherits.size() > 1 || other.inherits.size() > 1) || (inherits.size() == 1 && other.inherits.size() == 1)) { return inherits.equals(other.inherits); } return !(((inherits.size() == 1) && !inherits.get(0).getDataTypeName().equals(new DataTypeName("document"))) || ((other.inherits.size() == 1) && !other.inherits.get(0).getDataTypeName().equals(new DataTypeName("document")))); } return false; }
/** * Adds a document to the inherited document types of this. * If this type is already directly inherited, nothing is done * * @param type An already DocumentType object. */ public void inherit(DocumentType type) { //TODO: There is also a check like the following in SDDocumentType addField(), try to move that to this class' addField() to get it proper, // as this method is called only when the doc types are exported. verifyTypeConsistency(type); if (isRegistered()) { throw new IllegalStateException("You cannot add inheritance to a document type that is already registered."); } if (type == null) { throw new IllegalArgumentException("The document type cannot be null in inherit()"); } // If it inherits the exact same type if (inherits.contains(type)) return; // If we inherit a type, don't inherit the supertype if (inherits.size() == 1 && inherits.get(0).getDataTypeName().equals(new DataTypeName("document"))) { inherits.clear(); } inherits.add(type); }