/*
 * 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.facebook.presto.hive.metastore;

import com.google.common.collect.ArrayListMultimap;
import com.google.common.collect.ImmutableSetMultimap;
import com.google.common.collect.Multimap;
import com.google.common.collect.SetMultimap;

import static java.util.Objects.requireNonNull;

public class PrincipalPrivileges
{
    private final SetMultimap<String, HivePrivilegeInfo> userPrivileges;
    private final SetMultimap<String, HivePrivilegeInfo> rolePrivileges;

    public PrincipalPrivileges(
            Multimap<String, HivePrivilegeInfo> userPrivileges,
            Multimap<String, HivePrivilegeInfo> rolePrivileges)
    {
        this.userPrivileges = ImmutableSetMultimap.copyOf(requireNonNull(userPrivileges, "userPrivileges is null"));
        this.rolePrivileges = ImmutableSetMultimap.copyOf(requireNonNull(rolePrivileges, "rolePrivileges is null"));
    }

    public SetMultimap<String, HivePrivilegeInfo> getUserPrivileges()
    {
        return userPrivileges;
    }

    public SetMultimap<String, HivePrivilegeInfo> getRolePrivileges()
    {
        return rolePrivileges;
    }

    public static Builder builder()
    {
        return new Builder();
    }

    public static Builder builder(PrincipalPrivileges table)
    {
        return new Builder(table);
    }

    public static class Builder
    {
        private Multimap<String, HivePrivilegeInfo> userPrivileges = ArrayListMultimap.create();
        private Multimap<String, HivePrivilegeInfo> rolePrivileges = ArrayListMultimap.create();

        public Builder()
        {
        }

        public Builder(PrincipalPrivileges principalPrivileges)
        {
            userPrivileges.putAll(principalPrivileges.getUserPrivileges());
            rolePrivileges.putAll(principalPrivileges.getRolePrivileges());
        }

        public Builder setUserPrivileges(Multimap<String, HivePrivilegeInfo> userPrivileges)
        {
            this.userPrivileges = ArrayListMultimap.create(userPrivileges);
            return this;
        }

        public Builder addUserPriviledge(String userName, HivePrivilegeInfo privilege)
        {
            userPrivileges.put(userName, privilege);
            return this;
        }

        public Builder setRolePrivileges(Multimap<String, HivePrivilegeInfo> rolePrivileges)
        {
            this.rolePrivileges = ArrayListMultimap.create(rolePrivileges);
            return this;
        }

        public Builder addRolePriviledge(String roleName, HivePrivilegeInfo privilege)
        {
            rolePrivileges.put(roleName, privilege);
            return this;
        }
    }
}

@@ -604,60 +604,8 @@
 e;%0A%0A
-import com.google.common.collect.ArrayListMultimap;%0A
 impo
@@ -1613,1519 +1613,7 @@
    %7D
-%0A%0A    public static Builder builder()%0A    %7B%0A        return new Builder();%0A    %7D%0A%0A    public static Builder builder(PrincipalPrivileges table)%0A    %7B%0A        return new Builder(table);%0A    %7D%0A%0A    public static class Builder%0A    %7B%0A        private Multimap%3CString, HivePrivilegeInfo%3E userPrivileges = ArrayListMultimap.create();%0A        private Multimap%3CString, HivePrivilegeInfo%3E rolePrivileges = ArrayListMultimap.create();%0A%0A        public Builder()%0A        %7B%0A        %7D%0A%0A        public Builder(PrincipalPrivileges principalPrivileges)%0A        %7B%0A            userPrivileges.putAll(principalPrivileges.getUserPrivileges());%0A            rolePrivileges.putAll(principalPrivileges.getRolePrivileges());%0A        %7D%0A%0A        public Builder setUserPrivileges(Multimap%3CString, HivePrivilegeInfo%3E userPrivileges)%0A        %7B%0A            this.userPrivileges = ArrayListMultimap.create(userPrivileges);%0A            return this;%0A        %7D%0A%0A        public Builder addUserPriviledge(String userName, HivePrivilegeInfo privilege)%0A        %7B%0A            userPrivileges.put(userName, privilege);%0A            return this;%0A        %7D%0A%0A        public Builder setRolePrivileges(Multimap%3CString, HivePrivilegeInfo%3E rolePrivileges)%0A        %7B%0A            this.rolePrivileges = ArrayListMultimap.create(rolePrivileges);%0A            return this;%0A        %7D%0A%0A        public Builder addRolePriviledge(String roleName, HivePrivilegeInfo privilege)%0A        %7B%0A            rolePrivileges.put(roleName, privilege);%0A            return this;%0A        %7D%0A    %7D
 %0A%7D%0A

Remove unused builder from PrincipalPrivileges