/** * Adds numeric value to serializer with padding. <br> * Like setting padding to 3 and saving value of 35 will be saved as '035' * * @param key * key of value. * @param value * value to serialize. * @param padding * padding to use. * @param <T> * type of object. * * @throws IllegalArgumentException * when given number is floating point number. */ default <T extends Number> void addNumber(String key, @Nullable T value, @Signed int padding) { if (value == null) { this.add(key, null); } if (padding <= 0) { this.add(key, value); return; } if ((value instanceof Float) || (value instanceof Double)) { throw new IllegalArgumentException("Can't use padding for float or double!"); } if (this.getSerializationType() == SerializationType.YAML) // yaml reads padded value as octal, so we need escape it { this.add(key, String.format("%0" + padding + "d", value), String.class); return; } this.add(key, String.format("%0" + padding + "d", value)); }
/** * @param offset the offset to start at * @param limit the maximum number of results * @return the SQL-clause to limit the amount of retrieved results */ @Nonnull @Syntax(value = "SQL") public String getLimitClause(@Nonnegative final int offset, @Signed final int limit) { return (offset > 0 ? "OFFSET " + offset + " " : "") + (limit > 0 ? "FETCH FIRST " + limit + " ROWS ONLY" : ""); }
/** * Adds numeric value to serializer as hex value (like 0xABCDEF), it must be later read back by proper function in {@link DeserializationData}. * <br> * You can also set custom padding value, so values like 0xff, will be saved as 0x0000ff (padding = 6) * * @param key * key of value. * @param value * value to serialize. * @param padding * padding to use. * @param <T> * type of object. * * @throws IllegalArgumentException * when given number is floating point number. */ default <T extends Number> void addHexNumber(String key, @Nullable T value, @Signed int padding) { if (value == null) { this.add(key, null); } if ((value instanceof Float) || (value instanceof Double)) { throw new IllegalArgumentException("Can't use hex values for float or double!"); } this.add(key, String.format("0x%0" + padding + "x", value)); }
/** * Retrieves the maximum amount a server is allowed to wait for a single tick to process * before assuming the server is hanging. * * A value of -1 indicates, that the watchdog shall not shutdown the server regardless of * how long a tick needs to process. */ @Signed long getMaximumTickTime();
/** * Retrieves the threshold at which plugins will be compressed. * * @return a threshold in bytes. */ @Signed int getNetworkCompressionThreshold();
/** * Calculates the sum of the column-values by casting all single column-values to long * * @param <C> the type of the column-value * @param columnName the name of the column to sum the values * @param columnFunc the function mapping the record to its column-value * @return the sum of all the column-values */ @Signed public default <C extends Number> long sum(@Nonnull final String columnName, @Nonnull final Function<T, C> columnFunc) { return Objects.requireNonNull( aggregate( new Sum<>(columnName, columnFunc), null)).longValue(); }
/** * Calculates the sum of the column-values by casting all single column-values to long * * @param <C> the type of the column-value * @param func the SQL-function mapping the record to a value * @return the sum of all the column-values * @since 0.8 */ @Signed public default <C extends Number> long sum(@Nonnull final SQLFunction<T, C> func) { return Objects.requireNonNull( aggregate( new Sum<>(func), null)).longValue(); }
/** * Calculates the sum of the column-values by casting all single column-values to double * * @param <C> the type of the column-value * @param columnName the name of the column to sum its values * @param columnFunc the function mapping the record to its column-value * @return the sum of all the column-values */ @Signed public default <C extends Number> double sumFloating(@Nonnull final String columnName, @Nonnull final Function<T, C> columnFunc) { return Objects.requireNonNull( aggregate( new SumDouble<>(columnName, columnFunc), null)).doubleValue(); }
/** * Calculates the sum of the column-values by casting all single column-values to double * * @param <C> the type of the column-value * @param func the SQL-function mapping the record to a value * @return the sum of all the column-values * @since 0.8 */ @Signed public default <C extends Number> double sumFloating(@Nonnull final SQLFunction<T, C> func) { return Objects.requireNonNull( aggregate( new SumDouble<>(func), null)).doubleValue(); }
/** * Calculates the average column-value * @param <C> the type of the column-value * @param columnName the name of the column to retrieve the average value * @param columnFunc the function mapping the record to its column-value * @return the average column-value */ @Signed public default <C extends Number> double average(@Nonnull final String columnName, @Nonnull final Function<T, C> columnFunc) { return Objects.requireNonNull( aggregate( new Average<>(columnName, columnFunc), null)).doubleValue(); }
/** * Calculates the average column-value * @param <C> the type of the column-value * @param func the SQL-function mapping the record to a value * @return the average column-value * @since 0.8 */ @Signed public default <C extends Number> double average(@Nonnull final SQLFunction<T, C> func) { return Objects.requireNonNull( aggregate( new Average<>(func), null)).doubleValue(); }