Project

General

Profile

Download (3.31 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2016 EDIT
3
* European Distributed Institute of Taxonomy
4
* http://www.e-taxonomy.eu
5
*
6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7
* See LICENSE.TXT at the top of this package for the full license terms.
8
*/
9
package eu.etaxonomy.cdm.api.util;
10

    
11
import java.util.Arrays;
12
import java.util.EnumSet;
13
import java.util.HashSet;
14
import java.util.Set;
15

    
16
import eu.etaxonomy.cdm.model.common.RelationshipBase.Direction;
17
import eu.etaxonomy.cdm.model.common.RelationshipTermBase;
18

    
19
/**
20
 * Holds a RelationshipType ({@link RelationshipTermBase}) of type {@code <T>}
21
 * and gives it a direction which is one of:
22
 * <ul>
23
 * <li>direct, everted: {@link Direction.relatedTo}</li>
24
 * <li>inverse: {@link Direction.relatedFrom}</li>
25
 * <li>bidirectional: {@link Direction.relatedTo} and {@link Direction.relatedFrom}</li>
26
 * </ul>
27
 *
28
 * @author a.kohlbecker
29
 * @since Dec 7, 2012
30
 *
31
 * @param <T> a sub class of ({@link RelationshipTermBase})
32
 */
33
public class AbstractRelationshipEdge<T extends RelationshipTermBase> {
34

    
35
    private Set<T> relationshipTypes;
36
    private EnumSet<Direction> directions;
37

    
38
    public AbstractRelationshipEdge(T relationshipType, Direction ... direction) {
39
        super();
40
        this.relationshipTypes = new HashSet<>();
41
        this.relationshipTypes.add(relationshipType);
42
        directions = EnumSet.copyOf(Arrays.asList(direction));
43
    }
44

    
45
    public AbstractRelationshipEdge(Set<T> relationshipTypes, Direction ... direction) {
46
        super();
47
        this.relationshipTypes = relationshipTypes;
48
        directions = EnumSet.copyOf(Arrays.asList(direction));
49
    }
50

    
51
    public Set<T> getRelationshipTypes() {
52
        return relationshipTypes;
53
    }
54

    
55
    public void setRelationshipTypes(Set<T> relationshipTypes) {
56
        this.relationshipTypes = relationshipTypes;
57
    }
58

    
59
    public EnumSet<Direction> getDirections() {
60
        return directions;
61
    }
62

    
63
    public void setDirections(EnumSet<Direction> directions) {
64
        this.directions = directions;
65
    }
66

    
67
    /**
68
     * set the <code>directions</code> to {@link Direction.relatedTo}
69
     */
70
    public void setIsEvers() {
71
        directions = EnumSet.of(Direction.relatedTo);
72
    }
73

    
74
    /**
75
     * set the <code>directions</code> to {@link Direction.relatedFrom}
76
     */
77
    public void setIsInvers() {
78
        directions = EnumSet.of(Direction.relatedFrom);
79
    }
80

    
81
    /**
82
     * set the <code>directions</code> to both {@link Direction.relatedTo} and
83
     * {@link Direction.relatedFrom}
84
     */
85
    public void setIsBidirectional() {
86
        directions = EnumSet.allOf(Direction.class);
87
    }
88

    
89
    /**
90
     * @return <code>true</code> if the <code>directions</code> is set to
91
     *         {@link Direction.relatedTo}
92
     */
93
    public boolean isEvers() {
94
        return directions.equals(EnumSet.of(Direction.relatedTo));
95
    }
96

    
97
    /**
98
     * @return <code>true</code> if the <code>directions</code> is set to
99
     *         {@link Direction.relatedFrom}
100
     */
101
    public boolean isInvers() {
102
        return directions.equals(EnumSet.of(Direction.relatedFrom));
103
    }
104

    
105
    /**
106
     * @return <code>true</code> if the <code>directions</code> is set to both
107
     *         {@link Direction.relatedTo} and {@link Direction.relatedFrom}
108
     */
109
    public boolean isBidirectional() {
110
        return directions.equals(EnumSet.allOf(Direction.class));
111
    }
112
}
(1-1/18)