
software.amazon.awssdk.services.appmesh.model.HttpGatewayRouteMatch Maven / Gradle / Ivy
/*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
* the License. A copy of the License is located at
*
* http://aws.amazon.com/apache2.0
*
* or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
* CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
* and limitations under the License.
*/
package software.amazon.awssdk.services.appmesh.model;
import java.io.Serializable;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.function.BiConsumer;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import software.amazon.awssdk.annotations.Generated;
import software.amazon.awssdk.core.SdkField;
import software.amazon.awssdk.core.SdkPojo;
import software.amazon.awssdk.core.protocol.MarshallLocation;
import software.amazon.awssdk.core.protocol.MarshallingType;
import software.amazon.awssdk.core.traits.ListTrait;
import software.amazon.awssdk.core.traits.LocationTrait;
import software.amazon.awssdk.core.util.DefaultSdkAutoConstructList;
import software.amazon.awssdk.core.util.SdkAutoConstructList;
import software.amazon.awssdk.utils.ToString;
import software.amazon.awssdk.utils.builder.CopyableBuilder;
import software.amazon.awssdk.utils.builder.ToCopyableBuilder;
/**
*
* An object that represents the criteria for determining a request match.
*
*/
@Generated("software.amazon.awssdk:codegen")
public final class HttpGatewayRouteMatch implements SdkPojo, Serializable,
ToCopyableBuilder {
private static final SdkField> HEADERS_FIELD = SdkField
.> builder(MarshallingType.LIST)
.memberName("headers")
.getter(getter(HttpGatewayRouteMatch::headers))
.setter(setter(Builder::headers))
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("headers").build(),
ListTrait
.builder()
.memberLocationName(null)
.memberFieldInfo(
SdkField. builder(MarshallingType.SDK_POJO)
.constructor(HttpGatewayRouteHeader::builder)
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD)
.locationName("member").build()).build()).build()).build();
private static final SdkField HOSTNAME_FIELD = SdkField
. builder(MarshallingType.SDK_POJO).memberName("hostname")
.getter(getter(HttpGatewayRouteMatch::hostname)).setter(setter(Builder::hostname))
.constructor(GatewayRouteHostnameMatch::builder)
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("hostname").build()).build();
private static final SdkField METHOD_FIELD = SdkField. builder(MarshallingType.STRING).memberName("method")
.getter(getter(HttpGatewayRouteMatch::methodAsString)).setter(setter(Builder::method))
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("method").build()).build();
private static final SdkField PATH_FIELD = SdkField. builder(MarshallingType.SDK_POJO)
.memberName("path").getter(getter(HttpGatewayRouteMatch::path)).setter(setter(Builder::path))
.constructor(HttpPathMatch::builder)
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("path").build()).build();
private static final SdkField PORT_FIELD = SdkField. builder(MarshallingType.INTEGER).memberName("port")
.getter(getter(HttpGatewayRouteMatch::port)).setter(setter(Builder::port))
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("port").build()).build();
private static final SdkField PREFIX_FIELD = SdkField. builder(MarshallingType.STRING).memberName("prefix")
.getter(getter(HttpGatewayRouteMatch::prefix)).setter(setter(Builder::prefix))
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("prefix").build()).build();
private static final SdkField> QUERY_PARAMETERS_FIELD = SdkField
.> builder(MarshallingType.LIST)
.memberName("queryParameters")
.getter(getter(HttpGatewayRouteMatch::queryParameters))
.setter(setter(Builder::queryParameters))
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("queryParameters").build(),
ListTrait
.builder()
.memberLocationName(null)
.memberFieldInfo(
SdkField. builder(MarshallingType.SDK_POJO)
.constructor(HttpQueryParameter::builder)
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD)
.locationName("member").build()).build()).build()).build();
private static final List> SDK_FIELDS = Collections.unmodifiableList(Arrays.asList(HEADERS_FIELD, HOSTNAME_FIELD,
METHOD_FIELD, PATH_FIELD, PORT_FIELD, PREFIX_FIELD, QUERY_PARAMETERS_FIELD));
private static final long serialVersionUID = 1L;
private final List headers;
private final GatewayRouteHostnameMatch hostname;
private final String method;
private final HttpPathMatch path;
private final Integer port;
private final String prefix;
private final List queryParameters;
private HttpGatewayRouteMatch(BuilderImpl builder) {
this.headers = builder.headers;
this.hostname = builder.hostname;
this.method = builder.method;
this.path = builder.path;
this.port = builder.port;
this.prefix = builder.prefix;
this.queryParameters = builder.queryParameters;
}
/**
* For responses, this returns true if the service returned a value for the Headers property. This DOES NOT check
* that the value is non-empty (for which, you should check the {@code isEmpty()} method on the property). This is
* useful because the SDK will never return a null collection or map, but you may need to differentiate between the
* service returning nothing (or null) and the service returning an empty collection or map. For requests, this
* returns true if a value for the property was specified in the request builder, and false if a value was not
* specified.
*/
public final boolean hasHeaders() {
return headers != null && !(headers instanceof SdkAutoConstructList);
}
/**
*
* The client request headers to match on.
*
*
* Attempts to modify the collection returned by this method will result in an UnsupportedOperationException.
*
*
* This method will never return null. If you would like to know whether the service returned this field (so that
* you can differentiate between null and empty), you can use the {@link #hasHeaders} method.
*
*
* @return The client request headers to match on.
*/
public final List headers() {
return headers;
}
/**
*
* The host name to match on.
*
*
* @return The host name to match on.
*/
public final GatewayRouteHostnameMatch hostname() {
return hostname;
}
/**
*
* The method to match on.
*
*
* If the service returns an enum value that is not available in the current SDK version, {@link #method} will
* return {@link HttpMethod#UNKNOWN_TO_SDK_VERSION}. The raw value returned by the service is available from
* {@link #methodAsString}.
*
*
* @return The method to match on.
* @see HttpMethod
*/
public final HttpMethod method() {
return HttpMethod.fromValue(method);
}
/**
*
* The method to match on.
*
*
* If the service returns an enum value that is not available in the current SDK version, {@link #method} will
* return {@link HttpMethod#UNKNOWN_TO_SDK_VERSION}. The raw value returned by the service is available from
* {@link #methodAsString}.
*
*
* @return The method to match on.
* @see HttpMethod
*/
public final String methodAsString() {
return method;
}
/**
*
* The path to match on.
*
*
* @return The path to match on.
*/
public final HttpPathMatch path() {
return path;
}
/**
*
* The port number to match on.
*
*
* @return The port number to match on.
*/
public final Integer port() {
return port;
}
/**
*
* Specifies the path to match requests with. This parameter must always start with /
, which by itself
* matches all requests to the virtual service name. You can also match for path-based routing of requests. For
* example, if your virtual service name is my-service.local
and you want the route to match requests
* to my-service.local/metrics
, your prefix should be /metrics
.
*
*
* @return Specifies the path to match requests with. This parameter must always start with /
, which by
* itself matches all requests to the virtual service name. You can also match for path-based routing of
* requests. For example, if your virtual service name is my-service.local
and you want the
* route to match requests to my-service.local/metrics
, your prefix should be
* /metrics
.
*/
public final String prefix() {
return prefix;
}
/**
* For responses, this returns true if the service returned a value for the QueryParameters property. This DOES NOT
* check that the value is non-empty (for which, you should check the {@code isEmpty()} method on the property).
* This is useful because the SDK will never return a null collection or map, but you may need to differentiate
* between the service returning nothing (or null) and the service returning an empty collection or map. For
* requests, this returns true if a value for the property was specified in the request builder, and false if a
* value was not specified.
*/
public final boolean hasQueryParameters() {
return queryParameters != null && !(queryParameters instanceof SdkAutoConstructList);
}
/**
*
* The query parameter to match on.
*
*
* Attempts to modify the collection returned by this method will result in an UnsupportedOperationException.
*
*
* This method will never return null. If you would like to know whether the service returned this field (so that
* you can differentiate between null and empty), you can use the {@link #hasQueryParameters} method.
*
*
* @return The query parameter to match on.
*/
public final List queryParameters() {
return queryParameters;
}
@Override
public Builder toBuilder() {
return new BuilderImpl(this);
}
public static Builder builder() {
return new BuilderImpl();
}
public static Class extends Builder> serializableBuilderClass() {
return BuilderImpl.class;
}
@Override
public final int hashCode() {
int hashCode = 1;
hashCode = 31 * hashCode + Objects.hashCode(hasHeaders() ? headers() : null);
hashCode = 31 * hashCode + Objects.hashCode(hostname());
hashCode = 31 * hashCode + Objects.hashCode(methodAsString());
hashCode = 31 * hashCode + Objects.hashCode(path());
hashCode = 31 * hashCode + Objects.hashCode(port());
hashCode = 31 * hashCode + Objects.hashCode(prefix());
hashCode = 31 * hashCode + Objects.hashCode(hasQueryParameters() ? queryParameters() : null);
return hashCode;
}
@Override
public final boolean equals(Object obj) {
return equalsBySdkFields(obj);
}
@Override
public final boolean equalsBySdkFields(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (!(obj instanceof HttpGatewayRouteMatch)) {
return false;
}
HttpGatewayRouteMatch other = (HttpGatewayRouteMatch) obj;
return hasHeaders() == other.hasHeaders() && Objects.equals(headers(), other.headers())
&& Objects.equals(hostname(), other.hostname()) && Objects.equals(methodAsString(), other.methodAsString())
&& Objects.equals(path(), other.path()) && Objects.equals(port(), other.port())
&& Objects.equals(prefix(), other.prefix()) && hasQueryParameters() == other.hasQueryParameters()
&& Objects.equals(queryParameters(), other.queryParameters());
}
/**
* Returns a string representation of this object. This is useful for testing and debugging. Sensitive data will be
* redacted from this string using a placeholder value.
*/
@Override
public final String toString() {
return ToString.builder("HttpGatewayRouteMatch").add("Headers", hasHeaders() ? headers() : null)
.add("Hostname", hostname()).add("Method", methodAsString()).add("Path", path()).add("Port", port())
.add("Prefix", prefix()).add("QueryParameters", hasQueryParameters() ? queryParameters() : null).build();
}
public final Optional getValueForField(String fieldName, Class clazz) {
switch (fieldName) {
case "headers":
return Optional.ofNullable(clazz.cast(headers()));
case "hostname":
return Optional.ofNullable(clazz.cast(hostname()));
case "method":
return Optional.ofNullable(clazz.cast(methodAsString()));
case "path":
return Optional.ofNullable(clazz.cast(path()));
case "port":
return Optional.ofNullable(clazz.cast(port()));
case "prefix":
return Optional.ofNullable(clazz.cast(prefix()));
case "queryParameters":
return Optional.ofNullable(clazz.cast(queryParameters()));
default:
return Optional.empty();
}
}
@Override
public final List> sdkFields() {
return SDK_FIELDS;
}
private static Function