2 * Copyright (c) 2016 Ericsson India Global Services Pvt Ltd. 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.netvirt.elan.l2gw.ha.commands;
10 import java.util.ArrayList;
11 import java.util.Comparator;
12 import java.util.List;
13 import javax.annotation.Nonnull;
14 import javax.annotation.Nullable;
16 public abstract class BaseCommand<T> {
19 * Abstract method give diff between two List passed based on comparator.
20 * @param updated Updated List
21 * @param original Origina list to be compared with
22 * @param comparator based on which diff will be returned
23 * @param <U> U extends DataObject
24 * @return List of diff based on comparator
26 public <U> List<U> diffOf(@Nullable List<U> updated, @Nullable final List<U> original,
27 final Comparator<U> comparator) {
28 if (updated == null) {
29 return new ArrayList<>();
31 if (original == null) {
32 return new ArrayList<>(updated);
35 List<U> result = new ArrayList<>();
36 for (U ele : updated) {
37 boolean present = false;
38 for (U orig : original) {
39 if (0 == comparator.compare(ele, orig)) {
52 * Abstract method give diff between two List passed.
53 * @param updated Updated List
54 * @param original Origina list to be compared with
55 * @return List of diff based
58 public List<T> diffOf(List<T> updated, final List<T> original) {
59 if (updated == null) {
60 return new ArrayList<>();
62 if (original == null) {
63 return new ArrayList<>(updated);
65 List<T> result = new ArrayList<>();
66 for (T ele : updated) {
67 boolean present = false;
68 for (T orig : original) {
69 if (areEqual(ele, orig)) {
81 public abstract boolean areEqual(T objA, T objB);