1 |
51263
|
claudio.at
|
package eu.dnetlib.dhp.common.java.porttype;
|
2 |
|
|
|
3 |
|
|
import org.apache.avro.Schema;
|
4 |
|
|
import org.apache.commons.lang.NotImplementedException;
|
5 |
|
|
|
6 |
|
|
/**
|
7 |
|
|
* This port type accepts data stores in a format of Avro
|
8 |
|
|
* Object Container Files, i.e. Avro data files.
|
9 |
|
|
* This kind of file corresponds to a list of objects, each one being of the
|
10 |
|
|
* same type, i.e. each one is defined by the same Avro schema.
|
11 |
|
|
* @author Mateusz Kobos
|
12 |
|
|
*/
|
13 |
|
|
public class AvroPortType implements PortType {
|
14 |
|
|
|
15 |
|
|
private final Schema schema;
|
16 |
|
|
|
17 |
|
|
|
18 |
|
|
public AvroPortType(Schema schema) {
|
19 |
|
|
this.schema = schema;
|
20 |
|
|
}
|
21 |
|
|
|
22 |
|
|
@Override
|
23 |
|
|
public String getName() {
|
24 |
|
|
return schema.getFullName();
|
25 |
|
|
}
|
26 |
|
|
|
27 |
|
|
@Override
|
28 |
|
|
/** Simple check if the port types are exactly the same
|
29 |
|
|
* (as defined by the {@code equals} method).
|
30 |
|
|
*
|
31 |
|
|
* TODO: this should work in a more relaxed way -
|
32 |
|
|
* {@code this.accepts(other)} should be true if {@code this}
|
33 |
|
|
* describes a subset of structures defined in {@code other}. To be
|
34 |
|
|
* more precise: the JSON schema tree tree defined by {@code this} should
|
35 |
|
|
* form a sub-tree of the JSON schema tree defined by {@code other}. */
|
36 |
|
|
public boolean accepts(PortType other) {
|
37 |
|
|
return this.equals(other);
|
38 |
|
|
}
|
39 |
|
|
|
40 |
|
|
/**
|
41 |
|
|
* Two patterns are equal if their schemas are the same.
|
42 |
|
|
*/
|
43 |
|
|
@Override
|
44 |
|
|
public boolean equals(Object o){
|
45 |
|
|
if(!(o instanceof AvroPortType)){
|
46 |
|
|
return false;
|
47 |
|
|
}
|
48 |
|
|
AvroPortType other = (AvroPortType) o;
|
49 |
|
|
return this.schema.equals(other.schema);
|
50 |
|
|
}
|
51 |
|
|
|
52 |
|
|
@Override
|
53 |
|
|
public int hashCode(){
|
54 |
|
|
throw new NotImplementedException();
|
55 |
|
|
}
|
56 |
|
|
|
57 |
|
|
/**
|
58 |
|
|
* Returns avro schema.
|
59 |
|
|
* @return avro schema
|
60 |
|
|
*/
|
61 |
|
|
public Schema getSchema() {
|
62 |
|
|
return schema;
|
63 |
|
|
}
|
64 |
|
|
|
65 |
|
|
}
|