Package com.mdimension.jchronic.repeaters

Source Code of com.mdimension.jchronic.repeaters.Repeater

package com.mdimension.jchronic.repeaters;

import java.util.List;

import com.mdimension.jchronic.Options;
import com.mdimension.jchronic.tags.Pointer;
import com.mdimension.jchronic.tags.Tag;
import com.mdimension.jchronic.utils.Span;
import com.mdimension.jchronic.utils.Token;

public abstract class Repeater<T> extends Tag<T> implements Comparable<Repeater<?>> {
  public Repeater(T type) {
    super(type);
  }

  public static List<Token> scan(List<Token> tokens) {
    return Repeater.scan(tokens, new Options());
  }

  public static List<Token> scan(List<Token> tokens, Options options) {
    for (Token token : tokens) {
      Tag<?> t;
      t = RepeaterMonthName.scan(token);
      if (t != null) {
        token.tag(t);
      }
      t = RepeaterDayName.scan(token);
      if (t != null) {
        token.tag(t);
      }
      t = RepeaterDayPortion.scan(token);
      if (t != null) {
        token.tag(t);
      }
      t = RepeaterTime.scan(token, tokens, options);
      if (t != null) {
        token.tag(t);
      }
      t = RepeaterUnit.scan(token);
      if (t != null) {
        token.tag(t);
      }
    }
    return tokens;
  }

  public int compareTo(Repeater<?> other) {
    return Integer.valueOf(getWidth()).compareTo(Integer.valueOf(other.getWidth()));
  }

  /**
   * returns the width (in seconds or months) of this repeatable.
   */
  public abstract int getWidth();

  /**
   * returns the next occurance of this repeatable.
   */
  public Span nextSpan(Pointer.PointerType pointer) {
    if (getNow() == null) {
      throw new IllegalStateException("Start point must be set before calling #next");
    }
    return _nextSpan(pointer);
  }

  protected abstract Span _nextSpan(Pointer.PointerType pointer);

  public Span thisSpan(Pointer.PointerType pointer) {
    if (getNow() == null) {
      throw new IllegalStateException("Start point must be set before calling #this");
    }
    return _thisSpan(pointer);
  }

  protected abstract Span _thisSpan(Pointer.PointerType pointer);

  public abstract Span getOffset(Span span, int amount, Pointer.PointerType pointer);

  @Override
  public String toString() {
    return "repeater";
  }
}
TOP

Related Classes of com.mdimension.jchronic.repeaters.Repeater

TOP
Copyright © 2018 www.massapi.com. 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.