/** * Check whether the given String has actual text. * More specifically, returns <code>true</code> if the string not <code>null</code>, * its length is greater than 0, and it contains at least one non-whitespace character. * * @param str the String to check (may be <code>null</code>) * @return <code>true</code> if the String is not <code>null</code>, its length is * greater than 0, and it does not contain whitespace only * @see #hasText(CharSequence) */ public static boolean hasText(String str) { return hasText((CharSequence) str); }
private AliasAction(String index) { if (false == Strings.hasText(index)) { throw new IllegalArgumentException("[index] is required"); } this.index = index; }
/** * Build the operation. */ public Remove(String index, String alias) { super(index); if (false == Strings.hasText(alias)) { throw new IllegalArgumentException("[alias] is required"); } this.alias = alias; }
public static Request putScript(PutStoredScriptRequest putStoredScriptRequest) throws IOException { String endpoint = new EndpointBuilder().addPathPartAsIs("_scripts").addPathPart(putStoredScriptRequest.id()) .build(); Request request = new Request(HttpMethod.POST.name(), endpoint); Params params = new Params(request); params.withTimeout(putStoredScriptRequest.timeout()); params.withMasterTimeout(putStoredScriptRequest.masterNodeTimeout()); if (Strings.hasText(putStoredScriptRequest.context())) { params.putParam("context", putStoredScriptRequest.context()); } request.setEntity(createEntity(putStoredScriptRequest, REQUEST_BODY_CONTENT_TYPE)); return request; }
/** * This does a very basic pass at validating that a header's value contains only expected characters according to RFC-5987, and those * that it references. * <p> * https://tools.ietf.org/html/rfc5987 * <p> * This is only expected to be used for assertions. The idea is that only readable US-ASCII characters are expected; the rest must be * encoded with percent encoding, which makes checking for a valid character range very simple. * * @param value The header value to check * @return {@code true} if the {@code value} is not obviously wrong. */ public static boolean validHeaderValue(String value) { if (Strings.hasText(value) == false) { return false; } for (int i = 0; i < value.length(); i++) { char c = value.charAt(i); // 32 = ' ' (31 = unit separator); 126 = '~' (127 = DEL) if (c < 32 || c > 126) { return false; } } return true; }
void validateAliasStandalone(String alias, String indexRouting) { if (!Strings.hasText(alias)) { throw new IllegalArgumentException("alias name is required"); } MetaDataCreateIndexService.validateIndexOrAliasName(alias, InvalidAliasNameException::new); if (indexRouting != null && indexRouting.indexOf(',') != -1) { throw new IllegalArgumentException("alias [" + alias + "] has several index routing values associated with it"); } }
public static List<String> loadWordList(Reader reader, String comment) throws IOException { final List<String> result = new ArrayList<>(); BufferedReader br = null; try { if (reader instanceof BufferedReader) { br = (BufferedReader) reader; } else { br = new BufferedReader(reader); } String word; while ((word = br.readLine()) != null) { if (!Strings.hasText(word)) { continue; } if (!word.startsWith(comment)) { result.add(word.trim()); } } } finally { if (br != null) br.close(); } return result; }
private static String[] splitAndValidatePath(String fullFieldPath) { if (fullFieldPath.contains(".")) { String[] parts = fullFieldPath.split("\\."); for (String part : parts) { if (Strings.hasText(part) == false) { // check if the field name contains only whitespace if (Strings.isEmpty(part) == false) { throw new IllegalArgumentException( "object field cannot contain only whitespace: ['" + fullFieldPath + "']"); } throw new IllegalArgumentException( "object field starting or ending with a [.] makes object resolution ambiguous: [" + fullFieldPath + "]"); } } return parts; } else { if (Strings.isEmpty(fullFieldPath)) { throw new IllegalArgumentException("field name cannot be an empty string"); } return new String[] {fullFieldPath}; } }
NetworkTypes(final List<NodeInfo> nodeInfos) { final Map<String, AtomicInteger> transportTypes = new HashMap<>(); final Map<String, AtomicInteger> httpTypes = new HashMap<>(); for (final NodeInfo nodeInfo : nodeInfos) { final Settings settings = nodeInfo.getSettings(); final String transportType = settings.get(NetworkModule.TRANSPORT_TYPE_KEY, NetworkModule.TRANSPORT_DEFAULT_TYPE_SETTING.get(settings)); final String httpType = settings.get(NetworkModule.HTTP_TYPE_KEY, NetworkModule.HTTP_DEFAULT_TYPE_SETTING.get(settings)); if (Strings.hasText(transportType)) { transportTypes.computeIfAbsent(transportType, k -> new AtomicInteger()).incrementAndGet(); } if (Strings.hasText(httpType)) { httpTypes.computeIfAbsent(httpType, k -> new AtomicInteger()).incrementAndGet(); } } this.transportTypes = Collections.unmodifiableMap(transportTypes); this.httpTypes = Collections.unmodifiableMap(httpTypes); }
@Override public ActionRequestValidationException validate() { ActionRequestValidationException validationException = null; if (names == null) { validationException = addValidationError("names is null or empty", validationException); } else { for (String name : names) { if (name == null || !Strings.hasText(name)) { validationException = addValidationError("name is missing", validationException); } } } return validationException; }
/** * Validate a proposed alias. */ public void validateAlias(String alias, String index, @Nullable String indexRouting, Function<String, IndexMetaData> indexLookup) { validateAliasStandalone(alias, indexRouting); if (!Strings.hasText(index)) { throw new IllegalArgumentException("index name is required"); } IndexMetaData indexNamedSameAsAlias = indexLookup.apply(alias); if (indexNamedSameAsAlias != null) { throw new InvalidAliasNameException(indexNamedSameAsAlias.getIndex(), alias, "an index exists with the same name as the alias"); } }
/** * Build the operation. */ public Add(String index, String alias, @Nullable String filter, @Nullable String indexRouting, @Nullable String searchRouting, @Nullable Boolean writeIndex) { super(index); if (false == Strings.hasText(alias)) { throw new IllegalArgumentException("[alias] is required"); } this.alias = alias; this.filter = filter; this.indexRouting = indexRouting; this.searchRouting = searchRouting; this.writeIndex = writeIndex; }
if (Strings.hasText(repositoryName) && request.snapshots() != null && request.snapshots().length > 0) { final Set<String> requestedSnapshotNames = Sets.newHashSet(request.snapshots()); final RepositoryData repositoryData = snapshotsService.getRepositoryData(repositoryName);
public Builder name(String name) { if (Strings.hasText(name) == false){ throw new IllegalArgumentException("role name must be provided"); } else { this.name = name; } return this; }
private AliasAction(String index) { if (false == Strings.hasText(index)) { throw new IllegalArgumentException("[index] is required"); } this.index = index; }
/** * Build the operation. */ public Remove(String index, String alias) { super(index); if (false == Strings.hasText(alias)) { throw new IllegalArgumentException("[alias] is required"); } this.alias = alias; }
private static String[] splitAndValidatePath(String fullFieldPath) { String[] parts = fullFieldPath.split("\\."); for (String part : parts) { if (Strings.hasText(part) == false) { throw new IllegalArgumentException( "object field starting or ending with a [.] makes object resolution ambiguous: [" + fullFieldPath + "]"); } } return parts; }
highlighterContext.query, hitContext.docId(), numberOfFragments); for (Snippet fieldSnippet : fieldSnippets) { if (Strings.hasText(fieldSnippet.getText())) { snippets.add(fieldSnippet);
/** * Create a request to read the content of one or more index templates. If no template names are provided, all templates will be read * * @param names the names of templates to read */ public GetIndexTemplatesRequest(List<String> names) { Objects.requireNonNull(names); if (names.stream().anyMatch(name -> name == null || Strings.hasText(name) == false)) { throw new IllegalArgumentException("all index template names must be non null and non empty"); } this.names = unmodifiableList(names); }
if (Strings.hasText(sDocValueFields)) { String[] sFields = Strings.splitStringByCommaToArray(sDocValueFields); for (String field : sFields) {