You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tamaya.apache.org by an...@apache.org on 2014/12/21 00:15:13 UTC
incubator-tamaya git commit: TAMAYA-8: Added javadocs on
MetaInfoBuilder
Repository: incubator-tamaya
Updated Branches:
refs/heads/master 3927cda65 -> 238c07f16
TAMAYA-8: Added javadocs on MetaInfoBuilder
Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/commit/238c07f1
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/tree/238c07f1
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/diff/238c07f1
Branch: refs/heads/master
Commit: 238c07f16740faab3b7c0bee2902bf3d4a73e4d9
Parents: 3927cda
Author: anatole <an...@apache.org>
Authored: Sun Dec 21 00:15:02 2014 +0100
Committer: anatole <an...@apache.org>
Committed: Sun Dec 21 00:15:02 2014 +0100
----------------------------------------------------------------------
.../main/java/org/apache/tamaya/MetaInfo.java | 2 -
.../java/org/apache/tamaya/MetaInfoBuilder.java | 86 +++++++++++++++++---
2 files changed, 76 insertions(+), 12 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/238c07f1/api/src/main/java/org/apache/tamaya/MetaInfo.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/tamaya/MetaInfo.java b/api/src/main/java/org/apache/tamaya/MetaInfo.java
index e701529..e46ba9c 100644
--- a/api/src/main/java/org/apache/tamaya/MetaInfo.java
+++ b/api/src/main/java/org/apache/tamaya/MetaInfo.java
@@ -33,8 +33,6 @@ public final class MetaInfo{
public static final String SOURCE = "source";
public static final String SOURCE_EXPRESSION = "source-expression";
-// /** The key used for storing the data owner. */
-// private static final String OWNER_KEY = "_owner";
/** The meta information data. */
private final Map<String, String> metaInfo = new HashMap<>();
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/238c07f1/api/src/main/java/org/apache/tamaya/MetaInfoBuilder.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/tamaya/MetaInfoBuilder.java b/api/src/main/java/org/apache/tamaya/MetaInfoBuilder.java
index b5433ef..ad8e83b 100644
--- a/api/src/main/java/org/apache/tamaya/MetaInfoBuilder.java
+++ b/api/src/main/java/org/apache/tamaya/MetaInfoBuilder.java
@@ -19,63 +19,111 @@
package org.apache.tamaya;
import java.util.Arrays;
+import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.ConcurrentHashMap;
/**
- * Builder class to create new instances current {@lin MetaInfo}.
+ * Builder class to create new instances current {@link MetaInfo}. This class is not thread safe.
*/
public final class MetaInfoBuilder{
+ /** Current meta info data map. */
+ Map<String,String> map = new HashMap<>();
- Map<String,String> map = new ConcurrentHashMap<>();
-
+ /**
+ * Creates a new builder using an existing meta info as default.
+ * @param metaInfo the meta info, or null.
+ */
private MetaInfoBuilder(MetaInfo metaInfo){
if(metaInfo!=null){
this.map.putAll(metaInfo.toMap());
}
}
+ /**
+ * Creates a new builder, for a meta info with the given name.
+ * @param name the name, not null.
+ */
private MetaInfoBuilder(String name){
this.map.put(MetaInfo.NAME, Objects.requireNonNull(name));
}
+ /**
+ * Creates a new builder, for a meta info with the given meta info.
+ * @param metaInfo the meta info, or null.
+ * @return the new builder instance.
+ */
public static MetaInfoBuilder of(MetaInfo metaInfo){
return new MetaInfoBuilder(metaInfo);
}
+ /**
+ * Creates a new builder, for a meta info with the given name.
+ * @param name the name, not null.
+ * @return the new builder instance.
+ */
public static MetaInfoBuilder of(String name){
return new MetaInfoBuilder(name);
}
+ /**
+ * Creates a new builder, for a meta info with name '<noname>'..
+ * @return the new builder instance.
+ */
public static MetaInfoBuilder of(){
return new MetaInfoBuilder("<noname>");
}
+ /**
+ * Sets the name.
+ * @param name the name, not null.
+ * @return the builder for chaining.
+ */
public MetaInfoBuilder setName(String name){
Objects.requireNonNull(name);
map.put(MetaInfo.NAME, name);
return this;
}
+ /**
+ * Sets the type.
+ * @param type the type.
+ * @return the builder for chaining.
+ */
public MetaInfoBuilder setType(String type){
Objects.requireNonNull(type);
map.put(MetaInfo.TYPE, type);
return this;
}
+ /**
+ * Sets the info property.
+ * @param info the info.
+ * @return the builder for chaining.
+ */
public MetaInfoBuilder setInfo(String info){
Objects.requireNonNull(info);
map.put(MetaInfo.INFO, info);
return this;
}
+ /**
+ * Sets the sources from which a config/property source is read.
+ * @param sources the sources, not null.
+ * @return the builder for chaining.
+ */
public MetaInfoBuilder setSources(String... sources){
Objects.requireNonNull(sources);
map.put(MetaInfo.SOURCE, Arrays.toString(sources));
return this;
}
+ /**
+ * Applies all properties from the given meta info instance.
+ * @param metaInfo the other meta info, not null.
+ * @return the builder for chaining.
+ */
public MetaInfoBuilder setMetaInfo(MetaInfo metaInfo){
if(metaInfo!=null){
Objects.requireNonNull(metaInfo);
@@ -84,23 +132,33 @@ public final class MetaInfoBuilder{
return this;
}
+ /**
+ * Sets the source expressions used, to evaluate the sources read.
+ * @param sourceExpressions the expressions, not null.
+ * @return the builder for chaining.
+ */
public MetaInfoBuilder setSourceExpressions(String... sourceExpressions){
Objects.requireNonNull(sourceExpressions);
map.put(MetaInfo.SOURCE_EXPRESSION, Arrays.toString(sourceExpressions));
return this;
}
+ /**
+ * Sets the timestamp of the metainfo.
+ * @param timestamp the timestamp.
+ * @return the builder for chaining.
+ */
public MetaInfoBuilder setTimestamp(long timestamp){
map.put(MetaInfo.TIMESTAMP, String.valueOf(timestamp));
return this;
}
- public MetaInfoBuilder setContext(String context){
- Objects.requireNonNull(context);
- map.put(MetaInfo.CONTEXT, context);
- return this;
- }
-
+ /**
+ * Sets any key/value for the meta info.
+ * @param key the target key, not null.
+ * @param value the value, not null.
+ * @return the builder for chaining.
+ */
public MetaInfoBuilder set(String key, String value){
Objects.requireNonNull(key);
Objects.requireNonNull(value);
@@ -108,11 +166,20 @@ public final class MetaInfoBuilder{
return this;
}
+ /**
+ * Access a key present in the current meta info to be built.
+ * @param key the key, not null.
+ * @return the key's value, or null.
+ */
public String get(String key){
Objects.requireNonNull(key);
return map.get(key);
}
+ /**
+ * Builds a new MetaInfo instance, based on the current data.
+ * @return
+ */
public MetaInfo build(){
return new MetaInfo(this);
}
@@ -130,5 +197,4 @@ public final class MetaInfoBuilder{
return b.toString();
}
-
}