Ejemplo n.º 1
0
  /**
   * Create a new instance of SortedArray.<br>
   * If the comparator is {@code null}, the type of class must be a {@link Comparable} to use the
   * "natural order"
   *
   * @param typeClass Type of element
   * @param comparator Comparator to use
   * @param initialSize Initial array capacity
   * @param unique Indicates if the unique mode is enable
   */
  @SuppressWarnings("unchecked")
  public SortedArray(
      final Class<TYPE> typeClass,
      final Comparator<TYPE> comparator,
      final int initialSize,
      final boolean unique) {
    if (typeClass == null) {
      throw new NullPointerException("typeClass musn't be null");
    }

    this.comparator = comparator;

    if (comparator == null) {
      if (Reflector.isSubTypeOf(typeClass, Comparable.class) == true) {
        this.comparator = new ComparatorNatural<TYPE>();
      } else {
        throw new IllegalArgumentException(
            "comparator is null and the type class " + typeClass.getName() + " is not comparable");
      }
    }

    this.typeClass = typeClass;
    this.array = (TYPE[]) Array.newInstance(typeClass, Math.max(128, initialSize));

    this.unique = unique;
    this.size = 0;
  }
Ejemplo n.º 2
0
  /**
   * Obtain the sender instance for call distant methods for an interface
   *
   * @param <TYPE> Interface type
   * @param interfaceIDL Interface class
   * @return Sender instance for call distant methods for an interface
   * @throws ClassNotFoundException If the interface is not registered
   */
  @SuppressWarnings("unchecked")
  public static <TYPE> TYPE obtainSenderInstance(final Class<TYPE> interfaceIDL)
      throws ClassNotFoundException {
    final String className = interfaceIDL.getName() + JHelpIDL.SOURCE;
    TYPE sender = (TYPE) JHelpIDL.INSTANCES.get(className);

    if (sender == null) {
      sender = (TYPE) Reflector.newInstance(className, JHelpIDL.CLASS_LOADER);
      JHelpIDL.INSTANCES.put(className, sender);
    }

    return sender;
  }
Ejemplo n.º 3
0
  /**
   * Indicates if have to add class name to get the stored value in {@link ByteArray}
   *
   * @param type Type to read
   * @return {@code true} if have to add class name to get the stored value in {@link ByteArray}
   */
  private static boolean needClassAsReadParameter(final Class<?> type) {
    if (type.isPrimitive() == true) {
      return false;
    }

    if (type.isEnum() == true) {
      return true;
    }

    if (Reflector.isInherit(type, String.class) == true) {
      return false;
    }

    if (Reflector.isInherit(type, Binarizable.class) == true) {
      return true;
    }

    if (type.isArray() == false) {
      return false;
    }

    return JHelpIDL.needClassAsReadParameter(type.getComponentType());
  }
Ejemplo n.º 4
0
  /**
   * Obtain read or write method ending to read a value in {@link ByteArray}
   *
   * @param type Type to read
   * @return Read or write extention
   */
  private static String obtainEndByteArrayMethodName(final Class<?> type) {
    if (type.isPrimitive() == true) {
      final String name = type.getName();

      if (Reflector.PRIMITIVE_BOOLEAN.equals(name) == true) {
        return "Boolean";
      }

      if (Reflector.PRIMITIVE_BYTE.equals(name) == true) {
        return "Byte";
      }

      if (Reflector.PRIMITIVE_CHAR.equals(name) == true) {
        return "Char";
      }

      if (Reflector.PRIMITIVE_DOUBLE.equals(name) == true) {
        return "Double";
      }

      if (Reflector.PRIMITIVE_FLOAT.equals(name) == true) {
        return "Float";
      }

      if (Reflector.PRIMITIVE_INT.equals(name) == true) {
        return "Integer";
      }

      if (Reflector.PRIMITIVE_LONG.equals(name) == true) {
        return "Long";
      }

      if (Reflector.PRIMITIVE_SHORT.equals(name) == true) {
        return "Short";
      }

      return null;
    }

    if (type.isEnum() == true) {
      return "Enum";
    }

    if (Reflector.isInherit(type, String.class) == true) {
      return "String";
    }

    if (Reflector.isInherit(type, Binarizable.class) == true) {
      return "Binarizable";
    }

    if (type.isArray() == false) {
      return null;
    }

    final String name = JHelpIDL.obtainEndByteArrayMethodName(type.getComponentType());

    if (name == null) {
      return null;
    }

    return name + "Array";
  }