1
16 package org.modelmapper.internal;
17
18 import java.util.Map;
19
20 import org.modelmapper.config.Configuration;
21 import org.modelmapper.spi.NameableType;
22
23
28 class TypeInfoImpl<T> implements TypeInfo<T> {
29
30 private final T source;
31 private final Class<T> type;
32 private final InheritingConfiguration configuration;
33 private volatile Map<String, Accessor> accessors;
34 private volatile Map<String, Mutator> mutators;
35
36 TypeInfoImpl(T source, Class<T> sourceType, InheritingConfiguration configuration) {
37 this.source = source;
38 this.type = sourceType;
39 this.configuration = configuration;
40 }
41
42 @Override
43 public boolean equals(Object obj) {
44 if (obj == this)
45 return true;
46 if (!(obj instanceof TypeInfo))
47 return false;
48 TypeInfo<?> typeInfo = (TypeInfo<?>) obj;
49 return type.equals(typeInfo.getType()) && configuration.equals(typeInfo.getConfiguration());
50 }
51
52
55 public Map<String, Accessor> getAccessors() {
56 if (accessors == null)
57 synchronized (this) {
58 if (accessors == null)
59 accessors = PropertyInfoSetResolver.resolveAccessors(source, type, configuration);
60 }
61
62 return accessors;
63 }
64
65 public Configuration getConfiguration() {
66 return configuration;
67 }
68
69
72 public Map<String, Mutator> getMutators() {
73 if (mutators == null)
74 synchronized (this) {
75 if (mutators == null)
76 mutators = PropertyInfoSetResolver.resolveMutators(type, configuration);
77 }
78
79 return mutators;
80 }
81
82 public Class<T> getType() {
83 return type;
84 }
85
86 @Override
87 public int hashCode() {
88 return type.hashCode() * 31 + configuration.hashCode();
89 }
90
91 @Override
92 public String toString() {
93 return type.toString();
94 }
95
96 Mutator mutatorForAccessorMethod(String accessorMethodName) {
97 return getMutators().get(
98 configuration.getSourceNameTransformer().transform(accessorMethodName, NameableType.METHOD));
99 }
100 }
101