Clover icon

sunshower-base

  1. Project Clover database Fri Apr 6 2018 03:41:27 UTC
  2. Package io.sunshower.persistence.core

File HierarchichalEntity.java

 

Coverage histogram

../../../../img/srcFileCovDistChart0.png
50% of files have more coverage

Code metrics

4
10
5
1
48
38
7
0.7
2
5
1.4

Classes

Class Line # Actions
HierarchichalEntity 8 10 7
0.00%
 

Contributing tests

No tests hitting this source file were found.

Source view

1    package io.sunshower.persistence.core;
2   
3    import java.io.Serializable;
4    import java.util.*;
5    import javax.persistence.*;
6   
7    @MappedSuperclass
 
8    public abstract class HierarchichalEntity<T extends Serializable, U extends Hierarchical<T, U>>
9    extends AbstractEntity<T> implements Hierarchical<T, U> {
10   
11    @ManyToOne
12    @JoinColumn(name = "parent_id")
13    private U parent;
14   
 
15  0 toggle protected HierarchichalEntity(T id) {
16  0 super(id);
17    }
18   
 
19  0 toggle public Collection<U> getChildren() {
20  0 if (children() == null) {
21  0 return Collections.emptySet();
22    }
23  0 return Collections.unmodifiableSet(children());
24    }
25   
 
26  0 toggle public void setParent(U parent) {
27  0 this.parent = parent;
28    }
29   
 
30  0 toggle @Override
31    public U getParent() {
32  0 return parent;
33    }
34   
 
35  0 toggle @Override
36    @SuppressWarnings("unchecked")
37    public boolean addChild(U child) {
38  0 if (children() == null) {
39  0 setChildren(new HashSet<>());
40    }
41  0 child.setParent((U) this);
42  0 return children().add(child);
43    }
44   
45    protected abstract Set<U> children();
46   
47    protected abstract void setChildren(Set<U> children);
48    }