ItEr42S17CUGravacionModelosUnidadesTraballoItEr41S20: Extracting ITreeNode and ITreeParentNode interfaces for order elements.
This commit is contained in:
parent
b2fa8ba946
commit
b9ea81ca6f
5 changed files with 103 additions and 26 deletions
|
|
@ -61,9 +61,10 @@ import org.navalplanner.business.requirements.entities.DirectCriterionRequiremen
|
|||
import org.navalplanner.business.requirements.entities.IndirectCriterionRequirement;
|
||||
import org.navalplanner.business.resources.entities.Criterion;
|
||||
import org.navalplanner.business.templates.entities.OrderElementTemplate;
|
||||
import org.navalplanner.business.trees.ITreeNode;
|
||||
|
||||
public abstract class OrderElement extends BaseEntity implements
|
||||
ICriterionRequirable {
|
||||
ICriterionRequirable, ITreeNode<OrderElement> {
|
||||
|
||||
private InfoComponent infoComponent = new InfoComponent();
|
||||
|
||||
|
|
@ -938,4 +939,9 @@ public abstract class OrderElement extends BaseEntity implements
|
|||
return infoComponent;
|
||||
}
|
||||
|
||||
@Override
|
||||
public OrderElement getThis() {
|
||||
return this;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -46,24 +46,26 @@ import org.navalplanner.business.advance.exceptions.DuplicateAdvanceAssignmentFo
|
|||
import org.navalplanner.business.advance.exceptions.DuplicateValueTrueReportGlobalAdvanceException;
|
||||
import org.navalplanner.business.templates.entities.OrderElementTemplate;
|
||||
import org.navalplanner.business.templates.entities.OrderLineGroupTemplate;
|
||||
import org.navalplanner.business.trees.ITreeNode;
|
||||
import org.navalplanner.business.trees.ITreeParentNode;
|
||||
import org.navalplanner.business.trees.TreeNodeOnList;
|
||||
|
||||
|
||||
public class OrderLineGroup extends OrderElement implements
|
||||
ITreeNode<OrderElement> {
|
||||
ITreeParentNode<OrderElement> {
|
||||
|
||||
private final class ChildrenManipulator extends
|
||||
TreeNodeOnList<OrderElement, OrderLineGroup> {
|
||||
TreeNodeOnList<OrderElement> {
|
||||
|
||||
private final OrderLineGroup parent;
|
||||
|
||||
private ChildrenManipulator(OrderLineGroup parent,
|
||||
List<OrderElement> children) {
|
||||
super(parent, children);
|
||||
super(children);
|
||||
this.parent = parent;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onChildAdded(OrderElement newChild) {
|
||||
final OrderLineGroup parent = getParent();
|
||||
if (parent != null) {
|
||||
SchedulingState schedulingState = newChild
|
||||
.getSchedulingState();
|
||||
|
|
@ -88,10 +90,30 @@ public class OrderLineGroup extends OrderElement implements
|
|||
|
||||
@Override
|
||||
protected void setParentIfRequired(OrderElement newChild) {
|
||||
if (getParent() != null) {
|
||||
newChild.setParent(getParent());
|
||||
if (parent != null) {
|
||||
newChild.setParent(parent);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ITreeParentNode<OrderElement> getParent() {
|
||||
return OrderLineGroup.this.getParent();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ITreeParentNode<OrderElement> toContainer() {
|
||||
return OrderLineGroup.this.toContainer();
|
||||
}
|
||||
|
||||
@Override
|
||||
public OrderElement toLeaf() {
|
||||
return OrderLineGroup.this.toLeaf();
|
||||
}
|
||||
|
||||
@Override
|
||||
public OrderElement getThis() {
|
||||
return OrderLineGroup.this;
|
||||
}
|
||||
}
|
||||
|
||||
public static OrderLineGroup create() {
|
||||
|
|
@ -745,4 +767,9 @@ public class OrderLineGroup extends OrderElement implements
|
|||
return OrderLineGroupTemplate.create(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public OrderLineGroup getThis() {
|
||||
return this;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,23 +19,27 @@
|
|||
*/
|
||||
package org.navalplanner.business.trees;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Represents an entity that can work as a node at a tree<br />
|
||||
* @author Óscar González Fernández <ogonzalez@igalia.com>
|
||||
*
|
||||
*/
|
||||
public interface ITreeNode<T> {
|
||||
public interface ITreeNode<T extends ITreeNode<T>> {
|
||||
|
||||
public void add(T newChild);
|
||||
ITreeParentNode<T> getParent();
|
||||
|
||||
public void remove(T existentChild);
|
||||
List<T> getChildren();
|
||||
|
||||
public void replace(T previousChild, T newChild);
|
||||
ITreeParentNode<T> toContainer();
|
||||
|
||||
public void up(T existentChild);
|
||||
T toLeaf();
|
||||
|
||||
public void down(T existentChild);
|
||||
|
||||
public void add(int position, T newChild);
|
||||
/**
|
||||
* Using <a href="http://www.angelikalanger.com/GenericsFAQ/FAQSections/ProgrammingIdioms.html#FAQ206"
|
||||
* >getThis trick</a>
|
||||
* @return
|
||||
*/
|
||||
T getThis();
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,41 @@
|
|||
/*
|
||||
* This file is part of ###PROJECT_NAME###
|
||||
*
|
||||
* Copyright (C) 2009 Fundación para o Fomento da Calidade Industrial e
|
||||
* Desenvolvemento Tecnolóxico de Galicia
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.navalplanner.business.trees;
|
||||
|
||||
|
||||
/**
|
||||
* Represents an entity that can work as a node at a tree<br />
|
||||
* @author Óscar González Fernández <ogonzalez@igalia.com>
|
||||
*/
|
||||
public interface ITreeParentNode<T extends ITreeNode<T>> extends ITreeNode<T> {
|
||||
|
||||
public void add(T newChild);
|
||||
|
||||
public void remove(T existentChild);
|
||||
|
||||
public void replace(T previousChild, T newChild);
|
||||
|
||||
public void up(T existentChild);
|
||||
|
||||
public void down(T existentChild);
|
||||
|
||||
public void add(int position, T newChild);
|
||||
|
||||
}
|
||||
|
|
@ -23,16 +23,15 @@ import java.util.Collections;
|
|||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Implementation of {@link ITreeNode} that mutates a list <br />
|
||||
* Implementation of {@link ITreeParentNode} that mutates a list <br />
|
||||
* @author Óscar González Fernández <ogonzalez@igalia.com>
|
||||
*/
|
||||
public abstract class TreeNodeOnList<T, P> implements ITreeNode<T> {
|
||||
public abstract class TreeNodeOnList<T extends ITreeNode<T>> implements
|
||||
ITreeParentNode<T> {
|
||||
|
||||
private final List<T> children;
|
||||
private final P parent;
|
||||
|
||||
protected TreeNodeOnList(P parent, List<T> children) {
|
||||
this.parent = parent;
|
||||
protected TreeNodeOnList(List<T> children) {
|
||||
this.children = children;
|
||||
}
|
||||
|
||||
|
|
@ -43,10 +42,6 @@ public abstract class TreeNodeOnList<T, P> implements ITreeNode<T> {
|
|||
onChildAdded(newChild);
|
||||
}
|
||||
|
||||
protected P getParent() {
|
||||
return parent;
|
||||
}
|
||||
|
||||
protected abstract void setParentIfRequired(T newChild);
|
||||
|
||||
protected abstract void onChildAdded(T newChild);
|
||||
|
|
@ -92,4 +87,8 @@ public abstract class TreeNodeOnList<T, P> implements ITreeNode<T> {
|
|||
onChildAdded(newChild);
|
||||
}
|
||||
|
||||
public List<T> getChildren() {
|
||||
return Collections.unmodifiableList(children);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue