/** * Returns the internal value wrapped as Optional while expecting it to be an integer number. * <p> * If the value is empty or not an integer, an empty Optional will be returned. * * @return the internal value wrapped as Optional or an empty Optional if the value is not filled or non-integer */ public Optional<Integer> asOptionalInt() { return isFilled() ? Optional.of(getInteger()) : Optional.empty(); }
private AsyncExecutor findExecutor(String category) { return executors.computeIfAbsent(category, categoryName -> { Extension config = Sirius.getSettings().getExtension("async.executor", categoryName); return new AsyncExecutor(categoryName, config.get("poolSize").getInteger(), config.get("queueLength").getInteger()); }); }
@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(); }
@SuppressWarnings("unchecked") private <T> T continueCoerceWithBasicTypes(Class<T> targetClazz, T defaultValue) { if (Integer.class.equals(targetClazz) || int.class.equals(targetClazz)) { if (data instanceof Double) { return (T) (Integer) ((Long) Math.round((Double) data)).intValue(); } return (T) getInteger(); } if (Long.class.equals(targetClazz) || long.class.equals(targetClazz)) { if (data instanceof Double) { return (T) (Long) Math.round((Double) data); } return (T) getLong(); } if (String.class.equals(targetClazz)) { return (T) NLS.toMachineString(data); } if (BigDecimal.class.equals(targetClazz)) { return (T) getBigDecimal(); } if (Amount.class.equals(targetClazz)) { return (T) getAmount(); } return continueCoerceWithDateTypes(targetClazz, defaultValue); }
@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(); }
protected void init() { if (data != null) { return; } Extension cacheInfo = Sirius.getSettings().getExtension(EXTENSION_TYPE_CACHE, name); if (cacheInfo.isDefault()) { CacheManager.LOG.WARN("Cache %s does not exist! Using defaults...", name); } this.verificationInterval = cacheInfo.getMilliseconds(CONFIG_KEY_VERIFICATION); this.timeToLive = cacheInfo.getMilliseconds(CONFIG_KEY_TTL); this.maxSize = cacheInfo.get(CONFIG_KEY_MAX_SIZE).getInteger(); if (maxSize > 0) { this.data = CacheBuilder.newBuilder().maximumSize(maxSize).removalListener(this).build(); } else { this.data = CacheBuilder.newBuilder().removalListener(this).build(); } }