001 /**
002 * $Id: ObjectComparator.java,v 1.4 2010/12/30 17:33:23 oboehm Exp $
003 *
004 * Copyright (c) 2008 by Oliver Boehm
005 *
006 * Licensed under the Apache License, Version 2.0 (the "License");
007 * you may not use this file except in compliance with the License.
008 * You may obtain a copy of the License at
009 *
010 * http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing, software
013 * distributed under the License is distributed on an "AS IS" BASIS,
014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express orimplied.
015 * See the License for the specific language governing permissions and
016 * limitations under the License.
017 *
018 * (c)reated 11.02.2009 by oliver (ob@oasd.de)
019 */
020 package patterntesting.runtime.util;
021
022 import java.io.Serializable;
023 import java.util.Comparator;
024
025 /**
026 * Compares two objects using their string representation.
027 *
028 * @author <a href="boehm@javatux.de">oliver</a>
029 * @since 11.02.2009
030 * @version $Revision: 1.4 $
031 */
032 public class ObjectComparator implements Comparator<Object>, Serializable {
033
034 private static final long serialVersionUID = 20100106L;
035
036 /**
037 * Compare.
038 *
039 * @param o1 the object 1
040 * @param o2 the object 2
041 * @return 0 if both are equals
042 * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
043 */
044 public int compare(final Object o1, final Object o2) {
045 String s1 = o1.toString();
046 String s2 = o2.toString();
047 return s1.compareTo(s2);
048 }
049
050 }