All Downloads are FREE. Search and download functionalities are using the official Maven repository.

software.amazon.awssdk.enhanced.dynamodb.internal.immutable.ImmutableInfo 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.enhanced.dynamodb.internal.immutable;

import java.lang.reflect.Method;
import java.util.Collection;
import java.util.Optional;
import software.amazon.awssdk.annotations.NotThreadSafe;
import software.amazon.awssdk.annotations.SdkInternalApi;

@SdkInternalApi
public class ImmutableInfo {
    private final Class immutableClass;
    private final Class builderClass;
    private final Method staticBuilderMethod;
    private final Method buildMethod;
    private final Collection propertyDescriptors;

    private ImmutableInfo(Builder b) {
        this.immutableClass = b.immutableClass;
        this.builderClass = b.builderClass;
        this.staticBuilderMethod = b.staticBuilderMethod;
        this.buildMethod = b.buildMethod;
        this.propertyDescriptors = b.propertyDescriptors;
    }

    public Class immutableClass() {
        return immutableClass;
    }

    public Class builderClass() {
        return builderClass;
    }

    public Optional staticBuilderMethod() {
        return Optional.ofNullable(staticBuilderMethod);
    }

    public Method buildMethod() {
        return buildMethod;
    }

    public Collection propertyDescriptors() {
        return propertyDescriptors;
    }

    public static  Builder builder(Class immutableClass) {
        return new Builder<>(immutableClass);
    }

    @NotThreadSafe
    public static final class Builder {
        private final Class immutableClass;
        private Class builderClass;
        private Method staticBuilderMethod;
        private Method buildMethod;
        private Collection propertyDescriptors;

        private Builder(Class immutableClass) {
            this.immutableClass = immutableClass;
        }

        public Builder builderClass(Class builderClass) {
            this.builderClass = builderClass;
            return this;
        }

        public Builder staticBuilderMethod(Method builderMethod) {
            this.staticBuilderMethod = builderMethod;
            return this;
        }

        public Builder buildMethod(Method buildMethod) {
            this.buildMethod = buildMethod;
            return this;
        }

        public Builder propertyDescriptors(Collection propertyDescriptors) {
            this.propertyDescriptors = propertyDescriptors;
            return this;
        }

        public ImmutableInfo build() {
            return new ImmutableInfo<>(this);
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy