first project structure, imported old cnr-misc-utils

This commit is contained in:
Claudio Atzori 2019-05-30 15:35:18 +02:00
parent d42b5387f4
commit 54e4e2c4e3
97 changed files with 6764 additions and 0 deletions

View File

@ -0,0 +1,75 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>eu.dnetlib</groupId>
<artifactId>dnet-core</artifactId>
<version>1.0.0-SNAPSHOT</version>
</parent>
<artifactId>dnet-core-components</artifactId>
<groupId>eu.dnetlib</groupId>
<packaging>jar</packaging>
<version>1.0.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</dependency>
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
</dependency>
<dependency>
<groupId>dom4j</groupId>
<artifactId>dom4j</artifactId>
</dependency>
<dependency>
<groupId>jaxen</groupId>
<artifactId>jaxen</artifactId>
</dependency>
<dependency>
<groupId>saxonica</groupId>
<artifactId>saxon</artifactId>
</dependency>
<dependency>
<groupId>saxonica</groupId>
<artifactId>saxon-dom</artifactId>
</dependency>
<dependency>
<groupId>jgrapht</groupId>
<artifactId>jgrapht</artifactId>
</dependency>
<dependency>
<groupId>net.sf.ehcache</groupId>
<artifactId>ehcache</artifactId>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<optional>false</optional>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,39 @@
package eu.dnetlib.miscutils.cache;
import java.util.Map;
import java.util.Set;
/**
* Generic strongly typed cache.
*
* @author marko
*
* @param <K>
* key type
* @param <V>
* value type
*/
@Deprecated
public interface Cache<K, V> extends Map<K, V> {
V put(K key, CacheElement<V> element);
CacheElement<V> getElement(K key);
/**
* Short verision of put(K key, CacheElement<V> element) using default values for expiry time and other caching
* options.
*
* @param key
* key
* @param value
* value
*/
@Override
V put(K key, V value);
@Override
V get(Object key);
@Override
Set<K> keySet();
}

View File

@ -0,0 +1,73 @@
package eu.dnetlib.miscutils.cache;
/**
* A cache element encapsulates a value and a number of cache specific parameters like the expiration time.
*
* @author marko
*
* @param <T>
* type of payload
*/
@Deprecated
public class CacheElement<T> {
private T value;
private int timeToLive;
private int timeToIdle;
private long creationTime;
/**
* reference to the underlying implementation specific element instance, for all other properties not exposed here.
*/
Object specificElement;
CacheElement(final T value) {
this.value = value;
}
CacheElement(final T value, final int timeToLive, final int timeToIdle) {
this.value = value;
this.timeToLive = timeToLive;
this.timeToIdle = timeToIdle;
}
public T getValue() {
return value;
}
public void setValue(final T value) {
this.value = value;
}
public Integer getTimeToLive() {
return timeToLive;
}
public void setTimeToLive(final Integer timeToLive) {
this.timeToLive = timeToLive;
}
public Integer getTimeToIdle() {
return timeToIdle;
}
public void setTimeToIdle(final Integer timeToIdle) {
this.timeToIdle = timeToIdle;
}
public Object getSpecificElement() {
return specificElement;
}
public void setSpecificElement(final Object specificElement) {
this.specificElement = specificElement;
}
public long getCreationTime() {
return creationTime;
}
public void setCreationTime(long creationTime) {
this.creationTime = creationTime;
}
}

View File

@ -0,0 +1,178 @@
package eu.dnetlib.miscutils.cache;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import net.sf.ehcache.Element;
/**
* This is a wrapper to a EhCache instance exposed as a miscutils Cache object offering statically typed java Map-like
* behavior.
*
* @author marko
*
* @param <K>
* @param <V>
*/
@Deprecated
public class EhCache<K, V> implements Cache<K, V> { // NOPMD
public class MapEntry implements java.util.Map.Entry<K, V> {
transient K key;
MapEntry(final K key) {
this.key = key;
}
@Override
public K getKey() {
return key;
}
@Override
public V getValue() {
return get(key);
}
@Override
public V setValue(final V value) {
return put(key, value);
}
}
/**
* underlying cache implementation.
*/
private net.sf.ehcache.Cache cache;
public EhCache() {
// no operation
}
public EhCache(final net.sf.ehcache.Cache ehCache) {
basicSetCache(ehCache);
}
/**
* {@inheritDoc}
*
* @see eu.dnetlib.miscutils.cache.Cache#get(java.lang.Object) Java is really strange. Map<K,V> defines V
* get(Object), so we have to implement this method using Object otherwise the compiler signals a name clash.
*/
@Override
@SuppressWarnings("unchecked")
public V get(final Object key) {
final CacheElement<V> element = getElement((K) key);
if (element == null)
return null;
return element.getValue();
}
@Override
@SuppressWarnings("unchecked")
public CacheElement<V> getElement(final K key) {
final Element element = cache.get(key);
if (element == null)
return null;
final CacheElement<V> res = new CacheElement<V>((V) element.getObjectValue());
res.setTimeToLive(element.getTimeToLive());
res.setTimeToLive(element.getTimeToIdle());
res.setCreationTime(element.getCreationTime());
res.setSpecificElement(element);
return res;
}
@Override
public V put(final K key, final CacheElement<V> element) {
final boolean eternal = element.getTimeToLive() == 0;
if (eternal)
cache.put(new Element(key, element.getValue(),eternal));
else
cache.put(new Element(key, element.getValue(), element.getTimeToLive(), element.getTimeToIdle()));
return element.getValue();
}
@Override
public V put(final K key, final V value) {
return put(key, new CacheElement<V>(value));
}
@Override
public void clear() {
cache.removeAll();
}
@Override
public boolean containsKey(final Object arg0) {
return cache.isKeyInCache(arg0);
}
@Override
public boolean containsValue(final Object arg0) {
return cache.isValueInCache(arg0);
}
@Override
public Set<java.util.Map.Entry<K, V>> entrySet() {
final Set<java.util.Map.Entry<K, V>> res = new HashSet<java.util.Map.Entry<K, V>>();
for (K key : keySet())
res.add(new MapEntry(key)); // NOPMD
return res;
}
@Override
public boolean isEmpty() {
return size() == 0;
}
@Override
@SuppressWarnings("unchecked")
public Set<K> keySet() {
return new HashSet<K>(cache.getKeys());
}
@Override
public void putAll(final Map<? extends K, ? extends V> arg0) {
for (java.util.Map.Entry<? extends K, ? extends V> entry : arg0.entrySet())
put(entry.getKey(), entry.getValue());
}
@Override
public V remove(final Object arg0) {
final V val = get(arg0);
cache.remove(arg0);
return val;
}
@Override
public int size() {
return cache.getSize();
}
@Override
public Collection<V> values() {
final List<V> res = new ArrayList<V>();
for (K key : keySet())
res.add(get(key));
return res;
}
public net.sf.ehcache.Cache getCache() {
return cache;
}
public void setCache(final net.sf.ehcache.Cache cache) {
basicSetCache(cache);
}
private void basicSetCache(final net.sf.ehcache.Cache cache) {
this.cache = cache;
}
}

View File

@ -0,0 +1,58 @@
package eu.dnetlib.miscutils.collections;
import java.util.Collection;
import eu.dnetlib.miscutils.functional.UnaryFunction;
/**
* This is a utility class which helps you append suffixes or prefixes to a collection of strings.
*
* @author marko
*
*/
public class AffixCollection extends MappedCollection<String, String> {
/**
* Position of the affix.
*
* @author marko
*
*/
enum Position {
/**
* prefix.
*/
PREFIX,
/**
* suffix.
*/
SUFFIX
}
/**
* append a given suffix to every element of the input collection.
*
* @param coll
* @param suffix
*/
public AffixCollection(final Collection<String> coll, final String suffix) {
this(coll, suffix, Position.SUFFIX);
}
/**
* add a given affix to every element of the input collection, either as prefix or suffix.
*
* @param coll
* @param affix
* @param position
*/
public AffixCollection(final Collection<String> coll, final String affix, final Position position) {
super(coll, new UnaryFunction<String, String>() {
@Override
public String evaluate(String arg) {
return arg + affix;
}
});
}
}

View File

@ -0,0 +1,443 @@
/**
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package eu.dnetlib.miscutils.collections;
import java.io.Serializable;
import java.nio.charset.Charset;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.BitSet;
import java.util.Collection;
/**
* Implementation of a Bloom-filter, as described here:
* http://en.wikipedia.org/wiki/Bloom_filter
*
* For updates and bugfixes, see http://github.com/magnuss/java-bloomfilter
*
* Inspired by the SimpleBloomFilter-class written by Ian Clarke. This
* implementation provides a more evenly distributed Hash-function by
* using a proper digest instead of the Java RNG. Many of the changes
* were proposed in comments in his blog:
* http://blog.locut.us/2008/01/12/a-decent-stand-alone-java-bloom-filter-implementation/
*
* @param <E> Object type that is to be inserted into the Bloom filter, e.g. String or Integer.
* @author Magnus Skjegstad <magnus@skjegstad.com>
*/
public class BloomFilter<E> implements Serializable {
private static final long serialVersionUID = 1L;
private BitSet bitset;
private int bitSetSize;
private double bitsPerElement;
private int expectedNumberOfFilterElements; // expected (maximum) number of elements to be added
private int numberOfAddedElements; // number of elements actually added to the Bloom filter
private int k; // number of hash functions
static final Charset charset = Charset.forName("UTF-8"); // encoding used for storing hash values as strings
static final String hashName = "MD5"; // MD5 gives good enough accuracy in most circumstances. Change to SHA1 if it's needed
static final MessageDigest digestFunction;
static { // The digest method is reused between instances
MessageDigest tmp;
try {
tmp = java.security.MessageDigest.getInstance(hashName);
} catch (NoSuchAlgorithmException e) {
tmp = null;
}
digestFunction = tmp;
}
/**
* Constructs an empty Bloom filter. The total length of the Bloom filter will be
* c*n.
*
* @param c is the number of bits used per element.
* @param n is the expected number of elements the filter will contain.
* @param k is the number of hash functions used.
*/
public BloomFilter(double c, int n, int k) {
this.expectedNumberOfFilterElements = n;
this.k = k;
this.bitsPerElement = c;
this.bitSetSize = (int) Math.ceil(c * n);
numberOfAddedElements = 0;
this.bitset = new BitSet(bitSetSize);
}
/**
* Constructs an empty Bloom filter. The optimal number of hash functions (k) is estimated from the total size of the Bloom
* and the number of expected elements.
*
* @param bitSetSize defines how many bits should be used in total for the filter.
* @param expectedNumberOElements defines the maximum number of elements the filter is expected to contain.
*/
public BloomFilter(int bitSetSize, int expectedNumberOElements) {
this(bitSetSize / (double)expectedNumberOElements,
expectedNumberOElements,
(int) Math.round((bitSetSize / (double)expectedNumberOElements) * Math.log(2.0)));
}
/**
* Constructs an empty Bloom filter with a given false positive probability. The number of bits per
* element and the number of hash functions is estimated
* to match the false positive probability.
*
* @param falsePositiveProbability is the desired false positive probability.
* @param expectedNumberOfElements is the expected number of elements in the Bloom filter.
*/
public BloomFilter(double falsePositiveProbability, int expectedNumberOfElements) {
this(Math.ceil(-(Math.log(falsePositiveProbability) / Math.log(2))) / Math.log(2), // c = k / ln(2)
expectedNumberOfElements,
(int)Math.ceil(-(Math.log(falsePositiveProbability) / Math.log(2)))); // k = ceil(-log_2(false prob.))
}
/**
* Construct a new Bloom filter based on existing Bloom filter data.
*
* @param bitSetSize defines how many bits should be used for the filter.
* @param expectedNumberOfFilterElements defines the maximum number of elements the filter is expected to contain.
* @param actualNumberOfFilterElements specifies how many elements have been inserted into the <code>filterData</code> BitSet.
* @param filterData a BitSet representing an existing Bloom filter.
*/
public BloomFilter(int bitSetSize, int expectedNumberOfFilterElements, int actualNumberOfFilterElements, BitSet filterData) {
this(bitSetSize, expectedNumberOfFilterElements);
this.bitset = filterData;
this.numberOfAddedElements = actualNumberOfFilterElements;
}
/**
* Generates a digest based on the contents of a String.
*
* @param val specifies the input data.
* @param charset specifies the encoding of the input data.
* @return digest as long.
*/
public static int createHash(String val, Charset charset) {
return createHash(val.getBytes(charset));
}
/**
* Generates a digest based on the contents of a String.
*
* @param val specifies the input data. The encoding is expected to be UTF-8.
* @return digest as long.
*/
public static int createHash(String val) {
return createHash(val, charset);
}
/**
* Generates a digest based on the contents of an array of bytes.
*
* @param data specifies input data.
* @return digest as long.
*/
public static int createHash(byte[] data) {
return createHashes(data, 1)[0];
}
/**
* Generates digests based on the contents of an array of bytes and splits the result into 4-byte int's and store them in an array. The
* digest function is called until the required number of int's are produced. For each call to digest a salt
* is prepended to the data. The salt is increased by 1 for each call.
*
* @param data specifies input data.
* @param hashes number of hashes/int's to produce.
* @return array of int-sized hashes
*/
public static int[] createHashes(byte[] data, int hashes) {
int[] result = new int[hashes];
int k = 0;
byte salt = 0;
while (k < hashes) {
byte[] digest;
synchronized (digestFunction) {
digestFunction.update(salt);
salt++;
digest = digestFunction.digest(data);
}
for (int i = 0; i < digest.length/4 && k < hashes; i++) {
int h = 0;
for (int j = (i*4); j < (i*4)+4; j++) {
h <<= 8;
h |= ((int) digest[j]) & 0xFF;
}
result[k] = h;
k++;
}
}
return result;
}
/**
* Compares the contents of two instances to see if they are equal.
*
* @param obj is the object to compare to.
* @return True if the contents of the objects are equal.
*/
@Override
public boolean equals(Object obj) {
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
@SuppressWarnings("unchecked")
final BloomFilter<E> other = (BloomFilter<E>) obj;
if (this.expectedNumberOfFilterElements != other.expectedNumberOfFilterElements) {
return false;
}
if (this.k != other.k) {
return false;
}
if (this.bitSetSize != other.bitSetSize) {
return false;
}
if (this.bitset != other.bitset && (this.bitset == null || !this.bitset.equals(other.bitset))) {
return false;
}
return true;
}
/**
* Calculates a hash code for this class.
* @return hash code representing the contents of an instance of this class.
*/
@Override
public int hashCode() {
int hash = 7;
hash = 61 * hash + (this.bitset != null ? this.bitset.hashCode() : 0);
hash = 61 * hash + this.expectedNumberOfFilterElements;
hash = 61 * hash + this.bitSetSize;
hash = 61 * hash + this.k;
return hash;
}
/**
* Calculates the expected probability of false positives based on
* the number of expected filter elements and the size of the Bloom filter.
* <br /><br />
* The value returned by this method is the <i>expected</i> rate of false
* positives, assuming the number of inserted elements equals the number of
* expected elements. If the number of elements in the Bloom filter is less
* than the expected value, the true probability of false positives will be lower.
*
* @return expected probability of false positives.
*/
public double expectedFalsePositiveProbability() {
return getFalsePositiveProbability(expectedNumberOfFilterElements);
}
/**
* Calculate the probability of a false positive given the specified
* number of inserted elements.
*
* @param numberOfElements number of inserted elements.
* @return probability of a false positive.
*/
public double getFalsePositiveProbability(double numberOfElements) {
// (1 - e^(-k * n / m)) ^ k
return Math.pow((1 - Math.exp(-k * (double) numberOfElements
/ (double) bitSetSize)), k);
}
/**
* Get the current probability of a false positive. The probability is calculated from
* the size of the Bloom filter and the current number of elements added to it.
*
* @return probability of false positives.
*/
public double getFalsePositiveProbability() {
return getFalsePositiveProbability(numberOfAddedElements);
}
/**
* Returns the value chosen for K.<br />
* <br />
* K is the optimal number of hash functions based on the size
* of the Bloom filter and the expected number of inserted elements.
*
* @return optimal k.
*/
public int getK() {
return k;
}
/**
* Sets all bits to false in the Bloom filter.
*/
public void clear() {
bitset.clear();
numberOfAddedElements = 0;
}
/**
* Adds an object to the Bloom filter. The output from the object's
* toString() method is used as input to the hash functions.
*
* @param element is an element to register in the Bloom filter.
*/
public void add(E element) {
add(element.toString().getBytes(charset));
}
/**
* Adds an array of bytes to the Bloom filter.
*
* @param bytes array of bytes to add to the Bloom filter.
*/
public void add(byte[] bytes) {
int[] hashes = createHashes(bytes, k);
for (int hash : hashes)
bitset.set(Math.abs(hash % bitSetSize), true);
numberOfAddedElements ++;
}
/**
* Adds all elements from a Collection to the Bloom filter.
* @param c Collection of elements.
*/
public void addAll(Collection<? extends E> c) {
for (E element : c)
add(element);
}
/**
* Returns true if the element could have been inserted into the Bloom filter.
* Use getFalsePositiveProbability() to calculate the probability of this
* being correct.
*
* @param element element to check.
* @return true if the element could have been inserted into the Bloom filter.
*/
public boolean contains(E element) {
return contains(element.toString().getBytes(charset));
}
/**
* Returns true if the array of bytes could have been inserted into the Bloom filter.
* Use getFalsePositiveProbability() to calculate the probability of this
* being correct.
*
* @param bytes array of bytes to check.
* @return true if the array could have been inserted into the Bloom filter.
*/
public boolean contains(byte[] bytes) {
int[] hashes = createHashes(bytes, k);
for (int hash : hashes) {
if (!bitset.get(Math.abs(hash % bitSetSize))) {
return false;
}
}
return true;
}
/**
* Returns true if all the elements of a Collection could have been inserted
* into the Bloom filter. Use getFalsePositiveProbability() to calculate the
* probability of this being correct.
* @param c elements to check.
* @return true if all the elements in c could have been inserted into the Bloom filter.
*/
public boolean containsAll(Collection<? extends E> c) {
for (E element : c)
if (!contains(element))
return false;
return true;
}
/**
* Read a single bit from the Bloom filter.
* @param bit the bit to read.
* @return true if the bit is set, false if it is not.
*/
public boolean getBit(int bit) {
return bitset.get(bit);
}
/**
* Set a single bit in the Bloom filter.
* @param bit is the bit to set.
* @param value If true, the bit is set. If false, the bit is cleared.
*/
public void setBit(int bit, boolean value) {
bitset.set(bit, value);
}
/**
* Return the bit set used to store the Bloom filter.
* @return bit set representing the Bloom filter.
*/
public BitSet getBitSet() {
return bitset;
}
/**
* Returns the number of bits in the Bloom filter. Use count() to retrieve
* the number of inserted elements.
*
* @return the size of the bitset used by the Bloom filter.
*/
public int size() {
return this.bitSetSize;
}
/**
* Returns the number of elements added to the Bloom filter after it
* was constructed or after clear() was called.
*
* @return number of elements added to the Bloom filter.
*/
public int count() {
return this.numberOfAddedElements;
}
/**
* Returns the expected number of elements to be inserted into the filter.
* This value is the same value as the one passed to the constructor.
*
* @return expected number of elements.
*/
public int getExpectedNumberOfElements() {
return expectedNumberOfFilterElements;
}
/**
* Get expected number of bits per element when the Bloom filter is full. This value is set by the constructor
* when the Bloom filter is created. See also getBitsPerElement().
*
* @return expected number of bits per element.
*/
public double getExpectedBitsPerElement() {
return this.bitsPerElement;
}
/**
* Get actual number of bits per element based on the number of elements that have currently been inserted and the length
* of the Bloom filter. See also getExpectedBitsPerElement().
*
* @return number of bits per element.
*/
public double getBitsPerElement() {
return this.bitSetSize / (double)numberOfAddedElements;
}
}

View File

@ -0,0 +1,48 @@
package eu.dnetlib.miscutils.collections;
import java.util.List;
import com.google.common.collect.Lists;
/**
* Utility class which checks ensures that a given collection is not null.
*
* <p>
* CXF for example cannot distinguish from nulls. This helper allows you write:
* </p>
*
* <pre>
* for(String bla : EnsureCollection.list(somecode())) {....}
* </pre>
*
* @author marko
*
*/
public class EnsureCollection {
/**
* returns the argument or a new list if the argument is null.
*
* @param <T> a type
* @param aList a list
* @return passthrough or empty list
*/
public static <T> List<T> list(final List<T> aList) {
if (aList == null)
return Lists.newArrayList();
return aList;
}
/**
* Alias for static imports.
*
* @param <T> a type
* @param aList a list
* @return passthrough or empty list
*/
public static <T> List<T> notNullList(final List<T> aList) {
return list(aList);
}
}

View File

@ -0,0 +1,6 @@
package eu.dnetlib.miscutils.collections;
import eu.dnetlib.miscutils.functional.UnaryFunction;
public interface Filter<T> extends UnaryFunction<Boolean, T> {
}

View File

@ -0,0 +1,119 @@
package eu.dnetlib.miscutils.collections;
import java.util.*;
import com.google.common.collect.Lists;
import eu.dnetlib.miscutils.functional.UnaryFunction;
public class FilteredCollection<T> implements Iterable<T> {
final transient private Iterable<T> coll;
transient UnaryFunction<Boolean, T> filter;
class FilterIterator implements Iterator<T> {
final transient private Iterator<T> iter;
transient T nextElement;
public FilterIterator() {
this.iter = coll.iterator();
scanNext();
}
private void scanNext() {
while (iter.hasNext()) {
final T element = iter.next();
if (filter.evaluate(element)) {
nextElement = element;
return;
}
}
nextElement = null; // NOPMD
}
@Override
public boolean hasNext() {
return nextElement != null;
}
@Override
public T next() {
final T res = nextElement;
scanNext();
return res;
}
@Override
public void remove() {
// no operation
}
}
/**
* Static helper function, makes usage shorter.
*
* @param <X>
* @param coll
* @param filter
* @return
*/
public static <X> Iterable<X> filter(final Iterable<X> coll, final UnaryFunction<Boolean, X> filter) {
return new FilteredCollection<X>(coll, filter);
}
public static <X> Iterable<X> filter(final X[] coll, final UnaryFunction<Boolean, X> filter) {
return new FilteredCollection<X>(coll, filter);
}
/**
* Static helper function, makes common usage shorter.
*
* @param <X>
* @param <Y>
* @param coll
* @param mapper
* @return
*/
public static <X> List<X> listFilter(final Iterable<X> coll, final UnaryFunction<Boolean, X> filter) {
return Lists.newArrayList(filter(coll, filter));
}
public static <X> List<X> listFilter(final X[] coll, final UnaryFunction<Boolean, X> filter) {
return Lists.newArrayList(filter(coll, filter));
}
public FilteredCollection(final Collection<T> coll, final UnaryFunction<Boolean, T> filter) {
this.coll = coll;
this.filter = filter;
}
public FilteredCollection(final Iterable<T> coll, final UnaryFunction<Boolean, T> filter) {
this.coll = coll;
this.filter = filter;
}
public FilteredCollection(final T[] coll, final UnaryFunction<Boolean, T> filter) {
this.coll = Lists.newArrayList(coll);
this.filter = filter;
}
@Override
public Iterator<T> iterator() {
return new FilterIterator();
}
public static void main(final String[] args) {
final List<Object> list = new ArrayList<Object>();
list.add("ciao");
list.add(2);
list.add("bubu");
final TypeFilteredCollection<Object, String> filtered = new TypeFilteredCollection<Object, String>(list, String.class);
for (final String el : filtered)
System.out.println("element: " + el); // NOPMD
System.out.println("ok"); // NOPMD
}
}

