/** * Copy the current immutable object by setting a value for the {@link Server#getHost() host} attribute. * An equals check used to prevent copying of the same value by returning {@code this}. * @param value A new value for host * @return A modified copy of the {@code this} object */ public final ImmutableServer withHost(String value) { if (this.host.equals(value)) return this; String newValue = Objects.requireNonNull(value, "host"); return new ImmutableServer(this.name, newValue, this.port, this.scheme); }
/** * This instance is equal to all instances of {@code ImmutableServer} that have equal attribute values. * @return {@code true} if {@code this} is equal to {@code another} instance */ @Override public boolean equals(@Nullable Object another) { if (this == another) return true; return another instanceof ImmutableServer && equalTo((ImmutableServer) another); }
/** * 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(); }
/** * 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; }
/** * @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(); }
/** * Copy the current immutable object by setting a value for the {@link Server#getName() name} attribute. * An equals check used to prevent copying of the same value by returning {@code this}. * @param value A new value for name * @return A modified copy of the {@code this} object */ public final ImmutableServer withName(String value) { if (this.name.equals(value)) return this; String newValue = Objects.requireNonNull(value, "name"); return new ImmutableServer(newValue, this.host, this.port, this.scheme); }
/** * Copy the current immutable object by setting a value for the {@link Server#getPort() port} attribute. * An equals check used to prevent copying of the same value by returning {@code this}. * @param value A new value for port * @return A modified copy of the {@code this} object */ public final ImmutableServer withPort(String value) { if (this.port.equals(value)) return this; String newValue = Objects.requireNonNull(value, "port"); return new ImmutableServer(this.name, this.host, newValue, this.scheme); }
/** * Copy the current immutable object by setting a <i>present</i> value for the optional {@link Server#getScheme() scheme} attribute. * @param value The value for scheme * @return A modified copy of {@code this} object */ public final ImmutableServer withScheme(String value) { @Nullable String newValue = Objects.requireNonNull(value, "scheme"); if (Objects.equals(this.scheme, newValue)) return this; return new ImmutableServer(this.name, this.host, this.port, newValue); }
/** * Copy the current immutable object by setting an optional value for the {@link Server#getScheme() scheme} attribute. * An equality check is used on inner nullable value to prevent copying of the same value by returning {@code this}. * @param optional A value for scheme * @return A modified copy of {@code this} object */ public final ImmutableServer withScheme(Optional<String> optional) { @Nullable String value = optional.orElse(null); if (Objects.equals(this.scheme, value)) return this; return new ImmutableServer(this.name, this.host, this.port, value); }
/** * 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); }