Conditions | 14 |
Total Lines | 75 |
Code Lines | 54 |
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.OwlInputStep.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 | OwlInputStepMeta meta = (OwlInputStepMeta) smi; |
||
45 | OwlInputStepData data = (OwlInputStepData) sdi; |
||
46 | |||
47 | Object[] row = getRow(); |
||
48 | |||
49 | if (first) { |
||
50 | first = false; |
||
51 | RowMetaInterface rowMeta = getInputRowMeta(row != null); |
||
52 | data.outputRowMeta = rowMeta.clone(); |
||
53 | meta.getFields(data.outputRowMeta, getStepname(), null, null, this); |
||
54 | } |
||
55 | |||
56 | DataTable<String> table = meta.getVocabTable(); |
||
57 | boolean isTableEmpty = table.getValue(0, OwlInputStepMeta.Field.VOCAB_TABLE_URI.name()).isEmpty(); |
||
58 | |||
59 | if (!isTableEmpty){ |
||
60 | for (int k = 0; k < table.size(); k++) { |
||
61 | putOutRow(row, meta, data, |
||
62 | table.getValue(k, OwlInputStepMeta.Field.VOCAB_TABLE_PREFIX.name()), |
||
63 | table.getValue(k, OwlInputStepMeta.Field.VOCAB_TABLE_URI.name()), |
||
64 | table.getValue(k, OwlInputStepMeta.Field.VOCAB_TABLE_PROPERTY.name()), |
||
65 | table.getValue(k, OwlInputStepMeta.Field.VOCAB_TABLE_TYPE.name())); |
||
66 | } |
||
67 | } else { |
||
68 | table = meta.getMapTable(); |
||
69 | for (int k = 0; k < table.size(); k++) { |
||
70 | String owlFile = getOwlFile(table.getValue(k, OwlInputStepMeta.Field.MAP_TABLE_ONTOLOGY_URI.name())); |
||
71 | try { |
||
72 | model = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM); |
||
73 | this.logBasic("Attempting to read " + owlFile + " as RDF/XML"); |
||
74 | model.read(owlFile); |
||
75 | this.logBasic(owlFile + " has been read successfully"); |
||
76 | } catch (Exception eox) { |
||
77 | this.logBasic("Error reading " + owlFile + " as RDF/XML: " + eox.getMessage()); |
||
78 | Collection<Lang> registeredLanguages = RDFLanguages.getRegisteredLanguages(); |
||
79 | for (Lang c : registeredLanguages) { |
||
80 | try { |
||
81 | this.logBasic("Trying to read the file as... " + c.getName()); |
||
82 | model.read(owlFile, c.getName()); |
||
83 | this.logBasic(owlFile + " has been read successfully"); |
||
84 | break; |
||
85 | } catch (Exception e) { |
||
86 | this.logBasic("File could not be read as " + c.getName() + ": " + e.getMessage()); |
||
87 | } |
||
88 | } |
||
89 | } |
||
90 | |||
91 | if (!model.isEmpty()) { |
||
92 | String ontoField = table.getValue(k, OwlInputStepMeta.Field.MAP_TABLE_ONTOLOGY_NAME.name()); |
||
93 | for (Iterator<OntClass> i = model.listClasses(); i.hasNext();) { |
||
94 | OntClass cls = i.next(); |
||
95 | if (cls.getLocalName() != null) { |
||
96 | putOutRow(row, meta, data, |
||
97 | ontoField.trim(), cls.getURI(), "rdf:type", "rdfs:class"); |
||
98 | } |
||
99 | } |
||
100 | |||
101 | for (Iterator<OntProperty> j = model.listAllOntProperties(); j.hasNext();) { |
||
102 | OntProperty proper = j.next(); |
||
103 | if (proper.getLocalName() != null) { |
||
104 | putOutRow(row, meta, data, |
||
105 | ontoField.trim(), proper.getURI(), "rdf:type", "rdfs:property"); |
||
106 | } |
||
107 | } |
||
108 | } |
||
109 | } |
||
110 | } |
||
111 | |||
112 | if (row == null){ |
||
113 | setOutputDone(); |
||
114 | return false; |
||
115 | } |
||
116 | |||
117 | return true; |
||
118 | } |
||
177 |