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

org.springframework.data.simpledb.util.MapUtils 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
package org.springframework.data.simpledb.util;

import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Set;

public final class MapUtils {

	private MapUtils() {
		// utility class
	}

	/**
	 * Splits rawMap's entries into a number of chunk maps of max chunkSize elements
	 * 
	 * @param rawMap
	 * @param chunkSize
	 * @return
	 */
	public static List>> splitToChunksOfSize(Map> rawMap, int chunkSize) {
		List>> mapChunks = new LinkedList>>();

		Set>> rawEntries = rawMap.entrySet();

		Map> currentChunk = new LinkedHashMap>();
		int rawEntryIndex = 0;
		for(Map.Entry> rawEntry : rawEntries) {

			if(rawEntryIndex % chunkSize == 0) {
				if(currentChunk.size() > 0) {
					mapChunks.add(currentChunk);
				}
				currentChunk = new LinkedHashMap>();
			}

			currentChunk.put(rawEntry.getKey(), rawEntry.getValue());

			rawEntryIndex++;

			if(rawEntryIndex == rawMap.size()) {
				// finished iterating
				mapChunks.add(currentChunk);
			}
		}

		return mapChunks;
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy