Conditions | 18 |
Total Lines | 52 |
Code Lines | 39 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 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 de.tudresden.inf.lat.jcel.ontology.normalization.NormalizerSubClassOf.simplify(IntegerSubClassOfAxiom) 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 | /* |
||
109 | private Collection<NormalizedIntegerAxiom> simplify(IntegerSubClassOfAxiom axiom) { |
||
110 | Collection<NormalizedIntegerAxiom> ret = new ArrayList<>(); |
||
111 | IntegerClassExpression subClass = axiom.getSubClass(); |
||
112 | IntegerClassExpression superClass = axiom.getSuperClass(); |
||
113 | |||
114 | if (subClass.isLiteral() && superClass.isLiteral()) { |
||
115 | ret.add(getNormalizedAxiomFactory().createGCI0Axiom(((IntegerClass) subClass).getId(), |
||
116 | ((IntegerClass) superClass).getId(), axiom.getAnnotations())); |
||
117 | |||
118 | } else if (!subClass.isLiteral() && superClass.isLiteral() && (subClass instanceof IntegerObjectIntersectionOf) |
||
119 | && subClass.hasOnlyClasses()) { |
||
120 | |||
121 | IntegerObjectIntersectionOf intersection = (IntegerObjectIntersectionOf) subClass; |
||
122 | Set<IntegerClassExpression> operands = intersection.getOperands(); |
||
123 | if (operands.size() == 0) { |
||
124 | ret.add(getNormalizedAxiomFactory().createGCI0Axiom(IntegerEntityManager.topClassId, |
||
125 | ((IntegerClass) superClass).getId(), axiom.getAnnotations())); |
||
126 | |||
127 | } else if (operands.size() == 1) { |
||
128 | ret.add(getNormalizedAxiomFactory().createGCI0Axiom(((IntegerClass) operands.iterator().next()).getId(), |
||
129 | ((IntegerClass) superClass).getId(), axiom.getAnnotations())); |
||
130 | |||
131 | } else if (operands.size() == 2) { |
||
132 | Iterator<IntegerClassExpression> it = operands.iterator(); |
||
133 | int leftSubClassId = ((IntegerClass) it.next()).getId(); |
||
134 | int rightSubClassId = ((IntegerClass) it.next()).getId(); |
||
135 | int superClassId = ((IntegerClass) superClass).getId(); |
||
136 | ret.add(getNormalizedAxiomFactory().createGCI1Axiom(leftSubClassId, rightSubClassId, superClassId, |
||
137 | axiom.getAnnotations())); |
||
138 | |||
139 | } |
||
140 | |||
141 | } else if (subClass.isLiteral() && !superClass.isLiteral() |
||
142 | && (superClass instanceof IntegerObjectSomeValuesFrom) && superClass.hasOnlyClasses()) { |
||
143 | |||
144 | IntegerObjectSomeValuesFrom restriction = (IntegerObjectSomeValuesFrom) superClass; |
||
145 | IntegerClass filler = (IntegerClass) restriction.getFiller(); |
||
146 | Integer property = getObjectPropertyId(restriction.getProperty()); |
||
147 | ret.add(getNormalizedAxiomFactory().createGCI2Axiom(((IntegerClass) subClass).getId(), property, |
||
148 | filler.getId(), axiom.getAnnotations())); |
||
149 | |||
150 | } else if (!subClass.isLiteral() && superClass.isLiteral() && (subClass instanceof IntegerObjectSomeValuesFrom) |
||
151 | && subClass.hasOnlyClasses()) { |
||
152 | |||
153 | IntegerObjectSomeValuesFrom restriction = (IntegerObjectSomeValuesFrom) subClass; |
||
154 | IntegerClass filler = (IntegerClass) restriction.getFiller(); |
||
155 | Integer property = getObjectPropertyId(restriction.getProperty()); |
||
156 | ret.add(getNormalizedAxiomFactory().createGCI3Axiom(property, filler.getId(), |
||
157 | ((IntegerClass) superClass).getId(), axiom.getAnnotations())); |
||
158 | |||
159 | } |
||
160 | return ret; |
||
161 | } |
||
164 |