Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class SolvedShift implements Comparable{
- public String message;
- public String[] keywords = new String[0];
- public int offset;
- public SolvedShift(String m, int o, String k) {
- message = m;
- offset = o;
- addKeyword(k);
- }
- public int compareTo(Object o) {
- SolvedShift temp = (SolvedShift)o;
- if (temp.keywords.length > keywords.length) {
- return 1;
- } else if (temp.keywords.length > keywords.length) {
- return -1;
- } else {
- if (temp.getWordLength() > getWordLength()) {
- return 1;
- } else {
- return -1;
- }
- }
- }
- public int getWordLength() {
- int sum = 0;
- for (String str: keywords) {
- sum += str.length();
- }
- return sum;
- }
- public void addKeyword(String word) {
- String[] k = new String[keywords.length + 1];
- for (int i = 0; i < keywords.length; i++) {
- k[i] = keywords[i];
- }
- k[k.length - 1] = word;
- keywords = k;
- }
- public void removeKeyword(int index) {
- String[] result = new String[keywords.length - 1];
- int offset = 0;
- for (int i = 0; i < keywords.length; i++) {
- if (i == index) {
- offset++;
- } else {
- result[i-offset] = keywords[i];
- }
- }
- keywords = result;
- }
- public void cleanKeywords() {
- for (int i = keywords.length - 1; i >= 0; i--) {
- for (int n = i - 1; n >= 0; n--) {
- if (keywords[n] == keywords[i]) {
- removeKeyword(i);
- break;
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement