You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@curator.apache.org by ra...@apache.org on 2016/05/19 19:02:30 UTC

[15/35] curator git commit: removed SchemaKey - it was overkill

removed SchemaKey - it was overkill


Project: http://git-wip-us.apache.org/repos/asf/curator/repo
Commit: http://git-wip-us.apache.org/repos/asf/curator/commit/923a2d8b
Tree: http://git-wip-us.apache.org/repos/asf/curator/tree/923a2d8b
Diff: http://git-wip-us.apache.org/repos/asf/curator/diff/923a2d8b

Branch: refs/heads/CURATOR-3.0
Commit: 923a2d8b93d348bcacc6541be5f4013423ce43d2
Parents: 450976f
Author: randgalt <ra...@apache.org>
Authored: Tue May 3 09:40:55 2016 -0500
Committer: randgalt <ra...@apache.org>
Committed: Tue May 3 09:40:55 2016 -0500

----------------------------------------------------------------------
 .../curator/framework/schema/SchemaKey.java     | 77 --------------------
 .../curator/framework/schema/SchemaSet.java     | 12 +--
 .../framework/schema/SchemaSetLoader.java       | 10 +--
 .../curator/framework/schema/TestSchema.java    |  4 +-
 4 files changed, 14 insertions(+), 89 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/curator/blob/923a2d8b/curator-framework/src/main/java/org/apache/curator/framework/schema/SchemaKey.java
----------------------------------------------------------------------
diff --git a/curator-framework/src/main/java/org/apache/curator/framework/schema/SchemaKey.java b/curator-framework/src/main/java/org/apache/curator/framework/schema/SchemaKey.java
deleted file mode 100644
index a6ab23e..0000000
--- a/curator-framework/src/main/java/org/apache/curator/framework/schema/SchemaKey.java
+++ /dev/null
@@ -1,77 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you 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 org.apache.curator.framework.schema;
-
-import com.google.common.base.Preconditions;
-import java.util.UUID;
-
-public class SchemaKey
-{
-    private final String key;
-
-    public static SchemaKey named(String name)
-    {
-        return new SchemaKey(name);
-    }
-
-    public SchemaKey()
-    {
-        this(UUID.randomUUID().toString());
-    }
-
-    public SchemaKey(String key)
-    {
-        this.key = Preconditions.checkNotNull(key, "key cannot be null");
-    }
-
-    public String getKey()
-    {
-        return key;
-    }
-
-    @Override
-    public boolean equals(Object o)
-    {
-        if ( this == o )
-        {
-            return true;
-        }
-        if ( o == null || getClass() != o.getClass() )
-        {
-            return false;
-        }
-
-        SchemaKey schemaKey = (SchemaKey)o;
-
-        return key.equals(schemaKey.key);
-
-    }
-
-    @Override
-    public int hashCode()
-    {
-        return key.hashCode();
-    }
-
-    @Override
-    public String toString()
-    {
-        return key;
-    }
-}

