/** * @param json A JSON-bindable data structure * @return An immutable value type * @deprecated Do not use this method directly, it exists only for the <em>Jackson</em>-binding infrastructure */ @Deprecated @JsonCreator(mode = JsonCreator.Mode.DELEGATING) static ImmutableServer fromJson(Json json) { ImmutableServer.Builder builder = ImmutableServer.builder(); if (json.name != null) { builder.name(json.name); } if (json.host != null) { builder.host(json.host); } if (json.port != null) { builder.port(json.port); } if (json.scheme != null) { builder.scheme(json.scheme); } return builder.build(); }
/** * Builds a new {@link ImmutableServer ImmutableServer}. * @return An immutable instance of Server * @throws java.lang.IllegalStateException if any required attributes are missing */ public ImmutableServer build() { if (initBits != 0) { throw new IllegalStateException(formatRequiredAttributesMessage()); } return new ImmutableServer(name, host, port, scheme); }
/** * Check if a identical server already exist, if exist the function return it * If not but there exist a server with the same "uid", we create a new server with a different uid. * @return the unique server to use */ public Server getOrAddServerIfNotExist(final String name, final String host, final String port, final Optional<String> scheme) { // Search if exact same server exists for (final Server server : currentProjectServers.values()) { if (server.getHost().equals(host) && server.getPort().equals(port) && server.getScheme().equals(scheme) && server.getName().equals(name)) { return server; } } final Server server = ImmutableServer.builder().name( currentProjectServers.get(name) == null ? name : findUniqueName(name, currentProjectServers.keySet())).host(host).port(port).scheme( scheme).build(); currentProjectServers.put(server.getName(), server); return server; }
/** * Fill a builder with attribute values from the provided {@code Server} instance. * Regular attribute values will be replaced with those from the given instance. * Absent optional values will not replace present values. * @param instance The instance from which to copy values * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Builder from(Server instance) { Objects.requireNonNull(instance, "instance"); name(instance.getName()); host(instance.getHost()); port(instance.getPort()); Optional<String> schemeOptional = instance.getScheme(); if (schemeOptional.isPresent()) { scheme(schemeOptional); } return this; }
/** * Creates an immutable copy of a {@link Server} value. * Uses accessors to get values to initialize the new immutable instance. * If an instance is already immutable, it is returned as is. * @param instance The instance to copy * @return A copied immutable Server instance */ public static ImmutableServer copyOf(Server instance) { if (instance instanceof ImmutableServer) { return (ImmutableServer) instance; } return ImmutableServer.builder() .from(instance) .build(); }
/** * Creates a builder for {@link ImmutableServer ImmutableServer}. * @return A new ImmutableServer builder */ public static ImmutableServer.Builder builder() { return new ImmutableServer.Builder(); }