Advertisement
codeido

ScreenSplit.java

Dec 30th, 2016
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.35 KB | None | 0 0
  1. /**
  2.  * Specifies how many screens are visible.
  3.  */
  4. public enum ScreenSplit {
  5.     SCREENS_1("1 Screen", 0, 1),
  6.     SCREENS_2("2 Screens", 1, 2),
  7.     SCREENS_4("4 Screens", 2, 4),
  8.     SCREENS_9("9 Screens", 3, 9);
  9.  
  10.     public static final ScreenSplit DEFAULT_SPLIT = ScreenSplit.SCREENS_4;
  11.     public static final ScreenSplit MAX_SPLIT = ScreenSplit.SCREENS_9;
  12.  
  13.     private String stringValue;
  14.     /**
  15.      * Ordinal number.
  16.      */
  17.     private int intValue;
  18.     /**
  19.      * Number of visible screens.
  20.      */
  21.     private int screens;
  22.  
  23.     ScreenSplit(String stringValue, int intValue, int screens) {
  24.         this.stringValue = stringValue;
  25.         this.intValue = intValue;
  26.         this.screens = screens;
  27.     }
  28.  
  29.     /**
  30.      * Returns the enum constant of the specified enum type with the specified int value.
  31.      * @param intValue
  32.      * @return Enum constant
  33.      * @throws IllegalArgumentException if this enum type has no constant with the specified numeric value.
  34.      */
  35.     public static ScreenSplit valueOf(int intValue) throws IllegalArgumentException {
  36.         for (ScreenSplit enumerator : ScreenSplit.values()) {
  37.             if (enumerator.intValue == intValue) {
  38.                 return enumerator;
  39.             }
  40.         }
  41.         throw new IllegalArgumentException("No constant with the specified numeric value.");
  42.     }
  43.     /**
  44.      * Returns an array filled with specified enum type enumerators represented as their {@link ScreenSplit#toString()} value.
  45.      * @return Array of enum values.
  46.      */
  47.     public static String[] strings() {
  48.         ScreenSplit[] enumerators = ScreenSplit.values();
  49.         String[] strings = new String[enumerators.length];
  50.  
  51.         for (int index = 0; index < enumerators.length; index++) {
  52.             strings[index] = enumerators[index].toString();
  53.         }
  54.         return strings;
  55.     }
  56.  
  57.     /**
  58.      * {@inheritDoc}
  59.      */
  60.     @Override
  61.     public String toString() {
  62.         return this.stringValue;
  63.     }
  64.     /**
  65.      * Returns specified enum type enumerator ordinal number.
  66.      * @return Ordinal number.
  67.      */
  68.     public int getIntValue() {
  69.         return this.intValue;
  70.     }
  71.     /**
  72.      * Returns specified enum type enumerator number of visible screens.
  73.      * @return Number of visible screens.
  74.      */
  75.     public int getScreens() {
  76.         return this.screens;
  77.     }
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement