⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mmodel.java

📁 UML设计测试工具
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
            if (assoc.associatedClasses().equals(classes))                res.add(assoc);        }        return res;    }    /**     * Returns the set of all associations that exist between the specified     * classes (including inherited ones). The arity of the returned     * associations is equal to <code>classes.size()</code>.     *      * @return Set(MAssociation)     */    public Set getAllAssociationsBetweenClasses(Set classes) {        // FIXME: not implemented yet        return getAssociationsBetweenClasses(classes);    }    /**     * Adds a generalization from <code>child</code> to <code>parent</code>     * class.     *      * @exception MInvalidModelException     *                generalization is not well-formed, e.g., a cycle is     *                introduced into the generalization hierarchy.     */    public void addGeneralization(MGeneralization gen)            throws MInvalidModelException {        // generalization is irreflexive        if (gen.isReflexive())            throw new MInvalidModelException("Class `" + gen.child()                    + "' cannot be a superclass of itself.");        // check for cycles that might be introduced by adding the new        // generalization        if (fGenGraph.existsPath(gen.parent(), gen.child()))            throw new MInvalidModelException(                    "Detected cycle in generalization hierarchy. Class `"                            + gen.parent().name()                            + "' is already a subclass of `"                            + gen.child().name() + "'.");        // FIXME: check for any conflicts that might be introduced by        // the generalization: (1) attributes with same name, (2)        // inherited associations??        // silently ignore duplicates        fGenGraph.addEdge(gen);    }    /**     * Returns the generalization graph of this model.     *      * @return a DirectedGraph with MClass nodes and MGeneralization edges     */    public DirectedGraph generalizationGraph() {        return fGenGraph;    }    /**     * Adds an enumeration type.     *      * @exception MInvalidModel     *                model already contains an element with same name.     */    public void addEnumType(EnumType e) throws MInvalidModelException {        if (fEnumTypes.containsKey(e.name()))            throw new MInvalidModelException("Model already contains a type `"                    + e.name() + "'.");        fEnumTypes.put(e.name(), e);    }    /**     * Returns an enumeration type by name.     *      * @return null if enumeration type does not exist.     */    public EnumType enumType(String name) {        return (EnumType) fEnumTypes.get(name);    }    /**     * Returns an enumeration type for a given literal.     *      * @return null if enumeration type does not exist.     */    public EnumType enumTypeForLiteral(String literal) {        Iterator it = fEnumTypes.values().iterator();        while (it.hasNext()) {            EnumType t = (EnumType) it.next();            if (t.contains(literal))                return t;        }        return null;    }    /**     * Returns a set of all enumeration types.     */    public Set enumTypes() {        Set s = new HashSet();        s.addAll(fEnumTypes.values());        return s;    }    /**     * Adds a class invariant. The class + invariant name must have a unique     * name within the model.     *      * @exception MInvalidModel     *                model already contains an invariant with same name.     */    public void addClassInvariant(MClassInvariant inv)            throws MInvalidModelException {        String name = inv.cls().name() + "::" + inv.name();        if (fClassInvariants.containsKey(name))            throw new MInvalidModelException(                    "Duplicate definition of invariant `" + inv.name()                            + "' in class `" + inv.cls().name() + "'.");        fClassInvariants.put(name, inv);    }    /**     * Returns a collection containing all class invariants.     *      * @return collection of MClassInvariant objects.     */    public Collection classInvariants() {        return fClassInvariants.values();    }    /**     * Returns a collection containing all invariants for a given class.     *      * @return collection of MClassInvariant objects.     */    public Set classInvariants(MClass cls) {        Set res = new HashSet();        Iterator it = fClassInvariants.values().iterator();        while (it.hasNext()) {            MClassInvariant inv = (MClassInvariant) it.next();            if (inv.cls().equals(cls))                res.add(inv);        }        return res;    }    /**     * Returns a collection containing all invariants for a given class and its     * parents.     *      * @return collection of MClassInvariant objects.     */    public Set allClassInvariants(MClass cls) {        Set res = new HashSet();        Set parents = cls.allParents();        parents.add(cls);        Iterator it = fClassInvariants.values().iterator();        while (it.hasNext()) {            MClassInvariant inv = (MClassInvariant) it.next();            if (parents.contains(inv.cls()))                res.add(inv);        }        return res;    }    /**     * Returns the specified invariant. The name must be given as "class::inv".     *      * @return null if invariant <code>name</name> does not exist.     */    public MClassInvariant getClassInvariant(String name) {        return (MClassInvariant) fClassInvariants.get(name);    }    /**     * Adds a pre-/postcondition.     */    public void addPrePostCondition(MPrePostCondition ppc)            throws MInvalidModelException {        String name = ppc.cls().name() + "::" + ppc.operation().name()                + ppc.name();        if (fPrePostConditions.containsKey(name))            throw new MInvalidModelException(                    "Duplicate definition of pre-/postcondition `" + ppc.name()                            + "' in class `" + ppc.cls().name() + "'.");        fPrePostConditions.put(name, ppc);        if (ppc.isPre())            ppc.operation().addPreCondition(ppc);        else            ppc.operation().addPostCondition(ppc);    }    /**     * Returns a collection containing all pre-/postconditions.     *      * @return collection of MPrePostCondition objects.     */    public Collection prePostConditions() {        return fPrePostConditions.values();    }    /**     * Returns a string with some statistics about the model: Number of classes,     * associations, invariants, and operations.     */    public String getStats() {        String stats = " (";        int n = classes().size();        stats += n + " class";        if (n != 1)            stats += "es";        n = associations().size();        stats += ", " + n + " association";        if (n != 1)            stats += "s";        n = classInvariants().size();        stats += ", " + n + " invariant";        if (n != 1)            stats += "s";        n = 0;        Iterator it = classes().iterator();        while (it.hasNext()) {            MClass cls = (MClass) it.next();            n += cls.operations().size();        }        stats += ", " + n + " operation";        if (n != 1)            stats += "s";        n = fPrePostConditions.size();        stats += ", " + n + " pre-/postcondition";        if (n != 1) {            stats += "s";        }        return "Model " + name() + stats + ")";    }    /**     * Process this element with visitor.     */    public void processWithVisitor(MMVisitor v) {        v.visitModel(this);    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -