Ejemplo n.º 1
0
 public static final Type For(Component.Type addr) {
   if (null != Instance)
     try {
       Reference ref = new Reference(Component.Type.Tools.For(addr));
       Type type = Instance.dereference(ref);
       if (null != type) {
         String name = type.getName();
         if (null == name) throw new alto.sys.Error.Bug();
       }
       return type;
     } catch (java.io.IOException exc) {
       return null;
     }
   else throw new alto.sys.Error.State.Init("alto.io.Tools not initialized");
 }
Ejemplo n.º 2
0
    /** Boostrap and validate type and rtype instances in the file cache. */
    public Tools init() {
      /*
       * Install
       */
      alto.lang.Type[] types = this.bootstrap();
      /*
       * Validate
       */
      alto.lang.Type test;

      for (alto.lang.Type type : types) {

        String name = type.getName();
        test = Type.Tools.For(name);
        if (type != test && (!type.equals(test))) throw new alto.sys.Error.Bug(name + '@' + type);

        String fext = type.getFext();
        test = Type.Tools.Of(fext);
        if (type != test && (!type.equals(test))) throw new alto.sys.Error.Bug(fext + '@' + type);
      }
      return this;
    }
Ejemplo n.º 3
0
 /** @return First best (practical) matching type */
 public Type best(Type compareto) {
   Type[] list = this.list;
   if (null == list) return null;
   else {
     int count = list.length;
     if (1 == count) return list[0];
     else {
       Type best = null;
       for (int cc = 0; cc < count; cc++) {
         Type test = list[cc];
         if (test.equals(compareto) || compareto.equals(test)) {
           if (null == best) best = test;
           else if (test.getQ() > best.getQ()) // (in-order preference when eq(q))
           best = test;
           else if (test.isPractical() && best.isNotPractical()) best = test;
         }
       }
       if (best.isPractical()) return best;
       else return null;
     }
   }
 }