id
stringlengths
36
36
text
stringlengths
1
1.25M
e54bff2a-ddb6-4346-bb3a-10e29cbe5a8b
public Session getSession() { return this.sessionFactory.getCurrentSession(); }
89007fa4-32c0-485d-8c77-6d3603d5d066
@SuppressWarnings("unchecked") public T findById(PK id) { return (T) getSession().get(clazz, id); }
417e64dc-9b29-41ac-afb4-39dd71e345b2
@SuppressWarnings("unchecked") public T findByProperty(String propertyName,Object value) { Criteria c = getSession().createCriteria(clazz); c.add(Restrictions.eq(propertyName, value)); return (T) c.uniqueResult(); }
c3ce7795-9b1f-43a8-bf8d-11595dce1da6
@SuppressWarnings("unchecked") public List<T> findListByProperty(String propertyName,Object value) { Criteria c = getSession().createCriteria(clazz); c.add(Restrictions.eq(propertyName, value)); return c.list(); }
7d079e6a-2e7f-4cbe-a8d3-ab42f88e4b5e
public void del(T t) { getSession().delete(t); }
add43a71-9e47-4538-bc50-929a8a9a21ca
public void del(PK id) { getSession().delete(findById(id)); }
ad89625d-920f-4ad8-9478-5a5738b73e47
@SuppressWarnings("unchecked") public List<T> findAll() { Criteria c = getSession().createCriteria(clazz); return c.list(); }
43a24c46-1a94-4499-898f-846beb2cc6c8
public void save(T t) { getSession().saveOrUpdate(t); }
0b522641-638c-416b-85ae-57bcf4358247
public User findById(int userId) { return userDao.findById(userId); }
4f7ccb25-585d-4d4e-af31-3cc60ccf8db3
public void save(User user) { user.setEnable(true); userDao.save(user); }
5c7fbe9b-5c59-4da7-82b3-1df28a6a7349
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html"); PrintWriter out = response.getWriter(); out.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">"); out.println("<HTML>"); out.println(" <HEAD><TITLE>A Servlet</TITLE></HEAD>"); out.println(" <BODY>"); out.print(" This is "); out.print(this.getClass()); out.println(", using the GET method"); out.println(" </BODY>"); out.println("</HTML>"); out.flush(); out.close(); }
78ca4e30-fc71-408e-896e-b73bf3f7aec8
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html"); PrintWriter out = response.getWriter(); out.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">"); out.println("<HTML>"); out.println(" <HEAD><TITLE>A Servlet</TITLE></HEAD>"); out.println(" <BODY>"); out.print(" This is "); out.print(this.getClass()); out.println(", using the POST method"); out.println(" </BODY>"); out.println("</HTML>"); out.flush(); out.close(); }
f7b83631-be2c-4444-a9b9-1be65f6da864
public String home(Model model) { model.addAttribute("msg", "Hello,MVC!"); return "home"; }
c4b7d153-8012-4877-8eb9-3e2c53d17fc3
@RequestMapping public ModelAndView index() { ModelAndView mav = new ModelAndView(); mav.setViewName("home"); mav.addObject("msg", "ModelAndView"); return mav; }
c7faa5e5-a14d-411a-a3d9-48ac74c32d14
@Id @GeneratedValue(strategy=GenerationType.IDENTITY) public Integer getId() { return id; }
d92a0283-0605-4542-9e63-bea8f0166171
public void setId(Integer id) { this.id = id; }
a2fd9a0d-2c9c-41ab-948a-fdcbf8e169e6
public String getUsername() { return username; }
bc256fbf-2d7f-4d41-8f3b-371f905aaf02
public void setUsername(String username) { this.username = username; }
346191af-0414-4774-b7b3-131aae94aceb
public String getPassword() { return password; }
045c7eea-3d93-41d2-a912-b51cd0e0644c
public void setPassword(String password) { this.password = password; }
9ed2f05d-e4e9-4d03-985a-668df010e3d3
public Boolean getEnable() { return enable; }
4fe1be44-4264-46ca-932e-ea688084eee0
public void setEnable(Boolean enable) { this.enable = enable; }
0c345bb8-3cde-43bb-855e-cd5cecdc6351
public CompactByteArray() { this((byte)0); }
a680ed3a-f706-4414-ab9b-e74c6d21d8ec
public CompactByteArray(byte defaultValue) { int i; values = new byte[UNICODECOUNT]; indices = new char[INDEXCOUNT]; hashes = new int[INDEXCOUNT]; for (i = 0; i < UNICODECOUNT; ++i) { values[i] = defaultValue; } for (i = 0; i < INDEXCOUNT; ++i) { indices[i] = (char)(i<<BLOCKSHIFT); hashes[i] = 0; } isCompact = false; this.defaultValue = defaultValue; }
cfa5aa48-8e05-438c-af20-fc4b7307fdf0
public CompactByteArray(char indexArray[], byte newValues[]) { int i; if (indexArray.length != INDEXCOUNT) throw new IllegalArgumentException("Index out of bounds."); for (i = 0; i < INDEXCOUNT; ++i) { char index = indexArray[i]; if ((index < 0) || (index >= newValues.length+BLOCKCOUNT)) throw new IllegalArgumentException("Index out of bounds."); } indices = indexArray; values = newValues; isCompact = true; }
d9981c39-8e33-4921-8e3c-d182ce4272c8
public CompactByteArray(String indexArray, String valueArray) { this(RLEStringToCharArray(indexArray), RLEStringToByteArray(valueArray)); }
17542a29-436f-4b0c-9635-f6ff8bfe0425
static public final char[] RLEStringToCharArray(String s) { int length = (((int) s.charAt(0)) << 16) | ((int) s.charAt(1)); char[] array = new char[length]; int ai = 0; for (int i=2; i<s.length(); ++i) { char c = s.charAt(i); if (c == ESCAPE) { c = s.charAt(++i); if (c == ESCAPE) { array[ai++] = c; } else { int runLength = (int) c; char runValue = s.charAt(++i); for (int j=0; j<runLength; ++j) array[ai++] = runValue; } } else { array[ai++] = c; } } if (ai != length) throw new IllegalStateException("Bad run-length encoded short array"); return array; }
808dda88-c5c1-4db6-8ff3-6332c6b425b3
static public final byte[] RLEStringToByteArray(String s) { int length = (((int) s.charAt(0)) << 16) | ((int) s.charAt(1)); byte[] array = new byte[length]; boolean nextChar = true; char c = 0; int node = 0; int runLength = 0; int i = 2; for (int ai=0; ai<length; ) { // This part of the loop places the next byte into the local // variable 'b' each time through the loop. It keeps the // current character in 'c' and uses the boolean 'nextChar' // to see if we've taken both bytes out of 'c' yet. byte b; if (nextChar) { c = s.charAt(i++); b = (byte) (c >> 8); nextChar = false; } else { b = (byte) (c & 0xFF); nextChar = true; } // This part of the loop is a tiny state machine which handles // the parsing of the run-length encoding. This would be simpler // if we could look ahead, but we can't, so we use 'node' to // move between three nodes in the state machine. switch (node) { case 0: // Normal idle node if (b == ESCAPE_BYTE) { node = 1; } else { array[ai++] = b; } break; case 1: // We have seen one ESCAPE_BYTE; we expect either a second // one, or a run length and value. if (b == ESCAPE_BYTE) { array[ai++] = ESCAPE_BYTE; node = 0; } else { runLength = b; // Interpret signed byte as unsigned if (runLength < 0) runLength += 0x100; node = 2; } break; case 2: // We have seen an ESCAPE_BYTE and length byte. We interpret // the next byte as the value to be repeated. for (int j=0; j<runLength; ++j) array[ai++] = b; node = 0; break; } } if (node != 0) throw new IllegalStateException("Bad run-length encoded byte array"); if (i != s.length()) throw new IllegalStateException("Excess data in RLE byte array string"); return array; }
4080c2a4-7b10-4735-8f66-c2a3b8e05303
public byte elementAt(char index) { return (values[(indices[index >> BLOCKSHIFT] & 0xFFFF) + (index & BLOCKMASK)]); }
b360d2bf-ab90-435f-9698-f12731727b25
public void setElementAt(char index, byte value) { if (isCompact) expand(); values[(int)index] = value; touchBlock(index >> BLOCKSHIFT, value); }
9df41735-923c-48fb-9312-f3a1cfd9759a
public void setElementAt(char start, char end, byte value) { int i; if (isCompact) { expand(); } for (i = start; i <= end; ++i) { values[i] = value; touchBlock(i >> BLOCKSHIFT, value); } }
93297a4c-2857-4a9d-b2ac-8d4bbafe9eea
public void compact() { compact(false); }
1195ba28-54b1-4158-b7c2-f6cdcdb61a36
public void compact(boolean exhaustive) { if (!isCompact) { int limitCompacted = 0; int iBlockStart = 0; char iUntouched = 0xFFFF; for (int i = 0; i < indices.length; ++i, iBlockStart += BLOCKCOUNT) { indices[i] = 0xFFFF; boolean touched = blockTouched(i); if (!touched && iUntouched != 0xFFFF) { // If no values in this block were set, we can just set its // index to be the same as some other block with no values // set, assuming we've seen one yet. indices[i] = iUntouched; } else { int jBlockStart = 0; int j = 0; for (j = 0; j < limitCompacted; ++j, jBlockStart += BLOCKCOUNT) { if (hashes[i] == hashes[j] && arrayRegionMatches(values, iBlockStart, values, jBlockStart, BLOCKCOUNT)) { indices[i] = (char)jBlockStart; break; } } if (indices[i] == 0xFFFF) { // we didn't match, so copy & update System.arraycopy(values, iBlockStart, values, jBlockStart, BLOCKCOUNT); indices[i] = (char)jBlockStart; hashes[j] = hashes[i]; ++limitCompacted; if (!touched) { // If this is the first untouched block we've seen, // remember its index. iUntouched = (char)jBlockStart; } } } } // we are done compacting, so now make the array shorter int newSize = limitCompacted*BLOCKCOUNT; byte[] result = new byte[newSize]; System.arraycopy(values, 0, result, 0, newSize); values = result; isCompact = true; hashes = null; } }
f555b368-214b-4d97-8b03-71ff2acb9f8d
final static boolean arrayRegionMatches(byte[] source, int sourceStart, byte[] target, int targetStart, int len) { int sourceEnd = sourceStart + len; int delta = targetStart - sourceStart; for (int i = sourceStart; i < sourceEnd; i++) { if (source[i] != target[i + delta]) return false; } return true; }
7c592b3f-ba11-4f9e-a3d8-a8c1654ffe86
private final void touchBlock(int i, int value) { hashes[i] = (hashes[i] + (value<<1)) | 1; }
9da4cb04-0db8-40cd-9f42-7f7781bd106e
private final boolean blockTouched(int i) { return hashes[i] != 0; }
00c46a91-26d2-4cbb-b6c5-3e63bdae789a
public char[] getIndexArray() { return indices; }
676cfce2-28c0-47d4-b8fb-894699cd589e
public byte[] getValueArray() { return values; }
696a8c3e-949d-4819-a5f9-9653ad8b55a3
public Object clone() { try { CompactByteArray other = (CompactByteArray) super.clone(); other.values = (byte[])values.clone(); other.indices = (char[])indices.clone(); if (hashes != null) other.hashes = (int[])hashes.clone(); return other; } catch (CloneNotSupportedException e) { throw new IllegalStateException(); } }
dd40dfd1-b045-46d1-9b6b-92d3746d2ec2
public boolean equals(Object obj) { if (obj == null) return false; if (this == obj) // quick check return true; if (getClass() != obj.getClass()) // same class? return false; CompactByteArray other = (CompactByteArray) obj; for (int i = 0; i < UNICODECOUNT; i++) { // could be sped up later if (elementAt((char)i) != other.elementAt((char)i)) return false; } return true; // we made it through the guantlet. }
2339a5b0-97b9-4b3f-b880-7357af302756
public int hashCode() { int result = 0; int increment = Math.min(3, values.length/16); for (int i = 0; i < values.length; i+= increment) { result = result * 37 + values[i]; } return result; }
53dc6305-dd3f-4bd7-a83a-970a7add78f7
private void expand() { int i; if (isCompact) { byte[] tempArray; hashes = new int[INDEXCOUNT]; tempArray = new byte[UNICODECOUNT]; for (i = 0; i < UNICODECOUNT; ++i) { byte value = elementAt((char)i); tempArray[i] = value; touchBlock(i >> BLOCKSHIFT, value); } for (i = 0; i < INDEXCOUNT; ++i) { indices[i] = (char)(i<<BLOCKSHIFT); } values = null; values = tempArray; isCompact = false; } }
384a1826-b3fc-4a61-8cee-4522edd10a9e
public SupplementaryCharacterData(int[] table) { dataTable = table; }
fb16c101-daf9-4936-bd80-6dc81be865bd
public int getValue(int index) { // Index should be a valid supplementary character. assert index >= Character.MIN_SUPPLEMENTARY_CODE_POINT && index <= Character.MAX_CODE_POINT : "Invalid code point:" + Integer.toHexString(index); int i = 0; int j = dataTable.length - 1; int k; for (;;) { k = (i + j) / 2; int start = dataTable[k] >> 8; int end = dataTable[k+1] >> 8; if (index < start) { j = k; } else if (index > (end-1)) { i = k; } else { return dataTable[k] & 0xFF; } } }
67b0d28d-84f7-4057-8bc8-ee97e87c1513
public int[] getArray() { return dataTable; }
c6c3d601-228b-41e3-b3b0-bb51a712b393
static long getLong(byte[] buf, int offset) { long num = buf[offset]&0xFF; for (int i = 1; i < 8; i++) { num = num<<8 | (buf[offset+i]&0xFF); } return num; }
1b9ea019-30a9-4a0c-994e-f38f6dcc65d8
static int getInt(byte[] buf, int offset) { int num = buf[offset]&0xFF; for (int i = 1; i < 4; i++) { num = num<<8 | (buf[offset+i]&0xFF); } return num; }
2f50aab5-931d-499c-a5a1-0775568f0d22
static short getShort(byte[] buf, int offset) { short num = (short)(buf[offset]&0xFF); num = (short)(num<<8 | (buf[offset+1]&0xFF)); return num; }
bbcbb5fe-8b80-4800-a60d-2c2aa765e422
public RuleBasedBreakIterator(String datafile) throws IOException, MissingResourceException { readTables(datafile); }
a5b0ed60-d4cf-4999-9d55-9ecdbc612ced
protected void readTables(String datafile) throws IOException, MissingResourceException { byte[] buffer = readFile(datafile); /* Read header_info. */ int stateTableLength = OurBreakIterator.getInt(buffer, 0); int backwardsStateTableLength = OurBreakIterator.getInt(buffer, 4); int endStatesLength = OurBreakIterator.getInt(buffer, 8); int lookaheadStatesLength = OurBreakIterator.getInt(buffer, 12); int BMPdataLength = OurBreakIterator.getInt(buffer, 16); int nonBMPdataLength = OurBreakIterator.getInt(buffer, 20); int additionalDataLength = OurBreakIterator.getInt(buffer, 24); checksum = OurBreakIterator.getLong(buffer, 28); /* Read stateTable[numCategories * numRows] */ stateTable = new short[stateTableLength]; int offset = HEADER_LENGTH; for (int i = 0; i < stateTableLength; i++, offset+=2) { stateTable[i] = OurBreakIterator.getShort(buffer, offset); } /* Read backwardsStateTable[numCategories * numRows] */ backwardsStateTable = new short[backwardsStateTableLength]; for (int i = 0; i < backwardsStateTableLength; i++, offset+=2) { backwardsStateTable[i] = OurBreakIterator.getShort(buffer, offset); } /* Read endStates[numRows] */ endStates = new boolean[endStatesLength]; for (int i = 0; i < endStatesLength; i++, offset++) { endStates[i] = buffer[offset] == 1; } /* Read lookaheadStates[numRows] */ lookaheadStates = new boolean[lookaheadStatesLength]; for (int i = 0; i < lookaheadStatesLength; i++, offset++) { lookaheadStates[i] = buffer[offset] == 1; } /* Read a category table and indices for BMP characters. */ short[] temp1 = new short[BMP_INDICES_LENGTH]; // BMPindices for (int i = 0; i < BMP_INDICES_LENGTH; i++, offset+=2) { temp1[i] = OurBreakIterator.getShort(buffer, offset); } byte[] temp2 = new byte[BMPdataLength]; // BMPdata System.arraycopy(buffer, offset, temp2, 0, BMPdataLength); offset += BMPdataLength; charCategoryTable = new CompactByteArray(temp1, temp2); /* Read a category table for non-BMP characters. */ int[] temp3 = new int[nonBMPdataLength]; for (int i = 0; i < nonBMPdataLength; i++, offset+=4) { temp3[i] = OurBreakIterator.getInt(buffer, offset); } supplementaryCharCategoryTable = new SupplementaryCharacterData(temp3); /* Read additional data */ if (additionalDataLength > 0) { additionalData = new byte[additionalDataLength]; System.arraycopy(buffer, offset, additionalData, 0, additionalDataLength); } /* Set numCategories */ numCategories = stateTable.length / endStates.length; }
81d6def9-728c-4d4e-8dd1-2fc1b6e948ea
protected byte[] readFile(final String datafile) throws IOException, MissingResourceException { BufferedInputStream is; try { is = (BufferedInputStream)AccessController.doPrivileged( new PrivilegedExceptionAction() { public Object run() throws Exception { return new BufferedInputStream(getClass().getResourceAsStream("/sun/text/resources/" + datafile)); } } ); } catch (PrivilegedActionException e) { throw new InternalError(e.toString()); } int offset = 0; /* First, read magic, version, and header_info. */ int len = LABEL_LENGTH + 5; byte[] buf = new byte[len]; if (is.read(buf) != len) { throw new MissingResourceException("Wrong header length", datafile, ""); } /* Validate the magic number. */ for (int i = 0; i < LABEL_LENGTH; i++, offset++) { if (buf[offset] != LABEL[offset]) { throw new MissingResourceException("Wrong magic number", datafile, ""); } } /* Validate the version number. */ if (buf[offset] != supportedVersion) { throw new MissingResourceException("Unsupported version(" + buf[offset] + ")", datafile, ""); } /* Read data: totalDataSize + 8(for checksum) */ len = OurBreakIterator.getInt(buf, ++offset); buf = new byte[len]; if (is.read(buf) != len) { throw new MissingResourceException("Wrong data length", datafile, ""); } is.close(); return buf; }
c47b2701-1539-4462-8579-ad0149b980af
public Object run() throws Exception { return new BufferedInputStream(getClass().getResourceAsStream("/sun/text/resources/" + datafile)); }
f729ab63-4762-4f05-803f-42025ca5448e
byte[] getAdditionalData() { return additionalData; }
6a2241e7-dfca-4217-bbd2-ad6335c6104e
void setAdditionalData(byte[] b) { additionalData = b; }
2df80c3b-4d4e-42eb-9d1a-1be6e266f429
public Object clone() { RuleBasedBreakIterator result = (RuleBasedBreakIterator) super.clone(); if (text != null) { result.text = (CharacterIterator) text.clone(); } return result; }
72e74d61-7e68-49ad-bdb4-8d63aa48b331
public boolean equals(Object that) { try { if (that == null) { return false; } RuleBasedBreakIterator other = (RuleBasedBreakIterator) that; if (checksum != other.checksum) { return false; } if (text == null) { return other.text == null; } else { return text.equals(other.text); } } catch(ClassCastException e) { return false; } }
e95755d4-bf07-4c49-831c-a0118c12d5c7
public String toString() { StringBuffer sb = new StringBuffer(); sb.append('['); sb.append("checksum=0x" + Long.toHexString(checksum)); sb.append(']'); return sb.toString(); }
a04b20c1-09e7-4732-a336-95e20f771c6b
public int hashCode() { return (int)checksum; }
84a4832b-33c7-48ec-8bb6-f2d5d3c89e9a
public int first() { CharacterIterator t = getText(); t.first(); return t.getIndex(); }
624cf48d-a002-4aa5-a2a6-808f2305352b
public int last() { CharacterIterator t = getText(); // I'm not sure why, but t.last() returns the offset of the last character, // rather than the past-the-end offset t.setIndex(t.getEndIndex()); return t.getIndex(); }
2aec29ab-1474-4a73-bc4e-1770e94a2661
public int next(int n) { int result = current(); while (n > 0) { result = handleNext(); --n; } while (n < 0) { result = previous(); ++n; } return result; }
883cf4a2-e5ab-4ed4-85ed-e352e4488521
public int next() { return handleNext(); }
02ae2b96-ca3a-442d-b082-25507d20c3e9
public int previous() { // if we're already sitting at the beginning of the text, return DONE CharacterIterator text = getText(); if (current() == text.getBeginIndex()) { return BreakIterator.DONE; } // set things up. handlePrevious() will back us up to some valid // break position before the current position (we back our internal // iterator up one step to prevent handlePrevious() from returning // the current position), but not necessarily the last one before // where we started int start = current(); int lastResult = cachedLastKnownBreak; if (lastResult >= start || lastResult <= BreakIterator.DONE) { getPrevious(); lastResult = handlePrevious(); } else { //it might be better to check if handlePrevious() give us closer //safe value but handlePrevious() is slow too //So, this has to be done carefully text.setIndex(lastResult); } int result = lastResult; // iterate forward from the known break position until we pass our // starting point. The last break position before the starting // point is our return value while (result != BreakIterator.DONE && result < start) { lastResult = result; result = handleNext(); } // set the current iteration position to be the last break position // before where we started, and then return that value text.setIndex(lastResult); cachedLastKnownBreak = lastResult; return lastResult; }
533b6f2c-f02f-45a3-97e9-a0e7cb248de6
private int getPrevious() { char c2 = text.previous(); if (Character.isLowSurrogate(c2) && text.getIndex() > text.getBeginIndex()) { char c1 = text.previous(); if (Character.isHighSurrogate(c1)) { return Character.toCodePoint(c1, c2); } else { text.next(); } } return (int)c2; }
695de343-943f-46f2-9617-a8fe5d1c7f22
int getCurrent() { char c1 = text.current(); if (Character.isHighSurrogate(c1) && text.getIndex() < text.getEndIndex()) { char c2 = text.next(); text.previous(); if (Character.isLowSurrogate(c2)) { return Character.toCodePoint(c1, c2); } } return (int)c1; }
9bdfce4c-6cab-487c-abc3-3b8f2e4aef2c
private int getCurrentCodePointCount() { char c1 = text.current(); if (Character.isHighSurrogate(c1) && text.getIndex() < text.getEndIndex()) { char c2 = text.next(); text.previous(); if (Character.isLowSurrogate(c2)) { return 2; } } return 1; }
672289dd-6631-478e-b59e-084f8a14520a
int getNext() { int index = text.getIndex(); int endIndex = text.getEndIndex(); if (index == endIndex || (index = index + getCurrentCodePointCount()) >= endIndex) { return CharacterIterator.DONE; } text.setIndex(index); return getCurrent(); }
254bbeb8-f04a-4f07-8c7c-20235eb5d4c3
private int getNextIndex() { int index = text.getIndex() + getCurrentCodePointCount(); int endIndex = text.getEndIndex(); if (index > endIndex) { return endIndex; } else { return index; } }
85b06c76-69ee-40fa-abff-29a95ab63785
protected static final void checkOffset(int offset, CharacterIterator text) { if (offset < text.getBeginIndex() || offset > text.getEndIndex()) { throw new IllegalArgumentException("offset out of bounds"); } }
91bce629-d533-468b-a32a-f4e70f958908
public int following(int offset) { CharacterIterator text = getText(); checkOffset(offset, text); // Set our internal iteration position (temporarily) // to the position passed in. If this is the _beginning_ position, // then we can just use next() to get our return value text.setIndex(offset); if (offset == text.getBeginIndex()) { cachedLastKnownBreak = handleNext(); return cachedLastKnownBreak; } // otherwise, we have to sync up first. Use handlePrevious() to back // us up to a known break position before the specified position (if // we can determine that the specified position is a break position, // we don't back up at all). This may or may not be the last break // position at or before our starting position. Advance forward // from here until we've passed the starting position. The position // we stop on will be the first break position after the specified one. int result = cachedLastKnownBreak; if (result >= offset || result <= BreakIterator.DONE) { result = handlePrevious(); } else { //it might be better to check if handlePrevious() give us closer //safe value but handlePrevious() is slow too //So, this has to be done carefully text.setIndex(result); } while (result != BreakIterator.DONE && result <= offset) { result = handleNext(); } cachedLastKnownBreak = result; return result; }
05c59c32-f0ff-4d53-b554-6184af5594c5
public int preceding(int offset) { // if we start by updating the current iteration position to the // position specified by the caller, we can just use previous() // to carry out this operation CharacterIterator text = getText(); checkOffset(offset, text); text.setIndex(offset); return previous(); }
39e76c6e-05fd-4e15-aa60-f1e36ca6a919
public boolean isBoundary(int offset) { CharacterIterator text = getText(); checkOffset(offset, text); if (offset == text.getBeginIndex()) { return true; } // to check whether this is a boundary, we can use following() on the // position before the specified one and return true if the position we // get back is the one the user specified else { return following(offset - 1) == offset; } }
cf535576-b11c-4ab1-8ab9-bb69c03e7e43
public int current() { return getText().getIndex(); }
84d2138b-fd69-46c2-87cc-8726cd9b5137
public CharacterIterator getText() { // The iterator is initialized pointing to no text at all, so if this // function is called while we're in that state, we have to fudge an // iterator to return. if (text == null) { text = new StringCharacterIterator(""); } return text; }
f0a9c5d2-f6d3-49b8-9ba5-0c26a4234aae
public void setText(CharacterIterator newText) { // Test iterator to see if we need to wrap it in a SafeCharIterator. // The correct behavior for CharacterIterators is to allow the // position to be set to the endpoint of the iterator. Many // CharacterIterators do not uphold this, so this is a workaround // to permit them to use this class. int end = newText.getEndIndex(); boolean goodIterator; try { newText.setIndex(end); // some buggy iterators throw an exception here goodIterator = newText.getIndex() == end; } catch(IllegalArgumentException e) { goodIterator = false; } if (goodIterator) { text = newText; } else { text = new SafeCharIterator(newText); } text.first(); cachedLastKnownBreak = BreakIterator.DONE; }
d6f07228-89a5-4dfe-a11f-4b1929002719
protected int handleNext() { // if we're already at the end of the text, return DONE. CharacterIterator text = getText(); if (text.getIndex() == text.getEndIndex()) { return BreakIterator.DONE; } // no matter what, we always advance at least one character forward int result = getNextIndex(); int lookaheadResult = 0; // begin in state 1 int state = START_STATE; int category; int c = getCurrent(); // loop until we reach the end of the text or transition to state 0 while (c != CharacterIterator.DONE && state != STOP_STATE) { // look up the current character's character category (which tells us // which column in the state table to look at) category = lookupCategory(c); // if the character isn't an ignore character, look up a state // transition in the state table if (category != IGNORE) { state = lookupState(state, category); } // if the state we've just transitioned to is a lookahead state, // (but not also an end state), save its position. If it's // both a lookahead state and an end state, update the break position // to the last saved lookup-state position if (lookaheadStates[state]) { if (endStates[state]) { result = lookaheadResult; } else { lookaheadResult = getNextIndex(); } } // otherwise, if the state we've just transitioned to is an accepting // state, update the break position to be the current iteration position else { if (endStates[state]) { result = getNextIndex(); } } c = getNext(); } // if we've run off the end of the text, and the very last character took us into // a lookahead state, advance the break position to the lookahead position // (the theory here is that if there are no characters at all after the lookahead // position, that always matches the lookahead criteria) if (c == CharacterIterator.DONE && lookaheadResult == text.getEndIndex()) { result = lookaheadResult; } text.setIndex(result); return result; }
7f265ad3-7b5d-4aa6-8a5b-0146ed1bbbac
protected int handlePrevious() { CharacterIterator text = getText(); int state = START_STATE; int category = 0; int lastCategory = 0; int c = getCurrent(); // loop until we reach the beginning of the text or transition to state 0 while (c != CharacterIterator.DONE && state != STOP_STATE) { // save the last character's category and look up the current // character's category lastCategory = category; category = lookupCategory(c); // if the current character isn't an ignore character, look up a // state transition in the backwards state table if (category != IGNORE) { state = lookupBackwardState(state, category); } // then advance one character backwards c = getPrevious(); } // if we didn't march off the beginning of the text, we're either one or two // positions away from the real break position. (One because of the call to // previous() at the end of the loop above, and another because the character // that takes us into the stop state will always be the character BEFORE // the break position.) if (c != CharacterIterator.DONE) { if (lastCategory != IGNORE) { getNext(); getNext(); } else { getNext(); } } return text.getIndex(); }
eeabbd67-ded6-4f9c-82b4-fe9e19b69d67
protected int lookupCategory(int c) { if (c < Character.MIN_SUPPLEMENTARY_CODE_POINT) { return charCategoryTable.elementAt((char)c); } else { return supplementaryCharCategoryTable.getValue(c); } }
f08684e1-12dc-4ef7-9dc3-961b0b86f667
protected int lookupState(int state, int category) { return stateTable[state * numCategories + category]; }
e4512f2e-df40-419c-882a-538fc72b216c
protected int lookupBackwardState(int state, int category) { return backwardsStateTable[state * numCategories + category]; }
1a31eb61-77e1-4dea-9133-74c365cecc5b
SafeCharIterator(CharacterIterator base) { this.base = base; this.rangeStart = base.getBeginIndex(); this.rangeLimit = base.getEndIndex(); this.currentIndex = base.getIndex(); }
61b6ee21-d251-4b09-8616-0f8198984953
public char first() { return setIndex(rangeStart); }
0253f14d-8dfc-4e3f-90f6-608893b58b4b
public char last() { return setIndex(rangeLimit - 1); }
751fd5cd-0ff2-463a-8ecb-2d58dcfa7f60
public char current() { if (currentIndex < rangeStart || currentIndex >= rangeLimit) { return DONE; } else { return base.setIndex(currentIndex); } }
2e1091d9-cbb8-4394-9a56-76956db06473
public char next() { currentIndex++; if (currentIndex >= rangeLimit) { currentIndex = rangeLimit; return DONE; } else { return base.setIndex(currentIndex); } }
1c176c85-6ddc-4aab-af6a-045841ef4581
public char previous() { currentIndex--; if (currentIndex < rangeStart) { currentIndex = rangeStart; return DONE; } else { return base.setIndex(currentIndex); } }
d89f9cd1-151a-4b17-83eb-127124fe4705
public char setIndex(int i) { if (i < rangeStart || i > rangeLimit) { throw new IllegalArgumentException("Invalid position"); } currentIndex = i; return current(); }
29f6481e-a6c4-4d18-a590-7350c622f734
public int getBeginIndex() { return rangeStart; }
834c24ff-cc2c-4a35-90f4-9c8adf6b6bc9
public int getEndIndex() { return rangeLimit; }
eab617f5-5e05-4334-976c-06b29205b70d
public int getIndex() { return currentIndex; }
3bfce193-3629-45a8-8385-06f507f4b43d
public Object clone() { SafeCharIterator copy = null; try { copy = (SafeCharIterator) super.clone(); } catch(CloneNotSupportedException e) { throw new Error("Clone not supported: " + e); } CharacterIterator copyOfBase = (CharacterIterator) base.clone(); copy.base = copyOfBase; return copy; }
ac5273a8-5474-4446-a590-1ddc521e48aa
public DictionaryBasedBreakIterator(String dataFile, String dictionaryFile) throws IOException { super(dataFile); byte[] tmp = super.getAdditionalData(); if (tmp != null) { prepareCategoryFlags(tmp); super.setAdditionalData(null); } dictionary = new BreakDictionary(new BufferedInputStream(getClass().getResourceAsStream("/" + dictionaryFile))); }
d43a80d1-0537-4f47-b011-f5b1381e5b21
private void prepareCategoryFlags(byte[] data) { categoryFlags = new boolean[data.length]; for (int i = 0; i < data.length; i++) { categoryFlags[i] = (data[i] == (byte)1) ? true : false; } }
6068218b-f4aa-48b9-969d-62aeb982389e
public void setText(CharacterIterator newText) { super.setText(newText); cachedBreakPositions = null; dictionaryCharCount = 0; positionInCache = 0; }
ee82d910-53ee-4b42-99fc-0999b70bc717
public int first() { cachedBreakPositions = null; dictionaryCharCount = 0; positionInCache = 0; return super.first(); }
6fcb71da-bb5f-4ffe-8fb4-8dfd80757cb7
public int last() { cachedBreakPositions = null; dictionaryCharCount = 0; positionInCache = 0; return super.last(); }
27c46527-23a0-4b04-85fe-f39bb2bcea05
public int previous() { CharacterIterator text = getText(); // if we have cached break positions and we're still in the range // covered by them, just move one step backward in the cache if (cachedBreakPositions != null && positionInCache > 0) { --positionInCache; text.setIndex(cachedBreakPositions[positionInCache]); return cachedBreakPositions[positionInCache]; } // otherwise, dump the cache and use the inherited previous() method to move // backward. This may fill up the cache with new break positions, in which // case we have to mark our position in the cache else { cachedBreakPositions = null; int result = super.previous(); if (cachedBreakPositions != null) { positionInCache = cachedBreakPositions.length - 2; } return result; } }
5ee06d04-13b0-4f9f-b0aa-d168f9cb72a3
public int preceding(int offset) { CharacterIterator text = getText(); checkOffset(offset, text); // if we have no cached break positions, or "offset" is outside the // range covered by the cache, we can just call the inherited routine // (which will eventually call other routines in this class that may // refresh the cache) if (cachedBreakPositions == null || offset <= cachedBreakPositions[0] || offset > cachedBreakPositions[cachedBreakPositions.length - 1]) { cachedBreakPositions = null; return super.preceding(offset); } // on the other hand, if "offset" is within the range covered by the cache, // then all we have to do is search the cache for the last break position // before "offset" else { positionInCache = 0; while (positionInCache < cachedBreakPositions.length && offset > cachedBreakPositions[positionInCache]) { ++positionInCache; } --positionInCache; text.setIndex(cachedBreakPositions[positionInCache]); return text.getIndex(); } }
a58aa49f-34e7-49bb-a47d-794b09ac2152
public int following(int offset) { CharacterIterator text = getText(); checkOffset(offset, text); // if we have no cached break positions, or if "offset" is outside the // range covered by the cache, then dump the cache and call our // inherited following() method. This will call other methods in this // class that may refresh the cache. if (cachedBreakPositions == null || offset < cachedBreakPositions[0] || offset >= cachedBreakPositions[cachedBreakPositions.length - 1]) { cachedBreakPositions = null; return super.following(offset); } // on the other hand, if "offset" is within the range covered by the // cache, then just search the cache for the first break position // after "offset" else { positionInCache = 0; while (positionInCache < cachedBreakPositions.length && offset >= cachedBreakPositions[positionInCache]) { ++positionInCache; } text.setIndex(cachedBreakPositions[positionInCache]); return text.getIndex(); } }
4f28a01c-ee45-4602-b87e-faa8b4d63c8b
protected int handleNext() { CharacterIterator text = getText(); // if there are no cached break positions, or if we've just moved // off the end of the range covered by the cache, we have to dump // and possibly regenerate the cache if (cachedBreakPositions == null || positionInCache == cachedBreakPositions.length - 1) { // start by using the inherited handleNext() to find a tentative return // value. dictionaryCharCount tells us how many dictionary characters // we passed over on our way to the tentative return value int startPos = text.getIndex(); dictionaryCharCount = 0; int result = super.handleNext(); // if we passed over more than one dictionary character, then we use // divideUpDictionaryRange() to regenerate the cached break positions // for the new range if (dictionaryCharCount > 1 && result - startPos > 1) { divideUpDictionaryRange(startPos, result); } // otherwise, the value we got back from the inherited fuction // is our return value, and we can dump the cache else { cachedBreakPositions = null; return result; } } // if the cache of break positions has been regenerated (or existed all // along), then just advance to the next break position in the cache // and return it if (cachedBreakPositions != null) { ++positionInCache; text.setIndex(cachedBreakPositions[positionInCache]); return cachedBreakPositions[positionInCache]; } return -9999; // SHOULD NEVER GET HERE! }