Conditions | 13 |
Total Lines | 61 |
Code Lines | 36 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 1 |
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 br.ufrj.ppgi.greco.kettle.GraphTriplifyStep.tripleWriter(Object,Object[],GraphTriplifyStepData) 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 br.ufrj.ppgi.greco.kettle; |
||
95 | private int tripleWriter(Object model, Object[] row, GraphTriplifyStepData data) throws KettleStepException { |
||
96 | int numPutRows = 0; |
||
97 | |||
98 | // StmtIterator it = model.listStatements(); |
||
99 | // Testando usar reflexion |
||
100 | Object it = null; |
||
101 | try { |
||
102 | it = model.getClass().getMethod("listStatements").invoke(model); |
||
103 | if (it == null) |
||
104 | return 0; |
||
105 | |||
106 | // while (it.hasNext()) |
||
107 | while ((Boolean) it.getClass().getMethod("hasNext").invoke(it)) { |
||
108 | // Statement stmt = it.next(); |
||
109 | Object stmt = it.getClass().getMethod("next").invoke(it); |
||
110 | |||
111 | incrementLinesInput(); |
||
112 | |||
113 | // String subject = stmt.getSubject().toString(); |
||
114 | String subject = stmt.getClass().getMethod("getSubject").invoke(stmt).toString(); |
||
115 | // String predicate = stmt.getPredicate().toString(); |
||
116 | String predicate = stmt.getClass().getMethod("getPredicate").invoke(stmt).toString(); |
||
117 | // String object = stmt.getObject().toString(); |
||
118 | String object = stmt.getClass().getMethod("getObject").invoke(stmt).toString(); |
||
119 | |||
120 | if (subject != null && !subject.isEmpty() && predicate != null && !predicate.isEmpty() |
||
121 | && object != null) { |
||
122 | // Monta linha com a tripla |
||
123 | Object[] outputRow = row; |
||
124 | int i = 0; |
||
125 | outputRow = RowDataUtil.addValueData(outputRow, i++, subject); |
||
126 | outputRow = RowDataUtil.addValueData(outputRow, i++, predicate); |
||
127 | outputRow = RowDataUtil.addValueData(outputRow, i++, object); |
||
128 | |||
129 | // Joga tripla no fluxo |
||
130 | putRow(data.outputRowMeta, outputRow); |
||
131 | |||
132 | numPutRows++; |
||
133 | } else { |
||
134 | String triplaIgnorada = stmt.getClass().getMethod("getString").invoke(stmt).toString(); |
||
135 | logBasic("Tripla ignorada: " + triplaIgnorada); |
||
136 | } |
||
137 | } |
||
138 | } catch (IllegalAccessException e) { |
||
139 | // TODO Auto-generated catch block |
||
140 | e.printStackTrace(); |
||
141 | } catch (IllegalArgumentException e) { |
||
142 | // TODO Auto-generated catch block |
||
143 | e.printStackTrace(); |
||
144 | } catch (InvocationTargetException e) { |
||
145 | // TODO Auto-generated catch block |
||
146 | e.printStackTrace(); |
||
147 | } catch (NoSuchMethodException e) { |
||
148 | // TODO Auto-generated catch block |
||
149 | e.printStackTrace(); |
||
150 | } catch (SecurityException e) { |
||
151 | // TODO Auto-generated catch block |
||
152 | e.printStackTrace(); |
||
153 | } |
||
154 | |||
155 | return numPutRows; |
||
156 | } |
||
158 |