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 D5C2C200B89 for ; Tue, 6 Sep 2016 19:18:20 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id D470C160ACE; Tue, 6 Sep 2016 17:18:20 +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 2C829160AD2 for ; Tue, 6 Sep 2016 19:18:19 +0200 (CEST) Received: (qmail 62005 invoked by uid 500); 6 Sep 2016 17:18:18 -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 61996 invoked by uid 99); 6 Sep 2016 17:18:18 -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; Tue, 06 Sep 2016 17:18:18 +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 E20DD1A7B5D for ; Tue, 6 Sep 2016 17:18:17 +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 mx2-lw-us.apache.org ([10.40.0.8]) by localhost (spamd2-us-west.apache.org [10.40.0.9]) (amavisd-new, port 10024) with ESMTP id koZJ-7tpC3O0 for ; Tue, 6 Sep 2016 17:18:04 +0000 (UTC) Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx2-lw-us.apache.org (ASF Mail Server at mx2-lw-us.apache.org) with SMTP id DE5475FC7B for ; Tue, 6 Sep 2016 17:17:59 +0000 (UTC) Received: (qmail 58358 invoked by uid 99); 6 Sep 2016 17:17:58 -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; Tue, 06 Sep 2016 17:17:58 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id AD426E0551; Tue, 6 Sep 2016 17:17:58 +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: Tue, 06 Sep 2016 17:18:17 -0000 Message-Id: In-Reply-To: References: X-Mailer: ASF-Git Admin Mailer Subject: [21/50] [abbrv] incubator-tamaya-sandbox git commit: TAMAYA-114: Added further files for collection support. archived-at: Tue, 06 Sep 2016 17:18:21 -0000 TAMAYA-114: Added further files for collection support. 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/8e237d9f Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/tree/8e237d9f Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/diff/8e237d9f Branch: refs/heads/master Commit: 8e237d9f8055e976c0f20db1b62d41c1482f4a57 Parents: 4607b3d Author: anatole Authored: Sun Feb 14 23:34:07 2016 +0100 Committer: anatole Committed: Sun Feb 14 23:34:07 2016 +0100 ---------------------------------------------------------------------- .../internal/AdaptiveCombinationPolicy.java | 45 ++++++++++++-- .../internal/ArrayListConverter.java | 65 +++++++++++++++++++- .../internal/CollectionConverter.java | 36 +++++++++++ .../collections/internal/HashMapConverter.java | 52 +++++++++++++++- .../collections/internal/HashSetConverter.java | 46 +++++++++++++- .../internal/LinkedListConverter.java | 33 +++++++++- .../collections/internal/ListConverter.java | 36 +++++++++++ .../collections/internal/MapConverter.java | 36 +++++++++++ .../collections/internal/SetConverter.java | 36 +++++++++++ .../internal/SortedMapConverter.java | 37 +++++++++++ .../internal/SortedSetConverter.java | 36 +++++++++++ .../collections/internal/TreeMapConverter.java | 16 ++++- .../collections/internal/TreeSetConverter.java | 43 ++++++++++++- .../org.apache.tamaya.spi.PropertyConverter | 30 +++++++++ ...he.tamaya.spi.PropertyValueCombinationPolicy | 19 ++++++ .../collections/CollectionsBaseTests.java | 29 +++++++++ .../META-INF/javaconfiguration.properties | 30 ++++----- ...he.tamaya.spi.PropertyValueCombinationPolicy | 19 ------ 18 files changed, 588 insertions(+), 56 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/8e237d9f/collections/src/main/java/org/apache/tamaya/collections/internal/AdaptiveCombinationPolicy.java ---------------------------------------------------------------------- diff --git a/collections/src/main/java/org/apache/tamaya/collections/internal/AdaptiveCombinationPolicy.java b/collections/src/main/java/org/apache/tamaya/collections/internal/AdaptiveCombinationPolicy.java index 113d817..9170eb3 100644 --- a/collections/src/main/java/org/apache/tamaya/collections/internal/AdaptiveCombinationPolicy.java +++ b/collections/src/main/java/org/apache/tamaya/collections/internal/AdaptiveCombinationPolicy.java @@ -20,9 +20,11 @@ package org.apache.tamaya.collections.internal; import org.apache.tamaya.ConfigurationProvider; import org.apache.tamaya.spi.PropertySource; +import org.apache.tamaya.spi.PropertyValue; import org.apache.tamaya.spi.PropertyValueCombinationPolicy; import javax.annotation.Priority; +import java.util.HashMap; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; import java.util.logging.Level; @@ -40,8 +42,8 @@ public class AdaptiveCombinationPolicy implements PropertyValueCombinationPolicy private Map configuredPolicies = new ConcurrentHashMap<>(); @Override - public String collect(String currentValue, String key, PropertySource propertySource) { - String adaptiveCombinationPolicyClass = ConfigurationProvider.getConfiguration().get(key+"{combinationPolicy}"); + public Map collect(Map currentValue, String key, PropertySource propertySource){ + String adaptiveCombinationPolicyClass = ConfigurationProvider.getConfiguration().get('_' + key+".combinationPolicy"); if(adaptiveCombinationPolicyClass!=null){ PropertyValueCombinationPolicy delegatePolicy = null; try{ @@ -57,9 +59,44 @@ public class AdaptiveCombinationPolicy implements PropertyValueCombinationPolicy LOG.log(Level.SEVERE, "Error loading configured PropertyValueCombinationPolicy for key: " + key, e); } } - String newValue = propertySource.get(key); + // check for default collection combination policies for lists, sets, maps etc. + String collectionType = ConfigurationProvider.getConfiguration().get('_' + key+".collection-type"); + if(collectionType!=null) { + if (collectionType.startsWith("java.util.")) { + collectionType = collectionType.substring("java.util.".length()); + } + switch(collectionType){ + case "List": + case "ArrayList": + case "LinkedList": + case "Collection": + case "Set": + case "HashSet": + case "TreeSet": + case "SortedSet": + case "Map": + case "HashMap": + case "ConcurrentHashMap": + case "TreeMap": + case "SortedMap": + PropertyValue newValue = propertySource.get(key); + if(newValue!=null){ + Map newMapValue = new HashMap<>(currentValue); + String oldVal = newMapValue.get(key); + if(oldVal!=null){ + newMapValue.put(key,oldVal + ',' + newValue.getValue()); + } + return newMapValue; + }else{ + return newValue.getConfigEntries(); + } + default: + LOG.log(Level.SEVERE, "Unsupported collection-type for key: " + key + ": " + collectionType); + } + } + PropertyValue newValue = propertySource.get(key); if(newValue!=null){ - return newValue; + return newValue.getConfigEntries(); } return currentValue; } http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/8e237d9f/collections/src/main/java/org/apache/tamaya/collections/internal/ArrayListConverter.java ---------------------------------------------------------------------- diff --git a/collections/src/main/java/org/apache/tamaya/collections/internal/ArrayListConverter.java b/collections/src/main/java/org/apache/tamaya/collections/internal/ArrayListConverter.java index 0d7e6f3..4c6b06d 100644 --- a/collections/src/main/java/org/apache/tamaya/collections/internal/ArrayListConverter.java +++ b/collections/src/main/java/org/apache/tamaya/collections/internal/ArrayListConverter.java @@ -18,17 +18,76 @@ */ package org.apache.tamaya.collections.internal; +import org.apache.tamaya.TypeLiteral; +import org.apache.tamaya.spi.ConversionContext; import org.apache.tamaya.spi.PropertyConverter; import java.util.ArrayList; -import java.util.LinkedList; +import java.util.List; +import java.util.logging.Level; +import java.util.logging.Logger; /** * PropertyConverter for gnerating ArrayList representation of a values. */ -public class ArrayListConverter implements PropertyConverter> { +public class ArrayListConverter implements PropertyConverter { + + private static final Logger LOG = Logger.getLogger(ArrayListConverter.class.getName()); + + /** The shared instance, used by other collection converters in this package.*/ + private static ArrayListConverter INSTANCE = new ArrayListConverter(); + + /** + * Provide a shared instance, used by other collection converters in this package. + * @return the shared instance, never null. + */ + static ArrayListConverter getInstance(){ + return INSTANCE; + } + @Override - public ArrayList convert(String value) { + public ArrayList convert(String value, ConversionContext context) { + List rawList = split(value); + String converterClass = context.getConfiguration().get('_' + context.getKey()+".collection-valueParser"); + if(converterClass!=null){ + try { + PropertyConverter valueConverter = (PropertyConverter) Class.forName(converterClass).newInstance(); + ArrayList mlist = new ArrayList<>(); + ConversionContext ctx = new ConversionContext.Builder(context.getConfiguration(), context.getKey(), + TypeLiteral.of(context.getTargetType().getType())).build(); + for(String raw:rawList){ + Object convValue = valueConverter.convert(raw, ctx); + if(convValue!=null){ + mlist.add(convValue); + continue; + } + } + return mlist; + + } catch (Exception e) { + LOG.log(Level.SEVERE, "Error convertion config to ArrayList type.", e); + } + } return null; } + + static List split(String value) { + List result = new ArrayList<>(); + int start = 0; + int end = value.indexOf(',',start); + while(end>0) { + if (end>0 && (value.charAt(end - 1) != '\\')) { + result.add(value.substring(start, end)); + start = end + 1; + end = value.indexOf(',',start); + }else{ + end = value.indexOf(',',end + 1); + } + end = value.indexOf(',',start); + } + if(start < value.length()){ + result.add(value.substring(start)); + } + return result; + } } http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/8e237d9f/collections/src/main/java/org/apache/tamaya/collections/internal/CollectionConverter.java ---------------------------------------------------------------------- diff --git a/collections/src/main/java/org/apache/tamaya/collections/internal/CollectionConverter.java b/collections/src/main/java/org/apache/tamaya/collections/internal/CollectionConverter.java new file mode 100644 index 0000000..80d65cd --- /dev/null +++ b/collections/src/main/java/org/apache/tamaya/collections/internal/CollectionConverter.java @@ -0,0 +1,36 @@ +/* + * 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.collections.internal; + +import org.apache.tamaya.spi.ConversionContext; +import org.apache.tamaya.spi.PropertyConverter; + +import java.util.Collection; +import java.util.Collections; + +/** + * PropertyConverter for gnerating a LIST representation of values. + */ +public class CollectionConverter implements PropertyConverter { + + @Override + public Collection convert(String value, ConversionContext context) { + return Collections.unmodifiableCollection(ArrayListConverter.getInstance().convert(value, context)); + } +} http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/8e237d9f/collections/src/main/java/org/apache/tamaya/collections/internal/HashMapConverter.java ---------------------------------------------------------------------- diff --git a/collections/src/main/java/org/apache/tamaya/collections/internal/HashMapConverter.java b/collections/src/main/java/org/apache/tamaya/collections/internal/HashMapConverter.java index 917c31e..76ded4f 100644 --- a/collections/src/main/java/org/apache/tamaya/collections/internal/HashMapConverter.java +++ b/collections/src/main/java/org/apache/tamaya/collections/internal/HashMapConverter.java @@ -18,17 +18,63 @@ */ package org.apache.tamaya.collections.internal; +import org.apache.tamaya.TypeLiteral; +import org.apache.tamaya.spi.ConversionContext; import org.apache.tamaya.spi.PropertyConverter; import java.util.HashMap; -import java.util.TreeSet; +import java.util.List; +import java.util.logging.Level; +import java.util.logging.Logger; /** * PropertyConverter for gnerating HashMap representation of a values. */ -public class HashMapConverter implements PropertyConverter> { +public class HashMapConverter implements PropertyConverter { + private static final Logger LOG = Logger.getLogger(ArrayListConverter.class.getName()); + + /** The shared instance, used by other collection converters in this package.*/ + private static HashMapConverter INSTANCE = new HashMapConverter(); + + /** + * Provide a shared instance, used by other collection converters in this package. + * @return the shared instance, never null. + */ + static HashMapConverter getInstance(){ + return INSTANCE; + } + @Override - public HashMap convert(String value) { + public HashMap convert(String value, ConversionContext context) { + List rawList = ArrayListConverter.split(value); + String converterClass = context.getConfiguration().get('_' + context.getKey()+".collection-valueParser"); + if(converterClass!=null){ + try { + PropertyConverter valueConverter = (PropertyConverter) Class.forName(converterClass).newInstance(); + HashMap mlist = new HashMap<>(); + ConversionContext ctx = new ConversionContext.Builder(context.getConfiguration(), context.getKey(), + TypeLiteral.of(context.getTargetType().getType())).build(); + for(String raw:rawList){ + String[] items = splitItems(raw); + Object convValue = valueConverter.convert(items[1], ctx); + if(convValue!=null){ + mlist.put(items[0], convValue); + continue; + } + } + return mlist; + + } catch (Exception e) { + LOG.log(Level.SEVERE, "Error convertion config to HashMap type.", e); + } + } return null; } + + static String[] splitItems(String raw) { + String[] items = new String[2]; + // check for '[]' + // else split with ':' + return raw.split("::"); + } } http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/8e237d9f/collections/src/main/java/org/apache/tamaya/collections/internal/HashSetConverter.java ---------------------------------------------------------------------- diff --git a/collections/src/main/java/org/apache/tamaya/collections/internal/HashSetConverter.java b/collections/src/main/java/org/apache/tamaya/collections/internal/HashSetConverter.java index d41b6a2..2c402fb 100644 --- a/collections/src/main/java/org/apache/tamaya/collections/internal/HashSetConverter.java +++ b/collections/src/main/java/org/apache/tamaya/collections/internal/HashSetConverter.java @@ -18,16 +18,58 @@ */ package org.apache.tamaya.collections.internal; +import org.apache.tamaya.TypeLiteral; +import org.apache.tamaya.spi.ConversionContext; import org.apache.tamaya.spi.PropertyConverter; +import java.util.ArrayList; import java.util.HashSet; +import java.util.LinkedList; +import java.util.List; +import java.util.logging.Level; +import java.util.logging.Logger; /** * PropertyConverter for gnerating HashSet representation of a values. */ -public class HashSetConverter implements PropertyConverter> { +public class HashSetConverter implements PropertyConverter { + + private static final Logger LOG = Logger.getLogger(HashSetConverter.class.getName()); + + /** The shared instance, used by other collection converters in this package.*/ + private static HashSetConverter INSTANCE = new HashSetConverter(); + + /** + * Provide a shared instance, used by other collection converters in this package. + * @return the shared instance, never null. + */ + static HashSetConverter getInstance(){ + return INSTANCE; + } + @Override - public HashSet convert(String value) { + public HashSet convert(String value, ConversionContext context) { + List rawList = ArrayListConverter.split(value); + String converterClass = context.getConfiguration().get('_' + context.getKey()+".collection-valueParser"); + if(converterClass!=null){ + try { + PropertyConverter valueConverter = (PropertyConverter) Class.forName(converterClass).newInstance(); + HashSet mlist = new HashSet<>(); + ConversionContext ctx = new ConversionContext.Builder(context.getConfiguration(), context.getKey(), + TypeLiteral.of(context.getTargetType().getType())).build(); + for(String raw:rawList){ + Object convValue = valueConverter.convert(raw, ctx); + if(convValue!=null){ + mlist.add(convValue); + continue; + } + } + return mlist; + + } catch (Exception e) { + LOG.log(Level.SEVERE, "Error convertion config to HashSet type.", e); + } + } return null; } } http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/8e237d9f/collections/src/main/java/org/apache/tamaya/collections/internal/LinkedListConverter.java ---------------------------------------------------------------------- diff --git a/collections/src/main/java/org/apache/tamaya/collections/internal/LinkedListConverter.java b/collections/src/main/java/org/apache/tamaya/collections/internal/LinkedListConverter.java index aaca08d..d41211c 100644 --- a/collections/src/main/java/org/apache/tamaya/collections/internal/LinkedListConverter.java +++ b/collections/src/main/java/org/apache/tamaya/collections/internal/LinkedListConverter.java @@ -18,16 +18,45 @@ */ package org.apache.tamaya.collections.internal; +import org.apache.tamaya.TypeLiteral; +import org.apache.tamaya.spi.ConversionContext; import org.apache.tamaya.spi.PropertyConverter; import java.util.LinkedList; +import java.util.List; +import java.util.logging.Level; +import java.util.logging.Logger; /** * PropertyConverter for gnerating LinkedList representation of a values. */ -public class LinkedListConverter implements PropertyConverter> { +public class LinkedListConverter implements PropertyConverter { + private static final Logger LOG = Logger.getLogger(LinkedListConverter.class.getName()); + @Override - public LinkedList convert(String value) { + public LinkedList convert(String value, ConversionContext context) { + List rawList = ArrayListConverter.split(value); + String converterClass = context.getConfiguration().get('_' + context.getKey()+".collection-valueParser"); + if(converterClass!=null){ + try { + PropertyConverter valueConverter = (PropertyConverter) Class.forName(converterClass).newInstance(); + LinkedList mlist = new LinkedList<>(); + ConversionContext ctx = new ConversionContext.Builder(context.getConfiguration(), context.getKey(), + TypeLiteral.of(context.getTargetType().getType())).build(); + for(String raw:rawList){ + Object convValue = valueConverter.convert(raw, ctx); + if(convValue!=null){ + mlist.add(convValue); + continue; + } + } + return mlist; + + } catch (Exception e) { + LOG.log(Level.SEVERE, "Error convertion config to ArrayList type.", e); + } + } return null; } + } http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/8e237d9f/collections/src/main/java/org/apache/tamaya/collections/internal/ListConverter.java ---------------------------------------------------------------------- diff --git a/collections/src/main/java/org/apache/tamaya/collections/internal/ListConverter.java b/collections/src/main/java/org/apache/tamaya/collections/internal/ListConverter.java new file mode 100644 index 0000000..2299bac --- /dev/null +++ b/collections/src/main/java/org/apache/tamaya/collections/internal/ListConverter.java @@ -0,0 +1,36 @@ +/* + * 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.collections.internal; + +import org.apache.tamaya.spi.ConversionContext; +import org.apache.tamaya.spi.PropertyConverter; + +import java.util.Collections; +import java.util.List; + +/** + * PropertyConverter for gnerating a LIST representation of values. + */ +public class ListConverter implements PropertyConverter { + + @Override + public List convert(String value, ConversionContext context) { + return Collections.unmodifiableList(ArrayListConverter.getInstance().convert(value, context)); + } +} http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/8e237d9f/collections/src/main/java/org/apache/tamaya/collections/internal/MapConverter.java ---------------------------------------------------------------------- diff --git a/collections/src/main/java/org/apache/tamaya/collections/internal/MapConverter.java b/collections/src/main/java/org/apache/tamaya/collections/internal/MapConverter.java new file mode 100644 index 0000000..dcd2919 --- /dev/null +++ b/collections/src/main/java/org/apache/tamaya/collections/internal/MapConverter.java @@ -0,0 +1,36 @@ +/* + * 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.collections.internal; + +import org.apache.tamaya.spi.ConversionContext; +import org.apache.tamaya.spi.PropertyConverter; + +import java.util.Collections; +import java.util.Map; + +/** + * PropertyConverter for gnerating HashMap representation of a values. + */ +public class MapConverter implements PropertyConverter { + + @Override + public Map convert(String value, ConversionContext context) { + return Collections.unmodifiableMap(HashMapConverter.getInstance().convert(value, context)); + } +} http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/8e237d9f/collections/src/main/java/org/apache/tamaya/collections/internal/SetConverter.java ---------------------------------------------------------------------- diff --git a/collections/src/main/java/org/apache/tamaya/collections/internal/SetConverter.java b/collections/src/main/java/org/apache/tamaya/collections/internal/SetConverter.java new file mode 100644 index 0000000..ddf19ad --- /dev/null +++ b/collections/src/main/java/org/apache/tamaya/collections/internal/SetConverter.java @@ -0,0 +1,36 @@ +/* + * 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.collections.internal; + +import org.apache.tamaya.spi.ConversionContext; +import org.apache.tamaya.spi.PropertyConverter; + +import java.util.Collections; +import java.util.Set; + +/** + * PropertyConverter for gnerating a LIST representation of values. + */ +public class SetConverter implements PropertyConverter> { + + @Override + public Set convert(String value, ConversionContext context) { + return Collections.unmodifiableSet(HashSetConverter.getInstance().convert(value, context)); + } +} http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/8e237d9f/collections/src/main/java/org/apache/tamaya/collections/internal/SortedMapConverter.java ---------------------------------------------------------------------- diff --git a/collections/src/main/java/org/apache/tamaya/collections/internal/SortedMapConverter.java b/collections/src/main/java/org/apache/tamaya/collections/internal/SortedMapConverter.java new file mode 100644 index 0000000..1015751 --- /dev/null +++ b/collections/src/main/java/org/apache/tamaya/collections/internal/SortedMapConverter.java @@ -0,0 +1,37 @@ +/* + * 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.collections.internal; + +import org.apache.tamaya.spi.ConversionContext; +import org.apache.tamaya.spi.PropertyConverter; + +import java.util.Collections; +import java.util.SortedMap; +import java.util.SortedSet; + +/** + * PropertyConverter for gnerating a LIST representation of values. + */ +public class SortedMapConverter implements PropertyConverter { + + @Override + public SortedMap convert(String value, ConversionContext context) { + return Collections.unmodifiableSortedMap(TreeMapConverter.getInstance().convert(value, context)); + } +} http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/8e237d9f/collections/src/main/java/org/apache/tamaya/collections/internal/SortedSetConverter.java ---------------------------------------------------------------------- diff --git a/collections/src/main/java/org/apache/tamaya/collections/internal/SortedSetConverter.java b/collections/src/main/java/org/apache/tamaya/collections/internal/SortedSetConverter.java new file mode 100644 index 0000000..c0b8065 --- /dev/null +++ b/collections/src/main/java/org/apache/tamaya/collections/internal/SortedSetConverter.java @@ -0,0 +1,36 @@ +/* + * 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.collections.internal; + +import org.apache.tamaya.spi.ConversionContext; +import org.apache.tamaya.spi.PropertyConverter; + +import java.util.Collections; +import java.util.SortedSet; + +/** + * PropertyConverter for gnerating a LIST representation of values. + */ +public class SortedSetConverter implements PropertyConverter { + + @Override + public SortedSet convert(String value, ConversionContext context) { + return Collections.unmodifiableSortedSet(TreeSetConverter.getInstance().convert(value, context)); + } +} http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/8e237d9f/collections/src/main/java/org/apache/tamaya/collections/internal/TreeMapConverter.java ---------------------------------------------------------------------- diff --git a/collections/src/main/java/org/apache/tamaya/collections/internal/TreeMapConverter.java b/collections/src/main/java/org/apache/tamaya/collections/internal/TreeMapConverter.java index 6e74d5c..08b92fd 100644 --- a/collections/src/main/java/org/apache/tamaya/collections/internal/TreeMapConverter.java +++ b/collections/src/main/java/org/apache/tamaya/collections/internal/TreeMapConverter.java @@ -18,17 +18,29 @@ */ package org.apache.tamaya.collections.internal; +import org.apache.tamaya.spi.ConversionContext; import org.apache.tamaya.spi.PropertyConverter; -import java.util.HashMap; import java.util.TreeMap; /** * PropertyConverter for gnerating HashMap representation of a values. */ public class TreeMapConverter implements PropertyConverter> { + + /** The shared instance, used by other collection converters in this package.*/ + private static TreeMapConverter INSTANCE = new TreeMapConverter(); + + /** + * Provide a shared instance, used by other collection converters in this package. + * @return the shared instance, never null. + */ + static TreeMapConverter getInstance(){ + return INSTANCE; + } + @Override - public TreeMap convert(String value) { + public TreeMap convert(String value, ConversionContext context) { return null; } } http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/8e237d9f/collections/src/main/java/org/apache/tamaya/collections/internal/TreeSetConverter.java ---------------------------------------------------------------------- diff --git a/collections/src/main/java/org/apache/tamaya/collections/internal/TreeSetConverter.java b/collections/src/main/java/org/apache/tamaya/collections/internal/TreeSetConverter.java index 2797c91..fca00de 100644 --- a/collections/src/main/java/org/apache/tamaya/collections/internal/TreeSetConverter.java +++ b/collections/src/main/java/org/apache/tamaya/collections/internal/TreeSetConverter.java @@ -18,17 +18,56 @@ */ package org.apache.tamaya.collections.internal; +import org.apache.tamaya.TypeLiteral; +import org.apache.tamaya.spi.ConversionContext; import org.apache.tamaya.spi.PropertyConverter; -import java.util.HashSet; +import java.util.List; import java.util.TreeSet; +import java.util.logging.Level; +import java.util.logging.Logger; /** * PropertyConverter for gnerating HashSet representation of a values. */ public class TreeSetConverter implements PropertyConverter> { + + private static final Logger LOG = Logger.getLogger(TreeSetConverter.class.getName()); + + /** The shared instance, used by other collection converters in this package.*/ + private static TreeSetConverter INSTANCE = new TreeSetConverter(); + + /** + * Provide a shared instance, used by other collection converters in this package. + * @return the shared instance, never null. + */ + static TreeSetConverter getInstance(){ + return INSTANCE; + } + @Override - public TreeSet convert(String value) { + public TreeSet convert(String value, ConversionContext context) { + List rawList = ArrayListConverter.split(value); + String converterClass = context.getConfiguration().get('_' + context.getKey()+".collection-valueParser"); + if(converterClass!=null){ + try { + PropertyConverter valueConverter = (PropertyConverter) Class.forName(converterClass).newInstance(); + TreeSet mlist = new TreeSet<>(); + ConversionContext ctx = new ConversionContext.Builder(context.getConfiguration(), context.getKey(), + TypeLiteral.of(context.getTargetType().getType())).build(); + for(String raw:rawList){ + Object convValue = valueConverter.convert(raw, ctx); + if(convValue!=null){ + mlist.add(convValue); + continue; + } + } + return mlist; + + } catch (Exception e) { + LOG.log(Level.SEVERE, "Error convertion config to HashSet type.", e); + } + } return null; } } http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/8e237d9f/collections/src/main/resources/META-INF/services/org.apache.tamaya.spi.PropertyConverter ---------------------------------------------------------------------- diff --git a/collections/src/main/resources/META-INF/services/org.apache.tamaya.spi.PropertyConverter b/collections/src/main/resources/META-INF/services/org.apache.tamaya.spi.PropertyConverter new file mode 100644 index 0000000..c4cf2ae --- /dev/null +++ b/collections/src/main/resources/META-INF/services/org.apache.tamaya.spi.PropertyConverter @@ -0,0 +1,30 @@ +# +# 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 current 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. +# +org.apache.tamaya.collections.internal.ArrayListConverter +org.apache.tamaya.collections.internal.CollectionConverter +org.apache.tamaya.collections.internal.HashMapConverter +org.apache.tamaya.collections.internal.HashSetConverter +org.apache.tamaya.collections.internal.LinkedListConverter +org.apache.tamaya.collections.internal.ListConverter +org.apache.tamaya.collections.internal.MapConverter +org.apache.tamaya.collections.internal.SetConverter +org.apache.tamaya.collections.internal.SortedSetConverter +org.apache.tamaya.collections.internal.SortedMapConverter +org.apache.tamaya.collections.internal.TreeMapConverter +org.apache.tamaya.collections.internal.TreeSetConverter http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/8e237d9f/collections/src/main/resources/META-INF/services/org.apache.tamaya.spi.PropertyValueCombinationPolicy ---------------------------------------------------------------------- diff --git a/collections/src/main/resources/META-INF/services/org.apache.tamaya.spi.PropertyValueCombinationPolicy b/collections/src/main/resources/META-INF/services/org.apache.tamaya.spi.PropertyValueCombinationPolicy new file mode 100644 index 0000000..6b7a67b --- /dev/null +++ b/collections/src/main/resources/META-INF/services/org.apache.tamaya.spi.PropertyValueCombinationPolicy @@ -0,0 +1,19 @@ +# +# 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 current 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. +# +org.apache.tamaya.collections.internal.AdaptiveCombinationPolicy \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/8e237d9f/collections/src/test/java/org/apache/tamaya/collections/CollectionsBaseTests.java ---------------------------------------------------------------------- diff --git a/collections/src/test/java/org/apache/tamaya/collections/CollectionsBaseTests.java b/collections/src/test/java/org/apache/tamaya/collections/CollectionsBaseTests.java new file mode 100644 index 0000000..ca100ea --- /dev/null +++ b/collections/src/test/java/org/apache/tamaya/collections/CollectionsBaseTests.java @@ -0,0 +1,29 @@ +package org.apache.tamaya.collections; + +import org.junit.Test; + +/** + * Created by atsticks on 14.02.16. + */ +public class CollectionsBaseTests { + + @Test + public void testList_String(){ + + } + + @Test + public void testSet_String(){ + + } + + @Test + public void testMap_String(){ + + } + + @Test + public void testCollection_String(){ + + } +} http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/8e237d9f/collections/src/test/resources/META-INF/javaconfiguration.properties ---------------------------------------------------------------------- diff --git a/collections/src/test/resources/META-INF/javaconfiguration.properties b/collections/src/test/resources/META-INF/javaconfiguration.properties index 9848617..ca3c66e 100644 --- a/collections/src/test/resources/META-INF/javaconfiguration.properties +++ b/collections/src/test/resources/META-INF/javaconfiguration.properties @@ -18,34 +18,26 @@ # # Similar to etcd all keys starting with a _ are hidden by default (only directly accessible). -# Examples for collection syntax +# Config for base tests (no combination policy) +base.items=1,2,3,4,5,6,7,8,9,0 +base.map=1::a, 2::b, 3::c, [4:: ] +# Config for tests with combination policy list=a,b,c _list.collection-type=List -#list.{collection-combinationPolicy}=MyLeftAppendingCombinationPolicy - -arrayList=d;e;f +arrayList=d,e,f _arrayList.collection-type=java.util.ArrayList -_arrayList.collection-separator=; -#_arrayList.collection-valueParser=myParserClass - linkedList=g,h,i _linkedList.collection-type=java.util.LinkedList - set=a,b,b _set.collection-type=java.util.Set -_set.eval-combinationPolicy=WarnOnDuplicates - sortedSet=a,c,b _sortedSet.collection-type=java.util.TreeSet - -map=1:a,2:b,3:c +map=1::a, 2::b, 3::c _map.collection-type=Map -#_map.collection-keyParser=myParserClass -#_map.collection-valueParser=myParserClass - -sortedMap=|3:c||1:a||2:b| -_sortedMap.collection-type=java.util.TreeMap - -concurrentMap=|3:c||1:a||2:b| +sortedmap=[3 :: c], 1 :: a, 2 :: b +_sortedmap.collection-type=SorteedMap +treemap=[3 :: c], 1 :: a, 2 :: b +_treemap.collection-type=java.util.TreeMap +concurrentMap=[3::c], 1::a, key::value _concurrentMap.collection-type=java.util.ConcurrentHashMap \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/8e237d9f/collections/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertyValueCombinationPolicy ---------------------------------------------------------------------- diff --git a/collections/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertyValueCombinationPolicy b/collections/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertyValueCombinationPolicy deleted file mode 100644 index 6b7a67b..0000000 --- a/collections/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertyValueCombinationPolicy +++ /dev/null @@ -1,19 +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 current 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. -# -org.apache.tamaya.collections.internal.AdaptiveCombinationPolicy \ No newline at end of file