From: Egon W. <eg...@us...> - 2005-01-03 09:11:50
|
Update of /cvsroot/cdk/cdk/src/org/openscience/cdk/tools/manipulator In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv3650/src/org/openscience/cdk/tools/manipulator Added Files: RingSizeComparator.java Log Message: Moved RingSet.sort() to RingSetManipulator.sort() --- NEW FILE: RingSizeComparator.java --- /* $RCSfile: RingSizeComparator.java,v $ * $Author: egonw $ * $Date: 2005/01/03 09:11:41 $ * $Revision: 1.1 $ * * Copyright (C) 2004 The Chemistry Development Kit (CDK) project * * Contact: cdk...@li... * * This program 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 2.1 * of the License, or (at your option) any later version. * All we ask is that proper credit is given for our work, which includes * - but is not limited to - adding the above copyright notice to the beginning * of your source code files, and to any copyright notice that you may distribute * with programs based on this work. * * This program 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 this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ package org.openscience.cdk.tools.manipulator; import org.openscience.cdk.*; import java.util.Collections; import java.util.Comparator; import java.util.Enumeration; import java.util.Vector; /** * @cdk.module standard */ public class RingSizeComparator implements java.util.Comparator { /** Flag to denote that the set is order with the largest ring first? */ public final static int LARGE_FIRST = 1; /** Flag to denote that the set is order with the smallest ring first? */ public final static int SMALL_FIRST = 2; int sortOrder = SMALL_FIRST; /** * Constructs a new comparator to sort rings by size. * * @param order Sort order: either RingSet.SMALL_FIRST or * RingSet.LARGE_FIRST. */ public RingSizeComparator(int order) { sortOrder = order; } public int compare(Object object1, Object object2) throws ClassCastException { int size1 = ((Ring)object1).getAtomCount(); int size2 = ((Ring)object2).getAtomCount(); if (size1 == size2) return 0; if (size2 > size1 && sortOrder == SMALL_FIRST) { return 1; } if (size2 > size1 && sortOrder == LARGE_FIRST) { return -1; } if (size2 < size1 && sortOrder == SMALL_FIRST) { return -1; } if (size2 < size1 && sortOrder == LARGE_FIRST) { return 1; } return 0; } } |