Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 56F38200B90 for ; Sun, 25 Sep 2016 23:23:57 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 55E4B160AE3; Sun, 25 Sep 2016 21:23:57 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 47D5E160AE9 for ; Sun, 25 Sep 2016 23:23:56 +0200 (CEST) Received: (qmail 37655 invoked by uid 500); 25 Sep 2016 21:23:55 -0000 Mailing-List: contact commits-help@tamaya.incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@tamaya.incubator.apache.org Delivered-To: mailing list commits@tamaya.incubator.apache.org Received: (qmail 37605 invoked by uid 99); 25 Sep 2016 21:23:55 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd2-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 25 Sep 2016 21:23:55 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd2-us-west.apache.org (ASF Mail Server at spamd2-us-west.apache.org) with ESMTP id 0EFF11A0078 for ; Sun, 25 Sep 2016 21:23:55 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd2-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: -4.646 X-Spam-Level: X-Spam-Status: No, score=-4.646 tagged_above=-999 required=6.31 tests=[KAM_ASCII_DIVIDERS=0.8, KAM_LAZY_DOMAIN_SECURITY=1, RCVD_IN_DNSWL_HI=-5, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, RP_MATCHES_RCVD=-1.426] autolearn=disabled Received: from mx1-lw-eu.apache.org ([10.40.0.8]) by localhost (spamd2-us-west.apache.org [10.40.0.9]) (amavisd-new, port 10024) with ESMTP id 9TgEWRUJ-xLQ for ; Sun, 25 Sep 2016 21:23:53 +0000 (UTC) Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx1-lw-eu.apache.org (ASF Mail Server at mx1-lw-eu.apache.org) with SMTP id C605860E08 for ; Sun, 25 Sep 2016 21:23:50 +0000 (UTC) Received: (qmail 36550 invoked by uid 99); 25 Sep 2016 21:23:49 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 25 Sep 2016 21:23:49 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 78811E69AD; Sun, 25 Sep 2016 21:23:49 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: plexus@apache.org To: commits@tamaya.incubator.apache.org Date: Sun, 25 Sep 2016 21:24:02 -0000 Message-Id: <315710a67d074a81a060f3e91370f43b@git.apache.org> In-Reply-To: <52a24ee3fa43434897c8fbb3b85ab5f9@git.apache.org> References: <52a24ee3fa43434897c8fbb3b85ab5f9@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [14/50] [abbrv] incubator-tamaya-sandbox git commit: Moved PropertySourceBuilder from resource module to builder module. Minor Javadoc change. archived-at: Sun, 25 Sep 2016 21:23:57 -0000 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 Authored: Thu May 21 06:28:44 2015 +0200 Committer: anatole 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; * *

Support for configuration formats

* - * 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 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 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 properties; + /** The source's name. */ + private String name; + + public SimplePropertySource(String name, Map properties){ + this.properties = new HashMap<>(properties); + this.name = Objects.requireNonNull(name); + } + + @Override + public String getName() { + return name; + } + + @Override + public Map getProperties() { + return this.properties; + } + + @Override + public String toString(){ + return "SimplePropertySource(name="+name+", numProps="+properties.size()+")"; + } +}