001 /*--------------------------------------------------------------------------+
002 $Id: FormalParameterComparator.java 26283 2010-02-18 11:18:57Z juergens $
003 | |
004 | Copyright 2005-2010 Technische Universitaet Muenchen |
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 or implied. |
015 | See the License for the specific language governing permissions and |
016 | limitations under the License. |
017 +--------------------------------------------------------------------------*/
018 package edu.tum.cs.commons.reflect;
019
020 import java.util.Comparator;
021
022 /**
023 * This comparator orders formal parameters by their position within the formal
024 * parameter list of the defining method. This comparator raises an exception if
025 * the the compared parameters do not belong to the same method.
026 *
027 *
028 * @author Florian Deissenboeck
029 * @author $Author: juergens $
030 * @version $Rev: 26283 $
031 * @levd.rating GREEN Hash: 06C5FDF68F8F0EF99EE068876259CBC7
032 */
033 public class FormalParameterComparator implements Comparator<FormalParameter> {
034
035 /**
036 * Compae formal parameters by their position within the formal parameter
037 * list of the defining method.
038 *
039 * @throws IllegalArgumentException
040 * if parameters belong to different methods.
041 */
042 public int compare(FormalParameter p1, FormalParameter p2)
043 throws IllegalArgumentException {
044 if (!p1.getMethod().equals(p2.getMethod())) {
045 throw new IllegalArgumentException(
046 "Parameters must belong to same method");
047 }
048 return p1.getPosition() - p2.getPosition();
049 }
050 }