Ejemplo n.º 1
0
  /**
   * Returns the best converter helper matching the given parameters.
   *
   * @param <T> The target class.
   * @param source The source representation variant.
   * @param target The target class.
   * @param resource The parent resource.
   * @return The matched converter helper or null.
   */
  public static <T> ConverterHelper getBestHelper(
      Representation source, Class<T> target, UniformResource resource) {
    ConverterHelper result = null;
    float bestScore = -1.0F;
    float currentScore;

    for (ConverterHelper ch : Engine.getInstance().getRegisteredConverters()) {
      currentScore = ch.score(source, target, resource);

      if (currentScore > bestScore) {
        bestScore = currentScore;
        result = ch;
      }
    }

    return result;
  }
Ejemplo n.º 2
0
  /**
   * Returns the best converter helper matching the given parameters.
   *
   * @param source The object to convert to a representation.
   * @param target The target representation variant.
   * @param resource The optional parent resource.
   * @return The matched converter helper or null.
   */
  public static ConverterHelper getBestHelper(
      Object source, Variant target, UniformResource resource) {
    ConverterHelper result = null;
    float bestScore = -1.0F;
    float currentScore;

    for (ConverterHelper ch : Engine.getInstance().getRegisteredConverters()) {
      try {
        currentScore = ch.score(source, target, resource);

        if (currentScore > bestScore) {
          bestScore = currentScore;
          result = ch;
        }
      } catch (Exception e) {
        Context.getCurrentLogger()
            .log(Level.SEVERE, "Unable get the score of the " + ch + " converter helper.", e);
      }
    }

    return result;
  }