ruper2/src/java/core/org/krysalis/ruper/repository/compare NetworkComparator.java,NONE,1.1 AbstractRepositoryComparator.java,NONE,1.1

[email protected]
Newsgroups gmane.comp.krysalis.metamorphosis.cvs
Message-ID <[email protected]>
Update of /cvsroot/metamorphosis/ruper2/src/java/core/org/krysalis/ruper/repository/compare
In directory sc8-pr-cvs1:/tmp/cvs-serv1200/src/java/core/org/krysalis/ruper/repository/compare

Added Files:
	NetworkComparator.java AbstractRepositoryComparator.java 
Log Message:
RepositoryManager handles the repository selectors and comparators

--- NEW FILE: NetworkComparator.java ---
/*
 * Created on Sep 10, 2003
 */
package org.krysalis.ruper.repository.compare;

import java.util.Comparator;

import org.krysalis.ruper.repository.Repository;
import org.krysalis.ruper.repository.RepositoryAttribute;
/**
 * @author anou_mana
 */
public final class NetworkComparator extends AbstractRepositoryComparator {

	private static final NetworkComparator INSTANCE = new NetworkComparator();

	/**
	 * @param expression
	 */
	private NetworkComparator() {
		super();
	}

	public Comparator getInstance() {
		return INSTANCE;
	}

	public int compareRepositories(final Repository repository1, final Repository repository2) {
		int equals = -1;
		boolean remote1 = repository1.getAttributes().hasAttribute(RepositoryAttribute.REMOTE);
		boolean remote2 = repository2.getAttributes().hasAttribute(RepositoryAttribute.REMOTE);
		
		if( remote1 )
		{
			if(remote2)
				equals = 0;
			else
				equals = 1;
		}
		return equals;
	}
}

--- NEW FILE: AbstractRepositoryComparator.java ---
/*
 * Created on Sep 10, 2003
 */
package org.krysalis.ruper.repository.compare;

import java.util.Comparator;

import org.krysalis.ruper.repository.Repository;
import org.krysalis.ruper.util.text.MessageConstants;
import org.krysalis.ruper.util.text.Messages;

/**
 * @author anou_mana
 */
public abstract class AbstractRepositoryComparator implements Comparator {

	public int compare(final Object object1, final Object object2) {
		int comparison = 0;

		if (object1 instanceof Repository) {
			if (object2 instanceof Repository) {

				comparison =
					compareRepositories((Repository) object1, (Repository) object2);
			}
			else {
				throw new IllegalArgumentException(
					Messages.getString(
				MessageConstants.WRONG_TYPE,
						new Object[] {
							object2.getClass().getName(),
							Repository.class.getName()}));
			}
		}
		else {
			throw new IllegalArgumentException(
				Messages.getString(
					"WRONG_TYPE",
					new Object[] {
						object1.getClass().getName(),
						Repository.class.getName()}));
		}
		
		return comparison;
	}

	public abstract int compareRepositories(
		final Repository repository1,
		final Repository repository2);
}




-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.