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