Skip to content

Commit dfbeb84

Browse files
committed
metafacture-triples/ (main): Fix Checkstyle violations.
1 parent d1d49e8 commit dfbeb84

21 files changed

+229
-168
lines changed

metafacture-triples/src/main/java/org/metafacture/triples/AbstractTripleSort.java

Lines changed: 56 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,14 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16+
1617
package org.metafacture.triples;
1718

19+
import org.metafacture.framework.MetafactureException;
20+
import org.metafacture.framework.ObjectReceiver;
21+
import org.metafacture.framework.helpers.DefaultObjectPipe;
22+
import org.metafacture.framework.objects.Triple;
23+
1824
import java.io.File;
1925
import java.io.FileOutputStream;
2026
import java.io.IOException;
@@ -25,11 +31,6 @@
2531
import java.util.List;
2632
import java.util.PriorityQueue;
2733

28-
import org.metafacture.framework.MetafactureException;
29-
import org.metafacture.framework.ObjectReceiver;
30-
import org.metafacture.framework.helpers.DefaultObjectPipe;
31-
import org.metafacture.framework.objects.Triple;
32-
3334
/**
3435
* @author markus geipel
3536
*
@@ -39,7 +40,7 @@ public abstract class AbstractTripleSort extends DefaultObjectPipe<Triple, Objec
3940
* specifies the comparator
4041
*/
4142
public enum Compare {
42-
SUBJECT, PREDICATE, OBJECT, ALL;
43+
SUBJECT, PREDICATE, OBJECT, ALL
4344
}
4445

4546
/**
@@ -88,8 +89,8 @@ protected final Compare getCompare() {
8889
return compare;
8990
}
9091

91-
protected final void setSortOrder(final Order order) {
92-
this.order = order;
92+
protected final void setSortOrder(final Order newOrder) {
93+
order = newOrder;
9394
}
9495

9596
@Override
@@ -99,9 +100,11 @@ public final void process(final Triple namedValue) {
99100
if (!buffer.isEmpty()) {
100101
nextBatch();
101102
}
102-
} catch (final IOException e) {
103+
}
104+
catch (final IOException e) {
103105
throw new MetafactureException("Error writing to temp file after sorting", e);
104-
} finally {
106+
}
107+
finally {
105108
memoryLow = false;
106109
}
107110
}
@@ -118,7 +121,8 @@ private void nextBatch() throws IOException {
118121
for (final Triple triple : buffer) {
119122
triple.write(out);
120123
}
121-
} finally {
124+
}
125+
finally {
122126
out.close();
123127
}
124128
buffer.clear();
@@ -134,7 +138,8 @@ public final void onCloseStream() {
134138
sortedTriple(triple);
135139
}
136140
onFinished();
137-
} else {
141+
}
142+
else {
138143
final Comparator<Triple> comparator = createComparator(compare, order);
139144
final PriorityQueue<SortedTripleFileFacade> queue = new PriorityQueue<SortedTripleFileFacade>(11,
140145
new Comparator<SortedTripleFileFacade>() {
@@ -158,14 +163,17 @@ public int compare(final SortedTripleFileFacade o1, final SortedTripleFileFacade
158163
sortedTriple(triple);
159164
if (sortedFileFacade.isEmpty()) {
160165
sortedFileFacade.close();
161-
} else {
166+
}
167+
else {
162168
queue.add(sortedFileFacade);
163169
}
164170
}
165171
onFinished();
166-
} catch (final IOException e) {
172+
}
173+
catch (final IOException e) {
167174
throw new MetafactureException("Error merging temp files", e);
168-
} finally {
175+
}
176+
finally {
169177
for (final SortedTripleFileFacade sortedFileFacade : queue) {
170178
sortedFileFacade.close();
171179
}
@@ -176,7 +184,6 @@ public int compare(final SortedTripleFileFacade o1, final SortedTripleFileFacade
176184

177185
protected void onFinished() {
178186
// nothing to do
179-
180187
}
181188

182189
protected abstract void sortedTriple(Triple namedValue);
@@ -188,39 +195,39 @@ public final Comparator<Triple> createComparator() {
188195
public static Comparator<Triple> createComparator(final Compare compareBy, final Order order) {
189196
final Comparator<Triple> comparator;
190197
switch (compareBy) {
191-
case ALL:
192-
comparator = new Comparator<Triple>() {
193-
@Override
194-
public int compare(final Triple o1, final Triple o2) {
195-
return order.order(o1.compareTo(o2));
196-
}
197-
};
198-
break;
199-
case OBJECT:
200-
comparator = new Comparator<Triple>() {
201-
@Override
202-
public int compare(final Triple o1, final Triple o2) {
203-
return order.order(o1.getObject().compareTo(o2.getObject()));
204-
}
205-
};
206-
break;
207-
case SUBJECT:
208-
comparator = new Comparator<Triple>() {
209-
@Override
210-
public int compare(final Triple o1, final Triple o2) {
211-
return order.order(o1.getSubject().compareTo(o2.getSubject()));
212-
}
213-
};
214-
break;
215-
case PREDICATE:
216-
default:
217-
comparator = new Comparator<Triple>() {
218-
@Override
219-
public int compare(final Triple o1, final Triple o2) {
220-
return order.order(o1.getPredicate().compareTo(o2.getPredicate()));
221-
}
222-
};
223-
break;
198+
case ALL:
199+
comparator = new Comparator<Triple>() {
200+
@Override
201+
public int compare(final Triple o1, final Triple o2) {
202+
return order.order(o1.compareTo(o2));
203+
}
204+
};
205+
break;
206+
case OBJECT:
207+
comparator = new Comparator<Triple>() {
208+
@Override
209+
public int compare(final Triple o1, final Triple o2) {
210+
return order.order(o1.getObject().compareTo(o2.getObject()));
211+
}
212+
};
213+
break;
214+
case SUBJECT:
215+
comparator = new Comparator<Triple>() {
216+
@Override
217+
public int compare(final Triple o1, final Triple o2) {
218+
return order.order(o1.getSubject().compareTo(o2.getSubject()));
219+
}
220+
};
221+
break;
222+
case PREDICATE:
223+
default:
224+
comparator = new Comparator<Triple>() {
225+
@Override
226+
public int compare(final Triple o1, final Triple o2) {
227+
return order.order(o1.getPredicate().compareTo(o2.getPredicate()));
228+
}
229+
};
230+
break;
224231
}
225232

226233
return comparator;

metafacture-triples/src/main/java/org/metafacture/triples/MemoryWarningSystem.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
/*
1717
* Code based on http://www.javaspecialists.eu/archive/Issue092.html
1818
*/
19+
1920
package org.metafacture.triples;
2021

