char consumeCharacter(CharMatcher matcher) { checkState(hasMore(), "No more elements!"); char c = previewChar(); checkState(matcher.matches(c), "Unexpected character matched: " + c); position++; return c; }
char consumeCharacter(char c) { checkState(hasMore(), "No more elements!"); checkState(previewChar() == c, () -> "Unexpected character: " + c); position++; return c; }
/** * Creates a simple {@link ByteBuffer} backed data chunk. The resulting * instance doesn't have any kind of a lifecycle and as such, it doesn't need * to be released. * * @param byteBuffer a byte buffer to create the request chunk from * @return a request chunk */ static DataChunk create(ByteBuffer byteBuffer) { return create(false, byteBuffer); }
String consumeTokenIfPresent(CharMatcher matcher) { checkState(hasMore(), "No more elements!"); int startPosition = position; position = matcher.negate().indexIn(input, startPosition); return hasMore() ? input.substring(startPosition, position) : input.substring(startPosition); }
/** * Convert a numerical status code into the corresponding ResponseStatus. * <p> * As opposed to {@link Status#find(int)}, this method is guaranteed to always return an instance. * For an unknown {@link Status} it creates an ad-hoc {@link ResponseStatus}. * * @param statusCode the numerical status code * @return the matching ResponseStatus; either a {@link Status} or an ad-hoc {@link ResponseStatus} */ static ResponseStatus create(int statusCode) { return create(statusCode, null); }
private static String normalizeToken(String token) { checkState(TOKEN_MATCHER.matchesAllOf(token), () -> String.format("Parameter '%s' doesn't match token matcher: %s", token, TOKEN_MATCHER)); return Ascii.toLowerCase(token); }
private static String badPositionIndexes(int start, int end, int size) { if (start < 0 || start > size) { return badPositionIndex(start, size, "start index"); } if (end < 0 || end > size) { return badPositionIndex(end, size, "end index"); } // end < start return format("end index (%s) must not be less than start index (%s)", end, start); }
/** * Creates a new fluent API builder. * * @param name a cookie name. * @param value a cookie value. * @return a new fluent API builder */ public static Builder builder(String name, String value) { return new Builder(name, value); }
/** * Creates a new empty instance. * * @return new instance */ static ContextualRegistry create() { return new ListContextualRegistry(); }
/** * Creates an instance from provided multi-map. * * @param data multi-map data to copy. */ public ReadOnlyParameters(Map<String, List<String>> data) { this.data = copyMultimapAsImutable(data); }
/** * Returns a {@code char} matcher that matches any character except the one specified. * * <p>To negate another {@code CharMatcher}, use {@link #negate()}. */ public static CharMatcher isNot(final char match) { return new IsNot(match); }
/** * Returns a matcher that matches any character not matched by this matcher. */ public CharMatcher negate() { return new Negated(this); }
/** * Returns a matcher that matches any character matched by either this matcher or {@code other}. */ public CharMatcher or(CharMatcher other) { return new Or(this, other); }
@Override public CharMatcher negate() { return new NegatedFastMatcher(this); } }