com.github.shyiko.mappify.api.Mapper Maven / Gradle / Ivy
The newest version!
/*
* Copyright 2012 Stanley Shyiko
*
* Licensed 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 com.github.shyiko.mappify.api;
import java.util.*;
/**
* Contract for the object mapper. Implementations are required to be thread-safe.
*
* @author Stanley Shyiko
*/
public interface Mapper {
/**
* Map the source object onto the target one.
* @param source source object
* @param target target object
* @return target object
* @throws MappingException in case of failure during the mapping process
*/
T map(Object source, T target);
/**
* Map the source object onto the target one.
* @param source source object
* @param target target object
* @param mappingName mapping name
* @param return type
* @return target object
* @throws MappingException in case of failure during the mapping process
*/
T map(Object source, T target, String mappingName);
/**
* Map the source object onto the target one.
* @param source source object
* @param target target object
* @param mappingContext mapping context
* @param return type
* @return target object
* @throws MappingException in case of failure during the mapping process
*/
T map(Object source, T target, MappingContext mappingContext);
/**
* Map the source object onto the target one.
* @param source source object
* @param target target object
* @param mappingName mapping name
* @param mappingContext mapping context
* @param return type
* @return target object
* @throws MappingException in case of failure during the mapping process
*/
T map(Object source, T target, String mappingName, MappingContext mappingContext);
/**
* Map the source object into the object of target class.
* @param source source object. nullable
* @param targetClass target class
* @param return type
* @return target object. nullable
* @throws MappingException in case of failure during the mapping process
*/
T map(Object source, Class targetClass);
/**
* Map the source object into the object of target class.
* @param source source object. nullable
* @param targetClass target class
* @param mappingName mapping name
* @param return type
* @return target object. nullable
* @throws MappingException in case of failure during the mapping process
*/
T map(Object source, Class targetClass, String mappingName);
/**
* Map the source object into the object of target class.
* @param source source object. nullable
* @param targetClass target class
* @param mappingContext mapping context
* @param return type
* @return target object. nullable
* @throws MappingException in case of failure during the mapping process
*/
T map(Object source, Class targetClass, MappingContext mappingContext);
/**
* Map the source object into the object of target class.
* @param source source object. nullable
* @param targetClass target class
* @param mappingName mapping name
* @param mappingContext mapping context
* @param return type
* @return target object. nullable
* @throws MappingException in case of failure during the mapping process
*/
T map(Object source, Class targetClass, String mappingName, MappingContext mappingContext);
/**
* Map each element of source collection into corresponding object of target class.
* Result is added to the target collection.
* @param sourceCollection source collection
* @param targetClass target class
* @param targetCollection target collection
* @param collection type
* @param return type
* @return target collection
* @throws MappingException in case of failure during the mapping process
*/
, T> C map(
Collection sourceCollection, Class targetClass, C targetCollection);
/**
* Map each element of source collection into corresponding object of target class.
* Result is added to the target collection.
* @param sourceCollection source collection
* @param targetClass target class
* @param targetCollection target collection
* @param mappingName mapping name
* @param collection type
* @param return type
* @return target collection
* @throws MappingException in case of failure during the mapping process
*/
, T> C map(
Collection sourceCollection, Class targetClass, C targetCollection, String mappingName);
/**
* Map each element of source collection into corresponding object of target class.
* Result is added to the target collection.
* @param sourceCollection source collection
* @param targetClass target class
* @param targetCollection target collection
* @param mappingContext mapping context
* @param collection type
* @param return type
* @return target collection
* @throws MappingException in case of failure during the mapping process
*/
, T> C map(
Collection sourceCollection, Class targetClass, C targetCollection, MappingContext mappingContext);
/**
* Map each element of source collection into corresponding object of target class.
* Result is added to the target collection.
* @param sourceCollection source collection
* @param targetClass target class
* @param targetCollection target collection
* @param mappingName mapping name
* @param mappingContext mapping context
* @param collection type
* @param return type
* @return target collection
* @throws MappingException in case of failure during the mapping process
*/
, T> C map(
Collection sourceCollection, Class targetClass, C targetCollection, String mappingName,
MappingContext mappingContext);
/**
* Map each element of source collection into corresponding object of target class.
* Result is added to the target map (source object (key) -> target object (value)).
* @param sourceCollection source collection
* @param targetClass target class
* @param targetMap target map
* @param source type
* @param map type
* @param return type
* @return target map
* @throws MappingException in case of failure during the mapping process
*/
, T> C map(
Collection sourceCollection, Class targetClass, C targetMap);
/**
* Map each element of source collection into corresponding object of target class.
* Result is added to the target map (source object (key) -> target object (value)).
* @param sourceCollection source collection
* @param targetClass target class
* @param targetMap target map
* @param mappingName mapping name
* @param source type
* @param map type
* @param return type
* @return target map
* @throws MappingException in case of failure during the mapping process
*/
, T> C map(
Collection sourceCollection, Class targetClass, C targetMap, String mappingName);
/**
* Map each element of source collection into corresponding object of target class.
* Result is added to the target map (source object (key) -> target object (value)).
* @param sourceCollection source collection
* @param targetClass target class
* @param targetMap target map
* @param mappingContext mapping context
* @param source type
* @param map type
* @param return type
* @return target map
* @throws MappingException in case of failure during the mapping process
*/
, T> C map(
Collection sourceCollection, Class targetClass, C targetMap, MappingContext mappingContext);
/**
* Map each element of source collection into corresponding object of target class.
* Result is added to the target map (source object (key) -> target object (value)).
* @param sourceCollection source collection
* @param targetClass target class
* @param targetMap target map
* @param mappingName mapping name
* @param mappingContext mapping context
* @param source type
* @param map type
* @param return type
* @return target map
* @throws MappingException in case of failure during the mapping process
*/
, T> C map(
Collection sourceCollection, Class targetClass, C targetMap, String mappingName,
MappingContext mappingContext);
/**
* Map each element of source collection into corresponding object of target class.
* Result is returned in for of an array.
* @param sourceCollection source collection
* @param targetClass target class
* @param return type
* @return array of mapped instances
* @throws MappingException in case of failure during the mapping process
*/
T[] map(Collection sourceCollection, Class targetClass);
/**
* Map each element of source collection into corresponding object of target class.
* Result is returned in for of an array.
* @param sourceCollection source collection
* @param targetClass target class
* @param mappingName mapping name
* @param return type
* @return array of mapped instances
* @throws MappingException in case of failure during the mapping process
*/
T[] map(Collection sourceCollection, Class targetClass, String mappingName);
/**
* Map each element of source collection into corresponding object of target class.
* Result is returned in for of an array.
* @param sourceCollection source collection
* @param targetClass target class
* @param mappingContext mapping context
* @param return type
* @return array of mapped instances
* @throws MappingException in case of failure during the mapping process
*/
T[] map(Collection sourceCollection, Class targetClass, MappingContext mappingContext);
/**
* Map each element of source collection into corresponding object of target class.
* Result is returned in for of an array.
* @param sourceCollection source collection
* @param targetClass target class
* @param mappingName mapping name
* @param mappingContext mapping context
* @param return type
* @return array of mapped instances
* @throws MappingException in case of failure during the mapping process
*/
T[] map(Collection sourceCollection, Class targetClass, String mappingName, MappingContext mappingContext);
/**
* Map each element of source array into corresponding object of target class.
* Result is added to the target collection.
* @param sourceArray source array
* @param targetClass target class
* @param targetCollection target collection
* @param source type
* @param collection type
* @param return type
* @return target collection
* @throws MappingException in case of failure during the mapping process
*/
, T> C map(S[] sourceArray, Class targetClass, C targetCollection);
/**
* Map each element of source array into corresponding object of target class.
* Result is added to the target collection.
* @param sourceArray source array
* @param targetClass target class
* @param targetCollection target collection
* @param mappingName mapping name
* @param source type
* @param collection type
* @param return type
* @return target collection
* @throws MappingException in case of failure during the mapping process
*/
, T> C map(
S[] sourceArray, Class targetClass, C targetCollection, String mappingName);
/**
* Map each element of source array into corresponding object of target class.
* Result is added to the target collection.
* @param sourceArray source array
* @param targetClass target class
* @param targetCollection target collection
* @param mappingContext mapping context
* @param source type
* @param collection type
* @param return type
* @return target collection
* @throws MappingException in case of failure during the mapping process
*/
, T> C map(
S[] sourceArray, Class targetClass, C targetCollection, MappingContext mappingContext);
/**
* Map each element of source array into corresponding object of target class.
* Result is added to the target collection.
* @param sourceArray source array
* @param targetClass target class
* @param targetCollection target collection
* @param mappingName mapping name
* @param mappingContext mapping context
* @param source type
* @param collection type
* @param return type
* @return target collection
* @throws MappingException in case of failure during the mapping process
*/
, T> C map(
S[] sourceArray, Class targetClass, C targetCollection, String mappingName,
MappingContext mappingContext);
/**
* Map each element of source array into corresponding object of target class.
* Result is added to the target map (source object (key) -> target object (value)).
* @param sourceArray source array
* @param targetClass target class
* @param targetMap target map
* @param source type
* @param map type
* @param return type
* @return target map
* @throws MappingException in case of failure during the mapping process
*/
, T> C map(
S[] sourceArray, Class targetClass, C targetMap);
/**
* Map each element of source array into corresponding object of target class.
* Result is added to the target map (source object (key) -> target object (value)).
* @param sourceArray source array
* @param targetClass target class
* @param targetMap target map
* @param mappingName mapping name
* @param source type
* @param map type
* @param return type
* @return target map
* @throws MappingException in case of failure during the mapping process
*/
, T> C map(
S[] sourceArray, Class targetClass, C targetMap, String mappingName);
/**
* Map each element of source array into corresponding object of target class.
* Result is added to the target map (source object (key) -> target object (value)).
* @param sourceArray source array
* @param targetClass target class
* @param targetMap target map
* @param mappingContext mapping context
* @param source type
* @param map type
* @param return type
* @return target map
* @throws MappingException in case of failure during the mapping process
*/
, T> C map(
S[] sourceArray, Class targetClass, C targetMap, MappingContext mappingContext);
/**
* Map each element of source array into corresponding object of target class.
* Result is added to the target map (source object (key) -> target object (value)).
* @param sourceArray source array
* @param targetClass target class
* @param targetMap target map
* @param mappingName mapping name
* @param mappingContext mapping context
* @param source type
* @param map type
* @param return type
* @return target map
* @throws MappingException in case of failure during the mapping process
*/
, T> C map(
S[] sourceArray, Class targetClass, C targetMap, String mappingName, MappingContext mappingContext);
/**
* Map each element of source array into corresponding object of target class.
* Result is returned in for of an array.
* @param sourceArray source array
* @param targetClass target class
* @param source type
* @param return type
* @return array of mapped instances
* @throws MappingException in case of failure during the mapping process
*/
T[] map(S[] sourceArray, Class targetClass);
/**
* Map each element of source array into corresponding object of target class.
* Result is returned in for of an array.
* @param sourceArray source array
* @param targetClass target class
* @param mappingName mapping name
* @param source type
* @param return type
* @return array of mapped instances
* @throws MappingException in case of failure during the mapping process
*/
T[] map(S[] sourceArray, Class targetClass, String mappingName);
/**
* Map each element of source array into corresponding object of target class.
* Result is returned in for of an array.
* @param sourceArray source array
* @param targetClass target class
* @param mappingContext mapping context
* @param source type
* @param return type
* @return array of mapped instances
* @throws MappingException in case of failure during the mapping process
*/
T[] map(S[] sourceArray, Class targetClass, MappingContext mappingContext);
/**
* Map each element of source array into corresponding object of target class.
* Result is returned in for of an array.
* @param sourceArray source array
* @param targetClass target class
* @param mappingName mapping name
* @param mappingContext mapping context
* @param source type
* @param return type
* @return array of mapped instances
* @throws MappingException in case of failure during the mapping process
*/
T[] map(S[] sourceArray, Class targetClass, String mappingName, MappingContext mappingContext);
/**
* Determine whether mapper has mapping definition for source class -> target class.
* @param sourceClass source class
* @param targetClass target class
* @return true if mapper is capable of mapping source class to the target, false otherwise
*/
boolean allowsToMap(Class sourceClass, Class targetClass);
/**
* Determine whether mapper has mapping definition for source class -> target class.
* @param sourceClass source class
* @param targetClass target class
* @param mappingName mapping name
* @return true if mapper is capable of mapping source class to the target, false otherwise
*/
boolean allowsToMap(Class sourceClass, Class targetClass, String mappingName);
/**
* Alias for map(sourceCollection, targetClass, new ArrayList(sourceCollection.size())).
* @see #map(java.util.Collection, Class, java.util.Collection)
*/
ArrayList mapToArrayList(Collection sourceCollection, Class targetClass);
/**
* Alias for map(sourceCollection, targetClass, new ArrayList(sourceCollection.size()), mappingName).
* @see #map(java.util.Collection, Class, java.util.Collection, String)
*/
ArrayList mapToArrayList(Collection sourceCollection, Class targetClass, String mappingName);
/**
* Alias for map(sourceCollection, targetClass, new ArrayList(sourceCollection.size()), mappingContext).
* @see #map(java.util.Collection, Class, java.util.Collection, MappingContext)
*/
ArrayList mapToArrayList(Collection sourceCollection, Class targetClass, MappingContext mappingContext);
/**
* Alias for map(sourceCollection, targetClass, new ArrayList(sourceCollection.size()), mappingName, mappingContext).
* @see #map(java.util.Collection, Class, java.util.Collection, String, MappingContext)
*/
ArrayList mapToArrayList(
Collection sourceCollection, Class targetClass, String mappingName, MappingContext mappingContext);
/**
* Alias for map(sourceArray, targetClass, new ArrayList(sourceArray.length)).
* @see #map(Object[], Class, java.util.Collection)
*/
ArrayList mapToArrayList(S[] sourceArray, Class targetClass);
/**
* Alias for map(sourceArray, targetClass, new ArrayList(sourceArray.length), mappingName).
* @see #map(Object[], Class, java.util.Collection, String)
*/
ArrayList mapToArrayList(S[] sourceArray, Class targetClass, String mappingName);
/**
* Alias for map(sourceArray, targetClass, new ArrayList(sourceArray.length), mappingContext).
* @see #map(Object[], Class, java.util.Collection, MappingContext)
*/
ArrayList mapToArrayList(S[] sourceArray, Class targetClass, MappingContext mappingContext);
/**
* Alias for map(sourceArray, targetClass, new ArrayList(sourceArray.length), mappingName, mappingContext).
* @see #map(Object[], Class, java.util.Collection, String, MappingContext)
*/
ArrayList mapToArrayList(
S[] sourceArray, Class targetClass, String mappingName, MappingContext mappingContext);
/**
* Alias for map(sourceCollection, targetClass, new HashSet(sufficient initial capacity))).
* @see #map(java.util.Collection, Class, java.util.Collection)
*/
HashSet mapToHashSet(Collection sourceCollection, Class targetClass);
/**
* Alias for map(sourceCollection, targetClass, new HashSet(sufficient initial capacity), mappingName).
* @see #map(java.util.Collection, Class, java.util.Collection, String)
*/
HashSet mapToHashSet(Collection sourceCollection, Class targetClass, String mappingName);
/**
* Alias for map(sourceCollection, targetClass, new HashSet(sufficient initial capacity), mappingContext).
* @see #map(java.util.Collection, Class, java.util.Collection, MappingContext)
*/
HashSet mapToHashSet(Collection sourceCollection, Class targetClass, MappingContext mappingContext);
/**
* Alias for map(sourceCollection, targetClass, new HashSet(sufficient initial capacity), mappingName, mappingContext).
* @see #map(java.util.Collection, Class, java.util.Collection, String, MappingContext)
*/
HashSet mapToHashSet(
Collection sourceCollection, Class targetClass, String mappingName, MappingContext mappingContext);
/**
* Alias for map(sourceArray, targetClass, new HashSet(sufficient initial capacity)).
* @see #map(Object[], Class, java.util.Collection)
*/
HashSet mapToHashSet(S[] sourceArray, Class targetClass);
/**
* Alias for map(sourceArray, targetClass, new HashSet(sufficient initial capacity), mappingName).
* @see #map(Object[], Class, java.util.Collection, String)
*/
HashSet mapToHashSet(S[] sourceArray, Class targetClass, String mappingName);
/**
* Alias for map(sourceArray, targetClass, new HashSet(sufficient initial capacity), mappingContext).
* @see #map(Object[], Class, java.util.Collection, MappingContext)
*/
HashSet mapToHashSet(S[] sourceArray, Class targetClass, MappingContext mappingContext);
/**
* Alias for map(sourceArray, targetClass, new HashSet(sufficient initial capacity), mappingName, mappingContext).
* @see #map(Object[], Class, java.util.Collection, String, MappingContext)
*/
HashSet mapToHashSet(
S[] sourceArray, Class targetClass, String mappingName, MappingContext mappingContext);
/**
* Alias for map(sourceCollection, targetClass, new LinkedHashSet(sufficient initial capacity))).
* @see #map(java.util.Collection, Class, java.util.Collection)
*/
LinkedHashSet mapToLinkedHashSet(Collection sourceCollection, Class targetClass);
/**
* Alias for map(sourceCollection, targetClass, new LinkedHashSet(sufficient initial capacity), mappingName).
* @see #map(java.util.Collection, Class, java.util.Collection, String)
*/
LinkedHashSet mapToLinkedHashSet(Collection sourceCollection, Class targetClass, String mappingName);
/**
* Alias for map(sourceCollection, targetClass, new LinkedHashSet(sufficient initial capacity), mappingContext).
* @see #map(java.util.Collection, Class, java.util.Collection, MappingContext)
*/
LinkedHashSet mapToLinkedHashSet(
Collection sourceCollection, Class targetClass, MappingContext mappingContext);
/**
* Alias for map(sourceCollection, targetClass, new LinkedHashSet(sufficient initial capacity), mappingName, mappingContext).
* @see #map(java.util.Collection, Class, java.util.Collection, String, MappingContext)
*/
LinkedHashSet mapToLinkedHashSet(
Collection sourceCollection, Class targetClass, String mappingName, MappingContext mappingContext);
/**
* Alias for map(sourceArray, targetClass, new LinkedHashSet(sufficient initial capacity)).
* @see #map(Object[], Class, java.util.Collection)
*/
LinkedHashSet mapToLinkedHashSet(S[] sourceArray, Class targetClass);
/**
* Alias for map(sourceArray, targetClass, new LinkedHashSet(sufficient initial capacity), mappingName).
* @see #map(Object[], Class, java.util.Collection, String)
*/
LinkedHashSet mapToLinkedHashSet(S[] sourceArray, Class targetClass, String mappingName);
/**
* Alias for map(sourceArray, targetClass, new LinkedHashSet(sufficient initial capacity), mappingContext).
* @see #map(Object[], Class, java.util.Collection, MappingContext)
*/
LinkedHashSet mapToLinkedHashSet(S[] sourceArray, Class targetClass, MappingContext mappingContext);
/**
* Alias for map(sourceArray, targetClass, new LinkedHashSet(sufficient initial capacity), mappingName, mappingContext).
* @see #map(Object[], Class, java.util.Collection, String, MappingContext)
*/
LinkedHashSet mapToLinkedHashSet(
S[] sourceArray, Class targetClass, String mappingName, MappingContext mappingContext);
/**
* Alias for map(sourceCollection, targetClass, new HashMap(sufficient initial capacity))).
* @see #map(java.util.Collection, Class, java.util.Map)
*/
HashMap mapToHashMap(Collection sourceCollection, Class targetClass);
/**
* Alias for map(sourceCollection, targetClass, new HashMap(sufficient initial capacity), mappingName).
* @see #map(java.util.Collection, Class, java.util.Map, String)
*/
HashMap mapToHashMap(Collection sourceCollection, Class targetClass, String mappingName);
/**
* Alias for map(sourceCollection, targetClass, new HashMap(sufficient initial capacity), mappingContext).
* @see #map(java.util.Collection, Class, java.util.Map, MappingContext)
*/
HashMap mapToHashMap(
Collection sourceCollection, Class targetClass, MappingContext mappingContext);
/**
* Alias for map(sourceCollection, targetClass, new HashMap(sufficient initial capacity), mappingName, mappingContext).
* @see #map(java.util.Collection, Class, java.util.Map, String, MappingContext)
*/
HashMap mapToHashMap(
Collection sourceCollection, Class targetClass, String mappingName, MappingContext mappingContext);
/**
* Alias for map(sourceArray, targetClass, new HashMap(sufficient initial capacity)).
* @see #map(Object[], Class, java.util.Map)
*/
HashMap mapToHashMap(S[] sourceArray, Class targetClass);
/**
* Alias for map(sourceArray, targetClass, new HashMap(sufficient initial capacity), mappingName).
* @see #map(Object[], Class, java.util.Map, String)
*/
HashMap mapToHashMap(S[] sourceArray, Class targetClass, String mappingName);
/**
* Alias for map(sourceArray, targetClass, new HashMap(sufficient initial capacity), mappingContext).
* @see #map(Object[], Class, java.util.Map, MappingContext)
*/
HashMap mapToHashMap(S[] sourceArray, Class targetClass, MappingContext mappingContext);
/**
* Alias for map(sourceArray, targetClass, new HashMap(sufficient initial capacity), mappingName, mappingContext).
* @see #map(Object[], Class, java.util.Map, String, MappingContext)
*/
HashMap mapToHashMap(
S[] sourceArray, Class targetClass, String mappingName, MappingContext mappingContext);
/**
* Alias for map(sourceCollection, targetClass, new LinkedHashMap(sufficient initial capacity))).
* @see #map(java.util.Collection, Class, java.util.Map)
*/
LinkedHashMap mapToLinkedHashMap(Collection sourceCollection, Class targetClass);
/**
* Alias for map(sourceCollection, targetClass, new LinkedHashMap(sufficient initial capacity), mappingName).
* @see #map(java.util.Collection, Class, java.util.Map, String)
*/
LinkedHashMap mapToLinkedHashMap(
Collection sourceCollection, Class targetClass, String mappingName);
/**
* Alias for map(sourceCollection, targetClass, new LinkedHashMap(sufficient initial capacity), mappingContext).
* @see #map(java.util.Collection, Class, java.util.Map, MappingContext)
*/
LinkedHashMap mapToLinkedHashMap(
Collection sourceCollection, Class targetClass, MappingContext mappingContext);
/**
* Alias for map(sourceCollection, targetClass, new LinkedHashMap(sufficient initial capacity), mappingName, mappingContext).
* @see #map(java.util.Collection, Class, java.util.Map, String, MappingContext)
*/
LinkedHashMap mapToLinkedHashMap(
Collection sourceCollection, Class targetClass, String mappingName, MappingContext mappingContext);
/**
* Alias for map(sourceArray, targetClass, new LinkedHashMap(sufficient initial capacity)).
* @see #map(Object[], Class, java.util.Map)
*/
LinkedHashMap mapToLinkedHashMap(S[] sourceArray, Class targetClass);
/**
* Alias for map(sourceArray, targetClass, new LinkedHashMap(sufficient initial capacity), mappingName).
* @see #map(Object[], Class, java.util.Map, String)
*/
LinkedHashMap mapToLinkedHashMap(S[] sourceArray, Class targetClass, String mappingName);
/**
* Alias for map(sourceArray, targetClass, new LinkedHashMap(sufficient initial capacity), mappingContext).
* @see #map(Object[], Class, java.util.Map, MappingContext)
*/
LinkedHashMap mapToLinkedHashMap(S[] sourceArray, Class