| Conditions | 20 |
| Total Lines | 96 |
| Code Lines | 62 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
Complex classes like es.webbeta.Serializer.fillRawValue(JsonGenerator,ParentFieldData,Object,String[]) often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
| 1 | package es.webbeta; |
||
| 103 | private void fillRawValue(JsonGenerator gen, final ParentFieldData parentFieldData, final Object value, final String[] group) throws IOException { |
||
| 104 | typeChecker.check(value, new TypeCallback() { |
||
| 105 | |||
| 106 | @Override |
||
| 107 | public void itsByte(Byte value) throws IOException { |
||
| 108 | gen.writeNumber(value); |
||
| 109 | } |
||
| 110 | |||
| 111 | @Override |
||
| 112 | public void itsShort(Short value) throws IOException { |
||
| 113 | gen.writeNumber(value); |
||
| 114 | } |
||
| 115 | |||
| 116 | @Override |
||
| 117 | public void itsInteger(Integer value) throws IOException { |
||
| 118 | gen.writeNumber(value); |
||
| 119 | } |
||
| 120 | |||
| 121 | @Override |
||
| 122 | public void itsBigInteger(BigInteger value) throws IOException { |
||
| 123 | gen.writeNumber(value); |
||
| 124 | } |
||
| 125 | |||
| 126 | @Override |
||
| 127 | public void itsLong(Long value) throws IOException { |
||
| 128 | gen.writeNumber(value); |
||
| 129 | } |
||
| 130 | |||
| 131 | @Override |
||
| 132 | public void itsFloat(Float value) throws IOException { |
||
| 133 | gen.writeNumber(value); |
||
| 134 | } |
||
| 135 | |||
| 136 | @Override |
||
| 137 | public void itsDouble(Double value) throws IOException { |
||
| 138 | gen.writeNumber(value); |
||
| 139 | } |
||
| 140 | |||
| 141 | @Override |
||
| 142 | public void itsBigDecimal(BigDecimal value) throws IOException { |
||
| 143 | gen.writeNumber(value); |
||
| 144 | } |
||
| 145 | |||
| 146 | @Override |
||
| 147 | public void itsString(String value) throws IOException { |
||
| 148 | gen.writeString(value); |
||
| 149 | } |
||
| 150 | |||
| 151 | @Override |
||
| 152 | public void itsStringParseable(Object value) throws IOException { |
||
| 153 | gen.writeString(value.toString()); |
||
| 154 | } |
||
| 155 | |||
| 156 | @Override |
||
| 157 | public void itsBoolean(Boolean value) throws IOException { |
||
| 158 | gen.writeBoolean(value); |
||
| 159 | } |
||
| 160 | |||
| 161 | @Override |
||
| 162 | public void itsDate(Date value) throws IOException { |
||
| 163 | fillDateValue(gen, value); |
||
| 164 | } |
||
| 165 | |||
| 166 | @Override |
||
| 167 | public void itsSerializableObject(Object value) throws IOException { |
||
| 168 | if (parentFieldData != null && parentFieldData.getKlass() == value.getClass()) { |
||
| 169 | fillWith(false, gen, parentFieldData, value, parentFieldData.getGroups()); |
||
| 170 | } else |
||
| 171 | fillWith(false, gen, parentFieldData, value, group); |
||
| 172 | } |
||
| 173 | |||
| 174 | @Override |
||
| 175 | public void itsIterable(Iterable<?> value) throws IOException { |
||
| 176 | gen.writeStartArray(); |
||
| 177 | for (Object arrValue : value) { |
||
| 178 | String[] parentGroups = provider.getGroupsByFieldName(parentFieldData.getKlass(), parentFieldData.getFieldName()); |
||
| 179 | es.webbeta.serializer.ParentFieldData fieldData = |
||
| 180 | new es.webbeta.serializer.ParentFieldData(parentFieldData.getKlass(), parentFieldData.getFieldName(), parentGroups); |
||
| 181 | |||
| 182 | fillRawValue(gen, fieldData, arrValue, group); |
||
| 183 | } |
||
| 184 | gen.writeEndArray(); |
||
| 185 | } |
||
| 186 | |||
| 187 | @Override |
||
| 188 | public void itsMap(Map<?, ?> value) throws IOException { |
||
| 189 | gen.writeStartObject(); |
||
| 190 | for (Map.Entry<?, ?> entry : value.entrySet()) { |
||
| 191 | String[] parentGroups = provider.getGroupsByFieldName(parentFieldData.getKlass(), parentFieldData.getFieldName()); |
||
| 192 | es.webbeta.serializer.ParentFieldData fieldData = |
||
| 193 | new es.webbeta.serializer.ParentFieldData(parentFieldData.getKlass(), parentFieldData.getFieldName(), parentGroups); |
||
| 194 | |||
| 195 | gen.writeFieldName(entry.getKey().toString()); |
||
| 196 | fillRawValue(gen, fieldData, entry.getValue(), group); |
||
| 197 | } |
||
| 198 | gen.writeEndObject(); |
||
| 199 | } |
||
| 282 |