/*
* Copyright (c) 2014, 2015, Dynatrace and/or its affiliates. All rights reserved.
*
* This file is part of the Lock Contention Tracing Subsystem for the HotSpot
* Virtual Machine, which is developed at Christian Doppler Laboratory on
* Monitoring and Evolution of Very-Large-Scale Software Systems. Please
* contact us at if you need additional information
* or have any questions.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code 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 General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work. If not, see .
*
*/
package sun.evtracing.parser.metadata;
import java.util.Comparator;
import sun.evtracing.parser.metadata.JavaMethod;
public class JavaMethodDeepComparator implements Comparator {
public static final JavaMethodDeepComparator INSTANCE = new JavaMethodDeepComparator();
@Override
public int compare(JavaMethod o1, JavaMethod o2) {
if (o1 == o2) {
return 0;
}
if (o1.isSpecial() && o2.isSpecial()) {
if (o1.equals(o2)) {
return 0;
}
}
if (o1.isSet() && !o2.isSet()) {
return 1;
}
if (!o1.isSet() && o2.isSet()) {
return -1;
}
if (!o1.isSet() && !o2.isSet()) {
return System.identityHashCode(o1) - System.identityHashCode(o2);
}
int result = JavaClassDeepComparator.INSTANCE.compare(o1.clazz(), o2.clazz());
if (result == 0) {
result = o1.name().compareTo(o2.name());
if (result == 0) {
result = o1.signature().compareTo(o2.signature());
}
}
return result;
}
}