View File

@ -0,0 +1,109 @@
/**
*
*/
package eu.dnetlib.miscutils.collections;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import com.google.common.collect.Lists;
import eu.dnetlib.miscutils.functional.UnaryFunction;
/**
* @author marko
*
*/
public class MappedCollection<T, K> implements Iterable<T> {
private transient final Iterable<K> coll;
private transient final UnaryFunction<T, K> mapper;
/**
* Static helper function, makes usage shorter.
*
* @param <X>
* @param coll
* @param filter
* @return
*/
public static <X, Y> Iterable<X> map(final Iterable<Y> coll, final UnaryFunction<X, Y> mapper) {
return new MappedCollection<X, Y>(coll, mapper);
}
public static <X, Y> Iterable<X> map(final Y[] coll, final UnaryFunction<X, Y> mapper) {
return new MappedCollection<X, Y>(coll, mapper);
}
/**
* Static helper function, makes common usage shorter.
*
* @param <X>
* @param <Y>
* @param coll
* @param mapper
* @return
*/
public static <X, Y> List<X> listMap(final Iterable<Y> coll, final UnaryFunction<X, Y> mapper) {
return Lists.newArrayList(map(coll, mapper));
}
public static <X, Y> List<X> listMap(final Y[] coll, final UnaryFunction<X, Y> mapper) {
return Lists.newArrayList(map(coll, mapper));
}
/**
* Compatibility with pre 0.0.3 cnr-misc-utils.
*
* @param coll
* @param mapper
*/
public MappedCollection(final Collection<K> coll, final UnaryFunction<T, K> mapper) {
this.coll = coll;
this.mapper = mapper;
}
public MappedCollection(final Iterable<K> coll, final UnaryFunction<T, K> mapper) {
this.coll = coll;
this.mapper = mapper;
}
public MappedCollection(final K[] coll, final UnaryFunction<T, K> mapper) {
this.coll = Lists.newArrayList(coll);
this.mapper = mapper;
}
class MappedIterator implements Iterator<T> {
private transient final Iterator<K> iter;
public MappedIterator() {
this.iter = coll.iterator();
}
@Override
public T next() {
return mapper.evaluate(iter.next());
}
@Override
public boolean hasNext() {
return iter.hasNext();
}
@Override
public void remove() {
iter.remove();
}
}
/*
* (non-Javadoc)
*
* @see java.lang.Iterable#iterator()
*/
@Override
public Iterator<T> iterator() {
return new MappedIterator();
}
}

View File

@ -0,0 +1,30 @@
package eu.dnetlib.miscutils.collections;
public class Pair<K, V> {
private K k;
private V v;
public Pair(K k, V v) {
this.k = k;
this.v = v;
}
public K getKey() {
return k;
}
public V getValue() {
return v;
}
@Override
public boolean equals(Object obj) {
if (obj instanceof Pair<?, ?>) {
Pair<?, ?> tmp = (Pair<?, ?>) obj;
return k.equals(tmp.getKey()) && v.equals(tmp.getValue());
} else return false;
}
}

View File

@ -0,0 +1,73 @@
package eu.dnetlib.miscutils.collections;
import java.lang.reflect.InvocationTargetException;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
/**
* Helper for creating a named key/value pairs out of a String.split output.
*
* @author luca.santocono
*
* @param <K>
* key type
* @param <V>
* value type
*/
public class PositionalMapGenerator<K, V> {
/**
* keys in positional order.
*/
private final K[] keys;
/**
* positional keys declaration
*
* @param keys
* keys
*/
public PositionalMapGenerator( final K... keys) {
this.keys = keys;
}
/**
* Positionally map the input array with the configured keys.
*
* @param values
* value array
* @return map containing value array mapped with keys
*/
public Map<K, V> asMap(final V[] values) {
final Map<K, V> stringMap = new HashMap<K, V>();
for (int i = 0; i < values.length; i++)
stringMap.put(keys[i], values[i]);
return stringMap;
}
@SuppressWarnings("unchecked")
public <X, Y> X construct(final Class<X> clazz, final Class<Y> clavv, final V[] values) {
Class<Y>[] params = new Class[values.length];
Arrays.fill(params, clavv);
try {
return clazz.getDeclaredConstructor(params).newInstance(values);
} catch (IllegalArgumentException e) {
throw new IllegalStateException(e);
} catch (InstantiationException e) {
throw new IllegalStateException(e);
} catch (IllegalAccessException e) {
throw new IllegalStateException(e);
} catch (InvocationTargetException e) {
throw new IllegalStateException(e);
} catch (SecurityException e) {
throw new IllegalStateException(e);
} catch (NoSuchMethodException e) {
throw new IllegalStateException(e);
}
}
}

View File

@ -0,0 +1,78 @@
package eu.dnetlib.miscutils.collections;
import java.util.Map;
import eu.dnetlib.miscutils.functional.UnaryFunction;
/**
* A special case of a PositionalMapGenerator, bound for String values. It provides automatic split which returns an
* iterable of maps.
*
* @author marko
*
* @param <K>
* key
*/
public class PositionalStringMapGenerator<K> extends PositionalMapGenerator<K, String> {
/**
* Creates a new positional string map generator
*
* @param keys
*/
public PositionalStringMapGenerator(final K... keys) {
super(keys);
}
/**
* Pass a list of strings and return a list of maps where each key has a value according to the position in the
* splitted array relative to the position of the key in the constructor.
*
* @param elements
* list of strings which will be splitted
* @param separator
* separator
* @return iterable of maps contained splitted values
*/
public Iterable<Map<K, String>> split(Iterable<String> elements, final String separator) {
return new MappedCollection<Map<K, String>, String>(elements, new UnaryFunction<Map<K, String>, String>() {
@Override
public Map<K, String> evaluate(String value) {
return asMap(value.split(separator));
}
});
}
/**
* Pass a list of strings and return a list of objects constructed by passing the splitted string values to the
* constructor of the new object.
*
* <p>
* This method doesn't need to setup a list of key names in the constructor
* </p>
*
* @param <X>
* some class
* @param clazz
* some class
* @param elements
* list of strings to split
* @param separator
* separator
* @return iterable of instances of some class constructed with splitted values
*/
public <X> Iterable<X> split(final Class<X> clazz, Iterable<String> elements, final String separator) {
return new MappedCollection<X, String>(elements, new UnaryFunction<X, String>() {
@Override
public X evaluate(String value) {
return construct(clazz, String.class, value.split(separator));
}
});
}
}

View File

@ -0,0 +1,14 @@
package eu.dnetlib.miscutils.collections;
public class TypeFilter<T> implements Filter<T> {
transient final Class<? extends T> cls;
public TypeFilter(final Class<? extends T> cls) {
this.cls = cls;
}
@Override
public Boolean evaluate(final T element) {
return (cls.isInstance(element));
}
}

View File

@ -0,0 +1,21 @@
package eu.dnetlib.miscutils.collections;
import java.util.Collection;
import java.util.Iterator;
public class TypeFilteredCollection<T, S extends T> implements Iterable<S> {
private transient final Collection<T> coll;
private transient final Class<? extends S> cls;
public TypeFilteredCollection(final Collection<T> coll, final Class<? extends S> cls) {
this.coll = coll;
this.cls = cls;
}
@Override
@SuppressWarnings("unchecked")
public Iterator<S> iterator() {
final Filter<T> filter = new TypeFilter<T>(cls);
return (Iterator<S>) (new FilteredCollection<T>(coll, filter)).iterator();
}
}

View File

@ -0,0 +1,18 @@
package eu.dnetlib.miscutils.coupling;
/**
* In many occasions one component wants to disable some other component or some functionalty of another component
* but it's not advisable to couple these components too tightly. This class offers an abstraction to the concept of "Condition",
* where a component can parameterize it's behavior according to some external condition, which can be driven by another component.
*
* @author marko
*
*/
public interface ExternalCondition {
/**
* true if true.
*
* @return true if true
*/
boolean isTrue();
}

View File

@ -0,0 +1,33 @@
package eu.dnetlib.miscutils.coupling;
/**
* Simple implementation of an ExternalCondition object, where a condition provider has directly control to the global condition.
*
* @author marko
*
*/
public class StaticCondition implements ExternalCondition {
/**
* condition provider can set this field.
*/
boolean condition;
/**
* {@inheritDoc}
* @see eu.dnetlib.miscutils.coupling.ExternalCondition#isTrue()
*/
@Override
public synchronized boolean isTrue() {
return isCondition();
}
public synchronized boolean isCondition() {
return condition;
}
public synchronized void setCondition(boolean condition) {
this.condition = condition;
}
}

View File

@ -0,0 +1,109 @@
package eu.dnetlib.miscutils.datetime;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
/**
* various date utilities.
*
* @author michele
*
*/
public class DateUtils {
private static final SimpleDateFormat ISO8601FORMAT = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ", Locale.US);
private transient final Date date;
public DateUtils() {
this.date = new Date();
}
public DateUtils(final Date date) {
this.date = (Date) date.clone();
}
public String getDateAsISO8601String() {
String result;
synchronized (ISO8601FORMAT) {
result = ISO8601FORMAT.format(this.date);
}
//convert YYYYMMDDTHH:mm:ss+HH00 into YYYYMMDDTHH:mm:ss+HH:00
//- note the added colon for the Timezone
return result.substring(0, result.length() - 2) + ":" + result.substring(result.length() - 2);
}
public Long getPrecisionTime() {
return this.date.getTime();
}
public static long now() {
return new Date().getTime();
}
public static String now_ISO8601() { // NOPMD
String result;
synchronized (ISO8601FORMAT) {
result = ISO8601FORMAT.format(new Date());
}
//convert YYYYMMDDTHH:mm:ss+HH00 into YYYYMMDDTHH:mm:ss+HH:00
//- note the added colon for the Timezone
return result.substring(0, result.length() - 2) + ":" + result.substring(result.length() - 2);
}
/**
* parses a iso8601 date into a date.
*
* @param date
* string iso8601 date
* @return date object
*/
public Date parse(final String dateArg) {
String date = dateArg;
if ("".equals(date))
return null;
try {
if (date.endsWith("Z")) {
date = date.replace("Z", "+0000");
} else if (date.length() < 20) {
date += "+0000"; // NOPMD
} else {
final String end = date.substring(date.length() - 3);
date = date.substring(0, date.length() - 3) + end.replace(":", "");
}
synchronized (ISO8601FORMAT) {
return ISO8601FORMAT.parse(date);
}
} catch (ParseException e) {
throw new IllegalStateException("invalid iso8601 date '" + dateArg + "' (even after normalizing it to '" + date + "')");
}
}
public static String calculate_ISO8601(long l) {
String result = ISO8601FORMAT.format(new Date(l));
// convert YYYYMMDDTHH:mm:ss+HH00 into YYYYMMDDTHH:mm:ss+HH:00
//- note the added colon for the Timezone
result = result.substring(0, result.length() - 2) + ":" + result.substring(result.length() - 2);
return result;
}
/**
* Extracts the duration part of a ISO8601 formatted date. Duration part is the part after the 'T'.
*
* @param dateArg
* @return
*/
public String getDuration(final String dateArg) {
String[] splitted = dateArg.split("T");
if (splitted.length == 1)
return "0";
else
return splitted[1];
}
}

View File

@ -0,0 +1,804 @@
package eu.dnetlib.miscutils.datetime;
/*
* HumanTime.java
*
* Created on 06.10.2008
*
* Copyright (c) 2008 Johann Burkard (<mailto:jb@eaio.com>) <http://eaio.com>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
* documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
* Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
* WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*/
import java.io.Externalizable;
import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectOutput;
import java.util.Iterator;
/**
* HumanTime parses and formats time deltas for easier reading by humans. It can format time information without losing
* information but its main purpose is to generate more easily understood approximations. <h3>Using HumanTime</h3>
* <p>
* Use HumanTime by creating an instance that contains the time delta ({@link HumanTime#HumanTime(long)}), create an
* empty instance through ({@link HumanTime#HumanTime()}) and set the delta using the {@link #y()}, {@link #d()},
* {@link #h()}, {@link #s()} and {@link #ms()} methods or parse a {@link CharSequence} representation (
* {@link #eval(CharSequence)}). Parsing ignores whitespace and is case insensitive.
* </p>
* <h3>HumanTime format</h3>
* <p>
* HumanTime will format time deltas in years ("y"), days ("d"), hours ("h"), minutes ("m"), seconds ("s") and
* milliseconds ("ms"), separated by a blank character. For approximate representations, the time delta will be round up
* or down if necessary.
* </p>
* <h3>HumanTime examples</h3>
* <ul>
* <li>HumanTime.eval("1 d 1d 2m 3m").getExactly() = "2 d 5 m"</li>
* <li>HumanTime.eval("2m8d2h4m").getExactly() = "8 d 2 h 6 m"</li>
* <li>HumanTime.approximately("2 d 8 h 20 m 50 s") = "2 d 8 h"</li>
* <li>HumanTime.approximately("55m") = "1 h"</li>
* </ul>
* <h3>Implementation details</h3>
* <ul>
* <li>The time delta can only be increased.</li>
* <li>Instances of this class are thread safe.</li>
* <li>Getters using the Java Beans naming conventions are provided for use in environments like JSP or with expression
* languages like OGNL. See {@link #getApproximately()} and {@link #getExactly()}.</li>
* <li>To keep things simple, a year consists of 365 days.</li>
* </ul>
*
* @author <a href="mailto:jb@eaio.com">Johann Burkard</a>
* @version $Id: HumanTime.java 323 2008-10-08 19:06:22Z Johann $
* @see #eval(CharSequence)
* @see #approximately(CharSequence)
* @see <a href="http://johannburkard.de/blog/programming/java/date-formatting-parsing-humans-humantime.html">Date
* Formatting and Parsing for Humans in Java with HumanTime</a>
*/
public class HumanTime implements Externalizable, Comparable<HumanTime>, Cloneable {
/**
* The serial version UID.
*/
private static final long serialVersionUID = 5179328390732826722L;
/**
* One second.
*/
private static final long SECOND = 1000;
/**
* One minute.
*/
private static final long MINUTE = SECOND * 60;
/**
* One hour.
*/
private static final long HOUR = MINUTE * 60;
/**
* One day.
*/
private static final long DAY = HOUR * 24;
/**
* One year.
*/
private static final long YEAR = DAY * 365;
/**
* Percentage of what is round up or down.
*/
private static final int CEILING_PERCENTAGE = 15;
/**
* Parsing state.
*/
static enum State {
NUMBER, IGNORED, UNIT
}
static State getState(char c) {
State out;
switch (c) {
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
out = State.NUMBER;
break;
case 's':
case 'm':
case 'h':
case 'd':
case 'y':
case 'S':
case 'M':
case 'H':
case 'D':
case 'Y':
out = State.UNIT;
break;
default:
out = State.IGNORED;
}
return out;
}
/**
* Parses a {@link CharSequence} argument and returns a {@link HumanTime} instance.
*
* @param s
* the char sequence, may not be <code>null</code>
* @return an instance, never <code>null</code>
*/
public static HumanTime eval(final CharSequence s) {
HumanTime out = new HumanTime(0L);
int num = 0;
int start = 0;
int end = 0;
State oldState = State.IGNORED;
for (char c : new Iterable<Character>() {
/**
* @see java.lang.Iterable#iterator()
*/
@Override
public Iterator<Character> iterator() {
return new Iterator<Character>() {
private int p = 0;
/**
* @see java.util.Iterator#hasNext()
*/
@Override
public boolean hasNext() {
return p < s.length();
}
/**
* @see java.util.Iterator#next()
*/
@Override
public Character next() {
return s.charAt(p++);
}
/**
* @see java.util.Iterator#remove()
*/
@Override
public void remove() {
throw new UnsupportedOperationException();
}
};
}
}) {
State newState = getState(c);
if (oldState != newState) {
if (oldState == State.NUMBER && (newState == State.IGNORED || newState == State.UNIT)) {
num = Integer.parseInt(s.subSequence(start, end).toString());
} else if (oldState == State.UNIT && (newState == State.IGNORED || newState == State.NUMBER)) {
out.nTimes(s.subSequence(start, end).toString(), num);
num = 0;
}
start = end;
}
++end;
oldState = newState;
}
if (oldState == State.UNIT) {
out.nTimes(s.subSequence(start, end).toString(), num);
}
return out;
}
/**
* Parses and formats the given char sequence, preserving all data.
* <p>
* Equivalent to <code>eval(in).getExactly()</code>
*
* @param in
* the char sequence, may not be <code>null</code>
* @return a formatted String, never <code>null</code>
*/
public static String exactly(CharSequence in) {
return eval(in).getExactly();
}
/**
* Formats the given time delta, preserving all data.
* <p>
* Equivalent to <code>new HumanTime(in).getExactly()</code>
*
* @param l
* the time delta
* @return a formatted String, never <code>null</code>
*/
public static String exactly(long l) {
return new HumanTime(l).getExactly();
}
/**
* Parses and formats the given char sequence, potentially removing some data to make the output easier to
* understand.
* <p>
* Equivalent to <code>eval(in).getApproximately()</code>
*
* @param in
* the char sequence, may not be <code>null</code>
* @return a formatted String, never <code>null</code>
*/
public static String approximately(CharSequence in) {
return eval(in).getApproximately();
}
/**
* Formats the given time delta, preserving all data.
* <p>
* Equivalent to <code>new HumanTime(l).getApproximately()</code>
*
* @param l
* the time delta
* @return a formatted String, never <code>null</code>
*/
public static String approximately(long l) {
return new HumanTime(l).getApproximately();
}
/**
* The time delta.
*/
private long delta;
/**
* No-argument Constructor for HumanTime.
* <p>
* Equivalent to calling <code>new HumanTime(0L)</code>.
*/
public HumanTime() {
this(0L);
}
/**
* Constructor for HumanTime.
*
* @param delta
* the initial time delta, interpreted as a positive number
*/
public HumanTime(long delta) {
super();
this.delta = Math.abs(delta);
}
private void nTimes(String unit, int n) {
if ("ms".equalsIgnoreCase(unit)) {
ms(n);
} else if ("s".equalsIgnoreCase(unit)) {
s(n);
} else if ("m".equalsIgnoreCase(unit)) {
m(n);
} else if ("h".equalsIgnoreCase(unit)) {
h(n);
} else if ("d".equalsIgnoreCase(unit)) {
d(n);
} else if ("y".equalsIgnoreCase(unit)) {
y(n);
}
}
private long upperCeiling(long x) {
return (x / 100) * (100 - CEILING_PERCENTAGE);
}
private long lowerCeiling(long x) {
return (x / 100) * CEILING_PERCENTAGE;
}
private String ceil(long d, long n) {
return Integer.toString((int) Math.ceil((double) d / n));
}
private String floor(long d, long n) {
return Integer.toString((int) Math.floor((double) d / n));
}
/**
* Adds one year to the time delta.
*
* @return this HumanTime object
*/
public HumanTime y() {
return y(1);
}
/**
* Adds n years to the time delta.
*
* @param n
* n
* @return this HumanTime object
*/
public HumanTime y(int n) {
delta += YEAR * Math.abs(n);
return this;
}
/**
* Adds one day to the time delta.
*
* @return this HumanTime object
*/
public HumanTime d() {
return d(1);
}
/**
* Adds n days to the time delta.
*
* @param n
* n
* @return this HumanTime object
*/
public HumanTime d(int n) {
delta += DAY * Math.abs(n);
return this;
}
/**
* Adds one hour to the time delta.
*
* @return this HumanTime object
*/
public HumanTime h() {
return h(1);
}
/**
* Adds n hours to the time delta.
*
* @param n
* n
* @return this HumanTime object
*/
public HumanTime h(int n) {
delta += HOUR * Math.abs(n);
return this;
}
/**
* Adds one month to the time delta.
*
* @return this HumanTime object
*/
public HumanTime m() {
return m(1);
}
/**
* Adds n months to the time delta.
*
* @param n
* n
* @return this HumanTime object
*/
public HumanTime m(int n) {
delta += MINUTE * Math.abs(n);
return this;
}
/**
* Adds one second to the time delta.
*
* @return this HumanTime object
*/
public HumanTime s() {
return s(1);
}
/**
* Adds n seconds to the time delta.
*
* @param n
* seconds
* @return this HumanTime object
*/
public HumanTime s(int n) {
delta += SECOND * Math.abs(n);
return this;
}
/**
* Adds one millisecond to the time delta.
*
* @return this HumanTime object
*/
public HumanTime ms() {
return ms(1);
}
/**
* Adds n milliseconds to the time delta.
*
* @param n
* n
* @return this HumanTime object
*/
public HumanTime ms(int n) {
delta += Math.abs(n);
return this;
}
/**
* Returns a human-formatted representation of the time delta.
*
* @return a formatted representation of the time delta, never <code>null</code>
*/
public String getExactly() {
return getExactly(new StringBuilder()).toString();
}
/**
* Appends a human-formatted representation of the time delta to the given {@link Appendable} object.
*
* @param <T>
* the return type
* @param a
* the Appendable object, may not be <code>null</code>
* @return the given Appendable object, never <code>null</code>
*/
public <T extends Appendable> T getExactly(T a) {
try {
boolean prependBlank = false;
long d = delta;
if (d >= YEAR) {
a.append(floor(d, YEAR));
a.append(' ');
a.append('y');
prependBlank = true;
}
d %= YEAR;
if (d >= DAY) {
if (prependBlank) {
a.append(' ');
}
a.append(floor(d, DAY));
a.append(' ');
a.append('d');
prependBlank = true;
}
d %= DAY;
if (d >= HOUR) {
if (prependBlank) {
a.append(' ');
}
a.append(floor(d, HOUR));
a.append(' ');
a.append('h');
prependBlank = true;
}
d %= HOUR;
if (d >= MINUTE) {
if (prependBlank) {
a.append(' ');
}
a.append(floor(d, MINUTE));
a.append(' ');
a.append('m');
prependBlank = true;
}
d %= MINUTE;
if (d >= SECOND) {
if (prependBlank) {
a.append(' ');
}
a.append(floor(d, SECOND));
a.append(' ');
a.append('s');
prependBlank = true;
}
d %= SECOND;
if (d > 0) {
if (prependBlank) {
a.append(' ');
}
a.append(Integer.toString((int) d));
a.append(' ');
a.append('m');
a.append('s');
}
} catch (IOException ex) {
// What were they thinking...
}
return a;
}
/**
* Returns an approximate, human-formatted representation of the time delta.
*
* @return a formatted representation of the time delta, never <code>null</code>
*/
public String getApproximately() {
return getApproximately(new StringBuilder()).toString();
}
/**
* Appends an approximate, human-formatted representation of the time delta to the given {@link Appendable} object.
*
* @param <T>
* the return type
* @param a
* the Appendable object, may not be <code>null</code>
* @return the given Appendable object, never <code>null</code>
*/
public <T extends Appendable> T getApproximately(T a) {
try {
int parts = 0;
boolean rounded = false;
boolean prependBlank = false;
long d = delta;
long mod = d % YEAR;
if (mod >= upperCeiling(YEAR)) {
a.append(ceil(d, YEAR));
a.append(' ');
a.append('y');
++parts;
rounded = true;
prependBlank = true;
} else if (d >= YEAR) {
a.append(floor(d, YEAR));
a.append(' ');
a.append('y');
++parts;
rounded = mod <= lowerCeiling(YEAR);
prependBlank = true;
}
if (!rounded) {
d %= YEAR;
mod = d % DAY;
if (mod >= upperCeiling(DAY)) {
if (prependBlank) {
a.append(' ');
}
a.append(ceil(d, DAY));
a.append(' ');
a.append('d');
++parts;
rounded = true;
prependBlank = true;
} else if (d >= DAY) {
if (prependBlank) {
a.append(' ');
}
a.append(floor(d, DAY));
a.append(' ');
a.append('d');
++parts;
rounded = mod <= lowerCeiling(DAY);
prependBlank = true;
}
if (parts < 2) {
d %= DAY;
mod = d % HOUR;
if (mod >= upperCeiling(HOUR)) {
if (prependBlank) {
a.append(' ');
}
a.append(ceil(d, HOUR));
a.append(' ');
a.append('h');
++parts;
rounded = true;
prependBlank = true;
} else if (d >= HOUR && !rounded) {
if (prependBlank) {
a.append(' ');
}
a.append(floor(d, HOUR));
a.append(' ');
a.append('h');
++parts;
rounded = mod <= lowerCeiling(HOUR);
prependBlank = true;
}
if (parts < 2) {
d %= HOUR;
mod = d % MINUTE;
if (mod >= upperCeiling(MINUTE)) {
if (prependBlank) {
a.append(' ');
}
a.append(ceil(d, MINUTE));
a.append(' ');
a.append('m');
++parts;
rounded = true;
prependBlank = true;
} else if (d >= MINUTE && !rounded) {
if (prependBlank) {
a.append(' ');
}
a.append(floor(d, MINUTE));
a.append(' ');
a.append('m');
++parts;
rounded = mod <= lowerCeiling(MINUTE);
prependBlank = true;
}
if (parts < 2) {
d %= MINUTE;
mod = d % SECOND;
if (mod >= upperCeiling(SECOND)) {
if (prependBlank) {
a.append(' ');
}
a.append(ceil(d, SECOND));
a.append(' ');
a.append('s');
++parts;
rounded = true;
prependBlank = true;
} else if (d >= SECOND && !rounded) {
if (prependBlank) {
a.append(' ');
}
a.append(floor(d, SECOND));
a.append(' ');
a.append('s');
++parts;
rounded = mod <= lowerCeiling(SECOND);
prependBlank = true;
}
if (parts < 2) {
d %= SECOND;
if (d > 0 && !rounded) {
if (prependBlank) {
a.append(' ');
}
a.append(Integer.toString((int) d));
a.append(' ');
a.append('m');
a.append('s');
}
}
}
}
}
}
} catch (IOException ex) {
// What were they thinking...
}
return a;
}
/**
* Returns the time delta.
*
* @return the time delta
*/
public long getDelta() {
return delta;
}
/**
* @see java.lang.Object#equals(java.lang.Object)
*/
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (!(obj instanceof HumanTime)) {
return false;
}
return delta == ((HumanTime) obj).delta;
}
/**
* Returns a 32-bit representation of the time delta.
*
* @see java.lang.Object#hashCode()
*/
@Override
public int hashCode() {
return (int) (delta ^ (delta >> 32));
}
/**
* Returns a String representation of this.
* <p>
* The output is identical to {@link #getExactly()}.
*
* @see java.lang.Object#toString()
* @see #getExactly()
* @return a String, never <code>null</code>
*/
@Override
public String toString() {
return getExactly();
}
/**
* Compares this HumanTime to another HumanTime.
*
* @param t
* the other instance, may not be <code>null</code>
* @return which one is greater
*/
@Override
public int compareTo(HumanTime t) {
return delta == t.delta ? 0 : (delta < t.delta ? -1 : 1);
}
/**
* Deep-clones this object.
*
* @see java.lang.Object#clone()
* @throws CloneNotSupportedException
*/
@Override
public Object clone() throws CloneNotSupportedException {
return super.clone();
}
/**
* @see java.io.Externalizable#readExternal(java.io.ObjectInput)
*/
@Override
public void readExternal(ObjectInput in) throws IOException {
delta = in.readLong();
}
/**
* @see java.io.Externalizable#writeExternal(java.io.ObjectOutput)
*/
@Override
public void writeExternal(ObjectOutput out) throws IOException {
out.writeLong(delta);
}
}

