View Javadoc

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   * Copyright 2011 Tim Wood
17   *
18   * Licensed under the Apache License, Version 2.0 (the "License");
19   * you may not use this file except in compliance with the License.
20   * You may obtain a copy of the License at
21   *
22   * http://www.apache.org/licenses/LICENSE-2.0
23   *
24   * Unless required by applicable law or agreed to in writing, software
25   * distributed under the License is distributed on an "AS IS" BASIS,
26   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
27   * See the License for the specific language governing permissions and
28   * limitations under the License. 
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  }