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

org.cinchapi.concourse.util.Transformers Maven / Gradle / Ivy

Go to download

This is the api to interact with Concourse, a schemaless and distributed version control database with optimistic availability, serializable transactions and full-text search. Concourse provides a more intuitive approach to data management that is easy to deploy, access and scale with minimal tuning while also maintaining the referential integrity and ACID characteristics of traditional database systems.

The newest version!
/*
 * The MIT License (MIT)
 * 
 * Copyright (c) 2013 Jeff Nelson, Cinchapi Software Collective
 * 
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 * 
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */
package org.cinchapi.concourse.util;

import java.lang.reflect.Array;
import java.util.Map;
import java.util.Set;

import org.cinchapi.concourse.annotate.UtilityClass;

import com.google.common.base.Function;
import com.google.common.collect.Sets;

/**
 * A collection of tools used to transform objects in a collection using a
 * transformation {@link Function}.
 * 
 * @author jnelson
 */
@UtilityClass
public final class Transformers {

	/**
	 * Return an array whose content is equal to the content of {@code original}
	 * after it has been transformed by {@code function}.
	 * 
	 * @param original
	 * @param function
	 * @param vClass - the class object for the type to which the items in
	 *            {@code original} will be transformed
	 * @return the transformed array
	 */
	@SuppressWarnings("unchecked")
	public static  V[] transformArray(F[] original,
			Function function, Class vClass) {
		V[] transformed = (V[]) Array.newInstance(vClass, original.length);
		for (int i = 0; i < original.length; i++) {
			F item = original[i];
			transformed[i] = function.apply(item);
		}
		return transformed;
	}

	/**
	 * Return a Map whose keys are equal to the those in {@code original} after
	 * it has been transformed by {@code function}.
	 * 

* WARNING: There is the potential for data loss in the * event that {@code function} returns duplicate transformed results for * items in {@code original}. *

* * @param original * @param function * @return the transformed Map */ public static Map transformMap(Map original, Function function) { Map transformed = TLinkedHashMap.newTLinkedHashMap(); for (Map.Entry entry : original.entrySet()) { transformed.put(function.apply(entry.getKey()), entry.getValue()); } return transformed; } /** * Populate {@code transformed} with the items in {@code original} after * applying {@code function}. *

* WARNING: There is the potential for data loss in the * event that {@code function} returns duplicate transformed results for * items in {@code original}. *

* * @param original * @param function * @return the transformed Set */ public static Set transformSet(Set original, Function function) { Set transformed = Sets.newLinkedHashSet(); for (F item : original) { transformed.add(function.apply(item)); } return transformed; } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy