Ejemplo n.º 1
0
  /**
   * Computes the difference between two attributes using the given distance metric. This function
   * takes care of things like dynamic attributes and null values. This one allows reclamation of a
   * difference object.
   *
   * @param alpha the target attribute
   * @param alphaSpan the target attribute's span
   * @param beta the candidate attribute
   * @param betaSpan the candidate attribute's framespan
   * @param blackout the blackout data
   * @param blackoutSpan when the blackout is defined
   * @param ignore the don't-care data
   * @param ignoreSpan the don't-care framespan
   * @param frame the frame to compare
   * @param cfd information about the media
   * @param old cached difference object
   * @return the new difference object, or the same one, changed
   * @throws IgnoredValueException if the whole of the data on the frame was ignored
   */
  public static Measurable.Difference helpGetDiff(
      Attribute alpha,
      FrameSpan alphaSpan,
      Attribute beta,
      FrameSpan betaSpan,
      Attribute blackout,
      FrameSpan blackoutSpan,
      Attribute ignore,
      FrameSpan ignoreSpan,
      int frame,
      CanonicalFileDescriptor cfd,
      Measurable.Difference old)
      throws IgnoredValueException {
    if (alpha == null || alpha.getValue(alphaSpan, frame) == null) {
      return new Distances.DefaultDifference(
          null,
          (beta != null) ? beta.getValue(betaSpan, frame) : null,
          (blackout != null) ? blackout.getValue(blackoutSpan, frame) : null,
          (ignore != null) ? ignore.getValue(ignoreSpan, frame) : null,
          cfd);

    } else {
      Measurable a = alpha.getValue(alphaSpan, frame);
      return a.getDifference(
          (beta != null) ? beta.getValue(betaSpan, frame) : null,
          (blackout != null) ? blackout.getValue(blackoutSpan, frame) : null,
          (ignore != null) ? ignore.getValue(ignoreSpan, frame) : null,
          cfd,
          old);
    }
  }
Ejemplo n.º 2
0
 /** @inheritDoc */
 public Number getDistance(
     Attribute alpha,
     FrameSpan alphaSpan,
     Attribute beta,
     FrameSpan betaSpan,
     int frame,
     CanonicalFileDescriptor cfd) {
   Object a = alpha.getValue(alphaSpan, frame);
   Object b = beta.getValue(betaSpan, frame);
   if (a == null || b == null) {
     return a == b ? new Integer(0) : new Integer(1);
   } else if ((a instanceof Object[]) && (b instanceof Object[])) {
     return Arrays.equals((Object[]) a, (Object[]) b) ? new Integer(0) : new Integer(1);
   } else if ((a instanceof int[]) && (b instanceof int[])) {
     return Arrays.equals((int[]) a, (int[]) b) ? new Integer(0) : new Integer(1);
   } else if ((a instanceof double[]) && (b instanceof double[])) {
     return Arrays.equals((double[]) a, (double[]) b) ? new Integer(0) : new Integer(1);
   } else if ((a instanceof boolean[]) && (b instanceof boolean[])) {
     return Arrays.equals((boolean[]) a, (boolean[]) b) ? new Integer(0) : new Integer(1);
   } else {
     return a.equals(b) ? new Integer(0) : new Integer(1);
   }
 }
Ejemplo n.º 3
0
 /** @inheritDoc */
 public Number getDistance(
     Attribute alpha,
     FrameSpan alphaSpan,
     Attribute beta,
     FrameSpan betaSpan,
     Attribute blackout,
     FrameSpan blackoutSpan,
     Attribute ignore,
     FrameSpan ignoreSpan,
     int frame,
     CanonicalFileDescriptor cfd) {
   if (blackout != null && blackout.getValue(blackoutSpan, frame) != null) {
     return new Integer(1);
   } else {
     return getDistance(alpha, alphaSpan, beta, betaSpan, frame, cfd);
   }
 }