public boolean equals()

in geronimo-jcdi_2.0_spec/src/main/java/javax/enterprise/util/AnnotationLiteral.java [106:215]


    public boolean equals(Object other)
    {
        // use a private reference to prevent instance swapping as we don't use synchronization nor volatile on meths.
        Method[] methods = getMethods();

        if(other == this)
        {
            return true;
        }
        
        if(other == null)
        {
            return false;
        }
        
        if (other instanceof Annotation)
        {
            Annotation annotOther = (Annotation) other;
            if (this.annotationType().equals(annotOther.annotationType()))
            {
                for (Method method : methods)
                {
                    Object value = callMethod(this, method);
                    Object annotValue = callMethod(annotOther, method);
                    
                    if((value == null && annotValue != null) || (value != null && annotValue == null))
                    {
                        return false;
                    }
                    
                    if(value == null)
                    {
                        continue;
                    }
                    
                    Class<?> valueClass = value.getClass();
                    Class<?> annotValueClass = annotValue.getClass();
                    
                    if(valueClass.isPrimitive() && annotValueClass.isPrimitive())
                    {
                        if((valueClass != Float.TYPE && annotValue != Float.TYPE)
                                || (valueClass != Double.TYPE && annotValue != Double.TYPE))
                        {
                            if(value != annotValue)
                            {
                                return false;
                            }
                            
                        }
                    }
                    else if(valueClass.isArray() && annotValueClass.isArray())
                    {
                        Class<?> type = valueClass.getComponentType();
                        if(type.isPrimitive())
                        {
                            if(Long.TYPE == type)
                            {
                                if(!Arrays.equals(((Long[])value),(Long[])annotValue)) return false;
                            }
                            else if(Integer.TYPE == type)
                            {
                                if(!Arrays.equals(((Integer[])value),(Integer[])annotValue)) return false;
                            }
                            else if(Short.TYPE == type)
                            {
                                if(!Arrays.equals(((Short[])value),(Short[])annotValue)) return false;
                            }
                            else if(Double.TYPE == type)
                            {
                                if(!Arrays.equals(((Double[])value),(Double[])annotValue)) return false;
                            }
                            else if(Float.TYPE == type)
                            {
                                if(!Arrays.equals(((Float[])value),(Float[])annotValue)) return false;
                            }
                            else if(Boolean.TYPE == type)
                            {
                                if(!Arrays.equals(((Boolean[])value),(Boolean[])annotValue)) return false;
                            }
                            else if(Byte.TYPE == type)
                            {
                                if(!Arrays.equals(((Byte[])value),(Byte[])annotValue)) return false;
                            }
                            else if(Character.TYPE == type)
                            {
                                if(!Arrays.equals(((Character[])value),(Character[])annotValue)) return false;
                            }                    
                        }
                        else
                        {
                            if(!Arrays.equals(((Object[])value),(Object[])annotValue)) return false;
                        }
                    }
                    
                    else if (annotValue != null)
                    {
                        if (!value.equals(annotValue))
                        {
                            return false;
                        }
                    } 

                }
                
                return true;
            }
        }

        return false;
    }