1 package org.opendaylight.controller.md.sal.common.impl.routing;
6 import org.opendaylight.controller.md.sal.common.api.routing.RouteChange;
8 import com.google.common.collect.ImmutableMap;
9 import com.google.common.collect.ImmutableSet;
11 public class RoutingUtils {
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);
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);
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);
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;
38 public RouteChangeImpl(ImmutableMap<C, Set<P>> removal, ImmutableMap<C, Set<P>> announcement) {
40 this.removal = removal;
41 this.announcement = announcement;
45 public Map<C, Set<P>> getAnnouncements() {
50 public Map<C, Set<P>> getRemovals() {
55 public int hashCode() {
58 result = prime * result + ((announcement == null) ? 0 : announcement.hashCode());
59 result = prime * result + ((removal == null) ? 0 : removal.hashCode());
64 public boolean equals(Object obj) {
71 if (getClass() != obj.getClass()) {
74 RouteChangeImpl other = (RouteChangeImpl) obj;
75 if (announcement == null) {
76 if (other.announcement != null)
78 } else if (!announcement.equals(other.announcement))
80 if (removal == null) {
81 if (other.removal != null) {
84 } else if (!removal.equals(other.removal))