View File

@ -0,0 +1,50 @@
package eu.dnetlib.miscutils.dom4j; // NOPMD
import java.io.StringReader;
import java.util.ArrayList;
import java.util.List;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.Node;
import org.dom4j.io.SAXReader;
import eu.dnetlib.miscutils.collections.TypeFilteredCollection;
/**
* This class allows to avoid casts and unnecessary suppress warnings statements which would be necessary when using the dom4j API.
*
* @author marko
*
*/
public class XPathHelper {
public static Iterable<Element> selectElements(final Node base, final String xpath) {
@SuppressWarnings("unchecked")
final List<Node> children = base.selectNodes(xpath);
return new TypeFilteredCollection<Node, Element>(children, Element.class);
}
public static Iterable<Element> selectElements(final String base, final String xpath) {
Document document;
try {
document = new SAXReader().read(new StringReader(base));
return selectElements(document, xpath);
} catch (DocumentException e) {
return new ArrayList<Element>();
}
}
public static Element selectElement(final Node base, final String xpath) {
for (Element el : selectElements(base, xpath))
return el;
return null;
}
public static Element selectElement(final String base, final String xpath) {
for (Element el : selectElements(base, xpath))
return el;
return null;
}
}

View File

@ -0,0 +1,17 @@
package eu.dnetlib.miscutils.factory;
/**
* Provides a common interface for factory objects.
*
* @author marko
*
* @param <T>
*/
public interface Factory<T> {
/**
* returns a new instance.
*
* @return
*/
T newInstance();
}

View File

@ -0,0 +1,38 @@
package eu.dnetlib.miscutils.functional;
public class CompositeUnaryFunction<T, K> implements UnaryFunction<T, K> {
protected transient UnaryFunction<T, K> function;
public CompositeUnaryFunction(final UnaryFunction<T, K> function) {
this.function = function;
}
class UnaryHelper<X> extends CompositeUnaryFunction<T, X> {
private transient final UnaryFunction<K, X> comp;
private transient final UnaryFunction<T, K> base;
public UnaryHelper(final UnaryFunction<T, K> base, final UnaryFunction<K, X> comp) {
super(null);
this.comp = comp;
this.base = base;
}
@Override
public T evaluate(final X arg) {
return base.evaluate(comp.evaluate(arg));
}
}
public <X> CompositeUnaryFunction<T, X> of(UnaryFunction<K, X> comp) { // NOPMD
return new UnaryHelper<X>(this, comp);
}
@Override
public T evaluate(final K arg) {
return function.evaluate(arg);
}
}

View File

@ -0,0 +1,34 @@
package eu.dnetlib.miscutils.functional;
import java.lang.reflect.Constructor;
/**
* Functional helpers.
*
* @author marko
*
*/
public class Functional {
/**
* Given a class and a constructor type, return a unary function which invokes the constructor of that class.
*
* @param <A>
* @param <B>
* @param clazz
* @param argumentType
* @return
*/
static public <A, B> UnaryFunction<A, B> construct(final Class<? extends A> clazz, final Class<? extends B> argumentType) {
return new UnaryFunction<A, B>() {
@Override
public A evaluate(final B arg) {
try {
final Constructor<? extends A> constructor = clazz.getConstructor(new Class[] { argumentType });
return constructor.newInstance(arg);
} catch (Exception e) {
throw new IllegalArgumentException(e);
}
}
};
}
}

View File

@ -0,0 +1,22 @@
package eu.dnetlib.miscutils.functional;
/**
* Identity function
*
* @author marko
*
* @param <T>
*/
public class IdentityFunction<T> implements UnaryFunction<T, T> {
/**
* {@inheritDoc}
*
* @see eu.dnetlib.miscutils.functional.UnaryFunction#evaluate(java.lang.Object)
*/
@Override
public T evaluate(final T arg) {
return arg;
}
}

View File

@ -0,0 +1,52 @@
package eu.dnetlib.miscutils.functional;
import eu.dnetlib.miscutils.factory.Factory;
/**
* ThreadSafeUnaryFunction maintains a ThreadLocal of a UnaryFunction and
* delegates the application to the thread local function.
*
* @author claudio
*
* @param <T>
* @param <K>
*/
public class ThreadSafeUnaryFunction<T, K> implements UnaryFunction<T, K> {
/**
* ThreadLocal UnaryFunction
*/
private ThreadLocal<? extends UnaryFunction<T, K>> localFunction;
/**
* Builds a new ThreadSafeUnaryFunction.
* @param localFunction
*/
public ThreadSafeUnaryFunction(ThreadLocal<? extends UnaryFunction<T, K>> localFunction) {
super();
this.localFunction = localFunction;
}
/**
* Builds a new ThreadSafeUnaryFunction.
* @param localFunction
*/
public ThreadSafeUnaryFunction(final Factory<? extends UnaryFunction<T, K>> functionFactory) {
super();
this.localFunction = new ThreadLocal<UnaryFunction<T,K>>() {
@Override
protected synchronized UnaryFunction<T, K> initialValue() {
return functionFactory.newInstance();
}
};
}
/**
* method applies the evaluation by invoking the ThreadLocal function.
*/
@Override
public T evaluate(K arg) {
return localFunction.get().evaluate(arg);
}
}

View File

@ -0,0 +1,12 @@
/**
*
*/
package eu.dnetlib.miscutils.functional;
/**
* @author marko
*
*/
public interface UnaryFunction<T, K> {
T evaluate(K arg);
}

View File

@ -0,0 +1,20 @@
package eu.dnetlib.miscutils.functional.hash;
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.codec.digest.DigestUtils;
public class Hashing {
public static String md5(String s) {
return DigestUtils.md5Hex(s);
}
public static String decodeBase64(String s) {
return new String(Base64.decodeBase64(s.getBytes()));
}
public static String encodeBase64(String s) {
return new String(Base64.encodeBase64(s.getBytes()));
}
}

View File

@ -0,0 +1,12 @@
package eu.dnetlib.miscutils.functional.string;
import eu.dnetlib.miscutils.functional.UnaryFunction;
import org.apache.commons.lang3.StringEscapeUtils;
public class EscapeHtml implements UnaryFunction<String, String> {
@Override
public String evaluate(String arg) {
return StringEscapeUtils.escapeHtml4(arg);
}
}

View File

@ -0,0 +1,10 @@
package eu.dnetlib.miscutils.functional.string;
import eu.dnetlib.miscutils.functional.UnaryFunction;
import org.apache.commons.lang3.StringEscapeUtils;
public class EscapeXml implements UnaryFunction<String, String> {
@Override
public String evaluate(String arg) {
return StringEscapeUtils.escapeXml11(arg);
}
}

View File

@ -0,0 +1,12 @@
package eu.dnetlib.miscutils.functional.string;
import eu.dnetlib.miscutils.functional.UnaryFunction;
public class FastEscapeXml implements UnaryFunction<String, String> {
@Override
public String evaluate(String arg) {
return "<![CDATA[" + arg.replace("]]>", "]]]]><![CDATA[>") + "]]>";
}
}

View File

@ -0,0 +1,23 @@
package eu.dnetlib.miscutils.functional.string;
import eu.dnetlib.miscutils.functional.UnaryFunction;
/**
* Removes control characters from a string
*
* @author claudio
*
*/
public class Sanitizer implements UnaryFunction<String, String> {
@Override
public String evaluate(String s) {
return sanitize(s);
}
public static String sanitize(String s) {
return s.replaceAll("\\p{Cntrl}", "");
}
}

View File

@ -0,0 +1,12 @@
package eu.dnetlib.miscutils.functional.string;
import eu.dnetlib.miscutils.functional.UnaryFunction;
import org.apache.commons.lang3.StringEscapeUtils;
public class UnescapeHtml implements UnaryFunction<String, String> {
@Override
public String evaluate(final String arg) {
return StringEscapeUtils.unescapeHtml4(arg);
}
}

View File

