Package org.apache.poi.ss.formula.functions.LookupUtils

Examples of org.apache.poi.ss.formula.functions.LookupUtils.LookupValueComparer


   * @return zero based index
   */
  private static int findIndexOfValue(ValueEval lookupValue, ValueVector lookupRange,
      boolean matchExact, boolean findLargestLessThanOrEqual) throws EvaluationException {

    LookupValueComparer lookupComparer = createLookupComparer(lookupValue, matchExact);

    int size = lookupRange.getSize();
    if(matchExact) {
      for (int i = 0; i < size; i++) {
        if(lookupComparer.compareTo(lookupRange.getItem(i)).isEqual()) {
          return i;
        }
      }
      throw new EvaluationException(ErrorEval.NA);
    }

    if(findLargestLessThanOrEqual) {
      // Note - backward iteration
      for (int i = size - 1; i>=0;  i--) {
        CompareResult cmp = lookupComparer.compareTo(lookupRange.getItem(i));
        if(cmp.isTypeMismatch()) {
          continue;
        }
        if(!cmp.isLessThan()) {
          return i;
        }
      }
      throw new EvaluationException(ErrorEval.NA);
    }

    // else - find smallest greater than or equal to
    // TODO - is binary search used for (match_type==+1) ?
    for (int i = 0; i<size; i++) {
      CompareResult cmp = lookupComparer.compareTo(lookupRange.getItem(i));
      if(cmp.isEqual()) {
        return i;
      }
      if(cmp.isGreaterThan()) {
        if(i<1) {
View Full Code Here


   * @return zero based index
   */
  private static int findIndexOfValue(ValueEval lookupValue, ValueVector lookupRange,
      boolean matchExact, boolean findLargestLessThanOrEqual) throws EvaluationException {

    LookupValueComparer lookupComparer = createLookupComparer(lookupValue, matchExact);

    int size = lookupRange.getSize();
    if(matchExact) {
      for (int i = 0; i < size; i++) {
        if(lookupComparer.compareTo(lookupRange.getItem(i)).isEqual()) {
          return i;
        }
      }
      throw new EvaluationException(ErrorEval.NA);
    }

    if(findLargestLessThanOrEqual) {
      // Note - backward iteration
      for (int i = size - 1; i>=0;  i--) {
        CompareResult cmp = lookupComparer.compareTo(lookupRange.getItem(i));
        if(cmp.isTypeMismatch()) {
          continue;
        }
        if(!cmp.isLessThan()) {
          return i;
        }
      }
      throw new EvaluationException(ErrorEval.NA);
    }

    // else - find smallest greater than or equal to
    // TODO - is binary search used for (match_type==+1) ?
    for (int i = 0; i<size; i++) {
      CompareResult cmp = lookupComparer.compareTo(lookupRange.getItem(i));
      if(cmp.isEqual()) {
        return i;
      }
      if(cmp.isGreaterThan()) {
        if(i<1) {
View Full Code Here

   * @return zero based index
   */
  private static int findIndexOfValue(ValueEval lookupValue, ValueVector lookupRange,
      boolean matchExact, boolean findLargestLessThanOrEqual) throws EvaluationException {

    LookupValueComparer lookupComparer = createLookupComparer(lookupValue, matchExact);

    int size = lookupRange.getSize();
    if(matchExact) {
      for (int i = 0; i < size; i++) {
        if(lookupComparer.compareTo(lookupRange.getItem(i)).isEqual()) {
          return i;
        }
      }
      throw new EvaluationException(ErrorEval.NA);
    }

    if(findLargestLessThanOrEqual) {
      // Note - backward iteration
      for (int i = size - 1; i>=0;  i--) {
        CompareResult cmp = lookupComparer.compareTo(lookupRange.getItem(i));
        if(cmp.isTypeMismatch()) {
          continue;
        }
        if(!cmp.isLessThan()) {
          return i;
        }
      }
      throw new EvaluationException(ErrorEval.NA);
    }

    // else - find smallest greater than or equal to
    // TODO - is binary search used for (match_type==+1) ?
    for (int i = 0; i<size; i++) {
      CompareResult cmp = lookupComparer.compareTo(lookupRange.getItem(i));
      if(cmp.isEqual()) {
        return i;
      }
      if(cmp.isGreaterThan()) {
        if(i<1) {
View Full Code Here

   * @return zero based index
   */
  private static int findIndexOfValue(ValueEval lookupValue, ValueVector lookupRange,
      boolean matchExact, boolean findLargestLessThanOrEqual) throws EvaluationException {

    LookupValueComparer lookupComparer = createLookupComparer(lookupValue, matchExact);

    int size = lookupRange.getSize();
    if(matchExact) {
      for (int i = 0; i < size; i++) {
        if(lookupComparer.compareTo(lookupRange.getItem(i)).isEqual()) {
          return i;
        }
      }
      throw new EvaluationException(ErrorEval.NA);
    }

    if(findLargestLessThanOrEqual) {
      // Note - backward iteration
      for (int i = size - 1; i>=0;  i--) {
        CompareResult cmp = lookupComparer.compareTo(lookupRange.getItem(i));
        if(cmp.isTypeMismatch()) {
          continue;
        }
        if(!cmp.isLessThan()) {
          return i;
        }
      }
      throw new EvaluationException(ErrorEval.NA);
    }

    // else - find smallest greater than or equal to
    // TODO - is binary search used for (match_type==+1) ?
    for (int i = 0; i<size; i++) {
      CompareResult cmp = lookupComparer.compareTo(lookupRange.getItem(i));
      if(cmp.isEqual()) {
        return i;
      }
      if(cmp.isGreaterThan()) {
        if(i<1) {
View Full Code Here

TOP

Related Classes of org.apache.poi.ss.formula.functions.LookupUtils.LookupValueComparer

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.