Conditions | 14 |
Total Lines | 105 |
Code Lines | 75 |
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.TurtleGeneratorStep.processRow(StepMetaInterface,StepDataInterface) 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; |
||
43 | public boolean processRow(StepMetaInterface smi, StepDataInterface sdi) throws KettleException { |
||
44 | |||
45 | TurtleGeneratorStepMeta meta = (TurtleGeneratorStepMeta) smi; |
||
46 | TurtleGeneratorStepData data = (TurtleGeneratorStepData) sdi; |
||
47 | |||
48 | // Obtem linha do fluxo de entrada e termina caso nao haja mais entrada |
||
49 | Object[] row = getRow(); |
||
50 | if (row == null) { |
||
51 | setOutputDone(); |
||
52 | return false; |
||
53 | } |
||
54 | |||
55 | if (first) { |
||
56 | first = false; |
||
57 | |||
58 | RowMetaInterface rowMeta = getInputRowMeta(); |
||
59 | data.outputRowMeta = rowMeta.clone(); |
||
60 | |||
61 | // Adiciona os metadados do step atual |
||
62 | meta.getFields(data.outputRowMeta, getStepname(), null, null, this); |
||
63 | |||
64 | // Prefixos |
||
65 | String prefix = meta.getPrefixes().toString(); |
||
66 | prefix = prefix.replace("[", ""); |
||
67 | prefix = prefix.replace(", ", " <"); |
||
68 | prefix = prefix.replace("]", ">. "); |
||
69 | prefix = prefix.replace("<@", "@"); |
||
70 | prefix = prefix.replace(">. >.", ">."); |
||
71 | prefix = prefix.replace(" <>. ", ""); |
||
72 | prefix = prefix.replace(". ", "." + System.getProperty("line.separator")); |
||
73 | |||
74 | putOutRow(row, meta, data, prefix); |
||
75 | putOutRow(row, meta, data, ""); |
||
76 | putOutRow(row, meta, data, "#"); |
||
77 | putOutRow(row, meta, data, "# PROPERTIES DEFINITION"); |
||
78 | putOutRow(row, meta, data, "#"); |
||
79 | putOutRow(row, meta, data, ""); |
||
80 | |||
81 | DataTable<String> table = meta.getMapTable(); |
||
82 | for (int i = 0; i < table.size(); i++) { |
||
83 | String dimensionField = table.getValue(i, |
||
84 | TurtleGeneratorStepMeta.Field.MAP_TABLE_DIMENSIONS_FIELD_NAME.name()); |
||
85 | String labelDimensao = table.getValue(i, TurtleGeneratorStepMeta.Field.MAP_TABLE_LABELS_FIELD_NAME.name()); |
||
86 | String dimensionURIType = table.getValue(i, |
||
87 | TurtleGeneratorStepMeta.Field.MAP_TABLE_URI_TYPE_FIELD_NAME.name()); |
||
88 | if (dimensionField != null) { |
||
89 | putOutRow(row, meta, data, "exProp:" + removeSignals(dimensionField).toLowerCase() + " owl:sameAs <" + dimensionURIType + ">;"); |
||
90 | putOutRow(row, meta, data, " rdfs:label \"" + labelDimensao + "\"@en ."); |
||
91 | putOutRow(row, meta, data, ""); |
||
92 | } |
||
93 | } |
||
94 | |||
95 | if (TurtleGeneratorStepMeta.Field.MAP_TABLE_HIERARCHY_FIELD_NAME.name() != null) { |
||
96 | |||
97 | putOutRow(row, meta, data, "#"); |
||
98 | putOutRow(row, meta, data, "# HIERARCHIES"); |
||
99 | putOutRow(row, meta, data, "#"); |
||
100 | putOutRow(row, meta, data, ""); |
||
101 | |||
102 | table = meta.getMapTable2(); |
||
103 | for (int i = 0; i < table.size(); i++) { |
||
104 | String hierarquia = table.getValue(i, TurtleGeneratorStepMeta.Field.MAP_TABLE_HIERARCHY_FIELD_NAME.name()); |
||
105 | String hierarquiaDe = table.getValue(i, |
||
106 | TurtleGeneratorStepMeta.Field.MAP_TABLE_HIERARCHY_DE_FIELD_NAME.name()); |
||
107 | String hierarquiaLabel = table.getValue(i, |
||
108 | TurtleGeneratorStepMeta.Field.MAP_TABLE_HIERARCHY_LABEL_FIELD_NAME.name()); |
||
109 | String hierarquiaPara = table.getValue(i, |
||
110 | TurtleGeneratorStepMeta.Field.MAP_TABLE_HIERARCHY_PARA_FIELD_NAME.name()); |
||
111 | if (hierarquia != null && hierarquiaDe != null && hierarquiaPara != null) { |
||
112 | putOutRow(row, meta, data, "ex:" + removeSignals(hierarquiaDe).toLowerCase() + " a ex:" |
||
113 | + removeSignals(hierarquia).toLowerCase() + " ;"); |
||
114 | putOutRow(row, meta, data, " obo:part_of ex:" + removeSignals(hierarquiaPara) + ";"); |
||
115 | putOutRow(row, meta, data, " rdfs:label \"" + hierarquiaLabel + "\"@en ."); |
||
116 | putOutRow(row, meta, data, ""); |
||
117 | } |
||
118 | } |
||
119 | } |
||
120 | } |
||
121 | |||
122 | DataTable<String> table = meta.getMapTable(); |
||
123 | String line = ""; |
||
124 | |||
125 | for (int i = 0; i < table.size(); i++) { |
||
126 | String dimensionField = table.getValue(i, TurtleGeneratorStepMeta.Field.MAP_TABLE_DIMENSIONS_FIELD_NAME.name()); |
||
127 | String dimension = getInputRowMeta().getString(row, dimensionField, ""); |
||
128 | if (!dimension.startsWith("http")) { |
||
129 | if (i == 0) { |
||
130 | line = " exProp:" + removeSignals(dimensionField).toLowerCase() + " " + "\"" + dimension + "\";"; |
||
131 | } else |
||
132 | line = " exProp:" + removeSignals(dimensionField).toLowerCase() + " " + "\"" + dimension + "\";"; |
||
133 | } else { |
||
134 | line = " exProp:" + removeSignals(dimensionField).toLowerCase() + " " + "<" + dimension + ">;"; |
||
135 | } |
||
136 | if (i == 0) { |
||
137 | line = "ex:obj" + j + line; |
||
138 | } |
||
139 | putOutRow(row, meta, data, line); |
||
140 | } |
||
141 | |||
142 | putOutRow(row, meta, data, " rdfs:label \"" + meta.getunity() + "\" ."); |
||
143 | putOutRow(row, meta, data, ""); |
||
144 | |||
145 | j++; |
||
146 | |||
147 | return true; |
||
148 | } |
||
174 |