Update of /cvsroot/metamorphosis/ruper2/src/java/core/org/krysalis/ruper2/repository/compare
In directory sc8-pr-cvs1:/tmp/cvs-serv30481/src/java/core/org/krysalis/ruper2/repository/compare
Added Files:
AbstractRepositoryComparator.java PriorityComparator.java
Log Message:
Avoid clash with existing Ruper...
--- NEW FILE: AbstractRepositoryComparator.java ---
/*
* Created on Sep 10, 2003
*/
package org.krysalis.ruper2.repository.compare;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import org.krysalis.ruper2.repository.Repository;
import org.krysalis.ruper2.util.chainprocess.Handler;
import org.krysalis.ruper2.util.text.MessageConstants;
import org.krysalis.ruper2.util.text.Messages;
/**
* @author anou_mana
*/
public abstract class AbstractRepositoryComparator implements Comparator,Handler{
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(
MessageConstants.WRONG_TYPE,
new Object[] {
object1.getClass().getName(),
Repository.class.getName()}));
}
return comparison;
}
public abstract int compareRepositories(
final Repository repository1,
final Repository repository2);
public List process(final List list)
{
List processedList = new ArrayList(list);
Collections.sort(processedList, this);
return processedList;
}
}
--- NEW FILE: PriorityComparator.java ---
/*
* Created on Sep 10, 2003
*/
package org.krysalis.ruper2.repository.compare;
import java.util.Comparator;
import org.krysalis.ruper2.repository.Repository;
import org.krysalis.ruper2.repository.RepositoryAttribute;
/**
* @author anou_mana
*/
public final class PriorityComparator extends AbstractRepositoryComparator {
private static final PriorityComparator INSTANCE = new PriorityComparator();
/**
* @param expression
*/
private PriorityComparator() {
super();
}
public Comparator getInstance() {
return INSTANCE;
}
public int compareRepositories(final Repository repository1, final Repository repository2) {
int equals = -1;
int priority1 = ((Integer)repository1.getAttributes().get(RepositoryAttribute.PRIORITY)).intValue();
int priority2 = ((Integer)repository2.getAttributes().get(RepositoryAttribute.PRIORITY)).intValue();
if( priority1 > priority2 )
equals = 1;
else if (priority1 == priority2 )
equals =0;
return equals;
}
}
-------------------------------------------------------
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.