org.springframework.data.simpledb.attributeutil.AttributesKeySplitter Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of spring-data-simpledb Show documentation
Show all versions of spring-data-simpledb Show documentation
Provides a POJO centric model as per Spring Data interfaces to interact with Amazon SimpleDB, a non-relational datastore
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package org.springframework.data.simpledb.attributeutil;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
public final class AttributesKeySplitter {
private AttributesKeySplitter() {
/* utility class */
}
public static Map> splitNestedAttributeKeys(Map attributes) {
final Map> nestedFieldAttributes = new HashMap>();
for(final Map.Entry entry : attributes.entrySet()) {
final String key = entry.getKey();
if(key.contains(".")) {
Map nestedFieldValues = new HashMap();
int prefixIndex = key.indexOf('.');
final String nestedFieldName = key.substring(0, prefixIndex);
final String subField = key.substring(prefixIndex + 1);
if(nestedFieldAttributes.containsKey(nestedFieldName)) {
nestedFieldValues = nestedFieldAttributes.get(nestedFieldName);
}
nestedFieldValues.put(subField, entry.getValue());
nestedFieldAttributes.put(nestedFieldName, nestedFieldValues);
}
}
return nestedFieldAttributes;
}
public static Map splitSimpleAttributesKeys(Map attributes) {
Map primitiveAttributes = new LinkedHashMap();
for(final Map.Entry entry : attributes.entrySet()) {
if(isSimpleKey(entry.getKey())) {
primitiveAttributes.put(entry.getKey(), entry.getValue());
}
}
return primitiveAttributes;
}
private static boolean isSimpleKey(final String key) {
return !key.contains(".");
}
}