/** * Like a String.indexOf but without MIN_SUPPLEMENTARY_CODE_POINT handling * * @param input to check the indexOf on * @param ch character to find the index of * @return index of the character, or -1 if not found */ public static int indexOf(String input, char ch) { return indexOf(input, ch, 0); }
boolean advanceToNextToken() { if (nextSplit == -1) { return false; } token = null; int oldNextSplit = nextSplit; nextSplit = StringUtil.indexOf(path, '.', oldNextSplit + 1); offset = oldNextSplit + 1; index++; return true; }
/** * Like a String.indexOf but without MIN_SUPPLEMENTARY_CODE_POINT handling * * @param input to check the indexOf on * @param ch character to find the index of * @return index of the character, or -1 if not found */ public static int indexOf(String input, char ch) { return indexOf(input, ch, 0); }
boolean advanceToNextToken() { if (nextSplit == -1) { return false; } token = null; int oldNextSplit = nextSplit; nextSplit = StringUtil.indexOf(path, '.', oldNextSplit + 1); offset = oldNextSplit + 1; index++; return true; }
/** * Inits the cursor with the given path and sets the current position to the first token. * * @param path path to initialise the cursor with */ void init(String path) { this.path = checkHasText(path, "path cannot be null or empty"); this.index = 0; this.offset = 0; this.nextSplit = StringUtil.indexOf(path, '.', 0); this.token = null; if (nextSplit == 0) { throw new IllegalArgumentException("The path cannot begin with a dot: " + path); } }
/** * Inits the cursor with the given path and sets the current position to the first token. * * @param path path to initialise the cursor with */ void init(String path) { this.path = checkHasText(path, "path cannot be null or empty"); this.index = 0; this.offset = 0; this.nextSplit = StringUtil.indexOf(path, '.', 0); this.token = null; if (nextSplit == 0) { throw new IllegalArgumentException("The path cannot begin with a dot: " + path); } }
/** * Sets the index to the given index without validating. If the index is out of bound the consecutive token() call * will throw a runtime exception. * * @param indexToNavigateTo value to set the cursor's index to. */ void index(int indexToNavigateTo) { this.index = 0; this.offset = 0; this.nextSplit = StringUtil.indexOf(path, '.', 0); this.token = null; for (int i = 1; i <= indexToNavigateTo; i++) { if (!advanceToNextToken()) { throw new IndexOutOfBoundsException("Index out of bound " + indexToNavigateTo + " in " + path); } } }
/** * Sets the index to the given index without validating. If the index is out of bound the consecutive token() call * will throw a runtime exception. * * @param indexToNavigateTo value to set the cursor's index to. */ void index(int indexToNavigateTo) { this.index = 0; this.offset = 0; this.nextSplit = StringUtil.indexOf(path, '.', 0); this.token = null; for (int i = 1; i <= indexToNavigateTo; i++) { if (!advanceToNextToken()) { throw new IndexOutOfBoundsException("Index out of bound " + indexToNavigateTo + " in " + path); } } }