1. /*
  2. * @(#)WordBreakTable.java 1.9 01/11/29
  3. *
  4. * Copyright 2002 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. /*
  8. * @(#)WordBreakTable.java 1.9 01/11/29
  9. *
  10. * (C) Copyright Taligent, Inc. 1996, 1997 - All Rights Reserved
  11. * (C) Copyright IBM Corp. 1996 - 1998 - All Rights Reserved
  12. *
  13. * Portions copyright (c) 1996-1998 Sun Microsystems, Inc.
  14. * All Rights Reserved.
  15. *
  16. * The original version of this source code and documentation
  17. * is copyrighted and owned by Taligent, Inc., a wholly-owned
  18. * subsidiary of IBM. These materials are provided under terms
  19. * of a License Agreement between Taligent and Sun. This technology
  20. * is protected by multiple US and International patents.
  21. *
  22. * This notice and attribution to Taligent may not be removed.
  23. * Taligent is a registered trademark of Taligent, Inc.
  24. *
  25. * Permission to use, copy, modify, and distribute this software
  26. * and its documentation for NON-COMMERCIAL purposes and without
  27. * fee is hereby granted provided that this copyright notice
  28. * appears in all copies. Please refer to the file "copyright.html"
  29. * for further important copyright and licensing information.
  30. *
  31. * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF
  32. * THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
  33. * TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
  34. * PARTICULAR PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR
  35. * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
  36. * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.
  37. *
  38. */
  39. package java.text;
  40. /**
  41. * This class implements a state transition table.
  42. * After each transition, using the get method, the
  43. * new state is returned along with information about
  44. * the state change (ex. was it a "marked" transition").
  45. * This class is internal only.
  46. */
  47. final class WordBreakTable
  48. {
  49. /**
  50. * Construct a table using existing data. See SentenceBreakBoundary and
  51. * the other SimpleTextBoundary subclasses for examples.
  52. * @param cols number of columns in the table
  53. * @param data an encoded byte array containing state and transition data
  54. */
  55. public WordBreakTable(int cols, byte data[])
  56. {
  57. this.data = data;
  58. this.cols = cols;
  59. }
  60. /**
  61. * Get the resulting state moving from oldState accepting input
  62. * @param oldState current state
  63. * @param input input
  64. * @return int resulting state and transition data
  65. */
  66. public int get(int oldState, int input)
  67. {
  68. return data[(oldState & INDEX_MASK) * cols + input];
  69. }
  70. /**
  71. * Checks to see if the transition into the specified state was "marked"
  72. * @param state the state as returned by get, initialState, or endState
  73. * @return true if transition into state was marked.
  74. */
  75. public boolean isMarkState(int state)
  76. {
  77. return (state & MARK_MASK) != 0;
  78. }
  79. /**
  80. * Check is a state is the end state
  81. * @param state the state to check
  82. * @return true if state is an end state
  83. */
  84. public boolean isEndState(int state)
  85. {
  86. return (state & INDEX_MASK) == END_STATE;
  87. }
  88. /**
  89. * Get the start state
  90. * @return the initial state
  91. */
  92. public int initialState()
  93. {
  94. return INITIAL_STATE;
  95. }
  96. static final byte MARK_MASK = (byte)0x80;
  97. static final byte INDEX_MASK = (byte)0x7F;
  98. private static final int INITIAL_STATE = 1;
  99. private static final int END_STATE = 0;
  100. private byte data[];
  101. private int cols;
  102. }