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

com.palantir.atlasdb.table.description.constraints.RowConstraintMetadata Maven / Gradle / Ivy

There is a newer version: 0.1152.0
Show newest version
/*
 * (c) Copyright 2018 Palantir Technologies Inc. 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.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License 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 com.palantir.atlasdb.table.description.constraints;

import com.google.common.collect.ImmutableList;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public final class RowConstraintMetadata {
    private final Class constraintClass;
    private final boolean isGeneric;
    private final String tableName;
    private final List rowVariables;
    private final List columnVariables;
    private final List allVariables;

    public static Builder builder(Class clazz) {
        return new Builder(clazz, false, null);
    }

    public static Builder builderGeneric(Class clazz, String tableName) {
        return new Builder(clazz, true, tableName);
    }

    private RowConstraintMetadata(
            Class constraintClass,
            List rowVariables,
            List columnVariables,
            List allVariables,
            boolean isGeneric,
            String tableName) {
        this.constraintClass = constraintClass;
        this.rowVariables = ImmutableList.copyOf(rowVariables);
        this.columnVariables = ImmutableList.copyOf(columnVariables);
        this.allVariables = ImmutableList.copyOf(allVariables);
        this.isGeneric = isGeneric;
        this.tableName = tableName;
    }

    public boolean isGeneric() {
        return isGeneric;
    }

    public String getTableName() {
        return tableName;
    }

    public Class getConstraintClass() {
        return constraintClass;
    }

    public List getRowVariables() {
        return rowVariables;
    }

    public List getColumnVariables() {
        return columnVariables;
    }

    public List getAllVariables() {
        return allVariables;
    }

    public static final class Builder {
        private final Class constraintClass;
        private final boolean isGeneric;
        private final String tableName;
        private final List rowVariables = new ArrayList<>();
        private final List columnVariables = new ArrayList<>();
        private final List allVariables = new ArrayList<>();

        public Builder(Class constraintClass, boolean isGeneric, String tableName) {
            this.constraintClass = constraintClass;
            this.isGeneric = isGeneric;
            this.tableName = tableName;
        }

        public Builder addRowVariables(String... variables) {
            Collections.addAll(rowVariables, variables);
            Collections.addAll(allVariables, variables);
            return this;
        }

        public Builder addColumnVariables(String... variables) {
            Collections.addAll(columnVariables, variables);
            Collections.addAll(allVariables, variables);
            return this;
        }

        public RowConstraintMetadata build() {
            return new RowConstraintMetadata(
                    constraintClass, rowVariables, columnVariables, allVariables, isGeneric, tableName);
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy