Coverage Report - com.jeantessier.dependency.Node
 
Classes in this File Line Coverage Branch Coverage Complexity
Node
89%
41/46
79%
19/24
1.667
 
 1  
 /*
 2  
  *  Copyright (c) 2001-2009, Jean Tessier
 3  
  *  All rights reserved.
 4  
  *  
 5  
  *  Redistribution and use in source and binary forms, with or without
 6  
  *  modification, are permitted provided that the following conditions
 7  
  *  are met:
 8  
  *  
 9  
  *      * Redistributions of source code must retain the above copyright
 10  
  *        notice, this list of conditions and the following disclaimer.
 11  
  *  
 12  
  *      * Redistributions in binary form must reproduce the above copyright
 13  
  *        notice, this list of conditions and the following disclaimer in the
 14  
  *        documentation and/or other materials provided with the distribution.
 15  
  *  
 16  
  *      * Neither the name of Jean Tessier nor the names of his contributors
 17  
  *        may be used to endorse or promote products derived from this software
 18  
  *        without specific prior written permission.
 19  
  *  
 20  
  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 21  
  *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 22  
  *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 23  
  *  A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR
 24  
  *  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 25  
  *  EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 26  
  *  PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 27  
  *  PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
 28  
  *  LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
 29  
  *  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 30  
  *  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 31  
  */
 32  
 
 33  
 package com.jeantessier.dependency;
 34  
 
 35  
 import java.util.*;
 36  
 
 37  
 public abstract class Node implements Comparable {
 38  7185
     private String  name      = "";
 39  7185
     private boolean confirmed = false;
 40  
     
 41  7185
     private Collection<Node> inbound  = new HashSet<Node>();
 42  7185
     private Collection<Node> outbound = new HashSet<Node>();
 43  
 
 44  7185
     public Node(String name, boolean confirmed) {
 45  7185
         this.name      = name;
 46  7185
         this.confirmed = confirmed;
 47  7185
     }
 48  
 
 49  
     public String getName() {
 50  58899
         return name;
 51  
     }
 52  
 
 53  
     public boolean isConfirmed() {
 54  7593
         return confirmed;
 55  
     }
 56  
 
 57  
     // Only to be used by NodeFactory and DeletingVisitor
 58  
     void setConfirmed(boolean confirmed) {
 59  180
         this.confirmed = confirmed;
 60  180
     }
 61  
     
 62  
     public boolean canAddDependencyTo(Node node) {
 63  14311
         return !equals(node);
 64  
     }
 65  
     
 66  
     public void addDependency(Node node) {
 67  3226
         if (canAddDependencyTo(node) && node.canAddDependencyTo(this)) {
 68  3222
             outbound.add(node);
 69  3222
             node.inbound.add(this);
 70  
         }
 71  3226
     }
 72  
 
 73  
     public void addDependencies(Collection<Node> nodes) {
 74  0
         for (Node node : nodes) {
 75  0
             addDependency(node);
 76  
         }
 77  0
     }
 78  
 
 79  
     public void removeDependency(Node node) {
 80  559
         outbound.remove(node);
 81  559
         node.inbound.remove(this);
 82  559
     }
 83  
 
 84  
     public void removeDependencies(Collection<? extends Node> nodes) {
 85  1
         for (Node node : nodes) {
 86  2
             removeDependency(node);
 87  
         }
 88  1
     }
 89  
 
 90  
     public Collection<Node> getInboundDependencies() {
 91  5180
         return Collections.unmodifiableCollection(inbound);
 92  
     }
 93  
 
 94  
     public Collection<Node> getOutboundDependencies() {
 95  6409
         return Collections.unmodifiableCollection(outbound);
 96  
     }
 97  
 
 98  
     public abstract void accept(Visitor visitor);
 99  
     public abstract void acceptInbound(Visitor visitor);
 100  
     public abstract void acceptOutbound(Visitor visitor);
 101  
 
 102  
     public int hashCode() {
 103  13633
         return getName().hashCode();
 104  
     }
 105  
 
 106  
     public boolean equals(Object object) {
 107  
         boolean result;
 108  
 
 109  21615
         if (this == object) {
 110  2325
             result = true;
 111  19290
         } else if (object == null || getClass() != object.getClass()) {
 112  9422
             result = false;
 113  
         } else {
 114  9868
             Node other = (Node) object;
 115  9868
             result = compareTo(other) == 0;
 116  
         }
 117  
 
 118  21615
         return result;
 119  
     }
 120  
 
 121  
     public int compareTo(Object object) {
 122  
         int result;
 123  
 
 124  11797
         if (this == object) {
 125  512
             result = 0;
 126  11285
         } else if (object == null) {
 127  0
             throw new ClassCastException("compareTo: expected a " + getClass().getName() + " but got null");
 128  11285
         } else if (!(object instanceof Node)) {
 129  0
             throw new ClassCastException("compareTo: expected a " + getClass().getName() + " but got a " + object.getClass().getName());
 130  
         } else {
 131  11285
             Node other = (Node) object;
 132  11285
             result = getName().compareTo(other.getName());
 133  
         }
 134  
 
 135  11797
         return result;
 136  
     }
 137  
 
 138  
     public String toString() {
 139  14603
         return getName();
 140  
     }
 141  
 }