001/* 002 * Copyright (c) 2004-2012, Willem Cazander 003 * All rights reserved. 004 * 005 * Redistribution and use in source and binary forms, with or without modification, are permitted provided 006 * that the following conditions are met: 007 * 008 * * Redistributions of source code must retain the above copyright notice, this list of conditions and the 009 * following disclaimer. 010 * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and 011 * the following disclaimer in the documentation and/or other materials provided with the distribution. 012 * 013 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 014 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 015 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 016 * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 017 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 018 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 019 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR 020 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 021 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 022 */ 023 024package org.x4o.xml.impl; 025 026import java.util.Comparator; 027 028import org.x4o.xml.element.ElementAttributeHandler; 029 030 031/** 032 * The DefaultGlobalAttributeHandlerComparator.<br> 033 * This Comparator compares the NextAttribute names with the attributeName of the ElementAttributeHandlers.<br> 034 * 035 * @author Willem Cazander 036 * @version 1.0 Feb 14, 2007 037 */ 038public class DefaultGlobalAttributeHandlerComparator implements Comparator<ElementAttributeHandler> { 039 040 /** 041 * @param e1 The first ElementAttributeHandler to compare. 042 * @param e2 The second ElementAttributeHandler to compare. 043 * @return 0 is same. 044 * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object) 045 */ 046 public int compare(ElementAttributeHandler e1, ElementAttributeHandler e2) { 047 048 for (String param:e1.getNextAttributes()) { 049 if(param.equals(e2.getAttributeName())) { 050 return -1; 051 } 052 } 053 for (String param:e2.getNextAttributes()) { 054 if(param.equals(e1.getAttributeName())) { 055 return 1; 056 } 057 } 058 return 0; 059 } 060}