View Javadoc
1   package fr.ifremer.quadrige3.synchro.vo;
2   
3   /*-
4    * #%L
5    * Quadrige3 Core :: Quadrige3 Synchro Core
6    * $Id:$
7    * $HeadURL:$
8    * %%
9    * Copyright (C) 2017 Ifremer
10   * %%
11   * This program is free software: you can redistribute it and/or modify
12   * it under the terms of the GNU Affero General Public License as published by
13   * the Free Software Foundation, either version 3 of the License, or
14   * (at your option) any later version.
15   * 
16   * This program is distributed in the hope that it will be useful,
17   * but WITHOUT ANY WARRANTY; without even the implied warranty of
18   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19   * GNU General Public License for more details.
20   * 
21   * You should have received a copy of the GNU Affero General Public License
22   * along with this program.  If not, see <http://www.gnu.org/licenses/>.
23   * #L%
24   */
25  
26  import com.google.common.collect.Lists;
27  
28  import java.io.Serializable;
29  import java.text.Collator;
30  import java.util.List;
31  
32  /**
33   * bean representing a synchronized table
34   * 
35   * Created by Ludovic on 30/11/2016.
36   */
37  public class SynchroTableMetaVO implements Serializable, Comparable<SynchroTableMetaVO> {
38  
39  	private final String name;
40  
41  	private final boolean root;
42  
43  	private final boolean updatable;
44  
45  	private final boolean data;
46  
47  	private boolean toUpdate;
48  
49  	/**
50  	 * children is not serializable because it is used only to represent direct relation in UI
51  	 */
52  	private final transient List<SynchroTableMetaVO> children;
53  
54  	public SynchroTableMetaVO(String name, boolean root, boolean updatable, boolean data) {
55  		this.name = name;
56  		this.root = root;
57  		this.updatable = updatable;
58  		this.data = data;
59  		this.children = Lists.newArrayList();
60  	}
61  
62  	public SynchroTableMetaVO(SynchroTableMetaVO tableMeta) {
63  		this(tableMeta.getName(), tableMeta.isRoot(), tableMeta.isUpdatable(), tableMeta.isData());
64  	}
65  
66  	public String getName() {
67  		return name;
68  	}
69  
70  	public boolean isRoot() {
71  		return root;
72  	}
73  
74  	public boolean isUpdatable() {
75  		return updatable;
76  	}
77  
78  	public boolean isData() {
79  		return data;
80  	}
81  
82  	public List<SynchroTableMetaVO> getChildren() {
83  		return children;
84  	}
85  
86  	public void addChildren(SynchroTableMetaVO children) {
87  		this.children.add(children);
88  	}
89  
90  	@Override
91  	public boolean equals(Object o) {
92  		if (this == o)
93  			return true;
94  		if (o == null || getClass() != o.getClass())
95  			return false;
96  
97  		SynchroTableMetaVO that = (SynchroTableMetaVO) o;
98  
99  		return name.equals(that.name);
100 	}
101 
102 	@Override
103 	public int hashCode() {
104 		return name.hashCode();
105 	}
106 
107 	@Override
108 	public int compareTo(SynchroTableMetaVO that) {
109 		if (this == that)
110 			return 0;
111 		if (that == null)
112 			return -1;
113 
114 		return Collator.getInstance().compare(this.getName(), that.getName());
115 	}
116 
117 	@Override
118 	public String toString() {
119 		return getName();
120 	}
121 
122 	public String toExtendedString() {
123 		return getName() + (isRoot() && isUpdatable() ? " (root & updatable)" : isRoot() ? " (root)" : isUpdatable() ? " (updatable)" : "")
124 				+ (isData() ? " (data)" : " (referential)");
125 	}
126 
127 	public boolean isToUpdate() {
128 		return toUpdate;
129 	}
130 
131 	public SynchroTableMetaVO setToUpdate(boolean toUpdate) {
132 		this.toUpdate = toUpdate;
133 		return this;
134 	}
135 }