001    package EVolve.data;
002    
003    /* EVolve - an Extensible Software Visualization Framework
004     * Copyright (C) 2001-2002 Qin Wang
005     *
006     * This library is free software; you can redistribute it and/or
007     * modify it under the terms of the GNU Library General Public
008     * License as published by the Free Software Foundation; either
009     * version 2 of the License, or (at your option) any later version.
010     *
011     * This library is distributed in the hope that it will be useful,
012     * but WITHOUT ANY WARRANTY; without even the implied warranty of
013     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
014     * Library General Public License for more details.
015     *
016     * You should have received a copy of the GNU Library General Public
017     * License along with this library; if not, write to the
018     * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
019     * Boston, MA 02111-1307, USA.
020     */
021    
022    /*
023     * EVolve is distributed at http://www.sable.mcgill.ca/EVolve/
024     */
025    
026    
027    public class NumericStringComparator implements EntityComparator {
028            public String getName() {
029                    return "Numerical";
030            }
031    
032            public int compare(Entity entity1, Entity entity2) {
033                    String name1 = entity1.getName();
034                    String name2 = entity2.getName();
035    
036                    try {
037                            return Integer.parseInt(name1) - Integer.parseInt(name2);
038                    } catch (NumberFormatException e) {
039                            return name1.compareTo(name2);
040                    }
041            }
042    
043        public Object clone() {
044            try {
045                return super.clone();
046            } catch (CloneNotSupportedException e) {
047                return null;
048            }
049        }
050    }