001 /*
002 * JBoss, Home of Professional Open Source.
003 * Copyright 2008, Red Hat Middleware LLC, and individual contributors
004 * as indicated by the @author tags. See the copyright.txt file in the
005 * distribution for a full listing of individual contributors.
006 *
007 * This is free software; you can redistribute it and/or modify it
008 * under the terms of the GNU Lesser General Public License as
009 * published by the Free Software Foundation; either version 2.1 of
010 * the License, or (at your option) any later version.
011 *
012 * This software is distributed in the hope that it will be useful,
013 * but WITHOUT ANY WARRANTY; without even the implied warranty of
014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015 * Lesser General Public License for more details.
016 *
017 * You should have received a copy of the GNU Lesser General Public
018 * License along with this software; if not, write to the Free
019 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
021 */
022 package org.jboss.dna.connector.federation.merge;
023
024 import java.util.Iterator;
025 import java.util.NoSuchElementException;
026 import net.jcip.annotations.ThreadSafe;
027 import org.jboss.dna.connector.federation.contribution.Contribution;
028
029 /**
030 * @author Randall Hauch
031 */
032 @ThreadSafe
033 public class OneContributionMergePlan extends MergePlan {
034
035 private static final long serialVersionUID = 1L;
036 private final Contribution contribution;
037
038 /**
039 * @param contribution the contribution for this merge plan
040 */
041 /*package*/OneContributionMergePlan( Contribution contribution ) {
042 assert contribution != null;
043 this.contribution = contribution;
044 }
045
046 /**
047 * {@inheritDoc}
048 *
049 * @see org.jboss.dna.connector.federation.merge.MergePlan#getContributionCount()
050 */
051 @Override
052 public int getContributionCount() {
053 return 1;
054 }
055
056 /**
057 * {@inheritDoc}
058 *
059 * @see org.jboss.dna.connector.federation.merge.MergePlan#getContributionFrom(java.lang.String)
060 */
061 @Override
062 public Contribution getContributionFrom( String sourceName ) {
063 return isSource(sourceName) ? contribution : null;
064 }
065
066 /**
067 * {@inheritDoc}
068 *
069 * @see java.lang.Iterable#iterator()
070 */
071 public Iterator<Contribution> iterator() {
072 return new Iterator<Contribution>() {
073 private boolean next = true;
074
075 public boolean hasNext() {
076 return next;
077 }
078
079 @SuppressWarnings( "synthetic-access" )
080 public Contribution next() {
081 if (next) {
082 next = false;
083 return contribution;
084 }
085 throw new NoSuchElementException();
086 }
087
088 public void remove() {
089 throw new UnsupportedOperationException();
090 }
091 };
092 }
093
094 /**
095 * {@inheritDoc}
096 *
097 * @see org.jboss.dna.connector.federation.merge.MergePlan#isSource(java.lang.String)
098 */
099 @Override
100 public boolean isSource( String sourceName ) {
101 return contribution.getSourceName().equals(sourceName);
102 }
103
104 /**
105 * {@inheritDoc}
106 *
107 * @see java.lang.Object#hashCode()
108 */
109 @Override
110 public int hashCode() {
111 return contribution.hashCode();
112 }
113
114 }