You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tamaya.apache.org by pl...@apache.org on 2016/09/25 21:24:02 UTC

[14/50] [abbrv] incubator-tamaya-sandbox git commit: Moved PropertySourceBuilder from resource module to builder module. Minor Javadoc change.

Moved PropertySourceBuilder from resource module to builder module.
Minor Javadoc change.


Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/commit/8e555f4d
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/tree/8e555f4d
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/diff/8e555f4d

Branch: refs/heads/master
Commit: 8e555f4dc9658afd2204262df7f3010daf71b15b
Parents: d03d92d
Author: anatole <an...@apache.org>
Authored: Thu May 21 06:28:44 2015 +0200
Committer: anatole <an...@apache.org>
Committed: Thu May 21 06:28:44 2015 +0200

----------------------------------------------------------------------
 .../tamaya/builder/ConfigurationBuilder.java    |   2 +-
 .../tamaya/builder/PropertySourceBuilder.java   | 118 +++++++++++++++++++
 .../tamaya/builder/SimplePropertySource.java    |  55 +++++++++
 3 files changed, 174 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/8e555f4d/src/main/java/org/apache/tamaya/builder/ConfigurationBuilder.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/tamaya/builder/ConfigurationBuilder.java b/src/main/java/org/apache/tamaya/builder/ConfigurationBuilder.java
index 799b114..82eb3eb 100644
--- a/src/main/java/org/apache/tamaya/builder/ConfigurationBuilder.java
+++ b/src/main/java/org/apache/tamaya/builder/ConfigurationBuilder.java
@@ -71,7 +71,7 @@ import static java.lang.String.format;
  *
  * <p><strong>Support for configuration formats</strong></p>
  *
- * The configuration builder allows you to add property resources
+ * The configuration builder allows you to put property resources
  * via a URL, as shown in the code example above, without implementing
  * a {@link org.apache.tamaya.spi.PropertySource PropertySource} or providing an
  * instance of a {@link org.apache.tamaya.spi.PropertySource PropertySource}.

http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/8e555f4d/src/main/java/org/apache/tamaya/builder/PropertySourceBuilder.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/tamaya/builder/PropertySourceBuilder.java b/src/main/java/org/apache/tamaya/builder/PropertySourceBuilder.java
new file mode 100644
index 0000000..e298939
--- /dev/null
+++ b/src/main/java/org/apache/tamaya/builder/PropertySourceBuilder.java
@@ -0,0 +1,118 @@
+/*
+ * 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.tamaya.builder;
+
+import org.apache.tamaya.spi.PropertySource;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Objects;
+
+/**
+ * Simple builder for building a {@link org.apache.tamaya.spi.PropertySource}.
+ */
+public final class PropertySourceBuilder {
+    /** The ordinal to be used. */
+    private int ordinal;
+    /** The name to be used. */
+    private String name;
+    /** The properties. */
+    private Map<String,String> properties = new HashMap<>();
+
+    /** private constructor. */
+    private PropertySourceBuilder(String name){
+        this.name = Objects.requireNonNull(name);
+    }
+
+    /**
+     * Gets a new instance of a builder.
+     * @param name The name of the property source, not null.
+     * @return a new instance.
+     */
+    public static PropertySourceBuilder of(String name){
+        return new PropertySourceBuilder(name);
+    }
+
+    /**
+     * Gets a new instance of a builder.
+     * @param name The name of the property source, not null.
+     * @return a new instance.
+     */
+    public static PropertySourceBuilder from(String name){
+        return new PropertySourceBuilder(name);
+    }
+
+    /**
+     * Sets a new property key/value.
+     * @param key the property key, not null.
+     * @param value the property value, not null.
+     * @return the bulder for chaining.
+     */
+    public PropertySourceBuilder put(String key, String value){
+        this.properties.put(key, value);
+        return this;
+    }
+
+    /**
+     * Put all the given key, values.
+     * @param values the new key/values, not null.
+     * @return the bulder for chaining.
+     */
+    public PropertySourceBuilder putAll(Map<String, String> values){
+        this.properties.putAll(values);
+        return this;
+    }
+
+    /**
+     * Sets the ordinal to be used explicitly (instead evaluating it using {@code tamaya.ordinal}.
+     * @param ordinal the explicit ordinal to be used.
+     * @return the bulder for chaining.
+     */
+    public PropertySourceBuilder withOrdinal(int ordinal){
+        this.ordinal = ordinal;
+        return this;
+    }
+
+    /**
+     * Puts all values from the given property source.
+     * @param propertySource the property source, not null.
+     * @return the bulder for chaining.
+     */
+    public PropertySourceBuilder putAll(PropertySource propertySource){
+        this.properties.putAll(propertySource.getProperties());
+        return this;
+    }
+
+    /**
+     * Creates a new immutable {@link org.apache.tamaya.spi.PropertySource} instance.
+     * @return a new immutable {@link org.apache.tamaya.spi.PropertySource} instance, never null.
+     */
+    public PropertySource build(){
+        return new SimplePropertySource(name, properties);
+    }
+
+    @Override
+    public String toString() {
+        return "PropertySourceBuilder{" +
+                "ordinal=" + ordinal +
+                ", name='" + name + '\'' +
+                ", properties=" + properties +
+                '}';
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/8e555f4d/src/main/java/org/apache/tamaya/builder/SimplePropertySource.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/tamaya/builder/SimplePropertySource.java b/src/main/java/org/apache/tamaya/builder/SimplePropertySource.java
new file mode 100644
index 0000000..f343973
--- /dev/null
+++ b/src/main/java/org/apache/tamaya/builder/SimplePropertySource.java
@@ -0,0 +1,55 @@
+/*
+ * 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.tamaya.builder;
+
+import org.apache.tamaya.spi.PropertySource;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Objects;
+
+/**
+* Simple property source implementation using a map.
+*/
+public class SimplePropertySource implements PropertySource {
+    /** The properties. */
+    private Map<String, String> properties;
+    /** The source's name. */
+    private String name;
+
+    public SimplePropertySource(String name, Map<String, String> properties){
+        this.properties = new HashMap<>(properties);
+        this.name = Objects.requireNonNull(name);
+    }
+
+    @Override
+    public String getName() {
+        return name;
+    }
+
+    @Override
+    public Map<String, String> getProperties() {
+        return this.properties;
+    }
+
+    @Override
+    public String toString(){
+        return "SimplePropertySource(name="+name+", numProps="+properties.size()+")";
+    }
+}