Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* The MIT License
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package com.influxdb.query.dsl.functions.properties;
import java.text.DecimalFormat;
import java.text.DecimalFormatSymbols;
import java.time.Instant;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoUnit;
import java.util.Arrays;
import java.util.Collection;
import java.util.LinkedHashMap;
import java.util.Locale;
import java.util.Map;
import java.util.function.Supplier;
import java.util.stream.Collectors;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import com.influxdb.query.dsl.Flux;
import com.influxdb.query.dsl.VariableAssignment;
import com.influxdb.utils.Arguments;
/**
* The function properties. Support named-property, property with values.
*
* @author Jakub Bednar (bednar@github) (28/06/2018 05:32)
*/
public final class FunctionsParameters {
private static final DateTimeFormatter DATE_FORMATTER = DateTimeFormatter
.ofPattern("yyyy-MM-dd'T'HH:mm:ss.nnnnnnnnn'Z'")
.withZone(ZoneId.of("UTC"));
private static final String DEFAULT_DELIMITER = ":";
private static final String FUNCTION_DELIMITER = " => ";
private static final int DOUBLE_FRACTION_DIGITS = 340;
private final Map> properties = new LinkedHashMap<>();
public static String escapeDoubleQuotes(final String val) {
return val.replace("\"", "\\\"");
}
private static final DecimalFormat DECIMAL_FORMAT = new DecimalFormat(
"0.0",
DecimalFormatSymbols.getInstance(Locale.ENGLISH)
);
static {
// https://stackoverflow.com/a/25307973
DECIMAL_FORMAT.setMaximumFractionDigits(DOUBLE_FRACTION_DIGITS);
}
private FunctionsParameters() {
}
@Nonnull
public static FunctionsParameters of() {
return new FunctionsParameters();
}
/**
* Serialize value for Flux property.
*
* @param value to serialize
* @return serialized value
*/
@Nullable
public static String serializeValue(
@Nonnull final Object value,
final boolean escapeStrings
) {
if (value instanceof String) {
if (escapeStrings) {
return '"' + escapeDoubleQuotes((String) value) + '"';
}
return (String) value;
}
if (value instanceof Integer || value instanceof Long) {
return value.toString();
}
if (value instanceof Number) {
String s = value.toString();
if (s.contains("E")) {
return DECIMAL_FORMAT.format(value);
} else {
return s;
}
}
Object serializedValue = value;
if (serializedValue.getClass().isArray()) {
serializedValue = Arrays.asList((Object[]) value);
}
// collection to delimited string ["one", "two", "three"]
if (serializedValue instanceof Collection) {
//noinspection unchecked
Collection