Ejemplo n.º 1
0
/** Instances of this class represent enumerated day values. */
public enum Day implements MpxjEnum {
  SUNDAY(1),
  MONDAY(2),
  TUESDAY(3),
  WEDNESDAY(4),
  THURSDAY(5),
  FRIDAY(6),
  SATURDAY(7);

  /**
   * Protected constructor.
   *
   * @param value day value
   */
  private Day(int value) {
    m_value = value;
  }

  /**
   * Retrieves the int representation of the day.
   *
   * @return task type value
   */
  @Override
  public int getValue() {
    return (m_value);
  }

  /**
   * This method provides a simple mechanism to retrieve the next day in correct sequence, including
   * the transition from Sunday to Monday.
   *
   * @return Day instance
   */
  public Day getNextDay() {
    int value = m_value + 1;
    if (value > 7) {
      value = 1;
    }
    return (getInstance(value));
  }

  /**
   * Retrieve a Day instance representing the supplied value.
   *
   * @param type type value
   * @return Day instance
   */
  public static Day getInstance(int type) {
    Day result;

    if (type < 0 || type >= TYPE_VALUES.length) {
      result = null;
    } else {
      result = TYPE_VALUES[type];
    }
    return result;
  }

  /** Array mapping int types to enums. */
  private static final Day[] TYPE_VALUES = EnumHelper.createTypeArray(Day.class, 1);

  private int m_value;
}
Ejemplo n.º 2
0
/** This class represents the grid line styles used by Microsoft Project. */
public enum LineStyle implements MpxjEnum {
  NONE(0, "None"),
  SOLID(1, "Solid"),
  DOTTED1(2, "Dotted1"),
  DOTTED2(3, "Dotted2"),
  DASHED(4, "Dashed");

  /**
   * Private constructor.
   *
   * @param type int version of the enum
   * @param name name of the enum
   */
  private LineStyle(int type, String name) {
    m_value = type;
    m_name = name;
  }

  /**
   * Retrieve an instance of the enum based on its int value.
   *
   * @param type int type
   * @return enum instance
   */
  public static LineStyle getInstance(int type) {
    if (type < 0 || type >= TYPE_VALUES.length) {
      type = NONE.getValue();
    }
    return (TYPE_VALUES[type]);
  }

  /**
   * Retrieve an instance of the enum based on its int value.
   *
   * @param type int type
   * @return enum instance
   */
  public static LineStyle getInstance(Number type) {
    int value;
    if (type == null) {
      value = -1;
    } else {
      value = NumberHelper.getInt(type);
    }
    return (getInstance(value));
  }

  /**
   * Accessor method used to retrieve the numeric representation of the enum.
   *
   * @return int representation of the enum
   */
  @Override
  public int getValue() {
    return (m_value);
  }

  /**
   * Retrieve the line style name. Currently this is not localised.
   *
   * @return style name
   */
  public String getName() {
    return (m_name);
  }

  /**
   * Retrieve the String representation of this line style.
   *
   * @return String representation of this line style
   */
  @Override
  public String toString() {
    return (getName());
  }

  /** Array mapping int types to enums. */
  private static final LineStyle[] TYPE_VALUES = EnumHelper.createTypeArray(LineStyle.class, 1);

  /** Internal representation of the enum int type. */
  private int m_value;

  private String m_name;
}