Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Copyright (C) 2016 Talsma ICT
*
* 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 nl.talsmasoftware.reflection.dto;
import nl.talsmasoftware.reflection.strings.ToStringBuilder;
import java.io.Serializable;
import java.lang.reflect.InvocationTargetException;
import java.math.BigDecimal;
import java.util.IdentityHashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import static java.util.Arrays.asList;
import static nl.talsmasoftware.reflection.beans.BeanReflectionSupport.getPropertyValues;
import static nl.talsmasoftware.reflection.beans.BeanReflectionSupport.setPropertyValue;
/**
* Abstract base class for DTO (data transfer objects) where {@link Object objects} are purely used for data
* representation, without any relevant object functionality. Traditionally, people often use the JavaBeans convention
* for such objects, meaning for every attribute, there will be a private field defined plus a getter and/or a setter
* method. This is rather cumbersome to program for a class where you're only interested in the data and (considering
* there are getters and setters) mutability is not a real issue. There are libraries such a Lombok to help you with
* this by generating this code for you.
*
* However, what is inherently wrong with plain public fields in this case? What do the getters and setters actually buy
* you in 'percieved' encapsulation?
*
* However, wouldn't it be nice to be able to use simply public fields and no methods whatsoever, but still be able to
* use the objects in {@link Object#hashCode() hash-based} collections, call {@link Object#equals(Object) equals()}
* and {@link Object#toString() toString()} methods or even {@link Object#clone() clone} the object?
*
* Well, now you can. Just extend this AbstractDTO object, add public fields and you're ready with your data transfer
* object.
*
* This abstract base class explicitly does support the use of public fields. What if you need to
* 'override' a field with a getter / setter method? No problem! This abstract superclass will detect property accessor
* methods and use those when applicable over the public fields.
*
* @author Sjoerd Talsma
*/
public abstract class AbstractDto implements Serializable, Cloneable {
// Recursion detection in circular data structures contained in property values:
private enum RecursionDetectors {
HASHCODE, EQUALS, CLONE;
private final ThreadLocal