public PatternVirtualFileVisitor(String rootPath, String subPattern, PathMatcher pathMatcher) { this.subPattern = subPattern; this.pathMatcher = pathMatcher; this.rootPath = (rootPath.isEmpty() || rootPath.endsWith("/") ? rootPath : rootPath + "/"); }
public static boolean empty( final String s ) { // Null-safe, short-circuit evaluation. return s == null || s.trim().isEmpty(); }
/** * Check that the given {@code String} is neither {@code null} nor of length 0. * <p>Note: this method returns {@code true} for a {@code String} that * purely consists of whitespace. * @param str the {@code String} to check (may be {@code null}) * @return {@code true} if the {@code String} is not {@code null} and has length * @see #hasLength(CharSequence) * @see #hasText(String) */ public static boolean hasLength(@Nullable String str) { return (str != null && !str.isEmpty()); }
List<String> list = new ArrayList<>(); // This is a clever way to create the iterator and call iterator.hasNext() like // you would do in a while-loop. It would be the same as doing: // Iterator<String> iterator = list.iterator(); // while (iterator.hasNext()) { for (Iterator<String> iterator = list.iterator(); iterator.hasNext();) { String string = iterator.next(); if (string.isEmpty()) { // Remove the current element from the iterator and the list. iterator.remove(); } }
@Override public T convert(String source) { if (source.isEmpty()) { // It's an empty enum identifier: reset the enum value to null. return null; } return (T) Enum.valueOf(this.enumType, source.trim()); } }
@Override public Character convert(String source) { if (source.isEmpty()) { return null; } if (source.length() > 1) { throw new IllegalArgumentException( "Can only convert a [String] with length of 1 to a [Character]; string value '" + source + "' has length of " + source.length()); } return source.charAt(0); }
static void checkName(String name) { if (name == null) throw new NullPointerException("name == null"); if (name.isEmpty()) throw new IllegalArgumentException("name is empty"); for (int i = 0, length = name.length(); i < length; i++) { char c = name.charAt(i); if (c <= '\u0020' || c >= '\u007f') { throw new IllegalArgumentException(Util.format( "Unexpected char %#04x at %d in header name: %s", (int) c, i, name)); } } }
@Override public void parse(CacheBuilderSpec spec, String key, String value) { checkArgument(value != null && !value.isEmpty(), "value of key %s omitted", key); try { parseInteger(spec, Integer.parseInt(value)); } catch (NumberFormatException e) { throw new IllegalArgumentException( format("key %s value set to %s, must be integer", key, value), e); } } }
@Override protected String computeNext() { if (lines.hasNext()) { String next = lines.next(); // skip last line if it's empty if (lines.hasNext() || !next.isEmpty()) { return next; } } return endOfData(); } };
@Override public void parse(CacheBuilderSpec spec, String key, String value) { checkArgument(value != null && !value.isEmpty(), "value of key %s omitted", key); try { parseLong(spec, Long.parseLong(value)); } catch (NumberFormatException e) { throw new IllegalArgumentException( format("key %s value set to %s, must be integer", key, value), e); } } }
private String resolveExpression(A annotation) { for (String attributeName : EXPRESSION_ATTRIBUTES) { Object val = AnnotationUtils.getValue(annotation, attributeName); if (val instanceof String) { String str = (String) val; if (!str.isEmpty()) { return str; } } } throw new IllegalStateException("Failed to resolve expression: " + annotation); }
@Override public T convert(String source) { if (source.isEmpty()) { return null; } return NumberUtils.parseNumber(source, this.targetType); } }
/** * Base64-decode the given byte array from an UTF-8 String. * @param src the encoded UTF-8 String * @return the original byte array */ public static byte[] decodeFromString(String src) { if (src.isEmpty()) { return new byte[0]; } return decode(src.getBytes(DEFAULT_CHARSET)); }
static int readInt(BufferedSource source) throws IOException { try { long result = source.readDecimalLong(); String line = source.readUtf8LineStrict(); if (result < 0 || result > Integer.MAX_VALUE || !line.isEmpty()) { throw new IOException("expected an int but was \"" + result + line + "\""); } return (int) result; } catch (NumberFormatException e) { throw new IOException(e.getMessage()); } }
private static String firstCharOnlyToUpper(String word) { return word.isEmpty() ? word : Ascii.toUpperCase(word.charAt(0)) + Ascii.toLowerCase(word.substring(1)); } }
/** * Sets this request's {@code Cache-Control} header, replacing any cache control headers already * present. If {@code cacheControl} doesn't define any directives, this clears this request's * cache-control headers. */ public Builder cacheControl(CacheControl cacheControl) { String value = cacheControl.toString(); if (value.isEmpty()) return removeHeader("Cache-Control"); return header("Cache-Control", value); }
private String getPartName(MethodParameter methodParam, @Nullable RequestPart requestPart) { String partName = (requestPart != null ? requestPart.name() : ""); if (partName.isEmpty()) { partName = methodParam.getParameterName(); if (partName == null) { throw new IllegalArgumentException("Request part name for argument type [" + methodParam.getNestedParameterType().getName() + "] not specified, and parameter name information not found in class file either."); } } return partName; }
private String getPartName(MethodParameter methodParam, @Nullable RequestPart requestPart) { String partName = (requestPart != null ? requestPart.name() : ""); if (partName.isEmpty()) { partName = methodParam.getParameterName(); if (partName == null) { throw new IllegalArgumentException("Request part name for argument type [" + methodParam.getNestedParameterType().getName() + "] not specified, and parameter name information not found in class file either."); } } return partName; }
private Expression parseTemplate(String expressionString, ParserContext context) throws ParseException { if (expressionString.isEmpty()) { return new LiteralExpression(""); } Expression[] expressions = parseExpressions(expressionString, context); if (expressions.length == 1) { return expressions[0]; } else { return new CompositeStringExpression(expressionString, expressions); } }