Пример #1
0
  /**
   * To add new objects.
   *
   * @param opDataCarrier {@link OutputDataCarrier}
   * @return boolean
   */
  @Override
  public boolean add(final OutputDataCarrier opDataCarrier) {
    boolean returnValue = true;
    if (maxResult == BatchConstants.ZERO) {
      returnValue = super.add(opDataCarrier);
    } else {
      if (super.size() == maxResult) {
        if (super.add(opDataCarrier)) {
          if (super.pollFirst() != null) {
            returnValue = true;
          } else {
            returnValue = false;
          }
        } else {
          final Iterator<OutputDataCarrier> itr = super.iterator();
          while (itr.hasNext()) {
            final OutputDataCarrier outputDataCarrier = itr.next();

            if (outputDataCarrier.equals(opDataCarrier)
                && opDataCarrier.getValue().compareTo(outputDataCarrier.getValue())
                    > BatchConstants.ZERO) {
              super.remove(outputDataCarrier);
              super.add(opDataCarrier);
              returnValue = true;
              break;
            }
          }
        }
      } else {
        returnValue = super.add(opDataCarrier);
      }
    }
    return returnValue;
  }
Пример #2
0
 /**
  * This is override compare method to compare two objects.
  *
  * @param outputDataCarrier1 {@link OutputDataCarrier}
  * @param outputDataCarrier2 {@link OutputDataCarrier}
  * @return int
  */
 @Override
 public int compare(
     final OutputDataCarrier outputDataCarrier1, final OutputDataCarrier outputDataCarrier2) {
   int returnVal = BatchConstants.ZERO;
   if (outputDataCarrier1 != null && outputDataCarrier2 != null) {
     returnVal =
         Float.valueOf(outputDataCarrier1.getConfidence())
             .compareTo(Float.valueOf(outputDataCarrier2.getConfidence()));
     if (returnVal == BatchConstants.ZERO) {
       returnVal = outputDataCarrier1.getValue().compareTo(outputDataCarrier2.getValue());
       if (returnVal == BatchConstants.ZERO) {
         final Span firstSpan = outputDataCarrier1.getSpan();
         final Span secSpan = outputDataCarrier2.getSpan();
         if (firstSpan != null
             && secSpan != null
             && firstSpan.getCoordinates() != null
             && secSpan.getCoordinates() != null) {
           final BigInteger s1Y1 = firstSpan.getCoordinates().getY1();
           final BigInteger s2Y1 = secSpan.getCoordinates().getY1();
           if (s1Y1 != null && s2Y1 != null) {
             returnVal = s1Y1.compareTo(s2Y1);
             if (returnVal == BatchConstants.ZERO) {
               final BigInteger s1X1 = firstSpan.getCoordinates().getX1();
               final BigInteger s2X1 = secSpan.getCoordinates().getX1();
               returnVal = compareCoordinateInfo(returnVal, firstSpan, secSpan, s1X1, s2X1);
             }
           }
         }
       }
     }
   }
   return returnVal;
 }