accumulo-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From joshelser <...@git.apache.org>
Subject [GitHub] accumulo pull request #279: ACCUMULO-3238 Table.ID Namespace.ID Refactor
Date Tue, 11 Jul 2017 16:35:38 GMT
Github user joshelser commented on a diff in the pull request:

    https://github.com/apache/accumulo/pull/279#discussion_r126741465
  
    --- Diff: core/src/main/java/org/apache/accumulo/core/client/impl/Namespaces.java ---
    @@ -100,50 +106,150 @@ private static ZooCache getZooCache(Instance instance) {
         return namespaceMap;
       }
     
    -  public static boolean exists(Instance instance, String namespaceId) {
    +  public static boolean exists(Instance instance, Namespace.ID namespaceId) {
         ZooCache zc = getZooCache(instance);
         List<String> namespaceIds = zc.getChildren(ZooUtil.getRoot(instance) + Constants.ZNAMESPACES);
    -    return namespaceIds.contains(namespaceId);
    -  }
    -
    -  public static String getNamespaceId(Instance instance, String namespace) throws NamespaceNotFoundException
{
    -    String id = getNameToIdMap(instance).get(namespace);
    -    if (id == null)
    -      throw new NamespaceNotFoundException(null, namespace, "getNamespaceId() failed
to find namespace");
    -    return id;
    +    return namespaceIds.contains(namespaceId.canonicalID());
       }
     
    +  /**
    +   * @deprecated Do not use - String for namespace ID is not type safe. Use {@link #getNamespaceName(Instance,
Namespace.ID)}
    +   */
    +  @Deprecated
       public static String getNamespaceName(Instance instance, String namespaceId) throws
NamespaceNotFoundException {
         String namespaceName = getIdToNameMap(instance).get(namespaceId);
         if (namespaceName == null)
           throw new NamespaceNotFoundException(namespaceId, null, "getNamespaceName() failed
to find namespace");
         return namespaceName;
       }
     
    +  /**
    +   * @deprecated Do not use - Not type safe, ambiguous String-String map. Use {@link
#getNameMap(Instance)}
    +   */
    +  @Deprecated
       public static SortedMap<String,String> getNameToIdMap(Instance instance) {
         return getMap(instance, true);
       }
     
    +  /**
    +   * @deprecated Do not use - Not type safe, ambiguous String-String map. Use {@link
#getIdMap(Instance)}
    +   */
    +  @Deprecated
       public static SortedMap<String,String> getIdToNameMap(Instance instance) {
         return getMap(instance, false);
       }
     
    -  public static List<String> getTableIds(Instance instance, String namespaceId)
throws NamespaceNotFoundException {
    +  public static List<Table.ID> getTableIds(Instance instance, Namespace.ID namespaceId)
throws NamespaceNotFoundException {
         String namespace = getNamespaceName(instance, namespaceId);
    -    List<String> names = new LinkedList<>();
    -    for (Entry<String,String> nameToId : Tables.getNameToIdMap(instance).entrySet())
    +    List<Table.ID> tableIds = new LinkedList<>();
    +    for (Entry<String,Table.ID> nameToId : Tables.getNameMap(instance).entrySet())
           if (namespace.equals(Tables.qualify(nameToId.getKey()).getFirst()))
    -        names.add(nameToId.getValue());
    -    return names;
    +        tableIds.add(nameToId.getValue());
    +    return tableIds;
    --- End diff --
    
    Depending on how the caller uses the return value, it could also be lazily constructed
instead of instantiating a new Collection each time.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

Mime
View raw message