http://git-wip-us.apache.org/repos/asf/curator/blob/923a2d8b/curator-framework/src/main/java/org/apache/curator/framework/schema/SchemaSet.java
----------------------------------------------------------------------
diff --git a/curator-framework/src/main/java/org/apache/curator/framework/schema/SchemaSet.java b/curator-framework/src/main/java/org/apache/curator/framework/schema/SchemaSet.java
index 3131862..d33519a 100644
--- a/curator-framework/src/main/java/org/apache/curator/framework/schema/SchemaSet.java
+++ b/curator-framework/src/main/java/org/apache/curator/framework/schema/SchemaSet.java
@@ -35,7 +35,7 @@ import java.util.concurrent.ExecutionException;
 public class SchemaSet
 {
     private final Logger log = LoggerFactory.getLogger(getClass());
-    private final Map<SchemaKey, Schema> schemas;
+    private final Map<String, Schema> schemas;
     private final Map<String, Schema> pathSchemas;
     private final CacheLoader<String, Schema> cacheLoader = new CacheLoader<String, Schema>()
     {
@@ -68,7 +68,7 @@ public class SchemaSet
      */
     public static SchemaSet getDefaultSchemaSet()
     {
-        return new SchemaSet(Collections.<SchemaKey, Schema>emptyMap(), true)
+        return new SchemaSet(Collections.<String, Schema>emptyMap(), true)
         {
             @Override
             public String toDocumentation()
@@ -80,10 +80,10 @@ public class SchemaSet
 
     /**
      * @param schemas the schemas for the set. The key of the map is a key/name for the schema that can be
-     *                used when calling {@link #getNamedSchema(SchemaKey)}
+     *                used when calling {@link #getNamedSchema(String)}
      * @param useDefaultSchema if true, return a default schema when there is no match. Otherwise, an exception is thrown
      */
-    public SchemaSet(Map<SchemaKey, Schema> schemas, boolean useDefaultSchema)
+    public SchemaSet(Map<String, Schema> schemas, boolean useDefaultSchema)
     {
         this.useDefaultSchema = useDefaultSchema;
         this.schemas = ImmutableMap.copyOf(Preconditions.checkNotNull(schemas, "schemas cannot be null"));
@@ -139,7 +139,7 @@ public class SchemaSet
      * @param name name
      * @return schema or null
      */
-    public Schema getNamedSchema(SchemaKey name)
+    public Schema getNamedSchema(String name)
     {
         return schemas.get(name);
     }
@@ -152,7 +152,7 @@ public class SchemaSet
     public String toDocumentation()
     {
         StringBuilder str = new StringBuilder("Curator Schemas:\n\n");
-        for ( Map.Entry<SchemaKey, Schema> schemaEntry : schemas.entrySet() )
+        for ( Map.Entry<String, Schema> schemaEntry : schemas.entrySet() )
         {
             str.append(schemaEntry.getKey()).append('\n').append(schemaEntry.getValue().toDocumentation()).append('\n');
         }

http://git-wip-us.apache.org/repos/asf/curator/blob/923a2d8b/curator-framework/src/main/java/org/apache/curator/framework/schema/SchemaSetLoader.java
----------------------------------------------------------------------
diff --git a/curator-framework/src/main/java/org/apache/curator/framework/schema/SchemaSetLoader.java b/curator-framework/src/main/java/org/apache/curator/framework/schema/SchemaSetLoader.java
index 3c4a0f8..c7db916 100644
--- a/curator-framework/src/main/java/org/apache/curator/framework/schema/SchemaSetLoader.java
+++ b/curator-framework/src/main/java/org/apache/curator/framework/schema/SchemaSetLoader.java
@@ -57,7 +57,7 @@ import java.util.regex.Pattern;
  */
 public class SchemaSetLoader
 {
-    private final Map<SchemaKey, Schema> schemas;
+    private final Map<String, Schema> schemas;
 
     /**
      * Called to map a data validator name in the JSON stream to an actual data validator
@@ -78,7 +78,7 @@ public class SchemaSetLoader
 
     public SchemaSetLoader(Reader in, DataValidatorMapper dataValidatorMapper)
     {
-        ImmutableMap.Builder<SchemaKey, Schema> builder = ImmutableMap.builder();
+        ImmutableMap.Builder<String, Schema> builder = ImmutableMap.builder();
         try
         {
             JsonNode root = new ObjectMapper().readTree(in);
@@ -96,7 +96,7 @@ public class SchemaSetLoader
         return new SchemaSet(schemas, useDefaultSchema);
     }
 
-    private void read(ImmutableMap.Builder<SchemaKey, Schema> builder, JsonNode node, DataValidatorMapper dataValidatorMapper)
+    private void read(ImmutableMap.Builder<String, Schema> builder, JsonNode node, DataValidatorMapper dataValidatorMapper)
     {
         for ( JsonNode child : node )
         {
@@ -104,7 +104,7 @@ public class SchemaSetLoader
         }
     }
 
-    private void readNode(ImmutableMap.Builder<SchemaKey, Schema> builder, JsonNode node, DataValidatorMapper dataValidatorMapper)
+    private void readNode(ImmutableMap.Builder<String, Schema> builder, JsonNode node, DataValidatorMapper dataValidatorMapper)
     {
         String name = getText(node, "name", null);
         String path = getText(node, "path", null);
@@ -136,7 +136,7 @@ public class SchemaSetLoader
             .watched(getAllowance(node, "watched"))
             .canBeDeleted(getBoolean(node, "canBeDeleted"))
             .build();
-        builder.put(new SchemaKey(name), schema);
+        builder.put(name, schema);
     }
 
     private String getText(JsonNode node, String name, String defaultValue)

http://git-wip-us.apache.org/repos/asf/curator/blob/923a2d8b/curator-framework/src/test/java/org/apache/curator/framework/schema/TestSchema.java
----------------------------------------------------------------------
diff --git a/curator-framework/src/test/java/org/apache/curator/framework/schema/TestSchema.java b/curator-framework/src/test/java/org/apache/curator/framework/schema/TestSchema.java
index eadae80..f3754f5 100644
--- a/curator-framework/src/test/java/org/apache/curator/framework/schema/TestSchema.java
+++ b/curator-framework/src/test/java/org/apache/curator/framework/schema/TestSchema.java
@@ -43,7 +43,9 @@ public class TestSchema extends BaseClassForTests
 
             try
             {
-                client.create().creatingParentsIfNeeded().forPath(schemaSet.getNamedSchema(SchemaKey.named("test")).getRawPath());
+                String rawPath = schemaSet.getNamedSchema("test").getRawPath();
+                Assert.assertEquals(rawPath, "/a/b/c");
+                client.create().creatingParentsIfNeeded().forPath(rawPath);
                 Assert.fail("Should've violated schema");
             }
             catch ( SchemaViolation dummy )