Tipo.java

Go to the documentation of this file.
00001 package plp.expressions1.util;
00002 
00003         import java.util.Collections;
00004         import java.util.EnumSet;
00005         import java.util.Set;
00006 
00015         public class Tipo {
00016                 
00017                 public enum Tipos{INTEIRO, BOOLEANO, STRING}
00018                 
00019                 public static final Tipo TIPO_INTEIRO = new Tipo(EnumSet.of(Tipos.INTEIRO));
00020                 public static final Tipo TIPO_BOOLEANO = new Tipo(EnumSet.of(Tipos.BOOLEANO));
00021                 public static final Tipo TIPO_STRING = new Tipo(EnumSet.of(Tipos.STRING));
00022                 public static final Tipo TIPO_INDEFINIDO = new Tipo(EnumSet.noneOf(Tipos.class));
00023                 
00024                 private Set<Tipos> tipo;
00025 
00034                 private Tipo prox;
00035 
00040                 public Tipo() {
00041                         this(EnumSet.allOf(Tipos.class));
00042                 }
00043 
00051                 public Tipo(Tipo prox) {
00052                         this(EnumSet.allOf(Tipos.class), prox);
00053                 }
00054 
00063                 public Tipo(Set<Tipos> tipo) {
00064                         this(tipo, null);
00065                 }
00066 
00077                 public Tipo(Set<Tipos> tipo, Tipo prox) {
00078                         this.tipo = tipo;
00079                         this.prox = prox;
00080                 }
00081 
00090                 public Set<Tipos> get() {
00091                         return Collections.unmodifiableSet(tipo);
00092                 }
00093 
00100                 public boolean eInteiro() {
00101                         return tipo.contains(Tipos.INTEIRO);
00102                 }
00103 
00110                 public boolean eBooleano() {
00111                         return tipo.contains(Tipos.BOOLEANO);
00112                 }
00113 
00120                 public boolean eString() {
00121                         return tipo.contains(Tipos.STRING);
00122                 }
00123 
00130                 public boolean eVoid() {
00131                         return tipo.isEmpty();
00132                 }
00133 
00140                 @Override
00141                 public boolean equals(Object obj) {
00142                         return (obj instanceof Tipo && 
00143                                         ((Tipo) obj).tipo.equals(tipo));
00144                 }
00145 
00156                 public Tipo intersecao(Tipo outroTipo) {
00157                         Tipo novoTipo;
00158                         if (tipo.equals(outroTipo.tipo)) {
00159                                 novoTipo = this;
00160                         } else {
00161                                 Set<Tipos> t = EnumSet.copyOf(tipo);
00162                                 t.retainAll(outroTipo.tipo);
00163                                 novoTipo = new Tipo(t);
00164                         }
00165                         return novoTipo;
00166                 }
00167 
00179                 public Tipo getProx() {
00180                         return prox;
00181                 } 
00182 
00183                 public boolean eValido() {
00184                    return (tipo.size() == 1);
00185                 }
00186 
00187             
00188 
00189 }

Generated on Tue Sep 12 21:52:02 2006 for PLP by  doxygen 1.4.7