Skip to content

Commit 197c7c7

Browse files
author
mgeipel
committed
fixed #41
1 parent c882b70 commit 197c7c7

File tree

2 files changed

+60
-24
lines changed

2 files changed

+60
-24
lines changed

src/main/java/org/culturegraph/mf/morph/Metamorph.java

Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,8 @@
1919
import java.io.IOException;
2020
import java.io.InputStream;
2121
import java.io.Reader;
22-
import java.util.ArrayList;
2322
import java.util.Collection;
2423
import java.util.Deque;
25-
import java.util.LinkedList;
2624
import java.util.List;
2725
import java.util.Map;
2826

@@ -33,7 +31,6 @@
3331
import org.culturegraph.mf.framework.annotations.In;
3432
import org.culturegraph.mf.framework.annotations.Out;
3533
import org.culturegraph.mf.stream.pipe.StreamFlattener;
36-
import org.culturegraph.mf.types.MultiHashMap;
3734
import org.culturegraph.mf.types.MultiMap;
3835
import org.culturegraph.mf.util.StreamConstants;
3936

@@ -58,24 +55,24 @@ public final class Metamorph implements StreamPipe<StreamReceiver>, NamedValueRe
5855

5956
private static final String ENTITIES_NOT_BALANCED = "Entity starts and ends are not balanced";
6057

61-
private final Registry<NamedValueReceiver> dataRegistry = new WildcardRegistry<NamedValueReceiver>();
62-
private final List<NamedValueReceiver> elseSources = new ArrayList<NamedValueReceiver>();
58+
private final Registry<NamedValueReceiver> dataRegistry = MorphCollectionFactory.createRegistry();
59+
private final List<NamedValueReceiver> elseSources = MorphCollectionFactory.createList();
6360

6461
//rivate final Registry<FlushListener> entityEndListenerRegistry = new WildcardRegistry<FlushListener>();
6562

66-
private final MultiMap multiMap = new MultiHashMap();
67-
private final List<Closeable> resources = new ArrayList<Closeable>();
63+
private final MultiMap multiMap = MorphCollectionFactory.createMultiMap();
64+
private final List<Closeable> resources = MorphCollectionFactory.createList();
6865

6966
private final StreamFlattener flattener = new StreamFlattener();
7067

71-
private final Deque<Integer> entityCountStack = new LinkedList<Integer>();
68+
private final Deque<Integer> entityCountStack = MorphCollectionFactory.createDeque();
7269
private int entityCount;
7370
private int currentEntityCount;
7471

7572
private StreamReceiver outputStreamReceiver;
7673
private MorphErrorHandler errorHandler = new DefaultErrorHandler();
7774
private int recordCount;
78-
private final List<FlushListener> recordEndListener = new ArrayList<FlushListener>();
75+
private final List<FlushListener> recordEndListener = MorphCollectionFactory.createList();
7976

8077
protected Metamorph() {
8178
// package private
@@ -301,21 +298,6 @@ public void receive(final String name, final String value, final NamedValueSourc
301298

302299
}
303300

304-
// /**
305-
// * @param from
306-
// * @param to
307-
// */
308-
// protected void addEntityMapping(final String from, final String toParam)
309-
// {
310-
// throw new NotImplementedException();
311-
// //entityMap.put(from, toParam);
312-
// }
313-
314-
// @Override
315-
// public void addEntityEndListener(final FlushListener entityEndListener, final String entityName) {
316-
// entityEndListenerRegistry.register(entityName, entityEndListener);
317-
// }
318-
319301
@Override
320302
public Map<String, String> getMap(final String mapName) {
321303
return multiMap.getMap(mapName);
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
* Copyright 2013 Deutsche Nationalbibliothek
3+
*
4+
* Licensed under the Apache License, Version 2.0 the "License";
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.culturegraph.mf.morph;
18+
19+
import java.util.ArrayList;
20+
import java.util.Deque;
21+
import java.util.LinkedList;
22+
import java.util.List;
23+
24+
import org.culturegraph.mf.types.MultiHashMap;
25+
import org.culturegraph.mf.types.MultiMap;
26+
27+
28+
/**
29+
* Sets the implementation for different Collections used in {@link Metamorph}.
30+
*
31+
* @author markus geipel
32+
*
33+
*/
34+
final class MorphCollectionFactory {
35+
private MorphCollectionFactory() {
36+
//no instances
37+
}
38+
39+
public static MultiMap createMultiMap(){
40+
return new MultiHashMap();
41+
}
42+
43+
public static <T> List<T> createList(){
44+
return new ArrayList<T>();
45+
}
46+
47+
public static <T> Deque<T> createDeque(){
48+
return new LinkedList<T>();
49+
}
50+
51+
public static <T> Registry<T> createRegistry(){
52+
return new WildcardRegistry<T>();
53+
}
54+
}

0 commit comments

Comments
 (0)