@Test(expected = UnsupportedOperationException.class) public void testGeneratePrefixes_IteratorRemove() throws Exception { final CharSequence input = "BANANAS"; Iterator<CharSequence> iterator = CharSequences.generatePrefixes(input).iterator(); iterator.next(); iterator.remove(); }
public static Iterable<CharSequence> generatePrefixes(final CharSequence input) { return new Iterable<CharSequence>() { @Override public Iterator<CharSequence> iterator() { return new Iterator<CharSequence>() { int currentIndex = 0; @Override public boolean hasNext() { return currentIndex < input.length(); } @Override public CharSequence next() { return input.subSequence(0, ++currentIndex); } @Override public void remove() { throw new UnsupportedOperationException("Modification not supported"); } }; } }; }
CharSequences { public static Iterable<CharSequence> generatePrefixes(final CharSequence input) { return new Iterable<CharSequence>() { @Override public Iterator<CharSequence> iterator() { return new Iterator<CharSequence>() { int currentIndex = 0; @Override public boolean hasNext() { return currentIndex < input.length(); } @Override public CharSequence next() { return input.subSequence(0, ++currentIndex); } @Override public void remove() { throw new UnsupportedOperationException("Modification not supported"); } }; } }; } }
CharSequences { public static Iterable<CharSequence> generatePrefixes(final CharSequence input) { return new Iterable<CharSequence>() { @Override public Iterator<CharSequence> iterator() { return new Iterator<CharSequence>() { int currentIndex = 0; @Override public boolean hasNext() { return currentIndex < input.length(); } @Override public CharSequence next() { return input.subSequence(0, ++currentIndex); } @Override public void remove() { throw new UnsupportedOperationException("Modification not supported"); } }; } }; } CharSequences(); }
CharSequences { public static Iterable<CharSequence> generatePrefixes(final CharSequence input) { return new Iterable<CharSequence>() { @Override public Iterator<CharSequence> iterator() { return new Iterator<CharSequence>() { int currentIndex = 0; @Override public boolean hasNext() { return currentIndex < input.length(); } @Override public CharSequence next() { return input.subSequence(0, ++currentIndex); } @Override public void remove() { throw new UnsupportedOperationException("Modification not supported"); } }; } }; } CharSequences(); static Iterable<CharSequence> generateSuffixes(final CharSequence input); static Iterable<CharSequence> generatePrefixes(final CharSequence input); static CharSequence getCommonPrefix(CharSequence first, CharSequence second); static CharSequence getSuffix(CharSequence input, int startIndex); static CharSequence getPrefix(CharSequence input, int endIndex); static CharSequence subtractPrefix(CharSequence main, CharSequence prefix); static CharSequence concatenate(final CharSequence first, final CharSequence second); static CharSequence reverse(CharSequence input); static CharSequence fromCharArray(final char[] characters); static char[] toCharArray(CharSequence charSequence); static String toString(CharSequence charSequence); }
CharSequences { public static Iterable<CharSequence> generatePrefixes(final CharSequence input) { return new Iterable<CharSequence>() { @Override public Iterator<CharSequence> iterator() { return new Iterator<CharSequence>() { int currentIndex = 0; @Override public boolean hasNext() { return currentIndex < input.length(); } @Override public CharSequence next() { return input.subSequence(0, ++currentIndex); } @Override public void remove() { throw new UnsupportedOperationException("Modification not supported"); } }; } }; } CharSequences(); static Iterable<CharSequence> generateSuffixes(final CharSequence input); static Iterable<CharSequence> generatePrefixes(final CharSequence input); static CharSequence getCommonPrefix(CharSequence first, CharSequence second); static CharSequence getSuffix(CharSequence input, int startIndex); static CharSequence getPrefix(CharSequence input, int endIndex); static CharSequence subtractPrefix(CharSequence main, CharSequence prefix); static CharSequence concatenate(final CharSequence first, final CharSequence second); static CharSequence reverse(CharSequence input); static CharSequence fromCharArray(final char[] characters); static char[] toCharArray(CharSequence charSequence); static String toString(CharSequence charSequence);  }