/** * Checks if the given value is filled and contains the given needle in its * string representation * * @param needle the substring to search * @return <tt>true</tt> if the given substring <tt>needle</tt> was found in the wrapped objects string * representation, <tt>false</tt> otherwise */ public boolean contains(String needle) { return asString("").contains(needle); }
/** * Returns a trimmed version of the string representation of the wrapped value. * <p> * The conversion method used is {@link #asString()}, therefore an empty value will yield {@code ""}. * * @return a string representing the wrapped value without leading or trailing spaces. */ @Nonnull public String trim() { return asString().trim(); }
/** * Checks if the string representation of the wrapped value starts with the given string. * * @param value the substring with which the string representation must start * @return <tt>true</tt> if the string representation starts with <tt>value</tt>, <tt>false</tt> otherwise. * If the current value is empty, it is treated as "" */ public boolean startsWith(@Nonnull String value) { return asString().startsWith(value); }
/** * Checks if the string representation of the wrapped value ends with the given string. * * @param value the substring with which the string representation must end * @return <tt>true</tt> if the string representation ends with <tt>value</tt>, <tt>false</tt> otherwise. * If the current value is empty, it is treated as "" */ public boolean endsWith(@Nonnull String value) { return asString().endsWith(value); }
/** * Determines if the given request contains an AWS4 auth token. * * @param ctx the request to check * @return <tt>true</tt> if the request contains an AWS4 auth token, <tt>false</tt> otherwise. */ public boolean supports(final WebContext ctx) { return AWS_AUTH4_PATTERN.matcher(ctx.getHeaderValue("Authorization").asString("")).matches(); }
/** * Returns the string for the given key. * * @param key the key used to lookup the string value * @return the string value stored of the given key */ public String getString(String key) { return get(key).asString(); }
/** * Returns the internal value wrapped as Optional. * <p> * If the value is empty, an empty Optional will be returned. * * @return the internal value wrapped as Optional or an empty Optional if the value is not filled */ public Optional<String> asOptionalString() { return isFilled() ? Optional.of(asString()) : Optional.empty(); }
/** * Returns the length of the string representation of the wrapped value. * * @return the length of the string representation of the wrapped value or 0, if the wrapped value is <tt>null</tt> */ public int length() { if (isNull()) { return 0; } return asString().length(); }
/** * Returns the string contents of the given field * * @param field the field to fetch * @return the string contents or "" if the field is empty */ @Nonnull public String getString(String field) { return get(field).asString(); }
/** * Returns the string contents of the given field * * @param field the field to fetch * @return the string contents or "" if the field is empty */ @Nonnull public String getString(Mapping field) { return get(field).asString(); }
/** * Reads a embedded map. * * @param key the key of the map to read * @return the map within the config */ public Map<String, String> getMap(String key) { Map<String, String> result = new HashMap<>(); config.getConfig(key) .entrySet() .forEach(e -> result.put(e.getKey(), Value.of(e.getValue().unwrapped()).asString())); return result; }
@Override protected Object transformFromElastic(Value data) { String valueAsString = data.asString(); if (Strings.isEmpty(valueAsString)) { return Amount.NOTHING; } return Amount.of(new BigDecimal(valueAsString)); }
@Override protected Object transformFromElastic(Value object) { String valueAsString = object.asString(); if (Strings.isEmpty(valueAsString)) { return null; } if (valueAsString.contains("+")) { return LocalDate.from(DateTimeFormatter.ISO_OFFSET_DATE.parse(valueAsString)); } else { return LocalDate.from(DateTimeFormatter.ISO_LOCAL_DATE.parse(valueAsString)); } }
private Optional<Database> determineSecondary(Extension ext) { if (!ext.get(KEY_SECONDARY_ENABLED).asBoolean()) { return Optional.empty(); } return Optional.ofNullable(dbs.get(ext.get(KEY_SECONDARY_DATABASE).asString())); }
@Override public void execute(Output output, String... params) throws Exception { String filter = Value.indexOf(0, params).asString().toLowerCase(); for (String name : index.getSchema().getTypeNames()) { if (Strings.isEmpty(filter) || name.toLowerCase().contains(filter)) { outputMapping(output, name); } } }
@Override public Object transformValue(Value value) { if (value.isFilled()) { return value.asString(); } if (this.isNullable() || Strings.isEmpty(defaultValue)) { return null; } return defaultValue; }
private void delete(Output output, Values values) { Class<? extends Entity> type = UpdateMappingCommand.findTypeOrReportError(output, values.at(1).asString()); if (type != null) { AtomicInteger rows = new AtomicInteger(); index.select(type).deliberatelyUnrouted().query(values.at(2).asString()).iterateAll(e -> { index.delete(e); rows.incrementAndGet(); }); outputAffectedRows(output, rows); } }
@Override public void readFromRequest(Entity entity, WebContext ctx) { try { if (ctx.get(getName()).isNull()) { return; } ((EntityRef<?>) getField().get(entity)).setId(ctx.get(getName()).asString()); } catch (IllegalAccessException e) { throw Exceptions.handle(IndexAccess.LOG, e); } }
@Override public Object transformValue(Value value) { if (value.isFilled()) { return NLS.parseUserString(Amount.class, value.asString()); } if (this.isNullable() || Strings.isEmpty(defaultValue)) { return Amount.NOTHING; } return Value.of(defaultValue).getAmount(); }
/** * Handles requests to / * * @param ctx the context describing the current request */ @Routed("/ui") public void index(WebContext ctx) { if (ctx.isUnsafePOST() && ctx.get("bucketName").isFilled()) { storage.getBucket(ctx.get("bucketName").asString()).create(); UserContext.message(Message.info("Bucket successfully created.")); } onError(ctx, null); }