1 package com.lexicalscope.fluentreflection.bean;
2
3 import static com.lexicalscope.fluentreflection.ReflectionMatchers.*;
4 import static com.lexicalscope.fluentreflection.bean.BeanMap.allProperties;
5
6 import java.util.Map;
7
8 import org.hamcrest.Matcher;
9
10 import com.lexicalscope.fluentreflection.FluentMember;
11 import com.lexicalscope.fluentreflection.FluentMethod;
12 import com.lexicalscope.fluentreflection.bean.BeanMap.KeySetCalculation;
13 import com.lexicalscope.fluentreflection.bean.BeanMap.PropertyNameConvertor;
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31 class BeanMapBuilderImpl implements BeanMapBuilder {
32 private PropertyNameConvertor propertyNameConvertor = new PropertyNameConvertor() {
33 @Override public String propertyName(final FluentMethod from) {
34 return from.property();
35 }
36 };
37 private Matcher<FluentMember> getterMatcher = isGetter();
38 private Matcher<FluentMember> setterMatcher = isSetter();
39 private KeySetCalculation keySetCalculation = allProperties();
40
41 @Override public Map<String, Object> build(final Object bean) {
42 return BeanMap.map(bean, propertyNameConvertor, getterMatcher, setterMatcher, keySetCalculation);
43 }
44
45 @Override public BeanMapBuilder keys(final KeySetCalculation keySetCalculation) {
46 this.keySetCalculation = keySetCalculation;
47 return this;
48 }
49
50 @Override public BeanMapBuilder getters(final Matcher<FluentMember> getterMatcher) {
51 this.getterMatcher = getterMatcher;
52 return this;
53 }
54
55 @Override public BeanMapBuilder setters(final Matcher<FluentMember> setterMatcher) {
56 this.setterMatcher = setterMatcher;
57 return this;
58 }
59
60 @Override public BeanMapBuilder propertyNames(final PropertyNameConvertor propertyNameConvertor) {
61 this.propertyNameConvertor = propertyNameConvertor;
62 return this;
63 }
64 }