Untangle the XML/Hello message decoders
[controller.git] / opendaylight / md-sal / sal-common-impl / src / main / java / org / opendaylight / controller / md / sal / common / impl / routing / RoutingUtils.java
1 /*
2  * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.controller.md.sal.common.impl.routing;
9
10 import java.util.Map;
11 import java.util.Set;
12
13 import org.opendaylight.controller.md.sal.common.api.routing.RouteChange;
14
15 import com.google.common.collect.ImmutableMap;
16 import com.google.common.collect.ImmutableSet;
17
18 public class RoutingUtils {
19     
20     public static <C,P> RouteChange<C,P> removalChange(C context,P path) {
21         final ImmutableMap<C, Set<P>> announcements = ImmutableMap.<C,Set<P>>of();
22         final ImmutableMap<C, Set<P>> removals = ImmutableMap.<C,Set<P>>of(context, ImmutableSet.of(path));
23         return new RouteChangeImpl<C,P>(announcements, removals);
24     }
25     
26     public static <C,P> RouteChange<C,P> announcementChange(C context,P path) {
27         final ImmutableMap<C, Set<P>> announcements = ImmutableMap.<C,Set<P>>of(context, ImmutableSet.of(path));
28         final ImmutableMap<C, Set<P>> removals = ImmutableMap.<C,Set<P>>of();
29         return new RouteChangeImpl<C,P>(announcements, removals);
30     }
31     
32     
33     public static <C,P> RouteChange<C,P> change(Map<C, Set<P>> announcements,
34             Map<C, Set<P>> removals) {
35         final ImmutableMap<C, Set<P>> immutableAnnouncements = ImmutableMap.<C,Set<P>>copyOf(announcements);
36         final ImmutableMap<C, Set<P>> immutableRemovals = ImmutableMap.<C,Set<P>>copyOf(removals);
37         return new RouteChangeImpl<C,P>(immutableAnnouncements, immutableRemovals);
38     }
39     
40     
41     private static class RouteChangeImpl<C,P> implements RouteChange<C, P> {
42         private final Map<C, Set<P>> removal;
43         private final Map<C, Set<P>> announcement;
44
45         public RouteChangeImpl(ImmutableMap<C, Set<P>> announcement, ImmutableMap<C, Set<P>> removal) {
46             super();
47             this.removal = removal;
48             this.announcement = announcement;
49         }
50
51         @Override
52         public Map<C, Set<P>> getAnnouncements() {
53             return announcement;
54         }
55         
56         @Override
57         public Map<C, Set<P>> getRemovals() {
58             return removal;
59         }
60
61         @Override
62         public int hashCode() {
63             final int prime = 31;
64             int result = 1;
65             result = prime * result + ((announcement == null) ? 0 : announcement.hashCode());
66             result = prime * result + ((removal == null) ? 0 : removal.hashCode());
67             return result;
68         }
69
70         @Override
71         public boolean equals(Object obj) {
72             if (this == obj) {
73                 return true;
74             }
75             if (obj == null) {
76                 return false;
77             }
78             if (getClass() != obj.getClass()) {
79                 return false;
80             }
81             RouteChangeImpl other = (RouteChangeImpl) obj;
82             if (announcement == null) {
83                 if (other.announcement != null)
84                     return false;
85             } else if (!announcement.equals(other.announcement))
86                 return false;
87             if (removal == null) {
88                 if (other.removal != null) {
89                     return false;
90                 }
91             } else if (!removal.equals(other.removal))
92                 return false;
93             return true;
94         }
95     }
96
97
98     
99 }

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.