@ -0,0 +1,197 @@
package eu.dnetlib.miscutils.functional.xml;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.StringReader;
import java.io.StringWriter;
import java.util.Map;
import javax.xml.transform.OutputKeys;
import javax.xml.transform.Result;
import javax.xml.transform.Source;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerConfigurationException;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.URIResolver;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import eu.dnetlib.miscutils.functional.UnaryFunction;
/**
* This function applies a stylesheet to something which can be transformed to a javax.xml.Source.
*
* <p>Subclasses are specialized and know how to transform K into a Source</p>
*
* @author marko
*
* @param <K>
*/
public abstract class AbstractApplyXslt<K> implements UnaryFunction<String, K> {
private static final String UNKNOWN_XSLT_NAME = "unknown xslt name";
private static final Log log = LogFactory.getLog(AbstractApplyXslt.class); // NOPMD by marko on 11/24/08 5:02 PM
private Transformer transformer;
/**
* optional, useful to keep track of xslt name for debugging purposes.
*/
private String xsltName;
public AbstractApplyXslt(final Resource xslt) {
this(xslt, null);
}
public AbstractApplyXslt(final Resource xslt, Map<String, String> parameters) {
this(new StreamSource(getInputStream(xslt)), getFileName((ClassPathResource) xslt), parameters);
}
public AbstractApplyXslt(final String xslt) {
this(xslt, UNKNOWN_XSLT_NAME);
}
public AbstractApplyXslt(final String xslt, String name) {
this(xslt, name, null);
}
public AbstractApplyXslt(final String xslt, String name, Map<String, String> parameters) {
this(new StreamSource(new StringReader(xslt)), name, parameters);
}
public AbstractApplyXslt(final Source xslt) {
this(xslt, UNKNOWN_XSLT_NAME);
}
public AbstractApplyXslt(final Source xslt, String name) {
this(xslt, name, null);
}
/**
* Base method for all the others.
* @param xslt
* @param name
* @param parameters
*/
public AbstractApplyXslt(final Source xslt, String name, Map<String, String> parameters) {
try {
this.xsltName = name;
TransformerFactory factory = TransformerFactory.newInstance();
if (! UNKNOWN_XSLT_NAME.equals(name))
factory.setURIResolver(new ExternalResourceURIResolver(name.replaceFirst("[^/]+$", "")));
transformer = factory.newTransformer(xslt);
if(parameters != null)
for(Map.Entry<String, String> parameter : parameters.entrySet())
transformer.setParameter(parameter.getKey(), parameter.getValue());
} catch (final Throwable e) {
log.error("Problems with transformer!\n" + xslt + "--" + name, e);
log.error(xsltDump(xslt));
throw new IllegalStateException(e);
}
}
/**
* This class contains the login enabling imports of peer external resources for the current xslt (<xsl:import>)
* The method resolve() first looks for the resource within the file system; if this fails, it looks in the classpath.
* @author Andrea Mannocci
*
*/
private class ExternalResourceURIResolver implements URIResolver {
private final String xsltBasePath;
public ExternalResourceURIResolver(String xsltBasePath) {
this.xsltBasePath = xsltBasePath;
}
@Override
public Source resolve(String href, String base) throws TransformerException {
String externalResource = this.xsltBasePath + href;
try{
log.debug("trying to load external resource from file system: " + externalResource);
return new StreamSource(new File(externalResource));
} catch (final Throwable e) {
log.debug("trying to load external resource from file system: " + externalResource);
return new StreamSource(getInputStream(new ClassPathResource(externalResource)));
}
}
}
private String xsltDump(Source xslt) {
Transformer transformer;
try {
transformer = TransformerFactory.newInstance().newTransformer();
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
StringWriter outWriter = new StringWriter();
Result result = new StreamResult(outWriter);
transformer.transform(xslt, result);
StringBuffer sb = outWriter.getBuffer();
return sb.toString();
} catch (TransformerConfigurationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (TransformerException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return "error dumping the xslt";
}
@Override
public String evaluate(final K input) {
try {
final StringWriter output = new StringWriter();
transformer.transform(toStream(input), new StreamResult(output));
return output.toString();
} catch (final TransformerException e) {
log.error("cannot transform record", e);
log.debug(input.toString());
return "";
}
}
public abstract Source toStream(K input);
public abstract String toString(K input);
/**
* Used only to convert checked to unchecked exception.
*
* @param xslt
* @return
*/
private static InputStream getInputStream(final Resource xslt) {
try {
return xslt.getInputStream();
} catch (final IOException e) {
throw new IllegalArgumentException(e);
}
}
private static String getFileName(ClassPathResource xslt) {
return xslt.getPath();
}
public Transformer getTransformer() {
return transformer;
}
public void setTransformer(final Transformer transformer) {
this.transformer = transformer;
}
public String getXsltName() {
return xsltName;
}
public void setXsltName(String xsltName) {
this.xsltName = xsltName;
}
}

View File

@ -0,0 +1,60 @@
package eu.dnetlib.miscutils.functional.xml;
import java.io.StringReader;
import java.util.Map;
import javax.xml.transform.Source;
import javax.xml.transform.stream.StreamSource;
import org.springframework.core.io.Resource;
/**
* Applies a stylesheet to a XML string and returns an XML string.
*
* @author marko
*
*/
public class ApplyXslt extends AbstractApplyXslt<String> {
public ApplyXslt(Resource xslt) {
super(xslt);
}
public ApplyXslt(Source xslt, String name) {
super(xslt, name);
}
public ApplyXslt(Source xslt) {
super(xslt);
}
public ApplyXslt(String xslt, String name) {
super(xslt, name);
}
public ApplyXslt(String xslt) {
super(xslt);
}
public ApplyXslt(Resource xslt, Map<String, String> parameters) {
super(xslt, parameters);
}
public ApplyXslt(Source xslt, String name, Map<String, String> parameters) {
super(xslt, name, parameters);
}
public ApplyXslt(String xslt, String name, Map<String, String> parameters) {
super(xslt, name, parameters);
}
@Override
public Source toStream(String input) {
return new StreamSource(new StringReader(input));
}
@Override
public String toString(String input) {
return input;
}
}

View File

@ -0,0 +1,80 @@
package eu.dnetlib.miscutils.functional.xml;
import java.io.StringWriter;
import java.util.Map;
import javax.xml.transform.OutputKeys;
import javax.xml.transform.Source;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import org.springframework.core.io.Resource;
import org.w3c.dom.Node;
/**
* Applies a stylesheet to a XML DOM and returns an XML string.
*
* @author marko
*
*/
public class ApplyXsltDom extends AbstractApplyXslt<Node> {
public ApplyXsltDom(Resource xslt) {
super(xslt);
}
public ApplyXsltDom(Source xslt, String name) {
super(xslt, name);
}
public ApplyXsltDom(Source xslt) {
super(xslt);
}
public ApplyXsltDom(String xslt, String name) {
super(xslt, name);
}
public ApplyXsltDom(String xslt) {
super(xslt);
}
public ApplyXsltDom(Resource xslt, Map<String, String> parameters) {
super(xslt, parameters);
}
public ApplyXsltDom(Source xslt, String name, Map<String, String> parameters) {
super(xslt, name, parameters);
}
public ApplyXsltDom(String xslt, String name, Map<String, String> parameters) {
super(xslt, name, parameters);
}
@Override
public Source toStream(Node input) {
return new DOMSource(input);
}
@Override
public String toString(Node input) {
return nodeToString(input);
}
private String nodeToString(Node node) {
StringWriter sw = new StringWriter();
try {
Transformer t = TransformerFactory.newInstance().newTransformer();
t.setOutputProperty(OutputKeys.INDENT, "yes");
t.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
t.transform(new DOMSource(node), new StreamResult(sw));
} catch (TransformerException te) {
System.out.println("nodeToString Transformer Exception");
}
return sw.toString();
}
}

View File

@ -0,0 +1,61 @@
package eu.dnetlib.miscutils.functional.xml;
import java.util.Map;
import javax.xml.transform.Source;
import org.dom4j.Document;
import org.dom4j.io.DocumentSource;
import org.springframework.core.io.Resource;
/**
* Applies a stylesheet to a XML DOM4j and returns an XML string.
*
* @author marko
*
*/
public class ApplyXsltDom4j extends AbstractApplyXslt<Document> {
public ApplyXsltDom4j(Resource xslt) {
super(xslt);
}
public ApplyXsltDom4j(Source xslt, String name) {
super(xslt, name);
}
public ApplyXsltDom4j(Source xslt) {
super(xslt);
}
public ApplyXsltDom4j(String xslt, String name) {
super(xslt, name);
}
public ApplyXsltDom4j(String xslt) {
super(xslt);
}
public ApplyXsltDom4j(Resource xslt, Map<String, String> parameters) {
super(xslt, parameters);
}
public ApplyXsltDom4j(Source xslt, String name, Map<String, String> parameters) {
super(xslt, name, parameters);
}
public ApplyXsltDom4j(String xslt, String name, Map<String, String> parameters) {
super(xslt, name, parameters);
}
@Override
public Source toStream(Document input) {
return new DocumentSource(input);
}
@Override
public String toString(Document input) {
return input.asXML();
}
}

View File

@ -0,0 +1,123 @@
package eu.dnetlib.miscutils.functional.xml;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.Random;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import com.google.common.base.Joiner;
import eu.dnetlib.miscutils.functional.hash.Hashing;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
/**
* This class provides some XSLT functions.
*
* <xsl:stylesheet ... xmlns:dnet="eu.dnetlib.miscutils.functional.xml.DnetXsltFunctions"> ... </xsl:stylesheet>
*
* @author michele
*
*/
public class DnetXsltFunctions {
private static final Log log = LogFactory.getLog(DnetXsltFunctions.class); // NOPMD by marko on 11/24/08 5:02 PM
private static volatile long seedUniquifier = 8682522807148012L;
private static String[] dateFormats = { "yyyy-MM-dd", "yyyy/MM/dd" };
private static final String[] normalizeDateFormats = { "yyyy-MM-dd'T'hh:mm:ss", "yyyy-MM-dd", "yyyy/MM/dd", "yyyy" };
private static final String normalizeOutFormat = new String("yyyy-MM-dd'T'hh:mm:ss'Z'");
public static String extractYear(String s) throws ParseException {
Calendar c = new GregorianCalendar();
for (String format : dateFormats) {
try {
c.setTime(new SimpleDateFormat(format).parse(s));
String year = String.valueOf(c.get(Calendar.YEAR));
return year;
} catch (ParseException e) {}
}
return "";
}
public static String normalizeDate(final String s, final boolean strict) {
final String date = s != null ? s.trim() : "";
for (String format : normalizeDateFormats) {
try {
Date parse = new SimpleDateFormat(format).parse(date);
String res = new SimpleDateFormat(normalizeOutFormat).format(parse);
return res;
} catch (ParseException e) {}
}
if (strict) {
throw new IllegalArgumentException("unable to normalize date: " + date);
} else {
//log.warn("unable to normalize date: " + s);
return "";
}
}
public static String randomInt(int max) {
return String.valueOf(new Random(++seedUniquifier + System.nanoTime()).nextInt(max));
}
public static String md5(String s) {
return Hashing.md5(s);
}
public static String decodeBase64(String s) {
return Hashing.decodeBase64(s);
}
public static String encodeBase64(String s) {
return Hashing.encodeBase64(s);
}
public static String lc(String s) {
return s.toLowerCase();
}
public static String uc(String s) {
return s.toUpperCase();
}
public static String decade(String s) {
String res = _decade(s.trim());
log.debug(s + "--> " + res);
return res;
}
private static String _decade(String s) {
Matcher m1 = Pattern.compile("(\\d\\d\\d)\\d").matcher(s);
if (m1.find()) {
String part = m1.group(1);
return part + "0-" + part + "9";
}
Matcher m2 = Pattern.compile("(\\d)\\d").matcher(s);
if (m2.find()) {
String part = m2.group(1);
return "19" + part + "0-19" + part + "9";
}
return "n/a";
}
public static String join(final String s1, final String separator, final String s2) {
if(StringUtils.isBlank(s1) || StringUtils.isBlank(s2)){
return "";
}
return Joiner.on(separator).join(s1, s2);
}
public static String pickFirst(final String s1, final String s2) {
return StringUtils.isNotBlank(s1) ? s1 : StringUtils.isNotBlank(s2) ? s2 : "";
}
}

View File

@ -0,0 +1,133 @@
package eu.dnetlib.miscutils.functional.xml;
import java.io.*;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.*;
import javax.xml.transform.dom.DOMResult;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import com.sun.org.apache.xml.internal.serialize.OutputFormat;
import com.sun.org.apache.xml.internal.serialize.XMLSerializer;
import eu.dnetlib.miscutils.functional.UnaryFunction;
import org.w3c.dom.Document;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
/**
* The Class IndentXmlString.
*/
public class IndentXmlString implements UnaryFunction<String, String> {
/*
* (non-Javadoc)
*
* @see eu.dnetlib.miscutils.functional.UnaryFunction#evaluate(java.lang.Object)
*/
@Override
public String evaluate(final String unformattedXml) {
try {
return doIndent(unformattedXml);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
/**
* Do indent.
*
* @param unformattedXml
* the unformatted xml
* @return the string
* @throws IOException
* Signals that an I/O exception has occurred.
*/
protected String doIndent(final String unformattedXml) throws IOException {
final Document document = parseXmlString(unformattedXml);
OutputFormat format = new OutputFormat(document);
format.setIndenting(true);
format.setIndent(2);
Writer out = new StringWriter();
XMLSerializer serializer = new XMLSerializer(out, format);
serializer.serialize(document);
return out.toString();
}
/**
* Parses the xml string.
*
* @param in
* the in
* @return the document
*/
protected Document parseXmlString(final String in) {
try {
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
db.setErrorHandler(null);
InputSource is = new InputSource(new StringReader(in));
return db.parse(is);
} catch (ParserConfigurationException e) {
throw new RuntimeException(e);
} catch (SAXException e) {
throw new RuntimeException(e);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
private String doIndent(final Document document) throws TransformerException, UnsupportedEncodingException {
final Transformer transformer = getTransformer();
final ByteArrayOutputStream out = new ByteArrayOutputStream();
transformer.transform(new DOMSource(document), new StreamResult(out));
return out.toString("utf-8");
}
private Transformer getTransformer() throws TransformerConfigurationException {
TransformerFactory tf = TransformerFactory.newInstance();
Transformer transformer = tf.newTransformer();
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
transformer.setOutputProperty(OutputKeys.DOCTYPE_PUBLIC, "yes");
transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");
return transformer;
}
private Document doIndentDocument(final Document document) throws TransformerException, UnsupportedEncodingException {
final Transformer transformer = getTransformer();
final DOMResult out = new DOMResult();
transformer.transform(new DOMSource(document), out);
return (Document) out.getNode();
}
/**
* Static helper Apply.
*
* @param xml
* the xml
* @return the indented xml string
*/
public static String apply(final String xml) {
return new IndentXmlString().evaluate(xml);
}
/**
* Static helper Apply.
*
* @param xml
* the xml
* @return the indented xml string
*/
public static Document apply(final Document xml) throws TransformerException, UnsupportedEncodingException {
return new IndentXmlString().doIndentDocument(xml);
}
}

View File

@ -0,0 +1,45 @@
package eu.dnetlib.miscutils.functional.xml;
import java.io.StringWriter;
import javax.xml.transform.OutputKeys;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerConfigurationException;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.TransformerFactoryConfigurationError;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import org.w3c.dom.Node;
import eu.dnetlib.miscutils.functional.UnaryFunction;
public class SerializeXml implements UnaryFunction<String, Node> {
Transformer transformer;
public SerializeXml() {
try {
this.transformer = TransformerFactory.newInstance().newTransformer();
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
} catch (TransformerConfigurationException e) {
throw new IllegalStateException(e);
} catch (TransformerFactoryConfigurationError e) {
throw new IllegalStateException(e);
}
}
@Override
public String evaluate(Node arg) {
StreamResult result = new StreamResult(new StringWriter());
DOMSource source = new DOMSource(arg);
try {
transformer.transform(source, result);
return result.getWriter().toString();
} catch (TransformerException e) {
throw new IllegalStateException(e);
}
}
}

View File

@ -0,0 +1,22 @@
package eu.dnetlib.miscutils.functional.xml;
/**
* The Class TryIndentXmlString. Tries to indent an xml string. If an error occurs (e.g. broken xml) it returns the original xml.
*/
public class TryIndentXmlString extends IndentXmlString {
/*
* (non-Javadoc)
*
* @see eu.dnetlib.miscutils.functional.xml.IndentXmlString#evaluate(java.lang.String)
*/
@Override
public String evaluate(final String unformattedXml) {
try {
return doIndent(unformattedXml);
} catch (Exception e) {
return unformattedXml;
}
}
}

View File

@ -0,0 +1,16 @@
package eu.dnetlib.miscutils.hstree;
/**
* This is the terminator node in a tree definition chain:
*
* TreeNode<L0, L1, TreeNode<L1, L2, TreeNode<L2, Void, NilTreeNode>>>
*
* Note the use of "Void" as the next-resource-parameter value in the last level.
*
*
* @author marko
*
*/
abstract public class NilTreeNode<V> extends TreeNode<Void, Void, V, TreeNode<Void, ?, V, ?>> { // NOPMD
}

View File

@ -0,0 +1,252 @@
package eu.dnetlib.miscutils.hstree;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Queue;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
/**
* This class implement statically typed complete tree of finite depth. The type signature of each tree node determines
* fully the depth and the types of all the children.
*
* <pre>
* class MyTree extends TreeNode&lt;RootPayload, L1Payload, TreeNode&lt;L1Payload, L2Payload, TreeNode&lt;L2Payload, Void, NilTreeNode&gt;&gt;&gt; {
*
* }
* </pre>
*
* However since java doesn't have type inferencing we'll have to write often the full type of intermediate nodes,
* especially during tree construction. Thus it's recommended that you split the chain into a number of dummy classes,
* serving only to the purpuse of declaring the type chain:
*
* <pre>
* class MyTree extends TreeNode&lt;RootPayload, L1Payload, L1Tree&gt; {
* }
*
* class L1Tree extends TreeNode&lt;L1Payload, L2Payload, L2Tree&gt; {
* }
*
* class L2Tree extends TreeNode&lt;L2Payload, Void, NilTreeNode&gt; {
* }
* </pre>
*
* NOTE: you could keep the whole definition inside a single file using inner classes.
*
* @author marko
*
* @param <T>
* Type of the payload (or resource)
* @param <N>
* Type of the next level payload
* @param <C>
* Type of the next level node (another TreeNode)
*/
public class TreeNode<T, N, V, C extends TreeNode<N, ?, V, ?>> {
public static final String CHILDR_UNDER_LEAF = "cannot create children under leaf nodes";
private static final Log log = LogFactory.getLog(TreeNode.class); // NOPMD by marko on 11/24/08 5:02 PM
T resource;
List<C> children = new ArrayList<C>();
transient Class<? extends C> childNodeType = autoChildNodeType(getClass());
/**
* Default constructor doesn't set the payload. This is used internally to construct a node. We cannot use the
* <code>TreeNode(T resource)</code> constructor only because it would force any implementor of "alias" subclasses
* of TreeNode to provide a dummy implementation of the constructor calling <code>super(resource)</code>
*
* However the constructor is protected because users should only create objects through <code>addChild</code> or in
* alternative they should provide they own constructor ovverrides.
*/
protected TreeNode() {
// no action
}
/**
* However the constructor is protected because users should only create objects through <code>addChild</code> or in
* alternative they should provide they own constructor ovverrides.
*
* @param resource
* payload
*/
protected TreeNode(final T resource) {
this.resource = resource;
}
/**
* Call this method to add a child node.
*
* Only the payload is needed, the tree node will be constructed automatically and it will be returned.
*
* <pre>
* L1Child c1 = root.addChild(new L1Resource());
* c1.addChild(new L2Resource());
* c1.addChild(new L2Resource()).addChild(new L3Resource());
* </pre>
*
* @param resource
* payload
* @return the new node
*/
@SuppressWarnings("unchecked")
public C addChild(final N resource) {
try {
if (childNodeType.equals(NilTreeNode.class))
throw new IllegalStateException(CHILDR_UNDER_LEAF);
C test;
try {
test = childNodeType.newInstance();
test.setResource(resource);
} catch (InstantiationException e) {
/*
* handle the situation when someone wants to create a one argument constructor hiding the default
* constructor provided by the base class. Nodes should normally be constructed using addChild but we
* don't want to force users to do it, and if they do it they shouldn't be punished with obscure
* InstantiationException caused by our evil usage of reflection. Of course we should do much more here
* in order to be more robust in the general case.
*/
try {
test = (C) childNodeType.getConstructors()[0].newInstance(resource); // NOPMD
} catch (InvocationTargetException e1) {
throw new IllegalStateException(e1);
} catch (InstantiationException e1) {
throw new IllegalStateException(e1);
}
}
getChildren().add(test);
return test;
} catch (IllegalArgumentException e) {
throw new IllegalStateException(e);
} catch (SecurityException e) {
throw new IllegalStateException(e);
} catch (IllegalAccessException e) {
throw new IllegalStateException(e);
}
}
/**
* This method is especially useful for leaf nodes when you want to append several children to the same parent node,
* without having to declare a temporary variable to hold the parent node (which could have long and ugly type)
*
* @param resource
* @return the parent node
*/
public TreeNode<T, N, V, C> appendChild(final N resource) {
addChild(resource);
return this;
}
/**
* This method applies a visitor to all nodes in a breadth first fashon
*
* Currently null payloads are skipped
*
* @see Visitor
* @param visitor
*/
public void breadthFirst(final V visitor) {
final Queue<TreeNode<?, ?, V, ?>> queue = new LinkedList<TreeNode<?, ?, V, ?>>();
queue.add(this);
while (!queue.isEmpty()) {
final TreeNode<?, ?, V, ?> current = queue.remove();
log.info("visiting " + current);
current.accept(visitor);
queue.addAll(current.getChildren());
}
}
/**
* depth first.
*
* Currently null payloads are skipped
*
* @see Visitor
* @param Visitor
*/
public void depthFirst(final V visitor) {
baseDepthFirst(visitor);
}
public void baseDepthFirst(final V visitor) {
accept(visitor);
for (C el : children)
el.baseDepthFirst(visitor);
}
/**
* For the curious, this method takes care of retrieving the runtime type information for the tree node element
* declared for children nodes.
*
* Because of java type erasure, this is not strictly needed for making this kind of tree work, but it's needed if
* we want to enable people typing ugly long signatures and use type aliases as described in the class
* documentation; otherwise a cast exception would occur.
*
* Aargh, any serious language which permits type polymorphysm should have a type alias feature
*
* @param clazz
* the class object of this class
* @return the class object of the node element describing children
*/
@SuppressWarnings({ "unchecked", "rawtypes"})
protected Class<? extends C> autoChildNodeType(final Class<? extends TreeNode> clazz) {
final Type superType = clazz.getGenericSuperclass();
if (superType instanceof ParameterizedType) {
final ParameterizedType paramSuperType = (ParameterizedType) superType;
int argumentIndex;
if (paramSuperType.getRawType() == TreeNode.class)
argumentIndex = 3;
else
argumentIndex = 2;
final Type argument = (paramSuperType).getActualTypeArguments()[argumentIndex];
return getRawType(argument);
} else {
return autoChildNodeType((Class<? extends TreeNode>) superType);
}
}
@SuppressWarnings("unchecked")
protected <X> X getRawType(final Type type) {
if (type instanceof ParameterizedType)
return (X) ((ParameterizedType) type).getRawType();
return (X) type;
}
public List<C> getChildren() {
return children;
}
public void setChildren(final List<C> children) {
this.children = children;
}
public T getResource() {
return resource;
}
public void setResource(final T resource) {
this.resource = resource;
}
public void accept(final V dummy) {
log.fatal("should be ovverriden");
}
}

View File

@ -0,0 +1,24 @@
package eu.dnetlib.miscutils.iterators;
import java.util.Iterator;
/**
* Useful if you want to quickly iterate an iterable with the new java 5 syntax.
*
* @author marko
*
* @param <T>
*/
public class IterableIterator<T> implements Iterable<T> {
private Iterator<T> iter;
public IterableIterator(Iterator<T> iter) {
this.iter = iter;
}
@Override
public Iterator<T> iterator() {
return iter;
}
}

View File

@ -0,0 +1,21 @@
package eu.dnetlib.miscutils.iterators;
import java.util.Iterator;
import java.util.List;
import eu.dnetlib.miscutils.collections.Pair;
public class IterablePair <A, B> implements Iterable<Pair<A, B>> {
private final List<A> first;
private final List<B> second;
public IterablePair(List<A> first, List<B> second) {
this.first = first;
this.second = second;
}
@Override
public Iterator<Pair<A, B>> iterator() {
return new ParallelIterator<A, B>(first.iterator(), second.iterator());
}
}

View File

@ -0,0 +1,29 @@
package eu.dnetlib.miscutils.iterators;
import java.util.Iterator;
import eu.dnetlib.miscutils.collections.Pair;
public class ParallelIterator <A, B> implements Iterator<Pair<A, B>> {
private final Iterator<A> iA;
private final Iterator<B> iB;
public ParallelIterator(Iterator<A> iA, Iterator<B> iB) {
this.iA = iA; this.iB = iB;
}
@Override
public boolean hasNext() { return iA.hasNext() && iB.hasNext(); }
@Override
public Pair<A, B> next() {
return new Pair<A, B>(iA.next(), iB.next());
}
@Override
public void remove() {
iA.remove();
iB.remove();
}
}

View File

@ -0,0 +1,29 @@
package eu.dnetlib.miscutils.iterators.xml;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.nio.charset.Charset;
import java.util.Iterator;
public class IterableXmlParser implements Iterable<String> {
private String element;
private InputStream inputStream;
public IterableXmlParser(String element, InputStream inputStream) {
this.element = element;
this.inputStream = inputStream;
}
public IterableXmlParser(String element, String xml) {
this.element = element;
this.inputStream = new ByteArrayInputStream(xml.getBytes(Charset.forName(XMLIterator.UTF_8)));
}
@Override
public Iterator<String> iterator() {
return new XMLIterator(element, inputStream);
}
}

View File

@ -0,0 +1,170 @@
package eu.dnetlib.miscutils.iterators.xml;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.io.StringWriter;
import java.nio.charset.Charset;
import java.nio.charset.CharsetDecoder;
import java.nio.charset.CodingErrorAction;
import java.util.Iterator;
import javax.xml.stream.XMLEventFactory;
import javax.xml.stream.XMLEventReader;
import javax.xml.stream.XMLEventWriter;
import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLOutputFactory;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.events.StartElement;
import javax.xml.stream.events.XMLEvent;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
public class XMLIterator implements Iterator<String> {
private static final Log log = LogFactory.getLog(XMLIterator.class);
private ThreadLocal<XMLInputFactory> inputFactory = new ThreadLocal<XMLInputFactory>() {
@Override
protected XMLInputFactory initialValue() {
return XMLInputFactory.newInstance();
}
};
private ThreadLocal<XMLOutputFactory> outputFactory = new ThreadLocal<XMLOutputFactory>() {
@Override
protected XMLOutputFactory initialValue() {
return XMLOutputFactory.newInstance();
}
};
private ThreadLocal<XMLEventFactory> eventFactory = new ThreadLocal<XMLEventFactory>() {
@Override
protected XMLEventFactory initialValue() {
return XMLEventFactory.newInstance();
}
};
public static final String UTF_8 = "UTF-8";
final XMLEventReader parser;
private XMLEvent current = null;
private String element;
private InputStream inputStream;
public XMLIterator(final String element, final InputStream inputStream) {
super();
this.element = element;
this.inputStream = inputStream;
this.parser = getParser();
try {
this.current = findElement(parser);
} catch (XMLStreamException e) {
log.warn("cannot init parser position. No element found: " + element);
current = null;
}
}
@Override
public boolean hasNext() {
return current != null;
}
@Override
public String next() {
String result = null;
try {
result = copy(parser);
current = findElement(parser);
return result;
} catch (XMLStreamException e) {
throw new RuntimeException(String.format("error copying xml, built so far: '%s'", result), e);
}
}
@Override
public void remove() {
throw new UnsupportedOperationException();
}
@SuppressWarnings("finally")
private String copy(final XMLEventReader parser) throws XMLStreamException {
final StringWriter result = new StringWriter();
try {
final XMLEventWriter writer = outputFactory.get().createXMLEventWriter(result);
final StartElement start = current.asStartElement();
final StartElement newRecord = eventFactory.get().createStartElement(start.getName(), start.getAttributes(), start.getNamespaces());
// new root record
writer.add(newRecord);
// copy the rest as it is
while (parser.hasNext()) {
final XMLEvent event = parser.nextEvent();
// TODO: replace with depth tracking instead of close tag tracking.
if (event.isEndElement() && event.asEndElement().getName().getLocalPart().equals(element)) {
writer.add(event);
break;
}
writer.add(event);
}
writer.close();
} finally {
return result.toString();
}
}
/**
* Looks for the next occurrence of the splitter element.
*
* @param parser
* @return
* @throws XMLStreamException
*/
private XMLEvent findElement(final XMLEventReader parser) throws XMLStreamException {
/*
* if (current != null && element.equals(current.asStartElement().getName().getLocalPart())) { return current; }
*/
XMLEvent peek = parser.peek();
if (peek != null && peek.isStartElement()) {
String name = peek.asStartElement().getName().getLocalPart();
if (element.equals(name)) { return peek; }
}
while (parser.hasNext()) {
final XMLEvent event = parser.nextEvent();
if (event != null && event.isStartElement()) {
String name = event.asStartElement().getName().getLocalPart();
if (element.equals(name)) { return event; }
}
}
return null;
}
private XMLEventReader getParser() {
try {
return inputFactory.get().createXMLEventReader(sanitize(inputStream));
} catch (XMLStreamException e) {
throw new RuntimeException(e);
}
}
private Reader sanitize(final InputStream in) {
final CharsetDecoder charsetDecoder = Charset.forName(UTF_8).newDecoder();
charsetDecoder.onMalformedInput(CodingErrorAction.REPLACE);
charsetDecoder.onUnmappableCharacter(CodingErrorAction.REPLACE);
return new InputStreamReader(in, charsetDecoder);
}
}

View File

@ -0,0 +1,216 @@
package eu.dnetlib.miscutils.jaxb;
import java.io.StringReader;
import java.io.StringWriter;
import java.lang.annotation.Annotation;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBElement;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;
import javax.xml.bind.Unmarshaller;
import javax.xml.bind.annotation.XmlRegistry;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.namespace.QName;
import javax.xml.transform.Result;
import javax.xml.transform.Source;
import javax.xml.transform.stream.StreamSource;
/**
* Common base class for implementing the Jaxb ObjectFactory pattern.
*
* @author marko
*
* @param <T>
* type of the roote element
*/
@XmlRegistry
public class JaxbFactory<T> {
/**
* jaxb context.
*/
private JAXBContext context;
/**
* class for the root element handled by this factory.
*/
private Class<T> clazz;
/**
* Prevent instantiating with 0 arguments.
*
* @throws JAXBException
*/
protected JaxbFactory() throws JAXBException {
// prevent instantiation
}
/**
* creates a new jaxb factory.
*
* This constructor is needed because spring constructor injection doesn't work well will varargs.
*
* @param clazz
* @throws JAXBException
*/
public JaxbFactory(final Class<? extends T> clazz) throws JAXBException {
this(clazz, new Class<?>[] {});
}
/**
* creates a new jaxb factory.
*
* @param clazz
* class for the root element
* @param classes
* other classes
* @throws JAXBException
* could happen
*/
@SuppressWarnings("unchecked")
public JaxbFactory(final Class<? extends T> clazz, Class<?>... classes) throws JAXBException {
Class<?>[] all = new Class<?>[classes.length + 1];
for (int i = 0; i < classes.length; i++)
all[i + 1] = classes[i];
all[0] = clazz;
this.clazz = (Class<T>) clazz;
context = JAXBContext.newInstance(all);
}
/**
* Create a new T instance.
*
* @return new T instance
*/
public T newInstance() {
try {
return clazz.newInstance();
} catch (InstantiationException e) {
throw new IllegalStateException("jaxb bean not instantiable, e");
} catch (IllegalAccessException e) {
throw new IllegalStateException("jaxb bean not instantiable, e");
}
}
/**
* Parses a given string and creates a java object.
*
* @param value
* serialized representation
* @return java object
* @throws JAXBException
* could happen
*/
public T parse(final String value) throws JAXBException {
return parse(new StreamSource(new StringReader(value)));
}
/**
* Parses a given source and creates a java object.
*
* @param source
* serialized representation
* @return java object
* @throws JAXBException
* could happen
*/
@SuppressWarnings("unchecked")
public T parse(final Source source) throws JAXBException {
final Unmarshaller unmarshaller = context.createUnmarshaller();
return (T) unmarshaller.unmarshal(source);
}
/**
* Serializes a java object to the xml representation.
*
* @param value
* java object
* @return xml string
* @throws JAXBException
* could happen
*/
public String serialize(final T value) throws JAXBException {
final Marshaller marshaller = context.createMarshaller();
final StringWriter buffer = new StringWriter();
marshaller.marshal(createElement(value), buffer);
return buffer.toString();
}
/**
* Serializes a java object to a xml sink.
*
* @param value
* java object
* @param result
* transform sink
* @throws JAXBException
* could happen
*/
public void serialize(final T value, final Result result) throws JAXBException {
final Marshaller marshaller = context.createMarshaller();
marshaller.marshal(createElement(value), result);
}
/**
* creates a jax element for a given java object.
*
* @param value
* java object
* @return jaxb element
*/
protected JAXBElement<T> createElement(final T value) {
final XmlRootElement ann = findAnnotation(XmlRootElement.class, clazz);
return new JAXBElement<T>(new QName(ann.namespace(), ann.name()), this.clazz, null, value);
}
/**
* recursively searches a given annotation.
*
* @param <T>
* annotation type
* @param annotation
* annotation to search
* @param clazz
* root of the class hierarchy.
* @return annotation
*/
private <X extends Annotation> X findAnnotation(final Class<X> annotation, final Class<?> clazz) {
if (clazz == null)
return null;
final X ann = clazz.getAnnotation(annotation);
if (ann != null)
return ann;
for (Class<?> iface : clazz.getInterfaces()) {
final X iann = findAnnotation(annotation, iface);
if (iann != null)
return iann;
}
final X parent = findAnnotation(annotation, clazz.getSuperclass());
if (parent != null)
return parent;
return null;
}
public JAXBContext getContext() {
return context;
}
public void setContext(final JAXBContext context) {
this.context = context;
}
public Class<? extends T> getClazz() {
return clazz;
}
public void setClazz(final Class<T> clazz) {
this.clazz = clazz;
}
}

View File

@ -0,0 +1,53 @@
package eu.dnetlib.miscutils.maps;
import java.util.Queue;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentLinkedQueue;
/**
*
* @author claudio
*
* @param <K>
* @param <V>
*/
public class ConcurrentSizedMap<K, V> extends ConcurrentHashMap<K, V> {
private static final long serialVersionUID = 5864196164431521782L;
public int DEFAULT_SIZE = 4;
private int queueSize;
private Queue<K> queue;
public ConcurrentSizedMap() {
super();
queue = new ConcurrentLinkedQueue<K>();
this.queueSize = DEFAULT_SIZE;
}
@Override
public V put(K key, V value) {
queue.add(key);
if (queue.size() > queueSize)
super.remove(queue.poll());
return super.put(key, value);
}
@Override
public V remove(Object key) {
queue.remove(key);
return super.remove(key);
}
public void setQueueSize(int queueSize) {
this.queueSize = queueSize;
}
public int getQueueSize() {
return queueSize;
}
}

View File

@ -0,0 +1 @@
net.sf.saxon.TransformerFactoryImpl

View File

@ -0,0 +1,22 @@
package eu.dnetlib.miscutils.collections;
import static org.junit.Assert.assertEquals;
import java.util.ArrayList;
import java.util.List;
import org.junit.Test;
public class AffixCollectionTest {
@Test
public void testIterator() {
final List<String> list = new ArrayList<String>();
list.add("100");
final AffixCollection mapped = new AffixCollection(list, "_test");
for (String el : mapped)
assertEquals("check array", "100_test", el);
}
}

View File

@ -0,0 +1,491 @@
/**
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package eu.dnetlib.miscutils.collections;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.UUID;
import org.junit.Test;
/**
* Tests for BloomFilter.java
*
* @author Magnus Skjegstad <magnus@skjegstad.com>
*/
public class BloomFilterTest {
static Random r = new Random();
@Test
public void testConstructorCNK() throws Exception {
System.out.println("BloomFilter(c,n,k)");
for (int i = 0; i < 10000; i++) {
double c = r.nextInt(20) + 1;
int n = r.nextInt(10000) + 1;
int k = r.nextInt(20) + 1;
BloomFilter<?> bf = new BloomFilter<Object>(c, n, k);
assertEquals(bf.getK(), k);
assertEquals(bf.getExpectedBitsPerElement(), c, 0);
assertEquals(bf.getExpectedNumberOfElements(), n);
assertEquals(bf.size(), c*n, 0);
}
}
/**
* Test of createHash method, of class BloomFilter.
* @throws Exception
*/
@Test
public void testCreateHash_String() throws Exception {
System.out.println("createHash");
String val = UUID.randomUUID().toString();
int result1 = BloomFilter.createHash(val);
int result2 = BloomFilter.createHash(val);
assertEquals(result2, result1);
int result3 = BloomFilter.createHash(UUID.randomUUID().toString());
assertNotSame(result3, result2);
int result4 = BloomFilter.createHash(val.getBytes("UTF-8"));
assertEquals(result4, result1);
}
/**
* Test of createHash method, of class BloomFilter.
* @throws UnsupportedEncodingException
*/
@Test
public void testCreateHash_byteArr() throws UnsupportedEncodingException {
System.out.println("createHash");
String val = UUID.randomUUID().toString();
byte[] data = val.getBytes("UTF-8");
int result1 = BloomFilter.createHash(data);
int result2 = BloomFilter.createHash(val);
assertEquals(result1, result2);
}
/**
* Test of createHash method, of class BloomFilter.
* @throws UnsupportedEncodingException
*/
@Test
public void testCreateHashes_byteArr() throws UnsupportedEncodingException {
System.out.println("createHashes");
String val = UUID.randomUUID().toString();
byte[] data = val.getBytes("UTF-8");
int[] result1 = BloomFilter.createHashes(data, 10);
int[] result2 = BloomFilter.createHashes(data, 10);
assertEquals(result1.length, 10);
assertEquals(result2.length, 10);
assertArrayEquals(result1, result2);
int[] result3 = BloomFilter.createHashes(data, 5);
assertEquals(result3.length, 5);
for (int i = 0; i < result3.length; i++)
assertEquals(result3[i], result1[i]);
}
/**
* Test of equals method, of class BloomFilter.
* @throws UnsupportedEncodingException
*/
@Test
public void testEquals() throws UnsupportedEncodingException {
System.out.println("equals");
BloomFilter<String> instance1 = new BloomFilter<String>(1000, 100);
BloomFilter<String> instance2 = new BloomFilter<String>(1000, 100);
for (int i = 0; i < 100; i++) {
String val = UUID.randomUUID().toString();
instance1.add(val);
instance2.add(val);
}
assert(instance1.equals(instance2));
assert(instance2.equals(instance1));
instance1.add("Another entry"); // make instance1 and instance2 different before clearing
instance1.clear();
instance2.clear();
assert(instance1.equals(instance2));
assert(instance2.equals(instance1));
for (int i = 0; i < 100; i++) {
String val = UUID.randomUUID().toString();
instance1.add(val);
instance2.add(val);
}
assertTrue(instance1.equals(instance2));
assertTrue(instance2.equals(instance1));
}
/**
* Test of hashCode method, of class BloomFilter.
* @throws UnsupportedEncodingException
*/
@Test
public void testHashCode() throws UnsupportedEncodingException {
System.out.println("hashCode");
BloomFilter<String> instance1 = new BloomFilter<String>(1000, 100);
BloomFilter<String> instance2 = new BloomFilter<String>(1000, 100);
assertTrue(instance1.hashCode() == instance2.hashCode());
for (int i = 0; i < 100; i++) {
String val = UUID.randomUUID().toString();
instance1.add(val);
instance2.add(val);
}
assertTrue(instance1.hashCode() == instance2.hashCode());
instance1.clear();
instance2.clear();
assertTrue(instance1.hashCode() == instance2.hashCode());
instance1 = new BloomFilter<String>(100, 10);
instance2 = new BloomFilter<String>(100, 9);
assertFalse(instance1.hashCode() == instance2.hashCode());
instance1 = new BloomFilter<String>(100, 10);
instance2 = new BloomFilter<String>(99, 9);
assertFalse(instance1.hashCode() == instance2.hashCode());
instance1 = new BloomFilter<String>(100, 10);
instance2 = new BloomFilter<String>(50, 10);
assertFalse(instance1.hashCode() == instance2.hashCode());
}
/**
* Test of expectedFalsePositiveProbability method, of class BloomFilter.
*/
@Test
public void testExpectedFalsePositiveProbability() {
// These probabilities are taken from the bloom filter probability table at
// http://pages.cs.wisc.edu/~cao/papers/summary-cache/node8.html
System.out.println("expectedFalsePositiveProbability");
BloomFilter<?> instance = new BloomFilter<Object>(1000, 100);
double expResult = 0.00819; // m/n=10, k=7
double result = instance.expectedFalsePositiveProbability();
assertEquals(instance.getK(), 7);
assertEquals(expResult, result, 0.000009);
instance = new BloomFilter<Object>(100, 10);
expResult = 0.00819; // m/n=10, k=7
result = instance.expectedFalsePositiveProbability();
assertEquals(instance.getK(), 7);
assertEquals(expResult, result, 0.000009);
instance = new BloomFilter<Object>(20, 10);
expResult = 0.393; // m/n=2, k=1
result = instance.expectedFalsePositiveProbability();
assertEquals(1, instance.getK());
assertEquals(expResult, result, 0.0005);
instance = new BloomFilter<Object>(110, 10);
expResult = 0.00509; // m/n=11, k=8
result = instance.expectedFalsePositiveProbability();
assertEquals(8, instance.getK());
assertEquals(expResult, result, 0.00001);
}
/**
* Test of clear method, of class BloomFilter.
*/
@Test
public void testClear() {
System.out.println("clear");
BloomFilter<?> instance = new BloomFilter<Object>(1000, 100);
for (int i = 0; i < instance.size(); i++)
instance.setBit(i, true);
instance.clear();
for (int i = 0; i < instance.size(); i++)
assertSame(instance.getBit(i), false);
}
/**
* Test of add method, of class BloomFilter.
* @throws Exception
*/
@Test
public void testAdd() throws Exception {
System.out.println("add");
BloomFilter<String> instance = new BloomFilter<String>(1000, 100);
for (int i = 0; i < 100; i++) {
String val = UUID.randomUUID().toString();
instance.add(val);
assert(instance.contains(val));
}
}
/**
* Test of addAll method, of class BloomFilter.
* @throws Exception
*/
@Test
public void testAddAll() throws Exception {
System.out.println("addAll");
List<String> v = new ArrayList<String>();
BloomFilter<String> instance = new BloomFilter<String>(1000, 100);
for (int i = 0; i < 100; i++)
v.add(UUID.randomUUID().toString());
instance.addAll(v);
for (int i = 0; i < 100; i++)
assert(instance.contains(v.get(i)));
}
/**
* Test of contains method, of class BloomFilter.
* @throws Exception
*/
@Test
public void testContains() throws Exception {
System.out.println("contains");
BloomFilter<String> instance = new BloomFilter<String>(10000, 10);
for (int i = 0; i < 10; i++) {
instance.add(Integer.toBinaryString(i));
assert(instance.contains(Integer.toBinaryString(i)));
}
assertFalse(instance.contains(UUID.randomUUID().toString()));
}
/**
* Test of containsAll method, of class BloomFilter.
* @throws Exception
*/
@Test
public void testContainsAll() throws Exception {
System.out.println("containsAll");
List<String> v = new ArrayList<String>();
BloomFilter<String> instance = new BloomFilter<String>(1000, 100);
for (int i = 0; i < 100; i++) {
v.add(UUID.randomUUID().toString());
instance.add(v.get(i));
}
assert(instance.containsAll(v));
}
/**
* Test of getBit method, of class BloomFilter.
*/
@Test
public void testGetBit() {
System.out.println("getBit");
BloomFilter<?> instance = new BloomFilter<Object>(1000, 100);
Random r = new Random();
for (int i = 0; i < 100; i++) {
boolean b = r.nextBoolean();
instance.setBit(i, b);
assertSame(instance.getBit(i), b);
}
}
/**
* Test of setBit method, of class BloomFilter.
*/
@Test
public void testSetBit() {
System.out.println("setBit");
BloomFilter<?> instance = new BloomFilter<Object>(1000, 100);
for (int i = 0; i < 100; i++) {
instance.setBit(i, true);
assertSame(instance.getBit(i), true);
}
for (int i = 0; i < 100; i++) {
instance.setBit(i, false);
assertSame(instance.getBit(i), false);
}
}
/**
* Test of size method, of class BloomFilter.
*/
@Test
public void testSize() {
System.out.println("size");
for (int i = 100; i < 1000; i++) {
BloomFilter<?> instance = new BloomFilter<Object>(i, 10);
assertEquals(instance.size(), i);
}
}
/** Test error rate *
* @throws UnsupportedEncodingException
*/
@Test
public void testFalsePositiveRate1() throws UnsupportedEncodingException {
// Numbers are from // http://pages.cs.wisc.edu/~cao/papers/summary-cache/node8.html
System.out.println("falsePositiveRate1");
for (int j = 10; j < 21; j++) {
System.out.print(j-9 + "/11");
List<byte[]> v = new ArrayList<byte[]>();
BloomFilter<Object> instance = new BloomFilter<Object>(100*j,100);
for (int i = 0; i < 100; i++) {
byte[] bytes = new byte[100];
r.nextBytes(bytes);
v.add(bytes);
}
instance.addAll(v);
long f = 0;
double tests = 300000;
for (int i = 0; i < tests; i++) {
byte[] bytes = new byte[100];
r.nextBytes(bytes);
if (instance.contains(bytes)) {
if (!v.contains(bytes)) {
f++;
}
}
}
double ratio = f / tests;
System.out.println(" - got " + ratio + ", math says " + instance.expectedFalsePositiveProbability());
assertEquals(instance.expectedFalsePositiveProbability(), ratio, 0.01);
}
}
/** Test for correct k **/
@Test
public void testGetK() {
// Numbers are from http://pages.cs.wisc.edu/~cao/papers/summary-cache/node8.html
System.out.println("testGetK");
BloomFilter<?> instance = null;
instance = new BloomFilter<Object>(2, 1);
assertEquals(1, instance.getK());
instance = new BloomFilter<Object>(3, 1);
assertEquals(2, instance.getK());
instance = new BloomFilter<Object>(4, 1);
assertEquals(3, instance.getK());
instance = new BloomFilter<Object>(5, 1);
assertEquals(3, instance.getK());
instance = new BloomFilter<Object>(6, 1);
assertEquals(4, instance.getK());
instance = new BloomFilter<Object>(7, 1);
assertEquals(5, instance.getK());
instance = new BloomFilter<Object>(8, 1);
assertEquals(6, instance.getK());
instance = new BloomFilter<Object>(9, 1);
assertEquals(6, instance.getK());
instance = new BloomFilter<Object>(10, 1);
assertEquals(7, instance.getK());
instance = new BloomFilter<Object>(11, 1);
assertEquals(8, instance.getK());
instance = new BloomFilter<Object>(12, 1);
assertEquals(8, instance.getK());
}
/**
* Test of contains method, of class BloomFilter.
*/
@Test
public void testContains_GenericType() {
System.out.println("contains");
int items = 100;
BloomFilter<String> instance = new BloomFilter<String>(0.01, items);
for (int i = 0; i < items; i++) {
String s = UUID.randomUUID().toString();
instance.add(s);
assertTrue(instance.contains(s));
}
}
/**
* Test of contains method, of class BloomFilter.
*/
@Test
public void testContains_byteArr() {
System.out.println("contains");
int items = 100;
BloomFilter<?> instance = new BloomFilter<Object>(0.01, items);
for (int i = 0; i < items; i++) {
byte[] bytes = new byte[500];
r.nextBytes(bytes);
instance.add(bytes);
assertTrue(instance.contains(bytes));
}
}
/**
* Test of count method, of class BloomFilter.
*/
@Test
public void testCount() {
System.out.println("count");
int expResult = 100;
BloomFilter<String> instance = new BloomFilter<String>(0.01, expResult);
for (int i = 0; i < expResult; i++) {
byte[] bytes = new byte[100];
r.nextBytes(bytes);
instance.add(bytes);
}
int result = instance.count();
assertEquals(expResult, result);
instance = new BloomFilter<String>(0.01, expResult);
for (int i = 0; i < expResult; i++) {
instance.add(UUID.randomUUID().toString());
}
result = instance.count();
assertEquals(expResult, result);
}
}

View File

@ -0,0 +1,47 @@
package eu.dnetlib.miscutils.collections;
import static org.junit.Assert.assertTrue;
import java.util.ArrayList;
import java.util.List;
import org.junit.Test;
import eu.dnetlib.miscutils.functional.CompositeUnaryFunction;
import eu.dnetlib.miscutils.functional.UnaryFunction;
public class FilteredCollectionTest {
@Test
public void testFilterComposition() {
final List<Integer> list = new ArrayList<Integer>();
list.add(1);
list.add(4);
list.add(8);
final Filter<Integer> fi1 = new Filter<Integer>() { // NOPMD
@Override
public Boolean evaluate(final Integer arg) {
return arg < 8;
}
};
final UnaryFunction<Integer, Integer> square = new UnaryFunction<Integer, Integer>() {
@Override
public Integer evaluate(final Integer arg) {
return arg * arg;
}
};
final FilteredCollection<Integer> fic = new FilteredCollection<Integer>(list, fi1);
for (Integer el : fic)
assertTrue("check array", el < 8);
final CompositeUnaryFunction<Boolean, Integer> cf1 = new CompositeUnaryFunction<Boolean, Integer>(fi1);
final FilteredCollection<Integer> fc2 = new FilteredCollection<Integer>(list, cf1.of(square));
for (Integer el : fc2)
assertTrue("check array", el < 8);
}
}

View File

@ -0,0 +1,29 @@
package eu.dnetlib.miscutils.collections;
import static org.junit.Assert.assertEquals;
import java.util.ArrayList;
import java.util.List;
import org.junit.Test;
import eu.dnetlib.miscutils.functional.UnaryFunction;
public class MappedCollectionTest {
@Test
public void testIterator() {
final List<Integer> list = new ArrayList<Integer>();
list.add(100);
final MappedCollection<String, Integer> mapped = new MappedCollection<String, Integer>(list, new UnaryFunction<String, Integer>() { //NOPMD
@Override
public String evaluate(final Integer arg) {
return arg.toString();
}
});
for (String el : mapped)
assertEquals("check array", el, "100");
}
}

View File

@ -0,0 +1,69 @@
package eu.dnetlib.miscutils.collections;
import java.io.StringReader;
import java.util.ArrayList;
import java.util.List;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.Node;
import org.dom4j.io.SAXReader;
import org.junit.Test;
import static org.junit.Assert.*; // NOPMD
public class TypeFilteredCollectionTest {
private void checkContainsTestString(final Iterable<String> iter) {
int count = 0; // NOPMD
for (String el : iter) {
assertEquals("check array", el, "test");
count++; // NOPMD
}
assertEquals("check count", count, 1);
}
@Test
public void testFilter() {
final List<Object> list = new ArrayList<Object>();
list.add(1);
list.add("test");
final TypeFilteredCollection<Object, String> tfc;
tfc = new TypeFilteredCollection<Object, String>(list, String.class);
checkContainsTestString(tfc);
}
@Test
public void testNull() {
final List<Object> list = new ArrayList<Object>();
assertNotNull("dummy", list);
list.add(null);
list.add("test");
final TypeFilteredCollection<Object, String> tfc;
tfc = new TypeFilteredCollection<Object, String>(list, String.class);
checkContainsTestString(tfc);
}
@Test
public void testJDom() throws DocumentException {
final String xmlSource = "<root><child/>xxxx<child/>xxxx</root>";
final Document document = new SAXReader().read(new StringReader(xmlSource));
@SuppressWarnings("unchecked")
final List<Node> children = document.selectNodes("//child");
final TypeFilteredCollection<Node, Element> tfc;
tfc = new TypeFilteredCollection<Node, Element>(children, Element.class);
for (Element el : tfc) {
assertEquals("check array", el.asXML(), "<child/>");
}
}
}

View File

@ -0,0 +1,40 @@
package eu.dnetlib.miscutils.datetime;
import java.text.ParseException;
import java.util.Date;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
public class DateUtilsTest {
private final DateUtils dateUtils = new DateUtils();
@Test
public void testGetDuration() {
String theDate = "1900-01-01T00:13:57";
String duration = dateUtils.getDuration(theDate);
assertEquals("00:13:57", duration);
}
@Test
public void getISOdateTimeFromLong(){
Long dateLong = Long.parseLong("1520531435465");
String iso = DateUtils.calculate_ISO8601(dateLong);
System.out.println(iso);
}
@Test
public void test1() throws ParseException {
String fromDate = "2019-04-11";
Date date = org.apache.commons.lang3.time.DateUtils.parseDate(
fromDate,
new String[] { "yyyy-MM-dd", "yyyy-MM-dd'T'HH:mm:ssXXX", "yyyy-MM-dd'T'HH:mm:ss.SSSX", "yyyy-MM-dd'T'HH:mm:ssZ",
"yyyy-MM-dd'T'HH:mm:ss.SX" });
long timestamp = date.toInstant().toEpochMilli();
System.out.println(timestamp);
}
}

View File

@ -0,0 +1,38 @@
/**
*
*/
package eu.dnetlib.miscutils.dom4j;
import static org.junit.Assert.assertEquals;
import java.io.StringReader;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;
import org.junit.Test;
/**
* @author marko
*
*/
public class XPathHelperTest {
/**
* Test method for {@link eu.dnetlib.miscutils.dom4j.XPathHelper#selectElements(org.dom4j.Node, java.lang.String)}.
*
* @throws DocumentException
*/
@Test
public void testSelectElements() throws DocumentException {
final String xmlSource = "<root><child/>xxxx<child/>xxxx</root>";
final Document document = new SAXReader().read(new StringReader(xmlSource));
for (Element el : XPathHelper.selectElements(document, "//child")) {
assertEquals("check elements", el.asXML(), "<child/>");
}
}
}

View File

@ -0,0 +1,86 @@
package eu.dnetlib.miscutils.functional;
import static org.junit.Assert.*; // NOPMD
import org.junit.Test;
public class CompositeUnaryFunctionTest {
@Test
public void testOf() {
final UnaryFunction<String, Integer> toStringBase = new UnaryFunction<String, Integer>() { // NOPMD
@Override
public String evaluate(final Integer arg) {
return arg.toString();
}
};
final UnaryFunction<Integer, String> fromStringBase = new UnaryFunction<Integer, String>() {
@Override
public Integer evaluate(final String arg) {
return Integer.decode(arg);
}
};
final CompositeUnaryFunction<String, Integer> toString = new CompositeUnaryFunction<String, Integer>(toStringBase);
final CompositeUnaryFunction<Integer, String> fromString = new CompositeUnaryFunction<Integer, String>(fromStringBase);
assertEquals("evaluation", toString.evaluate(10), "10");
assertEquals("evaluation", fromString.evaluate("10"), (Integer) 10);
final UnaryFunction<String, String> stringIdentity = toString.of(fromString);
final UnaryFunction<Integer, Integer> integerIdentity = fromString.of(toString);
final UnaryFunction<Integer, Integer> integerIdentity2 = fromString.of(stringIdentity).of(toString).of(integerIdentity);
assertEquals("string evaluation", stringIdentity.evaluate("10"), "10");
assertEquals("integer evaluation", integerIdentity.evaluate(10), (Integer) 10);
assertEquals("integer identity", integerIdentity2.evaluate(10), (Integer) 10);
}
private transient int calls;
private transient final static int TIMES = 100;
@Test
public void testRecursive() {
calls = 0;
final UnaryFunction<Integer, Integer> incrementBase = new UnaryFunction<Integer, Integer>() { // NOPMD
@Override
public Integer evaluate(final Integer arg) {
calls++;
return arg + 1;
}
};
final CompositeUnaryFunction<Integer, Integer> increment = new CompositeUnaryFunction<Integer, Integer>(incrementBase);
CompositeUnaryFunction<Integer, Integer> comp = increment;
for (int i = 1; i <= 100; i++) {
assertEquals("compare", comp.evaluate(0), (Integer) i);
comp = comp.of(increment);
}
assertEquals("number of calls", calls, (TIMES * (TIMES + 1) / 2));
}
@Test
public void testCurry() {
final UnaryFunction<UnaryFunction<Integer, Integer>, Integer> add = new UnaryFunction<UnaryFunction<Integer, Integer>, Integer>() { // NOPMD
@Override
public UnaryFunction<Integer, Integer> evaluate(final Integer arg) {
return new UnaryFunction<Integer, Integer>() {
@Override
public Integer evaluate(final Integer brg) {
return arg + brg;
}
};
}
};
final UnaryFunction<Integer, Integer> increment = add.evaluate(1);
assertEquals("check add", add.evaluate(1).evaluate(2), (Integer) 3);
assertEquals("check increment", increment.evaluate(1), (Integer) 2);
}
}

View File

@ -0,0 +1,58 @@
package eu.dnetlib.miscutils.functional;
import static org.junit.Assert.*;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import org.junit.Before;
import org.junit.Test;
import eu.dnetlib.miscutils.functional.ThreadSafeUnaryFunction;
import eu.dnetlib.miscutils.functional.UnaryFunction;
public class ThreadSafeUnaryFunctionTest {
/**
* Object under test.
*/
private ThreadSafeUnaryFunction<String, Integer> tsUnaryFunction;
private final static int N_THREAD = 10;
private ExecutorService executor;
@Before
public void setUp() {
executor = Executors.newFixedThreadPool(N_THREAD);
}
/**
* method creates N_THREAD threads such that each one performs a function.evaluate call
* @param function
*/
private void createThreads(final ThreadSafeUnaryFunction<String, Integer> function) {
for (int i = 0; i < N_THREAD; i++) {
final Integer j = i;
executor.execute(new Runnable() {
@Override
public void run() {
assertEquals(String.valueOf(j), function.evaluate(j));
}
});
}
}
@Test
public void testThreadSafeUnaryFunction_1() {
tsUnaryFunction = new ThreadSafeUnaryFunction<String, Integer>(new ThreadLocal<UnaryFunction<String, Integer>>() {
@Override
protected synchronized UnaryFunction<String, Integer> initialValue() {
return new UnsafeUnaryFunction();
}
});
createThreads(tsUnaryFunction);
}
}

View File

@ -0,0 +1,10 @@
package eu.dnetlib.miscutils.functional;
import eu.dnetlib.miscutils.functional.UnaryFunction;
public class UnsafeUnaryFunction implements UnaryFunction<String, Integer> {
@Override
public String evaluate(Integer arg) {
return String.valueOf(arg);
}
}

View File

@ -0,0 +1,34 @@
package eu.dnetlib.miscutils.functional.string;
import java.io.IOException;
import java.io.InputStream;
import java.io.StringWriter;
import org.apache.commons.io.IOUtils;
import org.junit.Test;
public class EscapeUnescapeTest {
@Test
public void testEscape() throws IOException {
String xml = getRecord();
System.out.println(xml);
System.out.println("##############");
String escaped = new EscapeHtml().evaluate(xml);
System.out.println(escaped);
String unescaped = new UnescapeHtml().evaluate(escaped);
System.out.println("##############");
System.out.println(unescaped);
}
private String getRecord() throws IOException {
InputStream is = getClass().getResourceAsStream("record.xml");
StringWriter sw = new StringWriter();
IOUtils.copy(is, sw);
return sw.toString();
}
}

View File

@ -0,0 +1,43 @@
package eu.dnetlib.miscutils.functional.string;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import java.io.StringWriter;
import org.apache.commons.io.IOUtils;
import org.junit.Test;
public class SanitizerTest {
@Test
public void testIdentity() {
verifyIdentity("+-@°#()!$%&/()?' ");
verifyIdentity("asça");
verifyIdentity("qwéèrtç°§");
verifyIdentity("AÁaáCĆcćEÉeéIÍiíLĹlĺNŃnńOÓoóRŔrŕSŚsśUÚuúYÝyýZŹzź");
verifyIdentity("AÂaâCĈcĉEÊeêGĜgĝHĤhĥIÎiîJĴjĵOÔoôSŜsŝUÛuûWŴwŵYŶyŷ");
verifyIdentity("CÇcçGĢgģKĶkķLĻlļNŅnņRŖrŗSŞsşTŢtţ");
verifyIdentity("ΑΒΓΔΕΖΗΘΙΚΛΜΝΞΟΠΡΣΤΥΦΧΨΩΆΈΉΊΌΎΏΪΫαβγδεζηθικλμνξοπρσςτυφχψωάέήίόύώΐΰ");
verifyIdentity("АБВГДЕЁЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯ");
verifyIdentity("абвгдеёжзийклмнопрстуфхцчшщъыьэюя");
verifyIdentity("ـآ آ ـا ا بـبـب ب تـتـت ت ثـثـث ث جـجـج ج حـحـح ح خـخـخ خ ـد د ـذ ذ ـر ر ـز ز سـسـس س");
}
@Test
public void testInvalid() throws Exception {
StringWriter sw = new StringWriter();
IOUtils.copy(getClass().getResourceAsStream("invalid.txt"), sw);
String pre = sw.toString();
String post = Sanitizer.sanitize(pre);
assertFalse(pre.equals(post));
}
private void verifyIdentity(String s) {
assertEquals(s, Sanitizer.sanitize(s));
}
}

View File

@ -0,0 +1,41 @@
package eu.dnetlib.miscutils.functional.xml;
import static org.junit.Assert.*;
import java.io.IOException;
import javax.xml.transform.TransformerFactory;
import org.apache.commons.io.IOUtils;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.runners.MockitoJUnit44Runner;
import org.springframework.core.io.ClassPathResource;
@RunWith(MockitoJUnit44Runner.class)
public class ApplyXsltTest {
TransformerFactory tf = TransformerFactory.newInstance();
private static final Class<?> transformerClass = net.sf.saxon.TransformerFactoryImpl.class;
@Test
public void testTransformerFactoryType() {
assertEquals(tf.getClass(), transformerClass);
}
@Test
public void applyXslt() throws IOException {
String record = IOUtils.toString((new ClassPathResource("/eu/dnetlib/miscutils/functional/xml/sampleRecord.xml")).getInputStream());
String layout = IOUtils.toString((new ClassPathResource("/eu/dnetlib/miscutils/functional/xml/sampleIndexLayout.xml")).getInputStream());
String indexXsltOfXslt = IOUtils.toString((new ClassPathResource("/eu/dnetlib/miscutils/functional/xml/layoutToRecordStylesheet.xsl")).getInputStream());
ApplyXslt applyXslt = new ApplyXslt(IOUtils.toString((new ClassPathResource("/eu/dnetlib/miscutils/functional/xml/recordStylesheet.xsl")).getInputStream()));
ApplyXslt xslt1 = new ApplyXslt(indexXsltOfXslt);
String indexXslt = xslt1.evaluate(layout);
ApplyXslt xslt2 = new ApplyXslt(indexXslt);
String response = xslt2.evaluate(record);
System.out.println(response);
}
}

View File

@ -0,0 +1,19 @@
package eu.dnetlib.miscutils.functional.xml;
import org.junit.Before;
import org.junit.Test;
public class IndentXmlStringTest {
@Before
public void setUp() throws Exception {
}
@Test
public void testEvaluate() {
String indented = new IndentXmlString().evaluate("<root><a/></root>");
System.out.println(indented);
}
}

View File

@ -0,0 +1,107 @@
package eu.dnetlib.miscutils.functional.xml;
import static org.junit.Assert.assertEquals;
import java.io.StringReader;
import java.io.StringWriter;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;
import org.dom4j.Document;
import org.dom4j.io.SAXReader;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.runners.MockitoJUnit44Runner;
@RunWith(MockitoJUnit44Runner.class)
public class dnetFunctionsTest {
private static final String XSLT =
"<?xml version='1.0' encoding='UTF-8'?>" +
"<xsl:stylesheet version='2.0' xmlns:xsl='http://www.w3.org/1999/XSL/Transform' xmlns:dnet='eu.dnetlib.miscutils.functional.xml.DnetXsltFunctions'>" +
"<xsl:template match='/'>" +
" <OUTS>" +
" <OUTPUT decade='{dnet:decade(//INPUT/DATE)}' />" +
" <OUTPUT year='{dnet:extractYear(//INPUT/DATE)}' />" +
" </OUTS>" +
"</xsl:template>" +
"</xsl:stylesheet>";
private Transformer transformer;
@Before
public void setUp() {
try {
transformer = TransformerFactory.newInstance().newTransformer(new StreamSource(new StringReader(XSLT)));
} catch (Exception e) {
System.out.println("**** INITIALIZATION FAILED ****");
}
}
@Test
public void testDecade_1() throws Exception {
assertEquals("1980-1989", process("primi anni 80", "decade"));
}
@Test
public void testDecade_2() throws Exception {
assertEquals("2000-2009", process("04-05-2007", "decade"));
}
@Test
public void testDecade_3() throws Exception {
assertEquals("1960-1969", process("1964", "decade"));
}
@Test
public void testDecade_4() throws Exception {
assertEquals("n/a", process("XXXXXXXXXXXX", "decade"));
}
@Test
public void testDecade_5() throws Exception {
assertEquals("1880-1889", process(" 1887-01-01 ", "decade"));
}
@Test
public void testDecade_6() throws Exception {
assertEquals("1880-1889", process("\n\n 1887-01-01 \n\n", "decade"));
}
@Test
public void testDecade_7() throws Exception {
assertEquals("1840-1849", process(" 1840-03-05 ", "decade"));
}
@Test
public void testYear_1() throws Exception {
assertEquals("1840", process("1840-03-05", "year"));
}
@Test
public void testYear_2() throws Exception {
assertEquals("1840", process("1840/03/05", "year"));
}
private String process(String s, String attr) throws Exception {
String xml = "<INPUT><DATE>" + s + "</DATE></INPUT>";
StringWriter strw = new StringWriter();
transformer.transform(new StreamSource(new StringReader(xml)), new StreamResult(strw));
Document document = (new SAXReader()).read(new StringReader((strw.toString())));
System.out.println(document.asXML());
String res = document.valueOf("/OUTS/OUTPUT/@" + attr);
System.out.println(s + " --> " + res);
return res;
}
}

View File

@ -0,0 +1,63 @@
package eu.dnetlib.miscutils.hstree;
import static org.junit.Assert.assertNotNull;
import org.junit.Test;
import eu.dnetlib.miscutils.hstree.sample.resources.ChildResource;
import eu.dnetlib.miscutils.hstree.sample.resources.SampleResource;
import eu.dnetlib.miscutils.hstree.sample.resources.SubResource;
import eu.dnetlib.miscutils.hstree.sample.tree.FirstChild;
import eu.dnetlib.miscutils.hstree.sample.tree.MyTreeNode;
import eu.dnetlib.miscutils.hstree.sample.tree.RootTree;
public class TreeNodeTest {
private static final String EXISTS = "exists";
/**
* This test simply shows how to create a statically checked tree. The tree grammar for this test is defined in
* package eu.rinfrastructures.genericstest.sample.tree and it contains resource payloads defined in package
* eu.rinfrastructures.genericstest.sample.resources
*/
@Test
public void simpleTest() {
final MyTreeNode<SampleResource, ChildResource, FirstChild> root = new RootTree(new SampleResource());
final FirstChild ch1 = root.addChild(new ChildResource());
assertNotNull(EXISTS, ch1);
ch1.addChild(new SubResource());
ch1.addChild(new SubResource());
final FirstChild ch2 = root.addChild(new ChildResource());
assertNotNull(EXISTS, ch2);
ch2.addChild(new SubResource());
ch2.addChild(new SubResource());
ch2.addChild(new SubResource());
}
@Test
public void typeSafeness() {
final MyTreeNode<SampleResource, ChildResource, FirstChild> root = new RootTree(new SampleResource());
final FirstChild ch1 = root.addChild(new ChildResource());
assertNotNull(EXISTS, ch1);
ch1.addChild(new SubResource());
// ILLEGAL:
//c1.addChild(new SampleResource());
}
@Test
public void cascade() {
final MyTreeNode<SampleResource, ChildResource, FirstChild> root = new RootTree(new SampleResource());
assertNotNull(EXISTS, root);
root.addChild(new ChildResource()).appendChild(new SubResource()).appendChild(new SubResource()).addChild(new SubResource());
}
}

View File

@ -0,0 +1,90 @@
package eu.dnetlib.miscutils.hstree;
import static org.junit.Assert.*; // NOPMD
import org.junit.Before;
import org.junit.Test;
import eu.dnetlib.miscutils.hstree.sample.resources.ChildResource;
import eu.dnetlib.miscutils.hstree.sample.resources.SampleResource;
import eu.dnetlib.miscutils.hstree.sample.resources.SubResource;
import eu.dnetlib.miscutils.hstree.sample.tree.FirstChild;
import eu.dnetlib.miscutils.hstree.sample.tree.MyComputingVisitor;
import eu.dnetlib.miscutils.hstree.sample.tree.MyLoggingVisitor;
import eu.dnetlib.miscutils.hstree.sample.tree.MyTreeNode;
import eu.dnetlib.miscutils.hstree.sample.tree.MyTreeVisitor;
import eu.dnetlib.miscutils.hstree.sample.tree.RootTree;
public class VisitorTest {
transient RootTree root = null;
transient MyTreeVisitor loggingVisitor = null;
transient MyComputingVisitor computingVisitor = null;
@Before
public void setUp() throws Exception {
root = new RootTree(new SampleResource());
root.addChild(new ChildResource()).appendChild(new SubResource()).appendChild(new SubResource()).addChild(new SubResource());
loggingVisitor = new MyLoggingVisitor();
computingVisitor = new MyComputingVisitor();
}
@Test
public void testVisit() {
final MyTreeNode<SampleResource, ChildResource, FirstChild> root = new RootTree(new SampleResource());
assertNotNull("exists", root);
final FirstChild ch1 = root.addChild(new ChildResource());
ch1.addChild(new SubResource());
ch1.addChild(new SubResource());
final FirstChild ch2 = root.addChild(new ChildResource());
ch2.addChild(new SubResource());
ch2.addChild(new SubResource());
ch2.addChild(new SubResource());
root.breadthFirst(loggingVisitor);
}
@Test
public void testVisit2() {
final MyTreeNode<SampleResource, ChildResource, FirstChild> root = new RootTree(new SampleResource());
assertNotNull("exists", root);
root.addChild(new ChildResource()).appendChild(new SubResource()).appendChild(new SubResource()).addChild(new SubResource());
root.appendChild(new ChildResource()).appendChild(new ChildResource()).appendChild(new ChildResource()).addChild(new ChildResource()).addChild(
new SubResource());
root.breadthFirst(loggingVisitor);
}
@Test
public void testVisit3() {
final MyTreeNode<SampleResource, ChildResource, FirstChild> root = new RootTree(new SampleResource());
assertNotNull("exists", root);
root.addChild(new ChildResource()).appendChild(new SubResource()).appendChild(new SubResource()).addChild(new SubResource());
root.appendChild(new ChildResource()).appendChild(new ChildResource()).appendChild(new ChildResource()).addChild(new ChildResource()).addChild(
new SubResource());
root.depthFirst(loggingVisitor);
}
@Test
public void testMyVisitor() {
assertNotNull("dummy", root);
root.accept(loggingVisitor);
root.getChildren().get(0).accept(loggingVisitor);
}
@Test
public void testComputingVisitor() {
assertNotNull("dummy", root);
root.breadthFirst(computingVisitor);
assertEquals("check count", 113, computingVisitor.getCount());
}
}

View File

@ -0,0 +1,44 @@
package eu.dnetlib.miscutils.hstree;
import static org.junit.Assert.assertTrue;
import org.junit.Test;
import eu.dnetlib.miscutils.hstree.sample.resources.ChildResource;
import eu.dnetlib.miscutils.hstree.sample.resources.SampleResource;
import eu.dnetlib.miscutils.hstree.sample.resources.SubResource;
import eu.dnetlib.miscutils.hstree.sample.wrongtree.WrongFirstChild;
import eu.dnetlib.miscutils.hstree.sample.wrongtree.WrongRootTree;
import eu.dnetlib.miscutils.hstree.sample.wrongtree.WrongSecondChild;
public class WrongTreeNodeTest {
/**
* Try to break/misalign the signatures of the 'sample.wrongtree' package. The code should not be able to compile.
*/
@Test
public void simpleTest() {
final WrongRootTree root = new WrongRootTree(new SampleResource());
final WrongFirstChild ch1 = root.addChild(new ChildResource());
ch1.addChild(new SubResource());
ch1.addChild(new SubResource());
final WrongFirstChild ch2 = root.addChild(new ChildResource());
ch2.addChild(new SubResource());
ch2.addChild(new SubResource());
final WrongSecondChild sc1 = ch2.addChild(new SubResource());
// of course we can do obscene things like this,
// but if somebody casts there is no escape.
boolean gotRuntimeEx = false; // NOPMD
try {
sc1.addChild((Void) null);
} catch (RuntimeException e) {
if (e.getMessage().equals(TreeNode.CHILDR_UNDER_LEAF))
gotRuntimeEx = true;
}
assertTrue("got exception", gotRuntimeEx); // TODO: exploit junit4 for checking exceptions
}
}

View File

@ -0,0 +1,5 @@
package eu.dnetlib.miscutils.hstree.sample.resources;
public class ChildResource extends Resource { // NOPMD
}

View File

@ -0,0 +1,5 @@
package eu.dnetlib.miscutils.hstree.sample.resources;
public class Resource { // NOPMD
}

View File

@ -0,0 +1,5 @@
package eu.dnetlib.miscutils.hstree.sample.resources;
public class SampleResource extends Resource { // NOPMD
}

View File

@ -0,0 +1,5 @@
package eu.dnetlib.miscutils.hstree.sample.resources;
public class SubResource extends Resource { // NOPMD
}

View File

@ -0,0 +1,12 @@
package eu.dnetlib.miscutils.hstree.sample.tree;
import eu.dnetlib.miscutils.hstree.sample.resources.ChildResource;
import eu.dnetlib.miscutils.hstree.sample.resources.SubResource;
public class FirstChild extends MyTreeNode<ChildResource, SubResource, SecondChild> {
@Override
public void accept(final MyTreeVisitor visitor) {
visitor.visit(getResource());
}
}

View File

@ -0,0 +1,41 @@
package eu.dnetlib.miscutils.hstree.sample.tree;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import eu.dnetlib.miscutils.hstree.sample.resources.ChildResource;
import eu.dnetlib.miscutils.hstree.sample.resources.SampleResource;
import eu.dnetlib.miscutils.hstree.sample.resources.SubResource;
public class MyComputingVisitor implements MyTreeVisitor {
private static final Log log = LogFactory.getLog(MyComputingVisitor.class); // NOPMD by marko on 11/24/08 5:02 PM
int count;
@Override
public void visit(final SampleResource resource) {
log.info("increasing sampleresource");
count += 100;
}
@Override
public void visit(final ChildResource resource) {
log.info("increasing childresource");
count += 10;
}
@Override
public void visit(final SubResource resource) {
log.info("increasing subresource");
count += 1;
}
public int getCount() {
return count;
}
public void setCount(final int count) {
this.count = count;
}
}

View File

@ -0,0 +1,49 @@
package eu.dnetlib.miscutils.hstree.sample.tree;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import eu.dnetlib.miscutils.hstree.sample.resources.ChildResource;
import eu.dnetlib.miscutils.hstree.sample.resources.SampleResource;
import eu.dnetlib.miscutils.hstree.sample.resources.SubResource;
public class MyLoggingVisitor implements MyTreeVisitor {
private static final Log log = LogFactory.getLog(MyLoggingVisitor.class); // NOPMD by marko on 11/24/08 5:02 PM
/*
* (non-Javadoc)
*
* @see
* eu.rinfrastructures.genericstest.sample.wrongtree.MyTreeVisitor#visit(eu.rinfrastructures.genericstest.sample
* .resources.SampleResource)
*/
@Override
public void visit(final SampleResource resource) {
log.info("sample");
}
/*
* (non-Javadoc)
*
* @see
* eu.rinfrastructures.genericstest.sample.wrongtree.MyTreeVisitor#visit(eu.rinfrastructures.genericstest.sample
* .resources.ChildResource)
*/
@Override
public void visit(final ChildResource resource) {
log.info("child");
}
/*
* (non-Javadoc)
*
* @see
* eu.rinfrastructures.genericstest.sample.wrongtree.MyTreeVisitor#visit(eu.rinfrastructures.genericstest.sample
* .resources.SubResource)
*/
@Override
public void visit(final SubResource resource) {
log.info("sub");
}
}

View File

@ -0,0 +1,14 @@
package eu.dnetlib.miscutils.hstree.sample.tree;
import eu.dnetlib.miscutils.hstree.TreeNode;
public class MyTreeNode<T, N, C extends TreeNode<N, ?, MyTreeVisitor, ?>> extends TreeNode<T, N, MyTreeVisitor, C> {
public MyTreeNode() {
// no action
}
public MyTreeNode(final T resource) {
super(resource);
}
}

View File

@ -0,0 +1,15 @@
package eu.dnetlib.miscutils.hstree.sample.tree;
import eu.dnetlib.miscutils.hstree.sample.resources.ChildResource;
import eu.dnetlib.miscutils.hstree.sample.resources.SampleResource;
import eu.dnetlib.miscutils.hstree.sample.resources.SubResource;
public interface MyTreeVisitor {
void visit(SampleResource resource);
void visit(ChildResource resource);
void visit(SubResource resource);
}

View File

@ -0,0 +1,16 @@
package eu.dnetlib.miscutils.hstree.sample.tree;
import eu.dnetlib.miscutils.hstree.sample.resources.ChildResource;
import eu.dnetlib.miscutils.hstree.sample.resources.SampleResource;
public class RootTree extends MyTreeNode<SampleResource, ChildResource, FirstChild> {
public RootTree(final SampleResource resource) {
super(resource);
}
@Override
public void accept(final MyTreeVisitor visitor) {
visitor.visit(getResource());
}
}

View File

@ -0,0 +1,12 @@
package eu.dnetlib.miscutils.hstree.sample.tree;
import eu.dnetlib.miscutils.hstree.NilTreeNode;
import eu.dnetlib.miscutils.hstree.sample.resources.SubResource;
public class SecondChild extends MyTreeNode<SubResource, Void, NilTreeNode<MyTreeVisitor>> {
@Override
public void accept(final MyTreeVisitor visitor) {
visitor.visit(getResource());
}
}

View File

@ -0,0 +1,10 @@
package eu.dnetlib.miscutils.hstree.sample.wrongtree;
import eu.dnetlib.miscutils.hstree.TreeNode;
import eu.dnetlib.miscutils.hstree.sample.resources.ChildResource;
import eu.dnetlib.miscutils.hstree.sample.resources.SubResource;
import eu.dnetlib.miscutils.hstree.sample.tree.MyLoggingVisitor;
public class WrongFirstChild extends TreeNode<ChildResource, SubResource, MyLoggingVisitor, WrongSecondChild> { // NOPMD
}

View File

@ -0,0 +1,14 @@
package eu.dnetlib.miscutils.hstree.sample.wrongtree;
import eu.dnetlib.miscutils.hstree.TreeNode;
import eu.dnetlib.miscutils.hstree.sample.resources.ChildResource;
import eu.dnetlib.miscutils.hstree.sample.resources.SampleResource;
import eu.dnetlib.miscutils.hstree.sample.tree.MyLoggingVisitor;
public class WrongRootTree extends TreeNode<SampleResource, ChildResource, MyLoggingVisitor, WrongFirstChild> {
public WrongRootTree(final SampleResource resource) {
super(resource);
}
}

View File

@ -0,0 +1,10 @@
package eu.dnetlib.miscutils.hstree.sample.wrongtree;
import eu.dnetlib.miscutils.hstree.NilTreeNode;
import eu.dnetlib.miscutils.hstree.TreeNode;
import eu.dnetlib.miscutils.hstree.sample.resources.SubResource;
import eu.dnetlib.miscutils.hstree.sample.tree.MyLoggingVisitor;
public class WrongSecondChild extends TreeNode<SubResource, Void, MyLoggingVisitor, NilTreeNode<MyLoggingVisitor>> { // NOPMD
}

View File

@ -0,0 +1,113 @@
package eu.dnetlib.miscutils.iterators.xml;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.StringReader;
import java.io.StringWriter;
import java.util.zip.GZIPInputStream;
import java.util.zip.ZipInputStream;
import org.apache.commons.io.IOUtils;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.io.SAXReader;
import org.junit.Before;
import org.junit.Test;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
public class IterableXmlParserTest {
private Resource xmlZip = new ClassPathResource("eu/dnetlib/miscutils/iterators/xml/opendoar.zip");
private Resource xmlGz = new ClassPathResource("eu/dnetlib/miscutils/iterators/xml/opendoar.xml.gz");
private Resource xmlZipErr = new ClassPathResource("eu/dnetlib/miscutils/iterators/xml/opendoarErr.zip");
private Resource xmlSingle = new ClassPathResource("eu/dnetlib/miscutils/iterators/xml/singleRepo.xml");
private String element = "repository";
private IterableXmlParser parser;
private SAXReader reader;
@Before
public void setUp() throws Exception {
reader = new SAXReader();
}
@Test
public void testGz() throws Exception {
doTest(new GZIPInputStream(xmlGz.getInputStream()), element);
}
@Test
public void test() throws Exception {
doTest(read(new ZipInputStream(xmlZip.getInputStream())), element);
}
@Test
public void testErr() throws Exception {
doTest(read(new ZipInputStream(xmlZipErr.getInputStream())), element);
}
@Test
public void testSingle() throws Exception {
doTest(xmlSingle.getInputStream(), element);
}
@Test
public void testOaiRecord() throws Exception {
int count = doTest(new ClassPathResource("eu/dnetlib/miscutils/iterators/xml/oaiRecord.xml").getInputStream(), "record");
assertTrue(count == 1);
}
@Test
public void testWeird() throws Exception {
int count = doTest(new ClassPathResource("eu/dnetlib/miscutils/iterators/xml/weirdRecords.xml").getInputStream(), "record");
assertTrue(count == 3);
}
@Test
public void testWeirdGz() throws Exception {
int count = doTest(new GZIPInputStream(new ClassPathResource("eu/dnetlib/miscutils/iterators/xml/weirdRecords.xml.gz").getInputStream()), "record");
assertTrue(count == 3);
}
private int doTest(final InputStream stream, final String element) throws DocumentException {
parser = new IterableXmlParser(element, stream);
int count = 0;
for (String xml : parser) {
System.out.println(xml);
Document doc = reader.read(new StringReader(xml));
assertNotNull(doc);
assertNotNull(doc.selectSingleNode("//" + element));
count++;
}
return count;
}
// helper method, reads the compressed text out of the xmlZip file
private InputStream read(final ZipInputStream zis) throws IOException {
final StringWriter sw = new StringWriter();
while (zis.getNextEntry() != null) {
byte[] buffer = new byte[1];
while (zis.read(buffer) != -1) {
IOUtils.write(buffer, sw, "UTF-8");
}
}
zis.close();
sw.close();
return new ByteArrayInputStream(sw.toString().getBytes());
}
}

View File

@ -0,0 +1,44 @@
package eu.dnetlib.miscutils.maps;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import org.junit.Before;
import org.junit.Test;
import eu.dnetlib.miscutils.maps.ConcurrentSizedMap;
public class ConcurrentSizedMapTest {
private ConcurrentSizedMap<String, String> map;
private int size = 2;
@Before
public void setUp() throws Exception {
map = new ConcurrentSizedMap<String, String>();
map.setQueueSize(size);
}
@Test
public void testMap() throws InterruptedException {
map.put("a", "value a");
assertNotNull((map.get("a")));
map.put("b", "value b");
assertNotNull((map.get("b")));
map.put("c", "value c");
assertNotNull((map.get("c")));
assertEquals(size, map.size());
assertNull(map.get("a"));
map.put("a", "new value a");
assertEquals("new value a", map.get("a"));
assertEquals(size, map.size());
}
}

View File

@ -0,0 +1 @@
<EndpointReference xmlns="http://www.w3.org/2005/08/addressing"><Address>http://localhost:8090/app/services/resultSet</Address><ReferenceParameters><ResourceIdentifier:ResourceIdentifier xmlns:ns2="http://mdstore.data.dnetlib.eu/" xmlns="http://www.driver.org" xmlns:wsa="http://www.w3.org/2005/08/addressing" xmlns:ns3="http://www.w3.org/2005/08/addressing" xmlns:ResourceIdentifier="http://www.driver.org">rs-a1028c6a-bdab-4dbd-b6d1-d97e997bcbf0</ResourceIdentifier:ResourceIdentifier></ReferenceParameters><Metadata><wsaw:InterfaceName xmlns:ns2="http://mdstore.data.dnetlib.eu/" xmlns:ns1="http://rmi.resultset.enabling.dnetlib.eu/" xmlns:wsa="http://www.w3.org/2005/08/addressing" xmlns:ns3="http://www.w3.org/2005/08/addressing" xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl">ns1:ResultSetService</wsaw:InterfaceName><wsaw:ServiceName EndpointName="ResultSetServicePort" xmlns="" xmlns:ns2="http://rmi.resultset.enabling.dnetlib.eu/" xmlns:wsa="http://www.w3.org/2005/08/addressing" xmlns:ns3="http://www.w3.org/2005/08/addressing" xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl" xmlns:ns6="http://www.w3.org/2005/08/addressing">ns2:ResultSetServiceService</wsaw:ServiceName><wsdl:definitions xmlns:ns2="http://mdstore.data.dnetlib.eu/" xmlns:wsa="http://www.w3.org/2005/08/addressing" xmlns:ns3="http://www.w3.org/2005/08/addressing" xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"><wsdl:import location="http://localhost:8090/app/services/resultSet?wsdl" namespace="http://rmi.resultset.enabling.dnetlib.eu/" xmlns="" xmlns:ns7="http://www.w3.org/2005/08/addressing"/></wsdl:definitions><infrastructure:infrastructure xmlns:ns2="http://mdstore.data.dnetlib.eu/" xmlns="http://dnetlib.eu/endpointReference" xmlns:wsa="http://www.w3.org/2005/08/addressing" xmlns:ns3="http://www.w3.org/2005/08/addressing" xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl" xmlns:infrastructure="http://dnetlib.eu/endpointReference">development</infrastructure:infrastructure></Metadata></EndpointReference>

View File

@ -0,0 +1,2 @@
Experimental electron densities were determined from high-resolution X-ray diffraction data sets measured with synchrotron radiation at 100 K,
whereas theoretical calculations were performed using DFT methods at the B3LYP-311++G(3df,3pd) level of approximation.

View File

@ -0,0 +1,46 @@
<?xml version="1.0" encoding="UTF-8"?>
<record xmlns:dri="http://www.driver-repository.eu/namespace/dri"
xmlns:oaf="http://namespace.openaire.eu/oaf" xmlns:oai="http://www.openarchives.org/OAI/2.0/">
<header>
<dri:objIdentifier>od_______908::92a0e1241032a6c3817c9e248ad570ee</dri:objIdentifier>
<dri:recordIdentifier>d2b15e4e-6596-4add-a0d9-865fa6152c9c_TURTdG9yZURTUmVzb3VyY2VzL01EU3RvcmVEU1Jlc291cmNlVHlwZQ==::oai:europepmc.org:2701111</dri:recordIdentifier>
<dri:dateOfCollection>2013-07-17T18:30:00Z</dri:dateOfCollection>
<dri:mdFormat/>
<dri:mdFormatInterpretation/>
<dri:repositoryId>4fd8cd43-226c-408b-8401-0840456a678a_UmVwb3NpdG9yeVNlcnZpY2VSZXNvdXJjZXMvUmVwb3NpdG9yeVNlcnZpY2VSZXNvdXJjZVR5cGU=</dri:repositoryId>
<setSpec>jcbfm</setSpec>
<setSpec>pmc-open</setSpec>
<oaf:datasourceprefix>od_______908</oaf:datasourceprefix>
</header>
<metadata>
<oai_dc:dc xmlns="http://www.openarchives.org/OAI/2.0/"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:oai_dc="http://www.openarchives.org/OAI/2.0/oai_dc/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.openarchives.org/OAI/2.0/oai_dc/ http://www.openarchives.org/OAI/2.0/oai_dc.xsd">
<dc:title>TIMP-1 attenuates bloodbrain barrier permeability in mice with acute liver failure</dc:title>
<dc:creator>Chen, Feng</dc:creator>
<dc:creator>Radisky, Evette S</dc:creator>
<dc:creator>Das, Pritam</dc:creator>
<dc:creator>Batra, Jyotica</dc:creator>
<dc:creator>Hata, Toshiyuki</dc:creator>
<dc:creator>Hori, Tomohide</dc:creator>
<dc:creator>Baine, Ann-Marie T</dc:creator>
<dc:creator>Gardner, Lindsay</dc:creator>
<dc:creator>Yue, Mei Y</dc:creator>
<dc:creator>Bu, Guojun</dc:creator>
<dc:creator>del Zoppo, Gregory</dc:creator>
<dc:creator>Patel, Tushar C</dc:creator>
<dc:creator>Nguyen, Justin H</dc:creator>
<dc:subject>Original Article</dc:subject>
<dc:description>Bloodbrain barrier (BBB) dysfunction in acute liver failure (ALF) results in increased BBB permeability that often precludes the patients from obtaining a life-saving liver transplantation. It remains controversial whether matrix metalloproteinase-9 (MMP-9) from the injured liver contributes to the deregulation of BBB function in ALF. We selectively upregulated a physiologic inhibitor of MMP-9 (TIMP-1) with a single intracerebroventricular injection of TIMP-1 cDNA plasmids at 48 and 72hours, or with pegylated-TIMP-1 protein. Acute liver failure was induced with tumor necrosis factor-α and &#x1d49f;-(+)-galactosamine in mice. Permeability of BBB was assessed with sodium fluorescein (NaF) extravasation. We found a significant increase in TIMP-1 within the central nervous system (CNS) after the administration of TIMP-1 cDNA plasmids and that increased TIMP-1 within the CNS resulted in an attenuation of BBB permeability, a reduction in activation of epidermal growth factor receptor and p38 mitogen-activated protein kinase signals, and a restoration of the tight junction protein occludin in mice with experimental ALF. Pegylated TIMP-1 provided similar protection against BBB permeability in mice with ALF. Our results provided a proof of principle that MMP-9 contributes to the BBB dysfunction in ALF and suggests a potential therapeutic role of TIMP-1 in ALF.</dc:description>
<dc:publisher>Nature Publishing Group</dc:publisher>
<dc:identifier>http://europepmc.org/articles/PMC3705430/</dc:identifier>
<dc:type>Text</dc:type>
<dc:language>en</dc:language>
<dc:rights/>
<dc:identifier>PMC: PMC3705430</dc:identifier>
<dc:date>2013</dc:date>
<dc:identifier>doi: 10.1038/jcbfm.2013.45</dc:identifier>
</oai_dc:dc>
</metadata>
</record>

View File

@ -0,0 +1,131 @@
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:nxsl="http://www.w3.org/1999/XSL/TransformXX"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<xsl:output omit-xml-declaration="yes" method="xml"
encoding="UTF-8" />
<xsl:namespace-alias stylesheet-prefix="nxsl"
result-prefix="xsl" />
<xsl:param name="format" />
<xsl:template match="/">
<xsl:apply-templates select="//LAYOUT" />
</xsl:template>
<xsl:template match="LAYOUT">
<nxsl:stylesheet version="1.0"
xmlns:dr="http://www.driver-repository.eu/namespace/dr" xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:dri="http://www.driver-repository.eu/namespace/dri" xmlns:dnet="eu.dnetlib.miscutils.functional.xml.DnetXsltFunctions"
xmlns:exsl="http://exslt.org/common"
extension-element-prefixes="exsl">
<nxsl:output version="1.0" omit-xml-declaration="yes"
method="xml" encoding="UTF8" />
<nxsl:variable name="format">
<xsl:value-of select="$format" />
</nxsl:variable>
<nxsl:template match="/">
<indexRecord>
<indexRecordIdentifier>
<nxsl:value-of select="//dri:objIdentifier" />
</indexRecordIdentifier>
<targetFields>
<nxsl:if test="$format != 'DMF' or string(//dc:title)">
<nxsl:if test="count(//*[local-name()='metadata']/*) &gt; 0">
<xsl:apply-templates select="FIELDS/FIELD[@indexable='true']" />
</nxsl:if>
</nxsl:if>
</targetFields>
<result>
<header>
<dri:objIdentifier>
<nxsl:value-of select="//dri:objIdentifier" />
</dri:objIdentifier>
<dri:repositoryId>
<nxsl:value-of select="//dri:repositoryId" />
</dri:repositoryId>
<dri:dateOfCollection>
<nxsl:value-of select="//dri:dateOfCollection" />
</dri:dateOfCollection>
<xsl:apply-templates select="FIELDS/FIELD"
mode="header" />
</header>
<metadata>
<xsl:apply-templates select="FIELDS/FIELD"
mode="result" />
</metadata>
</result>
</indexRecord>
</nxsl:template>
</nxsl:stylesheet>
</xsl:template>
<xsl:template match="FIELD[@indexable='true']">
<xsl:choose>
<!--
<xsl:when test="@name = 'description'">
<nxsl:for-each select="{@xpath}">
<xsl:element name="{@name}">
<nxsl:value-of select="substring(.,1,210)" />
</xsl:element>
</nxsl:for-each>
</xsl:when>
-->
<xsl:when test="@constant">
<xsl:element name="{@name}">
<xsl:value-of select="@constant" />
</xsl:element>
</xsl:when>
<xsl:when test="@value and not(@xpath)">
<nxsl:element name="{@name}">
<nxsl:value-of select="{@value}" />
</nxsl:element>
</xsl:when>
<xsl:otherwise>
<xsl:variable name="value">
<xsl:choose>
<xsl:when test="@value">
<xsl:value-of select="@value" />
</xsl:when>
<xsl:otherwise>
.
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<nxsl:for-each select="{@xpath}">
<xsl:element name="{@name}">
<xsl:if test="@external='true'">
<xsl:attribute name="external">true</xsl:attribute>
</xsl:if>
<xsl:choose>
<xsl:when test="@tokenizable='false'">
<nxsl:value-of select="normalize-space({normalize-space($value)})" />
</xsl:when>
<xsl:otherwise>
<nxsl:value-of select="{normalize-space($value)}" />
</xsl:otherwise>
</xsl:choose>
</xsl:element>
</nxsl:for-each>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template match="FIELD" mode="result">
<xsl:if test="@result='true'">
<nxsl:copy-of select="{@xpath}" />
</xsl:if>
</xsl:template>
<xsl:template match="FIELD" mode="header">
<xsl:if test="@header='true'">
<nxsl:copy-of select="{@xpath}" />
</xsl:if>
</xsl:template>
</xsl:stylesheet>

View File

@ -0,0 +1,109 @@
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:dri="http://www.driver-repository.eu/namespace/dri"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:dnet="eu.dnetlib.miscutils.functional.xml.DnetXsltFunctions"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:exsl="http://exslt.org/common"
xmlns:dr="http://www.driver-repository.eu/namespace/dr"
extension-element-prefixes="exsl"
version="1.0">
<xsl:output encoding="UTF8" method="xml" omit-xml-declaration="yes" version="1.0"/>
<xsl:variable name="format">EMF</xsl:variable>
<xsl:template match="/">
<indexRecord>
<indexRecordIdentifier>
<xsl:value-of select="//dri:objIdentifier"/>
</indexRecordIdentifier>
<targetFields>
<xsl:if test="$format != 'DMF' or string(//dc:title)">
<xsl:if test="count(//*[local-name()='metadata']/*) &gt; 0">
<xsl:for-each select="//*[local-name()='title']">
<title>
<xsl:value-of select="."/>
</title>
</xsl:for-each>
<xsl:for-each select="//*[local-name()='description']">
<description>
<xsl:value-of select="."/>
</description>
</xsl:for-each>
<xsl:for-each select="//*[local-name()='entityType']">
<entitytype>
<xsl:value-of select="normalize-space(.)"/>
</entitytype>
</xsl:for-each>
<xsl:for-each select="//*[local-name()='material']">
<material>
<xsl:value-of select="."/>
</material>
</xsl:for-each>
<xsl:for-each select="//*[local-name()='inscriptionType']">
<inscriptionType>
<xsl:value-of select="."/>
</inscriptionType>
</xsl:for-each>
<xsl:for-each select="//*[local-name()='dnetResourceIdentifier']">
<dnetresourceidentifier>
<xsl:value-of select="normalize-space(.)"/>
</dnetresourceidentifier>
</xsl:for-each>
<xsl:for-each select="//*[local-name()='objIdentifier']">
<objidentifier>
<xsl:value-of select="normalize-space(.)"/>
</objidentifier>
</xsl:for-each>
<xsl:for-each select="//*[local-name()='repositoryId']">
<repositoryId>
<xsl:value-of select="."/>
</repositoryId>
</xsl:for-each>
<xsl:for-each select="//*[local-name()='providerName']">
<repositoryname>
<xsl:value-of select="normalize-space(.)"/>
</repositoryname>
</xsl:for-each>
<xsl:for-each select="//*[local-name()='ProviderURI']">
<repositorylink>
<xsl:value-of select="normalize-space(.)"/>
</repositorylink>
</xsl:for-each>
<xsl:for-each select="//*[local-name()='entityType']">
<entitytypeforbrowsing>
<xsl:value-of select="normalize-space(.)"/>
</entitytypeforbrowsing>
</xsl:for-each>
<xsl:for-each select="//*[local-name()='material']">
<materialforbrowsing>
<xsl:value-of select="normalize-space(.)"/>
</materialforbrowsing>
</xsl:for-each>
<xsl:for-each select="//*[local-name()='inscriptionType']">
<inscriptiontypeforbrowsing>
<xsl:value-of select="normalize-space(.)"/>
</inscriptiontypeforbrowsing>
</xsl:for-each>
</xsl:if>
</xsl:if>
</targetFields>
<result>
<header>
<dri:objIdentifier>
<xsl:value-of select="//dri:objIdentifier"/>
</dri:objIdentifier>
<dri:repositoryId>
<xsl:value-of select="//dri:repositoryId"/>
</dri:repositoryId>
<dri:dateOfCollection>
<xsl:value-of select="//dri:dateOfCollection"/>
</dri:dateOfCollection>
</header>
<metadata>
<xsl:copy-of select="//*[local-name()='providerName']"/>
<xsl:copy-of select="//*[local-name()='ProviderURI']"/>
<xsl:copy-of select="//*[local-name()='eagleObject']"/>
</metadata>
</result>
</indexRecord>
</xsl:template>
</xsl:stylesheet>

View File

@ -0,0 +1,42 @@
<?xml version="1.0" encoding="UTF-8"?>
<RESOURCE_PROFILE>
<HEADER>
<RESOURCE_IDENTIFIER value="2-8b9503d9-8a86-4330-93ef-7e0cd9bc87c2_TURGb3JtYXREU1Jlc291cmNlcy9NREZvcm1hdERTUmVzb3VyY2VUeXBl"/>
<RESOURCE_TYPE value="MDFormatDSResourceType"/>
<RESOURCE_KIND value="MDFormatDSResources"/>
<RESOURCE_URI value=""/>
<DATE_OF_CREATION value="2008-05-22T14:40:04+02:00"/>
</HEADER>
<BODY>
<CONFIGURATION>
<NAME>EMF</NAME>
<DESCRIPTION>Eagle Metadata Format</DESCRIPTION>
<INTERPRETATION>cleaned</INTERPRETATION>
<SCHEMA uri=""/>
</CONFIGURATION>
<STATUS>
<LAYOUTS>
<LAYOUT name="index">
<FIELDS>
<FIELD result="false" stat="false" xpath="//*[local-name()='title']" indexable="true" name="title" tokenizable="true"/>
<FIELD indexable="true" xpath="//*[local-name()='description']" name="description" result="false" stat="false" tokenizable="true"/>
<FIELD name="entitytype" xpath="//*[local-name()='entityType']" stat="false" indexable="true" result="false" tokenizable="false"/>
<FIELD name="material" stat="false" indexable="true" xpath="//*[local-name()='material']" result="false" tokenizable="true"/>
<FIELD indexable="true" xpath="//*[local-name()='inscriptionType']" result="false" stat="false" name="inscriptionType" tokenizable="true"/>
<FIELD tokenizable="false" result="false" name="dnetresourceidentifier" xpath="//*[local-name()='dnetResourceIdentifier']" indexable="true" stat="false"/>
<FIELD name="objidentifier" indexable="true" result="false" stat="false" xpath="//*[local-name()='objIdentifier']" tokenizable="false"/>
<FIELD indexable="true" name="repositoryId" result="false" xpath="//*[local-name()='repositoryId']" stat="false"/>
<FIELD xpath="//*[local-name()='providerName']" result="true" indexable="true" tokenizable="false" stat="false" name="repositoryname"/>
<FIELD stat="false" indexable="true" name="repositorylink" result="true" tokenizable="false" xpath="//*[local-name()='ProviderURI']"/>
<FIELD stat="false" name="eagleObject" tokenizable="true" xpath="//*[local-name()='eagleObject']" indexable="false" result="true"/>
<!-- Browsing Fields -->
<FIELD xpath="//*[local-name()='entityType']" stat="false" browsingAliasFor="entityType" tokenizable="false" result="false" name="entitytypeforbrowsing" indexable="true"/>
<FIELD stat="false" result="false" indexable="true" browsingAliasFor="material" xpath="//*[local-name()='material']" tokenizable="false" name="materialforbrowsing"/>
<FIELD name="inscriptiontypeforbrowsing" tokenizable="false" xpath="//*[local-name()='inscriptionType']" stat="false" indexable="true" result="false" browsingAliasFor="inscriptionType"/>
</FIELDS>
</LAYOUT>
</LAYOUTS>
</STATUS>
</BODY>
</RESOURCE_PROFILE>

View File

@ -0,0 +1,87 @@
<?xml version="1.0" encoding="UTF-8"?><record>
<header>
<dri:objIdentifier xmlns:dri="http://www.driver-repository.eu/namespace/dri">367b05cf-13f6-4d3a-8c2d-9fd172b353ce_UmVwb3NpdG9yeVNlcnZpY2VSZXNvdXJjZXMvUmVwb3NpdG9yeVNlcnZpY2VSZXNvdXJjZVR5cGU=::http://irt.kcl.ac.uk/irt2009/IRT001.html_artifact</dri:objIdentifier>
<dri:dateOfCollection xmlns:dri="http://www.driver-repository.eu/namespace/dri">2014-03-19T11:41:15+01:00</dri:dateOfCollection>
<dri:repositoryId xmlns:dri="http://www.driver-repository.eu/namespace/dri">
367b05cf-13f6-4d3a-8c2d-9fd172b353ce_UmVwb3NpdG9yeVNlcnZpY2VSZXNvdXJjZXMvUmVwb3NpdG9yeVNlcnZpY2VSZXNvdXJjZVR5cGU=
</dri:repositoryId>
</header>
<metadata>
<eagleObject>
<dnetResourceIdentifier>artifact::BSR::f85e57d02d6efd679ce5a7a689c7960b</dnetResourceIdentifier>
<recordSourceInfo providerName="British School at Rome" providerAcronym="BSR" providerURI="http://www.bsr.ac.uk/it">http://irt.kcl.ac.uk/irt2009/IRT001.html</recordSourceInfo>
<editingInfo>
<dateEdited>2014-02-12</dateEdited>
<metadataEditor>PML</metadataEditor>
</editingInfo>
<metadataIpr url="">
Creative Commons licence Attribution UK 2.0
(http://creativecommons.org/licenses/by/2.0/uk/).
All reuse or distribution of this work must contain somewhere a link back to the URL
http://irt.kcl.ac.uk/
</metadataIpr>
<title lang="en">Reference to Apollo (?)</title>
<description lang="en">Fragment from the lower part of a small, white
marble
panel (
0.09
0.14
0.02
; no edges
surviving, but there is a space after 1. 3); re-used at a later date for an
inscription cut in third century capitals, of which the letters [...]TT[...] alone survive. </description>
<entityType>Artifact</entityType>
<artifact>
<artifactType>Inscription</artifactType>
<monumentType uri="">panel</monumentType>
<material uri="">white
marble</material>
<dimensions unit="">
<width/>
<height/>
<depth/>
</dimensions>
<decoration uri=""/>
<stateOfPreservation uri=""/>
<originDating notBefore="" notAfter="" datingMethod="" evidence="" period="">Second to early third centuries A.D. (lettering)</originDating>
<yearOfFinding/>
<findingSpot>
<romanProvinceItalicRegion uri="">Tripolitania</romanProvinceItalicRegion>
<ancientFindSpot uri="">Sabratha: Capitolium</ancientFindSpot>
<modernFindSpot uri=""/>
<modernCountry uri=""/>
<modernRegion uri=""/>
<modernProvince uri=""/>
</findingSpot>
<conservationPlace>
<conservationCountry uri="">Libya</conservationCountry>
<conservationRegion uri="http://www.geonames.org/2208578/marsa-zawaghah.html">Marsa
Zawaghah</conservationRegion>
<conservationCity uri=""/>
<museum uri=""/>
<position/>
<inventoryNumber/>
</conservationPlace>
<inscription>
<refersTrismegistosCard tm_id="">###refersTrismegistosCard0###</refersTrismegistosCard>
<inscriptionType uri=""/>
<engravingTechnique uri=""/>
<metre/>
<fieldSize unit="">
<width/>
<height/>
</fieldSize>
<paleographicCharacteristics>Rustic capitals: line 1, 0.05; line 2, 0.04; line 3, 0.03. </paleographicCharacteristics>
<letterSize unit="unit5">
<width>0</width>
<height>0</height>
</letterSize>
<hasInscriptionVisualRepresentation uri="thumbnail">visual::BSR::f85e57d02d6efd679ce5a7a689c7960b::1</hasInscriptionVisualRepresentation>
<hasTranslation>###relTranslationObj###</hasTranslation>
<hasTranscription>transcription::BSR::f85e57d02d6efd679ce5a7a689c7960b</hasTranscription>
</inscription>
</artifact>
</eagleObject>
</metadata>
</record>

View File

@ -0,0 +1,36 @@
<?xml version="1.0"?>
<cappello>
<oai:record xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:dr="http://www.driver-repository.eu/namespace/dr" xmlns:dri="http://www.driver-repository.eu/namespace/dri"
xmlns:oaf="http://namespace.openaire.eu/oaf" xmlns:oai="http://www.openarchives.org/OAI/2.0/"
xmlns:prov="http://www.openarchives.org/OAI/2.0/provenance" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<oai:header>
<dri:objIdentifier>webcrawl____::6469a2bd0de26af9612c1869d19edd18</dri:objIdentifier>
<dri:recordIdentifier>webcrawl____::6469a2bd0de26af9612c1869d19edd18</dri:recordIdentifier>
<dri:dateOfCollection />
<dri:repositoryId />
<oaf:datasourceprefix>webcrawl____</oaf:datasourceprefix>
</oai:header>
<oai:metadata>
<dc:title>Independent Associations of Glucose Status and Arterial
Stiffness With Left Ventricular Diastolic Dysfunction An 8-year
follow-up of the Hoorn Study</dc:title>
<oaf:dateAccepted>2012-01-01</oaf:dateAccepted>
<dc:publisher>AMER DIABETES ASSOC</dc:publisher>
<dc:language>eng</dc:language>
<oaf:journal issn="0149-5992">DIABETES CARE</oaf:journal>
<dc:subject />
<dc:description />
<dc:source />
<collectedfrom id="openaire____::081b82f96300b6a6e3d282bad31cb6e2"
name="Crossref" />
<oaf:identifier identifierType="doi">10.2337/dc11-1336</oaf:identifier>
<oaf:identifier identifierType="oai">webcrawl____::6469a2bd0de26af9612c1869d19edd18</oaf:identifier>
<oaf:accessrights>CLOSED</oaf:accessrights>
<dr:CobjCategory>0001</dr:CobjCategory>
<hostedby id="openaire____::55045bd2a65019fd8e6741a755395c8c"
name="Unknown Repository" />
<dc:identifier>http://dx.doi.org/10.2337/dc11-1336</dc:identifier>
</oai:metadata>
</oai:record>
</cappello>

View File

@ -0,0 +1,36 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE OpenDOAR SYSTEM "http://www.opendoar.org/api13.dtd">
<OpenDOAR apiVersion="1.3">
<copyright>Copyright 2012, University of Nottingham</copyright>
<licence>OpenDOAR data is available for re-use under a Creative Commons Attribution-Non-Commercial-Share Alike licence</licence>
<repositories>
<repository rID="781">
<rName>Aalborg University - Electronic Library</rName>
<rAcronym />
<rNamePreferred>Y</rNamePreferred>
<rUrl>http://www.aub.aau.dk/</rUrl>
<rOaiBaseUrl />
<uName>Aalborg Universitetsbiblioteks</uName>
<uAcronym />
<uNamePreferred>Y</uNamePreferred>
<uUrl>http://www.aub.aau.dk/</uUrl>
<oName>Aalborg Universitet</oName>
<oAcronym />
<oNamePreferred>Y</oNamePreferred>
<oUrl>http://www.aau.dk/</oUrl>
<postalAddress>Aalborg Universitetsbibliotek, Langagervej 2, 9220 Aalborg</postalAddress>
<country>
<cIsoCode>DK</cIsoCode>
<cCountry>Denmark</cCountry>
</country>
<paLatitude>57.035000</paLatitude>
<paLongitude>9.932300</paLongitude>
<paPhone>96 359400</paPhone>
<paFax />
<rDescription>This site is a university repository providing access to the research papers and publications of lecturers, and Ph.D theses, of Aalborg University. This site is poor in supporting information and background documentation, however contact details are readily available if problems are encountered.</rDescription>
<rRemarks />
<rNumOfItems>35</rNumOfItems>
<rDateHarvested>2012-06-27</rDateHarvested>
</repository>
</repositories>
</OpenDOAR>

View File

@ -0,0 +1,129 @@
<records>
<record xmlns:oai="http://www.openarchives.org/OAI/2.0/">
<header>
<identifier>oai:HAL:hal-00782129v1</identifier>
<datestamp>2013-01-29</datestamp>
<setSpec>type:COMM</setSpec>
<setSpec>subject:info</setSpec>
<setSpec>collection:UNIV-RENNES1</setSpec>
<setSpec>collection:CNRS</setSpec>
<setSpec>collection:INRIA</setSpec>
<setSpec>collection:INRIA-RENNES</setSpec>
<setSpec>collection:IRISA</setSpec>
<setSpec>collection:IRISA_SET</setSpec>
<setSpec>collection:TESTINRIA</setSpec>
</header>
<metadata xmlns:oai_dc="http://www.openarchives.org/OAI/2.0/oai_dc/" xmlns:dc="http://purl.org/dc/elements/1.1/">
<oai_dc:dc xmlns:tei="http://www.tei-c.org/ns/1.0">
<dc:publisher>HAL CCSD</dc:publisher>
<dc:title xml:lang="en">Coupling 3G with DVB networks for low cost services</dc:title>
<dc:creator>Jedidi, Azza</dc:creator>
<dc:creator>Tlais, Mazen</dc:creator>
<dc:creator>Weis, Fr&#xE9;d&#xE9;ric</dc:creator>
<dc:contributor>ACES (INRIA - IRISA) ; INRIA - Universit&#xE9; de Rennes 1 - Institut National des Sciences Appliqu&#xE9;es (INSA) - Rennes - CNRS</dc:contributor>
<dc:description>International audience</dc:description>
<dc:source>MASS'09 : International Conference on Management and Service Science</dc:source>
<dc:coverage>Wuhan, China</dc:coverage>
<dc:contributor>IEEE</dc:contributor>
<dc:publisher>IEEE</dc:publisher>
<dc:identifier>hal-00782129</dc:identifier>
<dc:identifier>https://hal.inria.fr/hal-00782129</dc:identifier>
<dc:source>https://hal.inria.fr/hal-00782129</dc:source>
<dc:source>IEEE. MASS'09 : International Conference on Management and Service Science, Sep 2009, Wuhan, China. IEEE, pp.1-5, &amp;lt;10.1109/ICMSS.2009.5303609&amp;gt;</dc:source>
<dc:identifier>DOI : 10.1109/ICMSS.2009.5303609</dc:identifier>
<dc:language>en</dc:language>
<dc:subject>[INFO.INFO-OH] Computer Science/Other</dc:subject>
<dc:type>Conference papers</dc:type>
<dc:description xml:lang="en">Next generation networks will result from the convergence of the different existing technologies, taking benefit from their complementary properties . In this context, recent research has addressed Digital Video Broadcast (DVB) networks, which benefit of very high broadcast capacities, and has tried to couple them with complementary networks. In our work, we focus on DVB-SH, satellite services for hand-held devices, which is a hybrid (satellite/terrestrial) standard. We couple DVB-SH with a 3G cellular network, thus providing a bidirectional interactivity path. DVB-SH benefits from a very high bandwidth capacity that allows unidirectional IP-TV channels broadcast. A residual bandwidth in the DVB-SH path may still be available because of two reasons; the variable bit rates of served flows and/or some DVB reserved channels by the 3G provider. In our work, we focus on this small residual bandwidth and its potential utilization. The idea is to realize an efficient switching of IP data, coming from 3G networks, to the residual bandwidth of DVB Networks. The goal is to use this architecture in order to provide interactive low cost services over DVB networks. Keyword: Network convergence, DVB, 3G, residual bandwidth, switching, multimedia, low cost services</dc:description>
<dc:date>2009-09-16</dc:date>
</oai_dc:dc>
</metadata>
</record>
<record xmlns:oai="http://www.openarchives.org/OAI/2.0/">
<header>
<identifier>oai:HAL:hal-00782130v1</identifier>
<datestamp>2013-06-03</datestamp>
<setSpec>type:COMM</setSpec>
<setSpec>subject:shs</setSpec>
<setSpec>collection:CNRS</setSpec>
<setSpec>collection:UNIV-MONTP3</setSpec>
<setSpec>collection:SHS</setSpec>
<setSpec>collection:PRAXILING</setSpec>
<setSpec>collection:AO-LINGUISTIQUE</setSpec>
</header>
<metadata xmlns:oai_dc="http://www.openarchives.org/OAI/2.0/oai_dc/" xmlns:dc="http://purl.org/dc/elements/1.1/">
<oai_dc:dc xmlns:tei="http://www.tei-c.org/ns/1.0">
<dc:publisher>HAL CCSD</dc:publisher>
<dc:title xml:lang="fr">R&#xE9;volution et disparition</dc:title>
<dc:creator>Steuckardt, Agn&#xE8;s</dc:creator>
<dc:contributor>PRAXILING UMR5267 (Praxiling) ; Universit&#xE9; Paul Val&#xE9;ry - Montpellier III - CNRS</dc:contributor>
<dc:description>International audience</dc:description>
<dc:source>Disparitions et changements linguistiques</dc:source>
<dc:source>Disparitions et changements linguistiques</dc:source>
<dc:contributor>Claire Badiou-Monferran; Thomas Verjans</dc:contributor>
<dc:identifier>hal-00782130</dc:identifier>
<dc:identifier>https://hal.archives-ouvertes.fr/hal-00782130</dc:identifier>
<dc:source>https://hal.archives-ouvertes.fr/hal-00782130</dc:source>
<dc:source>Claire Badiou-Monferran; Thomas Verjans. Disparitions et changements linguistiques, Dec 2010, France. &#xE0; para&#xEE;tre</dc:source>
<dc:language>fr</dc:language>
<dc:subject xml:lang="fr">Changement linguistique</dc:subject>
<dc:subject xml:lang="fr"> R&#xE9;f&#xE9;rent</dc:subject>
<dc:subject xml:lang="fr"> R&#xE9;volution fran&#xE7;aise</dc:subject>
<dc:subject>[SHS.LANGUE] Humanities and Social Sciences/Linguistics</dc:subject>
<dc:type>Conference papers</dc:type>
<dc:description xml:lang="fr">Cette &#xE9;tude suit, du d&#xE9;but de l'&#xE2;ge classique &#xE0; la R&#xE9;volution, les repr&#xE9;sentations de la disparition linguistique : si elles s'opposent sur la place r&#xE9;serv&#xE9;e aux mots du pass&#xE9;, elles se rejoignent dans une conception de la langue que Sylvain Auroux (1986) qualifiait de " politique ", o&#xF9; est attribu&#xE9; aux locuteurs un r&#xF4;le de v&#xE9;ritables " sujets de la langue ". Dans un second temps, elle met &#xE0; l'&#xE9;preuve de l'exp&#xE9;rience cette conception politique de la disparition, en prenant l'exemple des abolitions op&#xE9;r&#xE9;es pendant la p&#xE9;riode r&#xE9;volutionnaire.</dc:description>
<dc:date>2011</dc:date>
</oai_dc:dc>
</metadata>
</record>
<record xmlns:oai="http://www.openarchives.org/OAI/2.0/">
<header>
<identifier>oai:HAL:hal-00504740v2</identifier>
<datestamp>2013-06-12</datestamp>
<setSpec>type:COMM</setSpec>
<setSpec>subject:info</setSpec>
<setSpec>subject:spi</setSpec>
<setSpec>collection:L2S</setSpec>
<setSpec>collection:SUPELEC</setSpec>
<setSpec>collection:SUP_LSS</setSpec>
<setSpec>collection:SUP_SIGNAUX</setSpec>
</header>
<metadata xmlns:oai_dc="http://www.openarchives.org/OAI/2.0/oai_dc/" xmlns:dc="http://purl.org/dc/elements/1.1/">
<oai_dc:dc xmlns:tei="http://www.tei-c.org/ns/1.0">
<dc:publisher>HAL CCSD</dc:publisher>
<dc:title xml:lang="en">GPU implementation of a 3D bayesian CT algorithm and its application on real foam reconstruction</dc:title>
<dc:creator>Gac, Nicolas</dc:creator>
<dc:creator>Vabre, Alexandre</dc:creator>
<dc:creator>Mohammad-Djafari, Ali</dc:creator>
<dc:creator>Rabanal, Asier</dc:creator>
<dc:creator>Buyens, Fanny</dc:creator>
<dc:contributor>Laboratoire des signaux et syst&#xE8;mes (L2S) ; Universit&#xE9; Paris XI - Paris Sud - SUPELEC - UMR8506 CNRS</dc:contributor>
<dc:contributor>Laboratoire d'Int&#xE9;gration des Syst&#xE8;mes et des Technologies (LIST)</dc:contributor>
<dc:contributor>Financement OMTE DIGITEO</dc:contributor>
<dc:description>5 pages</dc:description>
<dc:description>International audience</dc:description>
<dc:source>The 1st CT Meeting Proceedings</dc:source>
<dc:source>The First International Conference on Image Formation in X-Ray Computed Tomography</dc:source>
<dc:coverage>Salt Lake City, United States</dc:coverage>
<dc:identifier>hal-00504740</dc:identifier>
<dc:identifier>https://hal.archives-ouvertes.fr/hal-00504740</dc:identifier>
<dc:identifier>https://hal.archives-ouvertes.fr/hal-00504740/document</dc:identifier>
<dc:source>https://hal.archives-ouvertes.fr/hal-00504740</dc:source>
<dc:source>The First International Conference on Image Formation in X-Ray Computed Tomography, Jun 2010, Salt Lake City, United States. http://www.ucair.med.utah.edu/CTmeeting/ProceedingsCTMeeting2010.pdf, pp.151-155</dc:source>
<dc:language>en</dc:language>
<dc:subject xml:lang="en">Computed Tomograhy (CT)</dc:subject>
<dc:subject xml:lang="en">Iterative 3D reconstruction</dc:subject>
<dc:subject xml:lang="en">Bayesian estimation</dc:subject>
<dc:subject xml:lang="en">GPU implementation</dc:subject>
<dc:subject>[INFO.INFO-IM] Computer Science/Medical Imaging</dc:subject>
<dc:subject>[INFO.INFO-DC] Computer Science/Distributed, Parallel, and Cluster Computing</dc:subject>
<dc:subject>[INFO.INFO-TS] Computer Science/Signal and Image Processing</dc:subject>
<dc:subject>[SPI.SIGNAL] Engineering Sciences/Signal and Image processing</dc:subject>
<dc:type>Conference papers</dc:type>
<dc:description xml:lang="en">A great number of image reconstruction algorithms, based on analytical filtered backprojection, are implemented for X-ray Computed Tomography (CT) [1, 3]. The limits of these methods appear when the number of projections is small, and/or not equidistributed around the object. In this specific context, iterative algebraic methods are implemented. A great number of them are mainly based on least square criterion. Recently, we proposed a regularized version based on Bayesian estimation approach. The main problem that appears when using such methods as well as any iterative algebraic methods is the computation time and especially for projection and backprojection steps. In this paper, first we show how we implemented some main steps of such algorithems which are the forward projection and backward backprojection steps on GPU hardware, and then we show some results on real application of the 3D tomographic reconstruction of metallic foams from a small number of projections. Through this application, we also show the good quality of results as well as a significant speed up of the computation with GPU implementation.</dc:description>
<dc:contributor>projet TomoX</dc:contributor>
<dc:date>2010-06-21</dc:date>
</oai_dc:dc>
</metadata>
</record>
</records>

270
pom.xml Normal file
View File

@ -0,0 +1,270 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>dnet-core</artifactId>
<groupId>eu.dnetlib</groupId>
<packaging>pom</packaging>
<version>1.0.0-SNAPSHOT</version>
<modules>
<module>dnet-core-components</module>
</modules>
<licenses>
<license>
<name>GNU Affero General Public License, Version 3</name>
<url>https://www.gnu.org/licenses/agpl-3.0.html</url>
<distribution>repo</distribution>
</license>
</licenses>
<issueManagement>
<system>Redmine</system>
<url>https://issue.openaire.research-infrastructures.eu/projects/dnet</url>
</issueManagement>
<ciManagement>
<system>jenkins</system>
<url>https://jenkins-dnet.d4science.org</url>
</ciManagement>
<scm>
<connection>scm:git:gitea@code-repo.d4science.org:D-Net/dnet-core.git</connection>
<developerConnection>scm:git:gitea@code-repo.d4science.org:D-Net/dnet-core.git</developerConnection>
<url>https://code-repo.d4science.org/D-Net/dnet-core</url>
<tag>HEAD</tag>
</scm>
<pluginRepositories>
</pluginRepositories>
<repositories>
<repository>
<id>dnet-deps</id>
<name>dnet-dependencies</name>
<url>http://maven.research-infrastructures.eu/nexus/content/repositories/dnet-deps</url>
<layout>default</layout>
</repository>
<repository>
<id>dnet45-releases</id>
<name>D-Net 45 Releases</name>
<url>http://maven.research-infrastructures.eu/nexus/content/repositories/dnet45-releases</url>
<layout>default</layout>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.5</version>
</dependency>
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<version>1.9</version>
</dependency>
<dependency>
<groupId>dom4j</groupId>
<artifactId>dom4j</artifactId>
<version>1.6.1</version>
</dependency>
<dependency>
<groupId>jaxen</groupId>
<artifactId>jaxen</artifactId>
<version>1.1.6</version>
</dependency>
<dependency>
<groupId>saxonica</groupId>
<artifactId>saxon</artifactId>
<version>9.1.0.8</version>
</dependency>
<dependency>
<groupId>saxonica</groupId>
<artifactId>saxon-dom</artifactId>
<version>9.1.0.8</version>
</dependency>
<dependency>
<groupId>jgrapht</groupId>
<artifactId>jgrapht</artifactId>
<version>0.7.2</version>
</dependency>
<dependency>
<groupId>net.sf.ehcache</groupId>
<artifactId>ehcache</artifactId>
<version>2.8.0</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>23.3-jre</version>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>1.6</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.9</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>[4.2.5.RELEASE]</version>
<optional>false</optional>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.5</version>
<scope>test</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
</dependencies>
<build>
<directory>target</directory>
<outputDirectory>target/classes</outputDirectory>
<finalName>${project.artifactId}-${project.version}</finalName>
<testOutputDirectory>target/test-classes</testOutputDirectory>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<version>2.5</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>3.0.1</version>
<executions>
<execution>
<id>attach-sources</id>
<phase>verify</phase>
<goals>
<goal>jar-no-fork</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19.1</version>
<configuration>
<redirectTestOutputToFile>true</redirectTestOutputToFile>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.10.4</version>
<configuration>
<detectLinks>true</detectLinks>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>3.0.0</version>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<version>2.5.3</version>
</plugin>
</plugins>
<extensions>
<extension>
<groupId>org.apache.maven.wagon</groupId>
<artifactId>wagon-ssh</artifactId>
<version>2.10</version>
</extension>
</extensions>
</build>
<distributionManagement>
<snapshotRepository>
<id>dnet45-snapshots</id>
<name>D-Net 45 Snapshots</name>
<url>http://maven.research-infrastructures.eu/nexus/content/repositories/dnet45-snapshots</url>
<layout>default</layout>
</snapshotRepository>
<repository>
<id>dnet45-releases</id>
<name>D-Net 45 Releases</name>
<url>http://maven.research-infrastructures.eu/nexus/content/repositories/dnet45-releases</url>
<layout>default</layout>
</repository>
</distributionManagement>
<reporting>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<configuration>
<detectLinks>true</detectLinks>
</configuration>
</plugin>
</plugins>
</reporting>
</project>