1
16 package org.modelmapper.convention;
17
18 import org.modelmapper.spi.PropertyType;
19 import org.modelmapper.spi.NamingConvention;
20
21
26 public class NamingConventions {
27
30 public static final NamingConvention JAVABEANS_ACCESSOR = new NamingConvention() {
31 public boolean applies(String propertyName, PropertyType propertyType) {
32 return PropertyType.FIELD.equals(propertyType)
33 || (propertyName.startsWith("get") && propertyName.length() > 3)
34 || (propertyName.startsWith("is") && propertyName.length() > 2);
35 }
36
37 @Override
38 public String toString() {
39 return "Javabeans Accessor";
40 }
41 };
42
43
46 public static final NamingConvention JAVABEANS_MUTATOR = new NamingConvention() {
47 public boolean applies(String propertyName, PropertyType propertyType) {
48 return PropertyType.FIELD.equals(propertyType)
49 || (propertyName.startsWith("set") && propertyName.length() > 3);
50 }
51
52 @Override
53 public String toString() {
54 return "Javabeans Mutator";
55 }
56 };
57
58
62 public static NamingConvention builder() {
63 return builder("");
64 }
65
66
72 public static NamingConvention builder(String prefix) {
73 return new BuilderNamingConventions(prefix);
74 }
75
76
79 private static class BuilderNamingConventions implements NamingConvention {
80 private String prefix;
81
82 private BuilderNamingConventions(String prefix) {
83 this.prefix = prefix;
84 }
85
86 public boolean applies(String propertyName, PropertyType propertyType) {
87 return PropertyType.METHOD.equals(propertyType) && propertyName.startsWith(prefix);
88 }
89
90 @Override
91 public String toString() {
92 return "Builder(prefix=" + prefix + ")";
93 }
94 }
95
96
101 public static final NamingConvention NONE = new NamingConvention() {
102 public boolean applies(String propertyName, PropertyType propertyType) {
103 return true;
104 }
105
106 @Override
107 public String toString() {
108 return "None";
109 }
110 };
111 }
112