1. /*
  2. * @(#)WordBreakTable.java 1.9 00/01/19
  3. *
  4. * Copyright 1996-2000 Sun Microsystems, Inc. All Rights Reserved.
  5. *
  6. * This software is the proprietary information of Sun Microsystems, Inc.
  7. * Use is subject to license terms.
  8. *
  9. */
  10. /*
  11. * (C) Copyright Taligent, Inc. 1996, 1997 - All Rights Reserved
  12. * (C) Copyright IBM Corp. 1996 - 1998 - All Rights Reserved
  13. *
  14. * The original version of this source code and documentation
  15. * is copyrighted and owned by Taligent, Inc., a wholly-owned
  16. * subsidiary of IBM. These materials are provided under terms
  17. * of a License Agreement between Taligent and Sun. This technology
  18. * is protected by multiple US and International patents.
  19. *
  20. * This notice and attribution to Taligent may not be removed.
  21. * Taligent is a registered trademark of Taligent, Inc.
  22. *
  23. */
  24. package java.text;
  25. /**
  26. * This class implements a state transition table.
  27. * After each transition, using the get method, the
  28. * new state is returned along with information about
  29. * the state change (ex. was it a "marked" transition").
  30. * This class is internal only.
  31. */
  32. final class WordBreakTable
  33. {
  34. /**
  35. * Construct a table using existing data. See SentenceBreakBoundary and
  36. * the other SimpleTextBoundary subclasses for examples.
  37. * @param cols number of columns in the table
  38. * @param data an encoded byte array containing state and transition data
  39. */
  40. public WordBreakTable(int cols, byte data[])
  41. {
  42. this.data = data;
  43. this.cols = cols;
  44. }
  45. /**
  46. * Get the resulting state moving from oldState accepting input
  47. * @param oldState current state
  48. * @param input input
  49. * @return int resulting state and transition data
  50. */
  51. public int get(int oldState, int input)
  52. {
  53. return data[(oldState & INDEX_MASK) * cols + input];
  54. }
  55. /**
  56. * Checks to see if the transition into the specified state was "marked"
  57. * @param state the state as returned by get, initialState, or endState
  58. * @return true if transition into state was marked.
  59. */
  60. public boolean isMarkState(int state)
  61. {
  62. return (state & MARK_MASK) != 0;
  63. }
  64. /**
  65. * Check is a state is the end state
  66. * @param state the state to check
  67. * @return true if state is an end state
  68. */
  69. public boolean isEndState(int state)
  70. {
  71. return (state & INDEX_MASK) == END_STATE;
  72. }
  73. /**
  74. * Get the start state
  75. * @return the initial state
  76. */
  77. public int initialState()
  78. {
  79. return INITIAL_STATE;
  80. }
  81. static final byte MARK_MASK = (byte)0x80;
  82. static final byte INDEX_MASK = (byte)0x7F;
  83. private static final int INITIAL_STATE = 1;
  84. private static final int END_STATE = 0;
  85. private byte data[];
  86. private int cols;
  87. }