Package er.chronic.utils

Examples of er.chronic.utils.Range


  public boolean match(List<Token> tokens, Map<Handler.HandlerType, List<Handler>> definitions) {
    return matchCount(tokens, definitions) != null;
  }
 
  public Range matchCount(List<Token> tokens, Map<Handler.HandlerType, List<Handler>> definitions) {
    Range range = _matchCount(tokens, definitions);
    return (range != null && range.getEnd() == tokens.size()) ? range : null;
  }
View Full Code Here


        }
        // next if !match && optional ?
      }
      else if (pattern instanceof HandlerTypePattern) {
        if (optional && tokenIndex == tokens.size()) {
          return new Range(0, tokens.size());
        }
        List<Handler> subHandlers = definitions.get(((HandlerTypePattern) pattern).getType());
        for (Handler subHandler : subHandlers) {
          Range range = subHandler._matchCount(tokens.subList(tokenIndex, tokens.size()), definitions);
          if (range != null) {
            if (tokenIndex == 0) {
              tokenStartIndex = (int)range.getEnd();
            }
            tokenIndex += range.getEnd();
          }
        }
        //return false;
      }
      else {
        throw new IllegalArgumentException("Unknown pattern: " + pattern);
      }
    }
    //if (tokenIndex != tokens.size()) {
      //return -1;
      //return false;
    //}
    return new Range(tokenStartIndex, tokenIndex);
  }
View Full Code Here

  public static Span tokensToSpan(List<Token> tokens, Options options) {
    if (options.isDebug()) {
      System.out.println("Chronic.tokensToSpan: " + tokens);
    }

    Range range = null;
    // maybe it's a specific date
    Map<Handler.HandlerType, List<Handler>> definitions = Handler.definitions(options);
    for (Handler handler : definitions.get(Handler.HandlerType.DATE)) {
      if (handler.isCompatible(options) && (range = handler.matchCount(tokens, definitions)) != null) {
        if (options.isDebug()) {
          System.out.println("Chronic.tokensToSpan: date " + handler);
        }
        List<Token> goodTokens = new LinkedList<Token>();
        for (Token token : range.subList(tokens)) {
          if (token.getTag(Separator.class) == null) {
            goodTokens.add(token);
          }
        }
        return handler.getHandler().handle(goodTokens, options);
      }
    }

    // I guess it's not a specific date, maybe it's just an anchor
    for (Handler handler : definitions.get(Handler.HandlerType.ANCHOR)) {
      if (handler.isCompatible(options) && (range = handler.matchCount(tokens, definitions)) != null) {
        if (options.isDebug()) {
          System.out.println("Chronic.tokensToSpan: anchor " + handler);
        }
        List<Token> goodTokens = new LinkedList<Token>();
        for (Token token : range.subList(tokens)) {
          if (token.getTag(Separator.class) == null) {
            goodTokens.add(token);
          }
        }
        return handler.getHandler().handle(goodTokens, options);
      }
    }

    // not an anchor, perhaps it's an arrow
    for (Handler handler : definitions.get(Handler.HandlerType.ARROW)) {
      if (handler.isCompatible(options) && (range = handler.matchCount(tokens, definitions)) != null) {
        if (options.isDebug()) {
          System.out.println("Chronic.tokensToSpan: arrow " + handler);
        }
        List<Token> goodTokens = new LinkedList<Token>();
        for (Token token : range.subList(tokens)) {
          if (token.getTag(SeparatorAt.class) == null && token.getTag(SeparatorSlashOrDash.class) == null && token.getTag(SeparatorComma.class) == null) {
            goodTokens.add(token);
          }
        }
        return handler.getHandler().handle(goodTokens, options);
      }
    }

    // not an arrow, let's hope it's a narrow
    for (Handler handler : definitions.get(Handler.HandlerType.NARROW)) {
      if (handler.isCompatible(options) && (range = handler.matchCount(tokens, definitions)) != null) {
        if (options.isDebug()) {
          System.out.println("Chronic.tokensToSpan: narrow " + handler);
        }
        //List<Token> goodTokens = new LinkedList<Token>();
        //for (Token token : tokens) {
        //if (token.getTag(Separator.class) == null) {
        //  goodTokens.add(token);
        //}
        //}
        return handler.getHandler().handle(range.subList(tokens), options);
      }
    }

    // I guess you're out of luck!
    if (options.isDebug()) {
View Full Code Here

    super(type);
  }

  @Override
  protected Range createRange(RepeaterDayPortion.DayPortion type) {
    Range range;
    if (type == RepeaterDayPortion.DayPortion.AM) {
      range = EnumRepeaterDayPortion.AM_RANGE;
    }
    else if (type == RepeaterDayPortion.DayPortion.PM) {
      range = EnumRepeaterDayPortion.PM_RANGE;
View Full Code Here

    super(type);
  }

  @Override
  protected Range createRange(Integer type) {
    Range range = new Range(type.intValue() * 60 * 60, (type.intValue() + 12) * 60 * 60);
    return range;
  }
View Full Code Here

TOP

Related Classes of er.chronic.utils.Range

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.