Line data Source code
1 : // Copyright (C) 2022 The Android Open Source Project 2 : // 3 : // Licensed under the Apache License, Version 2.0 (the "License"); 4 : // you may not use this file except in compliance with the License. 5 : // You may obtain a copy of the License at 6 : // 7 : // http://www.apache.org/licenses/LICENSE-2.0 8 : // 9 : // Unless required by applicable law or agreed to in writing, software 10 : // distributed under the License is distributed on an "AS IS" BASIS, 11 : // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 : // See the License for the specific language governing permissions and 13 : // limitations under the License. 14 : 15 : package com.google.gerrit.server.account; 16 : 17 : import com.google.gerrit.common.Nullable; 18 : import com.google.gerrit.entities.Account; 19 : import com.google.gerrit.server.data.AccountAttribute; 20 : import com.google.inject.Inject; 21 : import java.util.HashMap; 22 : import java.util.Map; 23 : 24 : public class AccountAttributeLoader { 25 : 26 : public interface Factory { 27 : AccountAttributeLoader create(); 28 : } 29 : 30 : private final InternalAccountDirectory directory; 31 3 : private final Map<Account.Id, AccountAttribute> created = new HashMap<>(); 32 : 33 : @Inject 34 3 : AccountAttributeLoader(InternalAccountDirectory directory) { 35 3 : this.directory = directory; 36 3 : } 37 : 38 : @Nullable 39 : public synchronized AccountAttribute get(@Nullable Account.Id id) { 40 3 : if (id == null) { 41 3 : return null; 42 : } 43 3 : return created.computeIfAbsent(id, k -> new AccountAttribute(k.get())); 44 : } 45 : 46 : public void fill() { 47 3 : directory.fillAccountAttributeInfo(created.values()); 48 3 : } 49 : }