diff options
Diffstat (limited to 'src/main/java/cuchaz/enigma/analysis/Token.java')
| -rw-r--r-- | src/main/java/cuchaz/enigma/analysis/Token.java | 72 |
1 files changed, 0 insertions, 72 deletions
diff --git a/src/main/java/cuchaz/enigma/analysis/Token.java b/src/main/java/cuchaz/enigma/analysis/Token.java deleted file mode 100644 index f0155e5..0000000 --- a/src/main/java/cuchaz/enigma/analysis/Token.java +++ /dev/null | |||
| @@ -1,72 +0,0 @@ | |||
| 1 | /******************************************************************************* | ||
| 2 | * Copyright (c) 2015 Jeff Martin. | ||
| 3 | * All rights reserved. This program and the accompanying materials | ||
| 4 | * are made available under the terms of the GNU Lesser General Public | ||
| 5 | * License v3.0 which accompanies this distribution, and is available at | ||
| 6 | * http://www.gnu.org/licenses/lgpl.html | ||
| 7 | * <p> | ||
| 8 | * Contributors: | ||
| 9 | * Jeff Martin - initial API and implementation | ||
| 10 | ******************************************************************************/ | ||
| 11 | |||
| 12 | package cuchaz.enigma.analysis; | ||
| 13 | |||
| 14 | public class Token implements Comparable<Token> { | ||
| 15 | |||
| 16 | public int start; | ||
| 17 | public int end; | ||
| 18 | public String text; | ||
| 19 | |||
| 20 | public Token(int start, int end, String text) { | ||
| 21 | this.start = start; | ||
| 22 | this.end = end; | ||
| 23 | this.text = text; | ||
| 24 | } | ||
| 25 | |||
| 26 | public int getRenameOffset(String to) { | ||
| 27 | int length = this.end - this.start; | ||
| 28 | return to.length() - length; | ||
| 29 | } | ||
| 30 | |||
| 31 | public void rename(StringBuffer source, String to) { | ||
| 32 | int oldEnd = this.end; | ||
| 33 | this.text = to; | ||
| 34 | this.end = this.start + to.length(); | ||
| 35 | |||
| 36 | source.replace(start, oldEnd, to); | ||
| 37 | } | ||
| 38 | |||
| 39 | public Token move(int offset) { | ||
| 40 | Token token = new Token(this.start + offset, this.end + offset, null); | ||
| 41 | token.text = text; | ||
| 42 | return token; | ||
| 43 | } | ||
| 44 | |||
| 45 | public boolean contains(int pos) { | ||
| 46 | return pos >= start && pos <= end; | ||
| 47 | } | ||
| 48 | |||
| 49 | @Override | ||
| 50 | public int compareTo(Token other) { | ||
| 51 | return start - other.start; | ||
| 52 | } | ||
| 53 | |||
| 54 | @Override | ||
| 55 | public boolean equals(Object other) { | ||
| 56 | return other instanceof Token && equals((Token) other); | ||
| 57 | } | ||
| 58 | |||
| 59 | @Override | ||
| 60 | public int hashCode() { | ||
| 61 | return start * 37 + end; | ||
| 62 | } | ||
| 63 | |||
| 64 | public boolean equals(Token other) { | ||
| 65 | return start == other.start && end == other.end && text.equals(other.text); | ||
| 66 | } | ||
| 67 | |||
| 68 | @Override | ||
| 69 | public String toString() { | ||
| 70 | return String.format("[%d,%d]", start, end); | ||
| 71 | } | ||
| 72 | } | ||