@Test public void shouldIndicateAbsenceOfSubstring() { Assert.assertEquals(-1, new TextNode("abcdef").indexOf(new TextNode("cdefg"))); Assert.assertEquals(-1, new TextNode("abcdef").indexOf(new TextNode("ac"))); Assert.assertEquals(-1, new TextNode("abcdef").indexOf(new TextNode("xab"))); Assert.assertEquals(-1, new TextNode("abcdef").indexOf(new TextNode("cdf"))); }
public int indexOf(final int thisFromIndex, final int thisEndIndex, final TextNode needle, final int needleFromIndex, final int needleToIndex) { final int searchLength = needleToIndex - needleFromIndex; if (searchLength <= 0) return thisFromIndex; final int maxIndex = thisEndIndex - searchLength; final char[] needleValue = needle.value.elements(); final char[] value = this.value.elements(); findStart: for (int startIndex = thisFromIndex; startIndex <= maxIndex; startIndex++) if (value[startIndex] == needleValue[needleFromIndex]) { for (int pos = 1; pos < searchLength; pos++) if (value[startIndex + pos] != needleValue[needleFromIndex + pos]) continue findStart; return startIndex; } return -1; }
TextNode extends AbstractJsonNode implements IPrimitiveNode,
		CharSequence, Appendable { public int indexOf(final int thisFromIndex, final int thisEndIndex, final TextNode needle, final int needleFromIndex, final int needleToIndex) { final int searchLength = needleToIndex - needleFromIndex; if (searchLength <= 0) return thisFromIndex; final int maxIndex = thisEndIndex - searchLength; final char[] needleValue = needle.value.elements(); final char[] value = this.value.elements(); findStart: for (int startIndex = thisFromIndex; startIndex <= maxIndex; startIndex++) if (value[startIndex] == needleValue[needleFromIndex]) { for (int pos = 1; pos < searchLength; pos++) if (value[startIndex + pos] != needleValue[needleFromIndex + pos]) continue findStart; return startIndex; } return -1; } }
TextNode extends AbstractJsonNode implements IPrimitiveNode,
		CharSequence, Appendable { public int indexOf(final int thisFromIndex, final int thisEndIndex, final TextNode needle, final int needleFromIndex, final int needleToIndex) { final int searchLength = needleToIndex - needleFromIndex; if (searchLength <= 0) return thisFromIndex; final int maxIndex = thisEndIndex - searchLength; final char[] needleValue = needle.value.elements(); final char[] value = this.value.elements(); findStart: for (int startIndex = thisFromIndex; startIndex <= maxIndex; startIndex++) if (value[startIndex] == needleValue[needleFromIndex]) { for (int pos = 1; pos < searchLength; pos++) if (value[startIndex + pos] != needleValue[needleFromIndex + pos]) continue findStart; return startIndex; } return -1; } TextNode();  TextNode(final CharSequence v); }
TextNode extends AbstractJsonNode implements IPrimitiveNode,
		CharSequence, Appendable { public int indexOf(final int thisFromIndex, final int thisEndIndex, final TextNode needle, final int needleFromIndex, final int needleToIndex) { final int searchLength = needleToIndex - needleFromIndex; if (searchLength <= 0) return thisFromIndex; final int maxIndex = thisEndIndex - searchLength; final char[] needleValue = needle.value.elements(); final char[] value = this.value.elements(); findStart: for (int startIndex = thisFromIndex; startIndex <= maxIndex; startIndex++) if (value[startIndex] == needleValue[needleFromIndex]) { for (int pos = 1; pos < searchLength; pos++) if (value[startIndex + pos] != needleValue[needleFromIndex + pos]) continue findStart; return startIndex; } return -1; } TextNode();  TextNode(final CharSequence v); @Override Appendable append(final char c); @Override Appendable append(final CharSequence csq); @Override Appendable append(final CharSequence csq, final int start, final int end); void append(final long number); Appendable append(final TextNode csq); Appendable append(final TextNode csq, final int start, final int end); @Override void appendAsString(final Appendable appendable); Formatter asFormatter(); @Override char charAt(final int index); @Override void clear(); @Override int compareToSameType(final IJsonNode other); boolean contentEquals(final CharSequence seq); @Override void copyValueFrom(final IJsonNode otherNode); @Override boolean equals(final Object obj); @Override Class<TextNode> getType(); @Override int hashCode(); int indexOf(final int thisFromIndex, final int thisEndIndex, final TextNode needle,
			final int needleFromIndex, final int needleToIndex); int indexOf(final TextNode needle); @Override int length(); void setLength(final int newLength); void setValue(final CharSequence value); void setValue(final CharSequence text, final int start, final int end); void setValue(final TextNode text, final int start, final int end); @Override CharSequence subSequence(final int start, final int end); char[] toArray(); static TextNode valueOf(final String v); void append(IJsonNode node); }
TextNode extends AbstractJsonNode implements IPrimitiveNode,
		CharSequence, Appendable { public int indexOf(final int thisFromIndex, final int thisEndIndex, final TextNode needle, final int needleFromIndex, final int needleToIndex) { final int searchLength = needleToIndex - needleFromIndex; if (searchLength <= 0) return thisFromIndex; final int maxIndex = thisEndIndex - searchLength; final char[] needleValue = needle.value.elements(); final char[] value = this.value.elements(); findStart: for (int startIndex = thisFromIndex; startIndex <= maxIndex; startIndex++) if (value[startIndex] == needleValue[needleFromIndex]) { for (int pos = 1; pos < searchLength; pos++) if (value[startIndex + pos] != needleValue[needleFromIndex + pos]) continue findStart; return startIndex; } return -1; } TextNode();  TextNode(final CharSequence v); @Override Appendable append(final char c); @Override Appendable append(final CharSequence csq); @Override Appendable append(final CharSequence csq, final int start, final int end); void append(final long number); Appendable append(final TextNode csq); Appendable append(final TextNode csq, final int start, final int end); @Override void appendAsString(final Appendable appendable); Formatter asFormatter(); @Override char charAt(final int index); @Override void clear(); @Override int compareToSameType(final IJsonNode other); boolean contentEquals(final CharSequence seq); @Override void copyValueFrom(final IJsonNode otherNode); @Override boolean equals(final Object obj); @Override Class<TextNode> getType(); @Override int hashCode(); int indexOf(final int thisFromIndex, final int thisEndIndex, final TextNode needle,
			final int needleFromIndex, final int needleToIndex); int indexOf(final TextNode needle); @Override int length(); void setLength(final int newLength); void setValue(final CharSequence value); void setValue(final CharSequence text, final int start, final int end); void setValue(final TextNode text, final int start, final int end); @Override CharSequence subSequence(final int start, final int end); char[] toArray(); static TextNode valueOf(final String v); void append(IJsonNode node); final static TextNode EMPTY_STRING; }