com.mangocar.util.BeanMapper.java Source code

Java tutorial

Introduction

Here is the source code for com.mangocar.util.BeanMapper.java

Source

/**
 * Copyright (c) 2005-2012 springside.org.cn
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 */
package com.mangocar.util;

import java.util.Collection;
import java.util.List;

import org.dozer.DozerBeanMapper;

import com.google.common.collect.Lists;

/**
 * ??Dozer, ?Bean<->BeanMapper.:
 * 
 * 1. ?Mapper?.
 * 2. ?.
 * 3. ??Collection.
 * 4. BA?B?.
 * 
 * @author calvin
 */
public class BeanMapper {

    /**
     * ?Dozer?, ????DozerMapper?.
     */
    private static DozerBeanMapper dozer = new DozerBeanMapper();

    /**
     * Dozer?.
     */
    public static <T> T map(Object source, Class<T> destinationClass) {
        return dozer.map(source, destinationClass);
    }

    /**
     * Dozer?Collection.
     */
    public static <T> List<T> mapList(Collection<?> sourceList, Class<T> destinationClass) {
        List<T> destinationList = Lists.newArrayList();
        for (Object sourceObject : sourceList) {
            T destinationObject = dozer.map(sourceObject, destinationClass);
            destinationList.add(destinationObject);
        }
        return destinationList;
    }

    /**
     * DozerA?B.
     */
    public static void copy(Object source, Object destinationObject) {
        dozer.map(source, destinationObject);
    }
}