Merge "Add consistency check of visible yang modules to netconf."
[controller.git] / opendaylight / md-sal / sal-common-impl / src / main / java / org / opendaylight / controller / md / sal / common / impl / routing / RoutingUtils.java
1 package org.opendaylight.controller.md.sal.common.impl.routing;
2
3 import java.util.Map;
4 import java.util.Set;
5
6 import org.opendaylight.controller.md.sal.common.api.routing.RouteChange;
7
8 import com.google.common.collect.ImmutableMap;
9 import com.google.common.collect.ImmutableSet;
10
11 public class RoutingUtils {
12     
13     public static <C,P> RouteChange<C,P> removalChange(C context,P path) {
14         final ImmutableMap<C, Set<P>> announcements = ImmutableMap.<C,Set<P>>of();
15         final ImmutableMap<C, Set<P>> removals = ImmutableMap.<C,Set<P>>of(context, ImmutableSet.of(path));
16         return new RouteChangeImpl<C,P>(announcements, removals);
17     }
18     
19     public static <C,P> RouteChange<C,P> announcementChange(C context,P path) {
20         final ImmutableMap<C, Set<P>> announcements = ImmutableMap.<C,Set<P>>of(context, ImmutableSet.of(path));
21         final ImmutableMap<C, Set<P>> removals = ImmutableMap.<C,Set<P>>of();
22         return new RouteChangeImpl<C,P>(announcements, removals);
23     }
24     
25     
26     public static <C,P> RouteChange<C,P> change(Map<C, Set<P>> announcements,
27             Map<C, Set<P>> removals) {
28         final ImmutableMap<C, Set<P>> immutableAnnouncements = ImmutableMap.<C,Set<P>>copyOf(announcements);
29         final ImmutableMap<C, Set<P>> immutableRemovals = ImmutableMap.<C,Set<P>>copyOf(removals);
30         return new RouteChangeImpl<C,P>(immutableAnnouncements, immutableRemovals);
31     }
32     
33     
34     private static class RouteChangeImpl<C,P> implements RouteChange<C, P> {
35         private final Map<C, Set<P>> removal;
36         private final Map<C, Set<P>> announcement;
37
38         public RouteChangeImpl(ImmutableMap<C, Set<P>> removal, ImmutableMap<C, Set<P>> announcement) {
39             super();
40             this.removal = removal;
41             this.announcement = announcement;
42         }
43
44         @Override
45         public Map<C, Set<P>> getAnnouncements() {
46             return announcement;
47         }
48         
49         @Override
50         public Map<C, Set<P>> getRemovals() {
51             return removal;
52         }
53
54         @Override
55         public int hashCode() {
56             final int prime = 31;
57             int result = 1;
58             result = prime * result + ((announcement == null) ? 0 : announcement.hashCode());
59             result = prime * result + ((removal == null) ? 0 : removal.hashCode());
60             return result;
61         }
62
63         @Override
64         public boolean equals(Object obj) {
65             if (this == obj) {
66                 return true;
67             }
68             if (obj == null) {
69                 return false;
70             }
71             if (getClass() != obj.getClass()) {
72                 return false;
73             }
74             RouteChangeImpl other = (RouteChangeImpl) obj;
75             if (announcement == null) {
76                 if (other.announcement != null)
77                     return false;
78             } else if (!announcement.equals(other.announcement))
79                 return false;
80             if (removal == null) {
81                 if (other.removal != null) {
82                     return false;
83                 }
84             } else if (!removal.equals(other.removal))
85                 return false;
86             return true;
87         }
88     }
89
90
91     
92 }