Skip to content

Commit a7cc52e

Browse files
authored
Merge pull request #34 from hazendaz/master
[ci] Enforce 2 character spacing
2 parents 47d1553 + 6303995 commit a7cc52e

19 files changed

+1164
-1176
lines changed

format.xml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
4+
Copyright 2012-2017 the original author or authors.
5+
6+
Licensed under the Apache License, Version 2.0 (the "License");
7+
you may not use this file except in compliance with the License.
8+
You may obtain a copy of the License at
9+
10+
http://www.apache.org/licenses/LICENSE-2.0
11+
12+
Unless required by applicable law or agreed to in writing, software
13+
distributed under the License is distributed on an "AS IS" BASIS,
14+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
See the License for the specific language governing permissions and
16+
limitations under the License.
17+
18+
-->
19+
<!DOCTYPE Format>
20+
<Format>
21+
<!-- Dummy format file -->
22+
</Format>
Lines changed: 90 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2012-2015 the original author or authors.
2+
* Copyright 2012-2017 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -32,109 +32,99 @@
3232
*/
3333
abstract class AbstractPropertySetter<T> {
3434

35-
/**
36-
* 'propertyName'='writermethod' index of {@link MemcachedConfiguration}
37-
* properties.
38-
*/
39-
private static Map<String, Method> WRITERS = new HashMap<String, Method>();
40-
41-
static {
42-
try {
43-
BeanInfo memcachedConfigInfo = Introspector.getBeanInfo(MemcachedConfiguration.class);
44-
for (PropertyDescriptor descriptor : memcachedConfigInfo.getPropertyDescriptors()) {
45-
WRITERS.put(descriptor.getName(), descriptor.getWriteMethod());
46-
}
47-
} catch (IntrospectionException e) {
48-
// handle quietly
49-
}
35+
/**
36+
* 'propertyName'='writermethod' index of {@link MemcachedConfiguration}
37+
* properties.
38+
*/
39+
private static Map<String, Method> WRITERS = new HashMap<String, Method>();
40+
41+
static {
42+
try {
43+
BeanInfo memcachedConfigInfo = Introspector.getBeanInfo(MemcachedConfiguration.class);
44+
for (PropertyDescriptor descriptor : memcachedConfigInfo.getPropertyDescriptors()) {
45+
WRITERS.put(descriptor.getName(), descriptor.getWriteMethod());
46+
}
47+
} catch (IntrospectionException e) {
48+
// handle quietly
5049
}
51-
52-
/**
53-
* The Config property key.
54-
*/
55-
private final String propertyKey;
56-
57-
/**
58-
* The {@link MemcachedConfiguration} property name.
59-
*/
60-
private final String propertyName;
61-
62-
/**
63-
* The {@link MemcachedConfiguration} property method writer.
64-
*/
65-
private final Method propertyWriterMethod;
66-
67-
/**
68-
* The default value used if something goes wrong during the conversion or
69-
* the property is not set in the config.
70-
*/
71-
private final T defaultValue;
72-
73-
/**
74-
* Build a new property setter.
75-
*
76-
* @param propertyKey the Config property key.
77-
* @param propertyName the {@link MemcachedConfiguration} property name.
78-
* @param defaultValue the property default value.
79-
*/
80-
public AbstractPropertySetter(final String propertyKey, final String propertyName, final T defaultValue) {
81-
this.propertyKey = propertyKey;
82-
this.propertyName = propertyName;
83-
84-
this.propertyWriterMethod = WRITERS.get(propertyName);
85-
if (this.propertyWriterMethod == null) {
86-
throw new RuntimeException("Class '"
87-
+ MemcachedConfiguration.class.getName()
88-
+ "' doesn't contain a property '"
89-
+ propertyName
90-
+ "'");
91-
}
92-
93-
this.defaultValue = defaultValue;
50+
}
51+
52+
/**
53+
* The Config property key.
54+
*/
55+
private final String propertyKey;
56+
57+
/**
58+
* The {@link MemcachedConfiguration} property name.
59+
*/
60+
private final String propertyName;
61+
62+
/**
63+
* The {@link MemcachedConfiguration} property method writer.
64+
*/
65+
private final Method propertyWriterMethod;
66+
67+
/**
68+
* The default value used if something goes wrong during the conversion or
69+
* the property is not set in the config.
70+
*/
71+
private final T defaultValue;
72+
73+
/**
74+
* Build a new property setter.
75+
*
76+
* @param propertyKey the Config property key.
77+
* @param propertyName the {@link MemcachedConfiguration} property name.
78+
* @param defaultValue the property default value.
79+
*/
80+
public AbstractPropertySetter(final String propertyKey, final String propertyName, final T defaultValue) {
81+
this.propertyKey = propertyKey;
82+
this.propertyName = propertyName;
83+
84+
this.propertyWriterMethod = WRITERS.get(propertyName);
85+
if (this.propertyWriterMethod == null) {
86+
throw new RuntimeException(
87+
"Class '" + MemcachedConfiguration.class.getName() + "' doesn't contain a property '" + propertyName + "'");
9488
}
9589

96-
/**
97-
* Extract a property from the, converts and puts it to the
98-
* {@link MemcachedConfiguration}.
99-
*
100-
* @param config the Config
101-
* @param memcachedConfiguration the {@link MemcachedConfiguration}
102-
*/
103-
public final void set(Properties config, MemcachedConfiguration memcachedConfiguration) {
104-
String propertyValue = config.getProperty(propertyKey);
105-
T value;
106-
107-
try {
108-
value = this.convert(propertyValue);
109-
if (value == null) {
110-
value = defaultValue;
111-
}
112-
} catch (Exception e) {
113-
value = defaultValue;
114-
}
115-
116-
try {
117-
propertyWriterMethod.invoke(memcachedConfiguration, value);
118-
} catch (Exception e) {
119-
throw new RuntimeException("Impossible to set property '"
120-
+ propertyName
121-
+ "' with value '"
122-
+ value
123-
+ "', extracted from ('"
124-
+ propertyKey
125-
+ "'="
126-
+ propertyValue
127-
+ ")", e);
128-
}
90+
this.defaultValue = defaultValue;
91+
}
92+
93+
/**
94+
* Extract a property from the, converts and puts it to the
95+
* {@link MemcachedConfiguration}.
96+
*
97+
* @param config the Config
98+
* @param memcachedConfiguration the {@link MemcachedConfiguration}
99+
*/
100+
public final void set(Properties config, MemcachedConfiguration memcachedConfiguration) {
101+
String propertyValue = config.getProperty(propertyKey);
102+
T value;
103+
104+
try {
105+
value = this.convert(propertyValue);
106+
if (value == null) {
107+
value = defaultValue;
108+
}
109+
} catch (Exception e) {
110+
value = defaultValue;
129111
}
130112

131-
/**
132-
* Convert a string representation to a proper Java Object.
133-
*
134-
* @param value the value has to be converted.
135-
* @return the converted value.
136-
* @throws Exception if any error occurs.
137-
*/
138-
protected abstract T convert(String value) throws Exception;
113+
try {
114+
propertyWriterMethod.invoke(memcachedConfiguration, value);
115+
} catch (Exception e) {
116+
throw new RuntimeException("Impossible to set property '" + propertyName + "' with value '" + value
117+
+ "', extracted from ('" + propertyKey + "'=" + propertyValue + ")", e);
118+
}
119+
}
120+
121+
/**
122+
* Convert a string representation to a proper Java Object.
123+
*
124+
* @param value the value has to be converted.
125+
* @return the converted value.
126+
* @throws Exception if any error occurs.
127+
*/
128+
protected abstract T convert(String value) throws Exception;
139129

140130
}
Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2012-2015 the original author or authors.
2+
* Copyright 2012-2017 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -22,23 +22,23 @@
2222
*/
2323
final class BooleanPropertySetter extends AbstractPropertySetter<Boolean> {
2424

25-
/**
26-
* Instantiates a String to Boolean setter.
27-
*
28-
* @param propertyKey the OSCache Config property key.
29-
* @param propertyName the {@link MemcachedConfiguration} property name.
30-
* @param defaultValue the property default value.
31-
*/
32-
public BooleanPropertySetter(final String propertyKey, final String propertyName, final Boolean defaultValue) {
33-
super(propertyKey, propertyName, defaultValue);
34-
}
25+
/**
26+
* Instantiates a String to Boolean setter.
27+
*
28+
* @param propertyKey the OSCache Config property key.
29+
* @param propertyName the {@link MemcachedConfiguration} property name.
30+
* @param defaultValue the property default value.
31+
*/
32+
public BooleanPropertySetter(final String propertyKey, final String propertyName, final Boolean defaultValue) {
33+
super(propertyKey, propertyName, defaultValue);
34+
}
3535

36-
/**
37-
* {@inheritDoc}
38-
*/
39-
@Override
40-
protected Boolean convert(String property) throws Exception {
41-
return Boolean.valueOf(property);
42-
}
36+
/**
37+
* {@inheritDoc}
38+
*/
39+
@Override
40+
protected Boolean convert(String property) throws Exception {
41+
return Boolean.valueOf(property);
42+
}
4343

4444
}

0 commit comments

Comments
 (0)