2122
import java.lang.management.ManagementFactory;
@@ -25,7 +26,6 @@
2526
import java.lang.management.MemoryType;
2627
import java.util.Collection;
2728
import java.util.concurrent.CopyOnWriteArrayList;
28-
2929
import javax.management.Notification;
3030
import javax.management.NotificationEmitter;
3131
import javax.management.NotificationListener;
@@ -61,7 +61,7 @@ public void handleNotification(final Notification notification, final Object han
6161
}, null, null);
6262
}
6363

64-
private static Collection<Listener> getListeners(){
64+
private static Collection<Listener> getListeners() {
6565
return LISTENERS;
6666
}
6767

@@ -97,10 +97,11 @@ private static void setUsageThreshold(final double threshold) {
9797
private static MemoryPoolMXBean findTenuredGenPool() {
9898
// I don't know whether this approach is better, or whether
9999
// we should rather check for the pool name "Tenured Gen"?
100-
for (final MemoryPoolMXBean pool : ManagementFactory.getMemoryPoolMXBeans())
100+
for (final MemoryPoolMXBean pool : ManagementFactory.getMemoryPoolMXBeans()) {
101101
if (pool.getType() == MemoryType.HEAP && pool.isUsageThresholdSupported()) {
102102
return pool;
103103
}
104+
}
104105
throw new AssertionError("Could not find tenured space");
105106
}
106107

metafacture-triples/src/main/java/org/metafacture/triples/SortedTripleFileFacade.java

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,19 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16+
1617
package org.metafacture.triples;
1718

19+
import org.metafacture.framework.MetafactureException;
20+
import org.metafacture.framework.objects.Triple;
21+
1822
import java.io.BufferedInputStream;
1923
import java.io.EOFException;
2024
import java.io.File;
2125
import java.io.FileInputStream;
2226
import java.io.IOException;
2327
import java.io.ObjectInputStream;
2428

25-
import org.metafacture.framework.MetafactureException;
26-
import org.metafacture.framework.objects.Triple;
27-
28-
2929
/**
3030
* @author markus geipel
3131
*
@@ -51,18 +51,18 @@ private void next() throws IOException {
5151
try {
5252
triple = Triple.read(in);
5353
empty = false;
54-
55-
} catch (EOFException e) {
54+
}
55+
catch (final EOFException e) {
5656
empty = true;
5757
triple = null;
5858
}
5959
}
6060

6161
public void close() {
62-
6362
try {
6463
in.close();
65-
} catch (IOException e) {
64+
}
65+
catch (final IOException e) {
6666
throw new MetafactureException("Error closing input stream", e);
6767
}
6868
if (file.exists()) {
@@ -78,10 +78,9 @@ public Triple peek() {
7878
}
7979

8080
public Triple pop() throws IOException {
81-
final Triple triple = peek();
81+
final Triple nextTriple = peek();
8282
next();
83-
return triple;
83+
return nextTriple;
8484
}
8585

86-
8786
}

metafacture-triples/src/main/java/org/metafacture/triples/StreamToTriples.java

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,8 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
package org.metafacture.triples;
1716

18-
import java.util.ArrayList;
19-
import java.util.List;
20-
import java.util.regex.Matcher;
21-
import java.util.regex.Pattern;
17+
package org.metafacture.triples;
2218

2319
import org.metafacture.formeta.formatter.ConciseFormatter;
2420
import org.metafacture.formeta.formatter.Formatter;
@@ -30,8 +26,13 @@
3026
import org.metafacture.framework.annotations.In;
3127
import org.metafacture.framework.annotations.Out;
3228
import org.metafacture.framework.helpers.DefaultStreamPipe;
33-
import org.metafacture.framework.objects.Triple;
3429
import org.metafacture.framework.objects.Triple.ObjectType;
30+
import org.metafacture.framework.objects.Triple;
31+
32+
import java.util.ArrayList;
33+
import java.util.List;
34+
import java.util.regex.Matcher;
35+
import java.util.regex.Pattern;
3536

3637
/**
3738
* Emits the literals which are received as triples such
@@ -82,6 +83,9 @@ public final class StreamToTriples extends DefaultStreamPipe<ObjectReceiver<Trip
8283
private String predicateName;
8384
private String currentId;
8485

86+
public StreamToTriples() {
87+
}
88+
8589
public boolean isRedirect() {
8690
return redirect;
8791
}
@@ -107,7 +111,8 @@ public void startRecord(final String identifier) {
107111
if (recordPredicate != null) {
108112
encodeLevel = 0;
109113
startEncode(recordPredicate);
110-
} else {
114+
}
115+
else {
111116
encodeLevel = 1;
112117
}
113118

@@ -140,7 +145,8 @@ public void startEntity(final String name) {
140145

141146
if (nestingLevel > encodeLevel) {
142147
formatter.startGroup(name);
143-
} else {
148+
}
149+
else {
144150
startEncode(name);
145151
}
146152
++nestingLevel;
@@ -153,7 +159,8 @@ public void endEntity() {
153159
--nestingLevel;
154160
if (nestingLevel == encodeLevel) {
155161
endEncode();
156-
} else {
162+
}
163+
else {
157164
formatter.endGroup();
158165
}
159166
}
@@ -165,10 +172,12 @@ public void literal(final String name, final String value) {
165172
if (nestingLevel > encodeLevel) {
166173
if (nestingLevel == 1 && redirect && StandardEventNames.ID.equals(name)) {
167174
currentId = value;
168-
} else {
175+
}
176+
else {
169177
formatter.literal(name, value);
170178
}
171-
} else {
179+
}
180+
else {
172181
dispatch(name, value, ObjectType.STRING);
173182
}
174183
}
@@ -188,17 +197,20 @@ private void dispatch(final String name, final String value, final ObjectType ty
188197
if (redirect) {
189198
if (StandardEventNames.ID.equals(name)) {
190199
currentId = value;
191-
} else {
200+
}
201+
else {
192202
final Matcher matcher = REDIRECT_PATTERN.matcher(name);
193203
if (matcher.find()) {
194204
getReceiver().process(new Triple(matcher.group(1), matcher.group(2), value, type));
195-
} else {
205+
}
206+
else {
196207
nameBuffer.add(name);
197208
valueBuffer.add(value);
198209
typeBuffer.add(type);
199210
}
200211
}
201-
} else {
212+
}
213+
else {
202214
getReceiver().process(new Triple(currentId, name, value, type));
203215
}
204216
}

0 commit comments

Comments
 (0)