/** * Splits a unique name into the descriptor type and id. * * @param uniqueName the unique name of an entity. * @return the type and id of the entity as tuple * @see #getUniqueName(String, Object) */ @Nonnull public static Tuple<String, String> splitUniqueName(@Nullable String uniqueName) { return Strings.split(uniqueName, "-"); }
/** * Extracts the customization name from a resource. * <p> * Valid names are paths like "customizations/[name]/..." or classes like "customizations.[name]...". * * @param resource the name of the resource * @return the name of the customizations or <tt>null</tt> if no config name is contained */ @Nullable public static String getCustomizationName(@Nullable String resource) { if (resource == null) { return null; } if (resource.startsWith("customizations/")) { return Strings.split(resource.substring(15), "/").getFirst(); } else if (resource.startsWith("customizations.")) { return Strings.split(resource.substring(15), ".").getFirst(); } else { return null; } }
/** * Returns a map of monitoring info about the redis server. * * @return a map containing statistical values supplied by the server */ public Map<String, String> getInfo() { try { return Arrays.stream(query(() -> "info", Jedis::info).split("\n")) .map(l -> Strings.split(l, ":")) .filter(t -> t.getFirst() != null && t.getSecond() != null) .collect(Collectors.toMap(Tuple::getFirst, Tuple::getSecond)); } catch (Exception e) { Exceptions.handle(Redis.LOG, e); return Collections.emptyMap(); } } }
@Override public Object transformValue(Value value) { if (value.isEmptyString()) { return Collections.emptyList(); } List<Tuple<Double, Double>> result = new ArrayList<>(); for (String location : value.asString().split("\n")) { Tuple<String, String> latLong = Strings.split(location, ","); try { Tuple<Double, Double> coordinate = Tuple.create(Double.parseDouble(latLong.getFirst()), Double.parseDouble(latLong.getSecond())); result.add(coordinate); } catch (NumberFormatException e) { Exceptions.ignore(e); } } return result; }
return root; Tuple<String, String> pair = Strings.split(path, "."); Method m = getter(root.getClass(), pair.getFirst()); try {
@Override public Callback<WebContext> preparePreDispatch(WebContext ctx) { String uri = getEffectiveURI(ctx); Tuple<String, String> bucketAndObject = Strings.split(uri, "/"); if (Strings.isEmpty(bucketAndObject.getSecond())) { return null; } Bucket bucket = storage.getBucket(bucketAndObject.getFirst()); if (!bucket.exists() && !storage.isAutocreateBuckets()) { return null; } InputStreamHandler handler = createInputStreamHandler(ctx); ctx.setContentHandler(handler); return req -> writeObject(req, bucketAndObject.getFirst(), bucketAndObject.getSecond(), handler); }
@Override public boolean dispatch(WebContext ctx) throws Exception { String uri = getEffectiveURI(ctx); if (Strings.isEmpty(uri)) { listBuckets(ctx); return true; } Tuple<String, String> bucketAndObject = Strings.split(uri, "/"); if (Strings.isEmpty(bucketAndObject.getSecond())) { bucket(ctx, bucketAndObject.getFirst()); return true; } Bucket bucket = storage.getBucket(bucketAndObject.getFirst()); if (!bucket.exists() && !storage.isAutocreateBuckets()) { return false; } readObject(ctx, bucketAndObject.getFirst(), bucketAndObject.getSecond()); return true; }