package FMM; import java.util.LinkedList; public class GoalModelBuildingBlock { public String name; public LinkedList links; private LinkedList intentions; public GoalModelBuildingBlock(String name) { this.name = name; links = new LinkedList(); intentions = new LinkedList(); } public LinkedList allLinks() { return links; } public LinkedList leafCollection() { LinkedList leaves = new LinkedList(); for(Intention i: intentions) { if (i.leaf==true) { leaves.add(i); } } return leaves; } public boolean add(Intention i) { return intentions.add(i); } public boolean add(ElementLink l) { boolean b1 = false , b2 =false, b3=false, linkIsNew = true, toIntentionIsNew = true, fromIntentionIsNew = true; for (ElementLink el: links) { if (el.name.equals(l.name)) { linkIsNew = false; break; } } if (linkIsNew) { b1 = links.add(l); } for (Intention i:intentions) { if (i.name.equals(l.toLinks().name)) { toIntentionIsNew = false; } if (i.name.equals(l.fromLinks().name)) { fromIntentionIsNew = false; } } if (toIntentionIsNew) b2 = intentions.add(l.toLinks()); if (fromIntentionIsNew) b3 = intentions.add(l.fromLinks()); return (b1 && b2 && b3); } public boolean delete(Intention i) { // we don't check if the deleted intention exist in an element links within this GoalTemplate and assume that GPF analyst checks the consistency for(Intention t: intentions) { if (i.name.equals(t.name)) return intentions.remove(t); } return false; } public boolean delete(ElementLink l) { // in the method we don't delete the to side intention of the link because other links may be using it. if that's not the case GPF analyst must use delete intention method for removing that intention. boolean b1 = false, b2 = false; for(ElementLink k: links) { if (k.name.equals(l.name)) { b1 = links.remove(k); break; } } for(Intention i: intentions) { if (l.fromLinks().name.equals(i.name)) { b2 = intentions.remove(i); break; } } return (b1&&b2); } public Intention mainGoal() { for(Intention t: intentions) { if (t.mainGoal) return(t); } return null; } boolean isEqualTo(GoalModelBuildingBlock gt) { boolean equal = false; if (this.name.equals(gt.name)) equal = true; else equal = false; return equal; } }