private String buildRelativePath(File reference, File child) { List<String> path = new ArrayList<>(); File iter = child; while (iter != null && !Objects.equal(iter, reference)) { path.add(0, iter.getName()); iter = iter.getParentFile(); } return Strings.join(path, "/"); } }
/** * Returns a string concatenation of the given array items. * <p> * Generates a string which contains the string representation of each item separated by the given separator. * This method will filter empty values (<tt>""</tt> or <tt>null</tt>) and ignore those. * * @param separator the separator to place between the items * @param parts the array of items to join * @return a string of all items joined together and separated by the given separator. Returns "" is the array was * empty. */ @Nonnull public static String join(@Nonnull String separator, @Nonnull String... parts) { return join(Arrays.asList(parts), separator); }
@Override public String toString() { return name + " (" + Strings.join(getColumns(), ", ") + ")"; }
private String toHeaderStringRepresentation(final String headerName, final HttpHeaders requestHeaders) { return headerName.toLowerCase().trim() + ":" + join(requestHeaders.getAll(headerName), ",").trim(); } }
/** * Provides a full report of all elements of this table. * * @return a string containing all elements of this table */ public String dump() { StringBuilder sb = new StringBuilder("TABLE "); sb.append(name); sb.append("{\n"); for (TableColumn col : columns) { sb.append(" COLUMN: "); sb.append(col); sb.append("\n"); } sb.append(" PK: "); sb.append(Strings.join(primaryKey, ", ")); sb.append("\n"); for (Key key : keys) { sb.append(" INDEX: "); sb.append(key); sb.append("\n"); } for (ForeignKey fk : foreignKeys) { sb.append(" FK: "); sb.append(fk); sb.append("\n"); } sb.append("}\n"); return sb.toString(); }
private StringBuilder buildCanonicalRequest(final WebContext ctx, final String signedHeaders) { StringBuilder canonicalRequest = new StringBuilder(ctx.getRequest().method().name()); canonicalRequest.append("\n"); canonicalRequest.append(ctx.getRequestedURI()); canonicalRequest.append("\n"); appendCanonicalQueryString(ctx, canonicalRequest); for (String name : signedHeaders.split(";")) { canonicalRequest.append(name.trim()); canonicalRequest.append(":"); canonicalRequest.append(Strings.join(ctx.getRequest().headers().getAll(name), ",").trim()); canonicalRequest.append("\n"); } canonicalRequest.append("\n"); canonicalRequest.append(signedHeaders); canonicalRequest.append("\n"); canonicalRequest.append(ctx.getHeader("x-amz-content-sha256")); return canonicalRequest; }
/** * Deletes all documents matched by the given query. * * @param indices the indices to search in * @param type the document type to search * @param routing the routing to use * @param query the query to execute * @return the response of the call */ public JSONObject deleteByQuery(List<String> indices, String type, @Nullable String routing, JSONObject query) { return performPost().routing(routing) .data(query) .execute(Strings.join(indices, ",") + "/" + type + API_DELETE_BY_QUERY) .response(); }
/** * Determines the number of hits for a given query. * * @param indices the indices to search in * @param type the document type to search * @param routing the routing to use * @param query the query to execute * @return the response of the call */ public JSONObject count(List<String> indices, String type, String routing, JSONObject query) { return performGet().routing(routing) .data(query) .execute(Strings.join(indices, ",") + "/" + type + "/_count") .response(); }
/** * Executes a search. * * @param indices the indices to search in * @param type the document type to search * @param routing the routing to use * @param from the number of items to skip * @param size the maximal result length * @param query the query to execute * @return the response of the call */ public JSONObject search(List<String> indices, String type, @Nullable String routing, int from, int size, JSONObject query) { return performGet().routing(routing) .withParam("size", size) .withParam("from", from) .data(query) .execute(Strings.join(indices, ",") + "/" + type + API_SEARCH) .response(); }
/** * Determines if a given query has at least one result. * * @param indices the indices to search in * @param type the document type to search * @param routing the routing to use * @param query the query to execute * @return the response of the call */ public JSONObject exists(List<String> indices, String type, String routing, JSONObject query) { return performGet().routing(routing) .withParam("size", 0) .withParam("terminate_after", 1) .data(query) .execute(Strings.join(indices, ",") + "/" + type + API_SEARCH) .response(); }
private <E extends Entity> E executeFind(@Nullable String index, @Nullable String routing, @Nonnull Class<E> clazz, String id, EntityDescriptor descriptor) throws Exception { GetResponse res = getClient().prepareGet(index, descriptor.getType(), id) .setPreference("_primary") .setRouting(routing) .execute() .actionGet(); if (!res.isExists()) { if (LOG.isFINE()) { LOG.FINE("FIND: %s.%s: NOT FOUND", index, descriptor.getType()); } return null; } else { E entity = clazz.newInstance(); entity.initSourceTracing(); entity.setId(res.getId()); entity.setVersion(res.getVersion()); descriptor.readSource(entity, res.getSource()); if (LOG.isFINE()) { LOG.FINE("FIND: %s.%s: FOUND: %s", index, descriptor.getType(), Strings.join(res.getSource())); } return entity; } }
/** * Creates a scroll search. * * @param indices the indices to search in * @param type the document type to search * @param routing the routing to use * @param from the number of items to skip * @param sizePerShard the maximal number of results per shard * @param ttlSeconds the ttl of the scroll cursor in seconds * @param query the query to execute * @return the response of the call */ public JSONObject createScroll(List<String> indices, String type, String routing, int from, int sizePerShard, int ttlSeconds, JSONObject query) { return performGet().routing(routing) .withParam("size", sizePerShard) .withParam("from", from) .withParam("scroll", ttlSeconds + "s") .data(query) .execute(Strings.join(indices, ",") + "/" + type + API_SEARCH) .response(); }
schema.getIndex(entity), descriptor.getType(), Strings.join(source));
schema.getIndex(entity), descriptor.getType(), Strings.join(source));
if (action.isFailed()) { OMA.LOG.WARN("Failed schema change action - SQL: %s reason: %s - error: %s", Strings.join(action.getSql(), "; "), action.getReason(), action.getError());