org.hpccsystems.ws.client.utils.CollectionDelta Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of wsclient Show documentation
Show all versions of wsclient Show documentation
This project allows a user to interact with ESP services in a controlled manner. The API calls available under org.hpccsystems.ws.client.platform allow for a user to target ESP's across multiple environments running a range of hpccsystems-platform versions. There is no guarantee that if a user utilizes org.hpccsystems.ws.client.gen generated stub code from wsdl, that the calls will be backwards compatible with older hpccsystems-platform versions.
/*******************************************************************************
* Copyright (c) 2014 HPCC Systems. 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
*
* Contributors: HPCC Systems - initial API and implementation
******************************************************************************/
package org.hpccsystems.ws.client.utils;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
/**
* Used internally to monitor and track changes in generic collections.
*
*/
public class CollectionDelta
{
private ArrayList before;
protected String cause;
protected ArrayList added;
protected ArrayList unchanged;
protected ArrayList removed;
public CollectionDelta(String cause)
{
this.cause = cause;
before = new ArrayList();
}
public CollectionDelta(String cause, Collection before)
{
this.cause = cause;
this.before = new ArrayList(before);
}
public CollectionDelta calcChanges(T[] after)
{
return calcChanges(new ArrayList(Arrays.asList(after)));
}
public CollectionDelta calcChanges(Collection after)
{
new ArrayList(after);
added = new ArrayList();
unchanged = new ArrayList();
removed = new ArrayList(before);
for (T item : after)
{
if (removed.contains(item))
{
unchanged.add(item);
removed.remove(item);
}
else
{
added.add(item);
}
}
return this;
}
public boolean hasChanged()
{
return !removed.isEmpty() || !added.isEmpty();
}
public boolean exists(DataSingleton item)
{
return added.contains(item) || unchanged.contains(item);
}
public String getCause()
{
return cause;
}
public boolean removeContains(DataSingleton item)
{
return removed.contains(item);
}
public ArrayList getAdded()
{
return added;
}
}