2 * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.controller.md.sal.common.impl.routing;
13 import org.opendaylight.controller.md.sal.common.api.routing.RouteChange;
15 import com.google.common.collect.ImmutableMap;
16 import com.google.common.collect.ImmutableSet;
18 public class RoutingUtils {
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);
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);
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);
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;
45 public RouteChangeImpl(ImmutableMap<C, Set<P>> announcement, ImmutableMap<C, Set<P>> removal) {
47 this.removal = removal;
48 this.announcement = announcement;
52 public Map<C, Set<P>> getAnnouncements() {
57 public Map<C, Set<P>> getRemovals() {
62 public int hashCode() {
65 result = prime * result + ((announcement == null) ? 0 : announcement.hashCode());
66 result = prime * result + ((removal == null) ? 0 : removal.hashCode());
71 public boolean equals(Object obj) {
78 if (getClass() != obj.getClass()) {
81 RouteChangeImpl<?, ?> other = (RouteChangeImpl<?, ?>) obj;
82 if (announcement == null) {
83 if (other.announcement != null)
85 } else if (!announcement.equals(other.announcement))
87 if (removal == null) {
88 if (other.removal != null) {
91 } else if (!removal.equals(other.removal))