-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of ssh://git@github.com/culturegraph/metafactur…
…e-core.git
- Loading branch information
Showing
6 changed files
with
318 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
src/main/java/org/culturegraph/mf/morph/collectors/Range.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/* | ||
* Copyright 2013 Deutsche Nationalbibliothek | ||
* | ||
* Licensed under the Apache License, Version 2.0 the "License"; | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.culturegraph.mf.morph.collectors; | ||
|
||
import java.util.SortedSet; | ||
import java.util.TreeSet; | ||
|
||
import org.culturegraph.mf.morph.Metamorph; | ||
import org.culturegraph.mf.morph.NamedValueSource; | ||
|
||
|
||
/** | ||
* Corresponds to the <code><range></code> tag. | ||
* | ||
* @author Christoph Böhme | ||
*/ | ||
public final class Range extends AbstractCollect { | ||
private final SortedSet<Integer> values = new TreeSet<Integer>(); | ||
|
||
private Integer first; | ||
|
||
public Range(final Metamorph metamorph) { | ||
super(metamorph); | ||
setNamedValueReceiver(metamorph); | ||
} | ||
|
||
@Override | ||
protected void emit() { | ||
for (final Integer i: values) { | ||
getNamedValueReceiver().receive(getName(), i.toString(), this, getRecordCount(), getEntityCount()); | ||
} | ||
} | ||
|
||
@Override | ||
protected boolean isComplete() { | ||
return false; | ||
} | ||
|
||
@Override | ||
protected void receive(final String name, final String value, final NamedValueSource source) { | ||
if (first == null) { | ||
first = Integer.valueOf(value); | ||
} else { | ||
final int last = Integer.valueOf(value).intValue(); | ||
for (int i = first.intValue(); i <= last; ++i) { | ||
values.add(Integer.valueOf(i)); | ||
} | ||
first = null; | ||
} | ||
} | ||
|
||
@Override | ||
protected void clear() { | ||
values.clear(); | ||
first = null; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.