• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2023 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 package org.chromium.base.shared_preferences;
6 
7 import androidx.annotation.NonNull;
8 
9 import org.chromium.build.annotations.CheckDiscard;
10 
11 import java.util.HashSet;
12 import java.util.List;
13 import java.util.Locale;
14 
15 @CheckDiscard("Preference key checking should only happen on build with asserts")
16 public class PreferenceKeyRegistry {
17     private final String mModule;
18     public final HashSet<String> mKeysInUse;
19     public final HashSet<String> mLegacyFormatKeys;
20     public final List<KeyPrefix> mLegacyPrefixes;
21 
PreferenceKeyRegistry( String module, List<String> keysInUse, List<String> legacyKeys, List<KeyPrefix> legacyPrefixes)22     public PreferenceKeyRegistry(
23             String module,
24             List<String> keysInUse,
25             List<String> legacyKeys,
26             List<KeyPrefix> legacyPrefixes) {
27         mModule = module;
28         mKeysInUse = new HashSet<>(keysInUse);
29         mLegacyFormatKeys = new HashSet<>(legacyKeys);
30         mLegacyPrefixes = legacyPrefixes;
31     }
32 
33     @NonNull
toDebugString()34     public String toDebugString() {
35         return String.format(
36                 Locale.getDefault(),
37                 "%s (%d in use, %d legacy, %d legacy prefixes)",
38                 mModule,
39                 mKeysInUse.size(),
40                 mLegacyFormatKeys.size(),
41                 mLegacyPrefixes.size());
42     }
43 }
44