org.jboss.jca.common.api.metadata.MergeUtil Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of ironjacamar-common-api Show documentation
Show all versions of ironjacamar-common-api Show documentation
IronJacamar is an implementation of the Java EE Connector Architecture 1.7 specification
The newest version!
/*
* IronJacamar, a Java EE Connector Architecture implementation
* Copyright 2008, Red Hat Inc, and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.jca.common.api.metadata;
import org.jboss.jca.common.api.metadata.spec.ConfigProperty;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
/**
*
* A static class with Merge Utilities methods.
*
* @author Stefano Maestri
*
*/
public class MergeUtil
{
/**
*
* Merge to List. The results is the union of the two arrays. Element present in left and right List
* (letft.equals(right) = true) are present only one and left ones are selected
*
* @param the type of List elements
* @param left left side List to merge
* @param right right side List to merge
* @return merged List
*/
public static List mergeList(List left, List right)
{
Set newSet = new HashSet((left == null ? 0 : left.size())
+ (right == null ? 0 : right.size()));
if (left != null)
newSet.addAll(left);
if (right != null)
newSet.addAll(right);
List newList = new ArrayList(newSet.size());
newList.addAll(newSet);
return newList;
}
/**
*
* F Merge to List of ConfigProperty. The results is the union of the two arrays.
* Element present in left and right List
* (letft.equals(right) = true) are present only one and left ones are selected
*
*
* @param left left side List to merge
* @param right right side List to merge
* @return merged List
*/
public static List mergeConfigList(
List left, List right)
{
ArrayList newList = new ArrayList((left == null ? 0 : left.size())
+ (right == null ? 0 : right.size()));
if (left == null)
{
if (right != null)
newList.addAll(right);
}
else
{
List leftNames = new ArrayList(left.size());
for (ConfigProperty l : left)
{
newList.add(l);
leftNames.add(l.getConfigPropertyName().getValue());
}
if (right != null)
{
for (ConfigProperty r : right)
{
boolean toAdd = true;
for (String name : leftNames)
{
if (name.equals(r.getConfigPropertyName().getValue()))
toAdd = false;
}
if (toAdd)
newList.add(r);
}
}
}
newList.trimToSize();
return newList;
}
}