/* * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0 which accompanies this distribution, * and is available at http://www.eclipse.org/legal/epl-v10.html */ package org.opendaylight.controller.md.sal.common.impl.routing; import java.util.Map; import java.util.Set; import org.opendaylight.controller.md.sal.common.api.routing.RouteChange; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; public class RoutingUtils { public static RouteChange removalChange(C context,P path) { final ImmutableMap> announcements = ImmutableMap.>of(); final ImmutableMap> removals = ImmutableMap.>of(context, ImmutableSet.of(path)); return new RouteChangeImpl(announcements, removals); } public static RouteChange announcementChange(C context,P path) { final ImmutableMap> announcements = ImmutableMap.>of(context, ImmutableSet.of(path)); final ImmutableMap> removals = ImmutableMap.>of(); return new RouteChangeImpl(announcements, removals); } public static RouteChange change(Map> announcements, Map> removals) { final ImmutableMap> immutableAnnouncements = ImmutableMap.>copyOf(announcements); final ImmutableMap> immutableRemovals = ImmutableMap.>copyOf(removals); return new RouteChangeImpl(immutableAnnouncements, immutableRemovals); } private static class RouteChangeImpl implements RouteChange { private final Map> removal; private final Map> announcement; public RouteChangeImpl(ImmutableMap> announcement, ImmutableMap> removal) { super(); this.removal = removal; this.announcement = announcement; } @Override public Map> getAnnouncements() { return announcement; } @Override public Map> getRemovals() { return removal; } @Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + ((announcement == null) ? 0 : announcement.hashCode()); result = prime * result + ((removal == null) ? 0 : removal.hashCode()); return result; } @Override public boolean equals(Object obj) { if (this == obj) { return true; } if (obj == null) { return false; } if (getClass() != obj.getClass()) { return false; } RouteChangeImpl other = (RouteChangeImpl) obj; if (announcement == null) { if (other.announcement != null) return false; } else if (!announcement.equals(other.announcement)) return false; if (removal == null) { if (other.removal != null) { return false; } } else if (!removal.equals(other.removal)) return false; return true; } } }