@UtilityClass public class Testcontainers { public void exposeHostPorts(int... ports) { for (int port : ports) { PortForwardingContainer.INSTANCE.exposeHostPort(port); } } }
@Data @Setter @Getter @Accessors(chain = true) @ToString public class WindowConfig { public static final String WINDOW_CONFIG_KEY = "__WINDOWCONFIGS__"; private Integer windowLengthCount; private Long windowLengthDurationMs; private Integer slidingIntervalCount; private Long slidingIntervalDurationMs; private String lateDataTopic; private Long maxLagMs; private Long watermarkEmitIntervalMs; private String timestampExtractorClassName; private String actualWindowFunctionClassName; }
@FieldDefaults(makeFinal = true, level = AccessLevel.PRIVATE) public class Application implements Iterable<RegisterEntry> { PersistentList<RegisterEntry> entries; public Application(final List<RegisterEntry> entries) { this.entries = Seq.fromIterable(entries); } @Override public Iterator<RegisterEntry> iterator() { return entries.iterator(); } public String toString() { return JacksonUtil.serializeToJson(entries); } }
/** * @author Jens Schauder */ @Value @Wither(AccessLevel.PACKAGE) public class ModelReport { String modelName, description, setName; }
@RequiredArgsConstructor private static class DelegatingDockerClientConfig implements DockerClientConfig { @Delegate final DockerClientConfig dockerClientConfig; } }
/** * Trivial class to print domain objects to the console in a somewhat readable format. * * @author Jens Schauder */ @UtilityClass public class Output { private final Logger LOG = LoggerFactory.getLogger(Output.class); public static void list(Iterable<?> categories, String title) { StringBuilder message = new StringBuilder(String.format("==== %s ====\n", title)); categories.forEach(category -> message.append(category.toString().replace(", ", ",\n\t"))); LOG.info(message.toString()); } }
/** * @author charlie (Dmitry Baev). */ @Data @Accessors(chain = true) public class TreeWidgetData implements Serializable { private static final long serialVersionUID = 1L; protected long total; protected List<TreeWidgetItem> items = new ArrayList<>(); }
/** * One of potentially multiple models that can be build from a single {@link LegoSet}. No getters or setters needed. * * @author Jens Schauder */ @Value @Wither(AccessLevel.PACKAGE) public class Model { String name, description; }
/** * Wraps a {@link DatasetsFinder} into an {@link IterableDatasetFinder}. */ @AllArgsConstructor public class IterableDatasetFinderImpl<T extends Dataset> implements IterableDatasetFinder<T> { @Delegate private final DatasetsFinder<T> datasetFinder; @Override public Iterator<T> getDatasetsIterator() throws IOException { return this.datasetFinder.findDatasets().iterator(); } }
/** */ @UtilityClass public class NamedEntity { // allowed characters for property, namespace, cluster and topic names are // alphanumeric (a-zA-Z_0-9) and these special chars -=:. // % is allowed as part of valid URL encoding private static final Pattern NAMED_ENTITY_PATTERN = Pattern.compile("^[-=:.\\w]*$"); public static void checkName(String name) throws IllegalArgumentException { Matcher m = NAMED_ENTITY_PATTERN.matcher(name); if (!m.matches()) { throw new IllegalArgumentException("Invalid named entity: " + name); } } }
/** * @author charlie (Dmitry Baev). */ @Data @Accessors(chain = true) public class Parameter implements Serializable { private static final long serialVersionUID = 1L; protected String name; protected String value; }
/** * Trivial class to print domain objects to the console in a somewhat readable format. * * @author Jens Schauder */ @UtilityClass public class Output { private final Logger LOG = LoggerFactory.getLogger(Output.class); public static void list(Iterable<?> categories, String title) { StringBuilder message = new StringBuilder(String.format("==== %s ====\n", title)); categories.forEach(category -> { message.append(category.toString().replace(", ", ",\n\t")); }); LOG.info(message.toString()); } }
/** * @author charlie (Dmitry Baev). */ @Data @Accessors(chain = true) public class TreeWidgetItem implements Serializable { private static final long serialVersionUID = 1L; protected String uid; protected String name; protected Statistic statistic; }
@UtilityClass public class MathUtils { /** * Compute sign safe mod * * @param dividend * @param divisor * @return */ public static int signSafeMod(long dividend, int divisor) { int mod = (int) (dividend % divisor); if (mod < 0) { mod += divisor; } return mod; } }
/** * @author charlie (Dmitry Baev). */ @Data @Accessors(chain = true) public class HistoryData implements Serializable { private static final long serialVersionUID = 1L; protected Statistic statistic = new Statistic(); protected List<HistoryItem> items = new ArrayList<>(); }
/** * Json kit * * @author biezhi * 2017/6/2 */ @UtilityClass public class JsonKit { private static final DefaultJsonSupport defaultJsonSupport = new DefaultJsonSupport(); private static JsonSupport jsonSupport = new DefaultJsonSupport(); public static void jsonSupprt(JsonSupport jsonSupport) { JsonKit.jsonSupport = jsonSupport; } public static String toString(Object object) { return jsonSupport.toString(object); } public static <T> T formJson(String json, Type type) { return jsonSupport.formJson(json, type); } public static Ason<?, ?> toAson(String value) { return defaultJsonSupport.toAson(value); } }
/** * Json kit * * @author biezhi * 2017/6/2 */ @UtilityClass public class JsonKit { private static final DefaultJsonSupport defaultJsonSupport = new DefaultJsonSupport(); private static JsonSupport jsonSupport = new DefaultJsonSupport(); public static void jsonSupprt(JsonSupport jsonSupport) { JsonKit.jsonSupport = jsonSupport; } public static String toString(Object object) { return jsonSupport.toString(object); } public static <T> T formJson(String json, Type type) { return jsonSupport.formJson(json, type); } public static Ason<?, ?> toAson(String value) { return defaultJsonSupport.toAson(value); } }
/** * Utility to retrieve the Cassandra release version. * * @author Mark Paluch */ @UtilityClass public class CassandraVersion { /** * Retrieve the Cassandra release version. * * @param session must not be {@literal null}. * @return the release {@link Version}. */ public static Version getReleaseVersion(Session session) { Assert.notNull(session, "Session must not be null"); ResultSet resultSet = session.execute("SELECT release_version FROM system.local;"); Row row = resultSet.one(); return Version.parse(row.getString(0)); } }
/** * @author Mark Paluch */ @UtilityClass class CassandraSocket { /** * @param host must not be {@literal null} or empty. * @param port * @return {@literal true} if the TCP port accepts a connection. */ public static boolean isConnectable(String host, int port) { Assert.hasText(host, "Host must not be null or empty!"); try (Socket socket = new Socket()) { socket.setSoLinger(true, 0); socket.connect(new InetSocketAddress(host, port), (int) TimeUnit.MILLISECONDS.convert(10, TimeUnit.SECONDS)); return true; } catch (Exception e) { return false; } } }
/** * Utility class to ensure that licenses have been accepted by the developer. */ @UtilityClass public class LicenseAcceptance { private static final String ACCEPTANCE_FILE_NAME = "container-license-acceptance.txt"; public static void assertLicenseAccepted(final String imageName) { try { final URL url = Resources.getResource(ACCEPTANCE_FILE_NAME); final List<String> acceptedLicences = Resources.readLines(url, Charsets.UTF_8); if (acceptedLicences.stream().map(String::trim).anyMatch(imageName::equals)) { return; } } catch (Exception ignored) { // suppressed } throw new IllegalStateException("The image " + imageName + " requires you to accept a license agreement. " + "Please place a file at the root of the classpath named " + ACCEPTANCE_FILE_NAME + ", e.g. at " + "src/test/resources/" + ACCEPTANCE_FILE_NAME + ". This file should contain the line:\n " + imageName); } }