@SuppressWarnings({"unchecked", "raw", "rawtypes"}) @Override protected Object transformFromDatasource(Class<? extends BaseMapper<?, ?, ?>> mapperType, Value data) { if (data.isNull()) { return null; } if (ordinal) { Object[] values = field.getType().getEnumConstants(); int index = data.asInt(0); index = Math.min(index, values.length - 1); return values[index]; } return data.asEnum((Class<Enum>) field.getType()); }
@SuppressWarnings("unchecked") @Override public Object transformValue(Value value) { if (value.isEmptyString()) { return null; } return value.get(); }
@Override protected Object transformFromDatasource(Class<? extends BaseMapper<?, ?, ?>> mapperType, Value object) { if (object.get() instanceof Long) { return Integer.valueOf(((Long) object.get()).intValue()); } if (object.is(String.class) ) { return object.getInteger(); } return object.get(); }
@Override protected Object transformFromRequest(String name, WebContext ctx) { Value value = ctx.get(name); if (value.isEmptyString()) { return null; } try { return NLS.parseUserString(LocalDate.class, value.getString()); } catch (IllegalArgumentException e) { Exceptions.ignore(e); UserContext.setFieldError(name, value.get()); throw Exceptions.createHandled() .withNLSKey("Property.invalidInput") .set("field", NLS.get(getField().getDeclaringClass().getSimpleName() + "." + name)) .set("value", value.asString()) .handle(); } }
Extension profile = Sirius.getSettings().getExtension("jdbc.profile", ext.get("profile").asString("default")); Context ctx = profile.getContext(); ctx.putAll(ext.getContext()); this.name = name; this.driver = ext.get(KEY_DRIVER).isEmptyString() ? Formatter.create(profile.get(KEY_DRIVER).asString()).set(ctx).format() : ext.get(KEY_DRIVER).asString(); this.service = ext.get(KEY_SERVICE).isEmptyString() ? Formatter.create(profile.get(KEY_SERVICE).asString()).set(ctx).format() : ext.get(KEY_SERVICE).asString(); this.url = ext.get(KEY_URL).isEmptyString() ? Formatter.create(profile.get(KEY_URL).asString()).set(ctx).format() : ext.get(KEY_URL).asString(); this.hostUrl = ext.get(KEY_HOST_URL).isEmptyString() ? Formatter.create(profile.get(KEY_HOST_URL).asString()).set(ctx).format() : ext.get(KEY_HOST_URL).asString(); applyPortMapping(); this.username = ext.get(KEY_USER).isEmptyString() ? Formatter.create(profile.get(KEY_USER).asString()).set(ctx).format() : ext.get(KEY_USER).asString(); this.password = ext.get(KEY_PASSWORD).isEmptyString() ? Formatter.create(profile.get(KEY_PASSWORD).asString()).set(ctx).format() : ext.get(KEY_PASSWORD).asString(); this.initialSize = ext.get(KEY_INITIAL_SIZE).isFilled() ? ext.get(KEY_INITIAL_SIZE).asInt(0) : profile.get(KEY_INITIAL_SIZE).asInt(0); this.maxActive = ext.get(KEY_MAX_ACTIVE).isFilled() ? ext.get(KEY_MAX_ACTIVE).asInt(10) : profile.get(KEY_MAX_ACTIVE).asInt(10);
/** * Returns a <tt>Value</tt> containing a translated value using the string representation * of the wrapped value as key. * * @param lang a two-letter language code for which the translation is requested * @return a <tt>Value</tt> containing a translated value by calling {@link NLS#get(String, String)} * if the string representation of the wrapped value starts with {@code $}. * The dollar sign is skipped when passing the key to <tt>NLS</tt>. Otherwise <tt>this</tt> is returned. * @see NLS#get(String, String) */ @Nonnull @CheckReturnValue public Value translate(String lang) { if (isFilled() && is(String.class)) { return Value.of(NLS.smartGet(asString(), lang)); } else { return this; } } }
private void createIndex(EntityDescriptor ed, MongoDatabase client, Index index) { try { Document document = new Document(); for (int i = 0; i < index.columns().length; i++) { Value setting = Value.of(index.columnSettings()[i]); document.append(index.columns()[i], setting.isNumeric() ? setting.asInt(1) : setting.asString()); } Mongo.LOG.INFO("Creating MongoDB index %s for: %s...", index.name(), ed.getRelationName()); client.getCollection(ed.getRelationName()).createIndex(document, new IndexOptions().unique(index.unique())); } catch (Exception e) { Exceptions.handle() .error(e) .to(Mongo.LOG) .withSystemErrorMessage("Failed to create index %s of %s (%s) - %s (%s)", index.name(), ed.getType().getName(), ed.getRelationName()) .handle(); } } }
/** * 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(); }
/** * Tries to convert the wrapped value to a roman numeral representation * This only works if the wrapped value can be converted to <tt>int</tt> and is >0 and <4000. * * @param defaultValue the value to be converted to roman numeral if the wrapped value can not be converted * @return a roman numeral representation of either the wrapped value or the defaultValue. values >=4000 and * <=0 are represented as an empty String */ public String asRomanNumeral(int defaultValue) { return RomanNumeral.toRoman(asInt(defaultValue)); }
/** * 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(); }
/** * Handles GET /bucket * * @param ctx the context describing the current request * @param bucket the bucket of which the contents should be listed */ private void listObjects(WebContext ctx, Bucket bucket) { int maxKeys = ctx.get("max-keys").asInt(1000); String marker = ctx.get("marker").asString(); String prefix = ctx.get("prefix").asString(); Response response = ctx.respondWith(); response.setHeader(HTTP_HEADER_NAME_CONTENT_TYPE, CONTENT_TYPE_XML); bucket.outputObjects(response.xml(), maxKeys, marker, prefix); }
/** * Returns the wrapped data converted to a string or <tt>defaultValue</tt> if the wrapped value is <tt>null</tt> * <p> * The conversion method used is {@link NLS#toMachineString(Object)} * * @param defaultValue the value to use if the wrapped object was <tt>null</tt> * @return a string representation of the wrapped object * or <tt>defaultValue</tt> if the wrapped value is <tt>null</tt> */ @Nonnull public String asString(@Nonnull String defaultValue) { return isNull() ? defaultValue : NLS.toMachineString(data); }
@Override public void execute(Output output, String... params) throws Exception { Value name = Value.indexOf(0, params); if (name.isEmptyString()) { output.line("No class name given. Try: doc <classname>"); return; } Injector.getAllLoadedClasses() .stream() .filter(c -> c.getName().toLowerCase().contains(name.asString().toLowerCase())) .forEach(c -> { output.line(c.getName()); output.separator(); for (Method m : c.getMethods()) { output.line(m.toString()); } output.blankLine(); }); }
@SuppressWarnings({"unchecked", "raw", "rawtypes"}) @Override public Object transformValue(Value value) { if (value.isFilled()) { return value.asEnum((Class<Enum>) field.getType()); } if (this.isNullable() || Strings.isEmpty(defaultValue)) { return null; } return Value.of(defaultValue).asEnum((Class<Enum>) field.getType()); }
@Override public void execute(Output output, String... params) throws Exception { boolean withTraces = Value.indexOf(0, params).isFilled(); boolean includeWaiting = "Y".equals(Value.indexOf(1, params).asString()); if (withTraces) { outputThreadInfos(output, includeWaiting, params[0]); } else { output.line("Usage: threads [<filter> (or 'all')] [Y=include WAITING/NATIVE]"); output.separator(); output.apply("%-15s %10s %53s", "STATE", "ID", "NAME"); output.separator(); for (ThreadInfo info : t.dumpAllThreads(false, false)) { output.apply("%-15s %10s %53s", info.isInNative() ? "NATIVE" : info.getThreadState().name(), info.getThreadId(), info.getThreadName()); } output.separator(); } }
@Override public Object transformValue(Value value) { if (value.isFilled()) { Integer result = value.getInteger(); if (result == null) { throw illegalFieldValue(value); } return result; } if (this.isNullable() || Strings.isEmpty(defaultValue)) { return null; } return Value.of(defaultValue).getInteger(); }