001package org.andromda.utils.beans.comparators; 002 003import java.io.Serializable; 004import java.util.Comparator; 005 006 007/** 008 * Used to sort Boolean values 009 * 010 * @author Chad Brandon 011 */ 012class BooleanComparator 013 implements Comparator, 014 Serializable 015{ 016 private static final long serialVersionUID = 34L; 017 018 /** 019 * Used to sort Boolean values, both objects are assumed 020 * to be Boolean instances. 021 * @param objectA 022 * @param objectB 023 * @return compare result 024 */ 025 public int compare( 026 Object objectA, 027 Object objectB) 028 { 029 Boolean aAsBoolean = (Boolean)objectA; 030 Boolean bAsBoolean = (Boolean)objectB; 031 int result = 0; 032 if (aAsBoolean.booleanValue() && !bAsBoolean.booleanValue()) 033 { 034 result = 1; 035 } 036 else if (!aAsBoolean.booleanValue() && bAsBoolean.booleanValue()) 037 { 038 result = -1; 039 } 040 return result; 041 } 042}