/*
 * 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.repo.publishing;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import org.alfresco.service.cmr.publishing.PublishingPackage;
import org.alfresco.service.cmr.publishing.PublishingPackageEntry;
import org.alfresco.service.cmr.repository.NodeRef;
/**
 * @author Brian
 * @author Nick Smith
 * @since 4.0
 */
public class PublishingPackageImpl implements PublishingPackage
{
    private final Map entries;
    private final Set nodesToPublish;
    private final Set nodesToUnpublish;
    
    public PublishingPackageImpl(Map entries)
    {
        Set toPublish = new HashSet();
        Set toUnpublish = new HashSet();
        for (PublishingPackageEntry entry : entries.values())
        {
            NodeRef node = entry.getNodeRef();
            if (entry.isPublish())
            {
                toPublish.add(node);
            }
            else
            {
                toUnpublish.add(node);
            }
        }
        HashMap entryMap = new HashMap(entries);
        this.entries = Collections.unmodifiableMap(entryMap);
        this.nodesToPublish = Collections.unmodifiableSet(toPublish);
        this.nodesToUnpublish = Collections.unmodifiableSet(toUnpublish);
    }
    
    /**
    * {@inheritDoc}
     */
    public Collection getEntries()
    {
        return entries.values();
    }
    public Map getEntryMap()
    {
        return entries;
    }
    
    /**
     * {@inheritDoc}
     */
     public Set getNodesToPublish()
     {
         return nodesToPublish;
     }
     /**
     * {@inheritDoc}
     */
     @Override
     public Set getNodesToUnpublish()
     {
         return nodesToUnpublish;
     }
}