private Tuple<String, Integer> mapPort(Tuple<String, Integer> hostAndPort) { Tuple<String, Integer> effectiveHostAndPort = PortMapper.mapPort(SERVICE_ELASTICSEARCH, hostAndPort.getFirst(), hostAndPort.getSecond()); if (!Objects.equals(effectiveHostAndPort.getSecond(), hostAndPort.getSecond())) { dockerDetected = true; } return effectiveHostAndPort; }
/** * Extracts all <tt>second</tt> components of the given collection of tuples and returns them as list. * * @param tuples the collection of tuples to process * @param <T> the type of the tuples involved * @param <K> the type of the first elements of the tuples * @param <V> the type of the second elements of the tuples * @return a list containing each <tt>second</tt> component of the collection of given tuples. */ public static <T extends Tuple<K, V>, K, V> List<V> seconds(@Nonnull Collection<T> tuples) { List<V> result = new ArrayList<>(tuples.size()); for (Tuple<K, V> t : tuples) { result.add(t.getSecond()); } return result; }
@Override public boolean equals(Object obj) { if (obj == null) { return false; } if (!(obj instanceof Tuple<?, ?>)) { return false; } Tuple<?, ?> other = (Tuple<?, ?>) obj; return Objects.equal(first, other.getFirst()) && Objects.equal(second, other.getSecond()); }
/** * Returns the underlying row as map. * * @return a map containing all fields and values represented by this row * @deprecated use {@link #getFieldsList()} which honors the field names in terms of upper- and lowercase. */ @Nonnull @Deprecated public Map<String, Object> getFields() { Map<String, Object> result = Maps.newTreeMap(); for (Map.Entry<String, Tuple<String, Object>> field : fields.entrySet()) { result.put(field.getKey(), field.getValue().getSecond()); } return Collections.unmodifiableMap(result); }
protected PreparedStatement getStmt() throws SQLException { if (stmt == null) { if (retrieveGeneratedKeys) { stmt = c.prepareStatement(sb.toString(), Statement.RETURN_GENERATED_KEYS); } else { stmt = c.prepareStatement(sb.toString(), ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); } for (Tuple<Integer, Object> t : parameters) { stmt.setObject(t.getFirst(), t.getSecond()); } } return stmt; }
/** * Returns the file extension of the given path or filename. * <p> * A path could be <tt>/dir/foo/test.txt</tt>, a filename would be <tt>test.txt</tt>. * * @param path the path to parse * @return the file extension (<tt>txt</tt> for <tt>test.txt</tt>) without the leading dot. Returns <tt>null</tt> if * the input is empty or does not contain a file extension. The a file contains several extensions, like * <tt>.txt.zip</tt>, only the last is returned. */ @Nullable public static String getFileExtension(@Nullable String path) { return Strings.splitAtLast(path, ".").getSecond(); }
private HttpHost makeHttpHost(Tuple<String, Integer> hostnameAndPort) { return new HttpHost(hostnameAndPort.getFirst(), hostnameAndPort.getSecond(), SCHEME_HTTP); }
@Override public String toString() { StringBuilder sb = new StringBuilder(); for (Tuple<String, String> e : getMDC()) { sb.append(e.getFirst()); sb.append(": "); sb.append(e.getSecond()); sb.append("\n"); } return sb.toString(); } }
@Override public String toString() { StringBuilder sb = new StringBuilder(); for (Tuple<Double, Double> location : data()) { sb.append(location.getFirst()); sb.append(","); sb.append(location.getSecond()); sb.append("\n"); } return sb.toString(); } }
private void fillPK(Connection c, Table table) throws SQLException { ResultSet rs = c.getMetaData().getPrimaryKeys(c.getSchema(), null, table.getName()); List<ComparableTuple<Integer, String>> keyFields = new ArrayList<>(); while (rs.next()) { keyFields.add(ComparableTuple.create(rs.getInt(COLUMN_KEY_SEQ), rs.getString(COLUMN_COLUMN_NAME))); } Collections.sort(keyFields); for (Tuple<Integer, String> key : keyFields) { table.getPrimaryKey().add(key.getSecond()); } rs.close(); }
/** * Returns the value associated with the given key. * * @param key the name of the field to retrieve * @return the value associated with the given key wrapped as {@link sirius.kernel.commons.Value} * @throws java.lang.IllegalArgumentException if an unknown column key is requested */ @Nonnull public Value getValue(@Nonnull Object key) { String upperCaseKey = key.toString().toUpperCase(); if (!fields.containsKey(upperCaseKey)) { throw new IllegalArgumentException(Strings.apply("Unknown column: %s in %s", upperCaseKey, this)); } return Value.of(fields.get(upperCaseKey).getSecond()); }
protected synchronized void initializeClient() { if (mongoClient != null) { return; } List<ServerAddress> hosts = Arrays.stream(dbHosts.split(",")) .map(String::trim) .map(hostname -> PortMapper.mapPort(SERVICE_NAME, hostname, MONGO_PORT)) .map(hostAndPort -> new ServerAddress(hostAndPort.getFirst(), hostAndPort.getSecond())) .filter(Objects::nonNull) .collect(Collectors.toList()); mongoClient = new MongoClient(hosts); createIndices(mongoClient.getDatabase(dbName)); }
/** * Merges the given multi map into this one. * <p> * If both maps contain values for the same key, to lists will be joined together. * <p> * <b>Note</b>: This will modify the callee instead of creating a new result map * * @param other the other map to merge into this one * @return the callee itself for further processing */ public MultiMap<K, V> merge(MultiMap<K, V> other) { if (other != null) { other.base.entrySet().stream().flatMap(Tuple::flatten).forEach(t -> put(t.getFirst(), t.getSecond())); } return this; }
@Override protected Tuple<Double, Double> copyValue(Tuple<Double, Double> value) { return Tuple.create(value.getFirst(), value.getSecond()); }
private void orderBy(Compiler compiler) { if (!orderBys.isEmpty()) { compiler.getWHEREBuilder().append(" ORDER BY "); Monoflop mf = Monoflop.create(); for (Tuple<Mapping, Boolean> e : orderBys) { if (mf.successiveCall()) { compiler.getWHEREBuilder().append(", "); } compiler.getWHEREBuilder().append(compiler.translateColumnName(e.getFirst())); compiler.getWHEREBuilder().append(e.getSecond() ? " ASC" : " DESC"); } } }
private Tuple<String, Integer> parsePort(Tuple<String, String> hostnameAndPort) { if (Strings.isFilled(hostnameAndPort.getSecond())) { try { return Tuple.create(hostnameAndPort.getFirst(), Integer.parseInt(hostnameAndPort.getSecond())); } catch (NumberFormatException e) { Exceptions.handle() .to(LOG) .withSystemErrorMessage("Invalid port in 'elasticsearch.hosts': %s %s", hostnameAndPort.getFirst(), hostnameAndPort.getSecond()) .handle(); } } return Tuple.create(hostnameAndPort.getFirst(), DEFAULT_HTTP_PORT); }
private void appendCanonicalQueryString(WebContext ctx, StringBuilder canonicalRequest) { QueryStringDecoder qsd = new QueryStringDecoder(ctx.getRequest().uri(), Charsets.UTF_8); List<Tuple<String, List<String>>> queryString = Tuple.fromMap(qsd.parameters()); queryString.sort(Comparator.comparing(Tuple::getFirst)); Monoflop mf = Monoflop.create(); for (Tuple<String, List<String>> param : queryString) { if (param.getSecond().isEmpty()) { appendQueryStringValue(param.getFirst(), "", canonicalRequest, mf.successiveCall()); } else { for (String value : param.getSecond()) { appendQueryStringValue(param.getFirst(), value, canonicalRequest, mf.successiveCall()); } } } canonicalRequest.append("\n"); }
protected QueryBuilder parseToken(LookaheadReader reader) { if (reader.current().is('(')) { return parseTokenInBrackets(reader); } boolean negate = checkIfNegated(reader); Tuple<String, String> fieldAndValue = parseFieldAndValue(reader); if (Strings.isEmpty(fieldAndValue.getSecond())) { return null; } QueryBuilder qry = compileToken(fieldAndValue.getFirst(), fieldAndValue.getSecond()); if (qry != null && negate) { return QueryBuilders.boolQuery().mustNot(qry); } else { return qry; } }
@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); }
/** * Translates a column name into an effective name by applying aliases and rewrites. * * @param column the column to translate * @return the translated name which is used in the database */ public String translateColumnName(Mapping column) { Tuple<String, EntityDescriptor> aliasAndDescriptor = determineAlias(column.getParent()); EntityDescriptor effectiveDescriptor = aliasAndDescriptor.getSecond(); if (effectiveDescriptor != null) { return aliasAndDescriptor.getFirst() + "." + effectiveDescriptor.rewritePropertyName(column.getName()); } else { return aliasAndDescriptor.getFirst() + "." + column.getName(); } }