Z3
src/api/java/Symbol.java
Go to the documentation of this file.
00001 
00018 package com.microsoft.z3;
00019 
00020 import com.microsoft.z3.enumerations.Z3_symbol_kind;
00021 
00025 public class Symbol extends Z3Object
00026 {
00030     protected Z3_symbol_kind getKind()
00031     {
00032         return Z3_symbol_kind.fromInt(Native.getSymbolKind(getContext().nCtx(),
00033                 getNativeObject()));
00034     }
00035 
00039     public boolean isIntSymbol()
00040     {
00041         return getKind() == Z3_symbol_kind.Z3_INT_SYMBOL;
00042     }
00043 
00047     public boolean isStringSymbol()
00048     {
00049         return getKind() == Z3_symbol_kind.Z3_STRING_SYMBOL;
00050     }
00051 
00052     public boolean equals(Object o)
00053     {
00054         Symbol casted = null;
00055         try {
00056             casted = Symbol.class.cast(o);
00057         }
00058         catch (ClassCastException e) {
00059             return false;
00060         }
00061 
00062         return this.getNativeObject() == casted.getNativeObject();
00063     }
00064 
00068     public String toString()
00069     {
00070         try
00071         {
00072             if (isIntSymbol())
00073                 return Integer.toString(((IntSymbol) this).getInt());
00074             else if (isStringSymbol())
00075                 return ((StringSymbol) this).getString();
00076             else
00077                 return new String(
00078                         "Z3Exception: Unknown symbol kind encountered.");
00079         } catch (Z3Exception ex)
00080         {
00081             return new String("Z3Exception: " + ex.getMessage());
00082         }
00083     }
00084 
00088     protected Symbol(Context ctx, long obj)
00089     {
00090         super(ctx, obj);
00091     }
00092 
00093     static Symbol create(Context ctx, long obj)
00094     {
00095         switch (Z3_symbol_kind.fromInt(Native.getSymbolKind(ctx.nCtx(), obj)))
00096         {
00097         case Z3_INT_SYMBOL:
00098             return new IntSymbol(ctx, obj);
00099         case Z3_STRING_SYMBOL:
00100             return new StringSymbol(ctx, obj);
00101         default:
00102             throw new Z3Exception("Unknown symbol kind encountered");
00103         }
00104     }
00105 }
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines