| 1 | package morfologik.fsa; |
| 2 | |
| 3 | import java.util.Set; |
| 4 | |
| 5 | /** |
| 6 | * FSA automaton flags. Where applicable, flags follow Daciuk's <code>fsa</code> |
| 7 | * package. |
| 8 | */ |
| 9 | public enum FSAFlags { |
| 10 | /** Daciuk: flexible FSA encoding. */ |
| 11 | FLEXIBLE(1 << 0), |
| 12 | |
| 13 | /** Daciuk: stop bit in use. */ |
| 14 | STOPBIT(1 << 1), |
| 15 | |
| 16 | /** Daciuk: next bit in use. */ |
| 17 | NEXTBIT(1 << 2), |
| 18 | |
| 19 | /** Daciuk: tails compression. */ |
| 20 | TAILS(1 << 3), |
| 21 | |
| 22 | /* |
| 23 | * These flags are outside of byte range (never occur in Daciuk's FSA). |
| 24 | */ |
| 25 | |
| 26 | /** |
| 27 | * The FSA contains right-language count numbers on states. |
| 28 | * |
| 29 | * @see FSA#getRightLanguageCount(int) |
| 30 | */ |
| 31 | NUMBERS(1 << 8), |
| 32 | |
| 33 | /** |
| 34 | * The FSA supports legacy built-in separator and filler characters (Daciuk's |
| 35 | * FSA package compatibility). |
| 36 | */ |
| 37 | SEPARATORS(1 << 9); |
| 38 | |
| 39 | /** |
| 40 | * Bit mask for the corresponding flag. |
| 41 | */ |
| 42 | public final int bits; |
| 43 | |
| 44 | /** */ |
| 45 | private FSAFlags(int bits) { |
| 46 | this.bits = bits; |
| 47 | } |
| 48 | |
| 49 | /** |
| 50 | * @param flags The bitset with flags. |
| 51 | * @return Returns <code>true</code> iff this flag is set in <code>flags</code>. |
| 52 | */ |
| 53 | public boolean isSet(int flags) { |
| 54 | return (flags & bits) != 0; |
| 55 | } |
| 56 | |
| 57 | /** |
| 58 | * @param flags A set of flags to encode. |
| 59 | * @return Returns the set of flags encoded as packed <code>short</code>. |
| 60 | */ |
| 61 | public static short asShort(Set<FSAFlags> flags) { |
| 62 | short value = 0; |
| 63 | for (FSAFlags f : flags) { |
| 64 | value |= f.bits; |
| 65 | } |
| 66 | return value; |
| 67 | } |
| 68 | } |