package xhl.core.validator;

import xhl.core.elements.*;

public class Type {
    public static final Type AnyType = new Type("AnyType");
    public static final Type Null = new Type("Null");
    public static final Type Element = new Type("Element");
    public static final Type Boolean = new Type("Boolean");
    public static final Type Number = new Type("Number");
    public static final Type String = new Type("String");
    public static final Type Symbol = new Type("Symbol");
    public static final Type List = new Type("List");
    public static final Type Map = new Type("Map");
    public static final Type Block = new Type("Block");
    public static final Type Combination = new Type("Combination");

    private final Symbol name;

    public Type(Symbol name) {
        this.name = name;
    }

    public Type(String name) {
        this(new Symbol(name));
    }

    @Override
    public boolean equals(Object obj) {
        if (obj instanceof Type)
            return name.equals(((Type) obj).name);
        else
            return false;
    }

    @Override
    public java.lang.String toString() {
        return name.toString();
    }

    /**
     * Check is a type is compatible with <code>that</code> type.
     * @param that
     * @return
     */
    public boolean is(Type that) {
        if (this.equals(AnyType) || that.equals(AnyType))
            return true;
        else
            return this.equals(that);
    }

    public boolean isNamed(String n) {
        return name.isNamed(n);
    }

    public static Type typeOfElement(Expression ex) {
        if (ex instanceof Symbol)
            return Symbol;
        if (ex instanceof SString)
            return String;
        if (ex instanceof SNumber)
            return Number;
        if (ex instanceof SBoolean)
            return Boolean;
        if (ex instanceof SList)
            return List;
        if (ex instanceof SMap)
            return Map;
        if (ex instanceof Combination)
            return Combination;
        if (ex instanceof Block)
            return Block;
        return AnyType;
    }
}
@@ -938,20 +938,23 @@
         
-if (
+return 
 obj inst
@@ -964,36 +964,19 @@
 eof Type
-)%0A            return
+ &&
  name.eq
@@ -1004,47 +1004,8 @@
 e);%0A
-        else%0A            return false;%0A
     
@@ -1260,20 +1260,23 @@
         
-if (
+return 
 this.equ
@@ -1315,34 +1315,23 @@
 ype)
-)%0A            return true;
+ %7C%7C this.equals
 %0A   
@@ -1339,21 +1339,16 @@
     
-else%0A
         
     
@@ -1343,38 +1343,16 @@
         
-    return this.equals
 (that);%0A

Simplify conditions in Type