All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.springframework.data.simpledb.attributeutil.AttributesKeySplitter Maven / Gradle / Ivy

Go to download

Provides a POJO centric model as per Spring Data interfaces to interact with Amazon SimpleDB, a non-relational datastore

There is a newer version: 1.0.1
Show newest version
/*
 * 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(".");
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy