/*
* Copyright (C) 2005-2011 Alfresco Software Limited.
*
* This file is part of Alfresco
*
* Alfresco 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 3 of the License, or
* (at your option) any later version.
*
* Alfresco 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 Alfresco. If not, see .
*/
package org.alfresco.util.schemacomp;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import org.alfresco.util.schemacomp.Difference.Where;
import org.alfresco.util.schemacomp.Result.Strength;
import org.alfresco.util.schemacomp.model.DbObject;
import org.alfresco.util.schemacomp.model.Schema;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.Predicate;
/**
* A collection of utility methods for determining differences between two database schemas.
*
* @author Matt Ward
*/
public class DefaultComparisonUtils implements ComparisonUtils
{
/**
* @param objToFind
* @return
*/
@Override
public DbObject findSameObjectAs(Collection extends DbObject> objects, final DbObject objToFind)
{
return (DbObject) CollectionUtils.find(objects, new Predicate()
{
@Override
public boolean evaluate(Object o)
{
DbObject object = (DbObject) o;
return object.sameAs(objToFind);
}
});
}
@Override
public List findEquivalentObjects(Schema schema, DbObject objToMatch)
{
EquivalentObjectSeeker objectSeeker = new EquivalentObjectSeeker(objToMatch);
schema.accept(objectSeeker);
return objectSeeker.getMatches();
}
@Override
public void compareSimpleCollections(DbProperty leftProp,
DbProperty rightProp, DiffContext ctx, Strength strength)
{
@SuppressWarnings("unchecked")
Collection extends Object> leftCollection = (Collection extends Object>) leftProp.getPropertyValue();
@SuppressWarnings("unchecked")
Collection extends Object> rightCollection = (Collection extends Object>) rightProp.getPropertyValue();
// TODO: Temporary code during refactoring
ArrayList extends Object> leftList = new ArrayList