equals compare Swing text attribute - Java javax.swing.text

Java examples for javax.swing.text:AttributeSet

Description

equals compare Swing text attribute

Demo Code


//package com.java2s;
import java.util.Enumeration;
import javax.swing.text.AttributeSet;

public class Main {
    public static boolean equals(AttributeSet a0, AttributeSet a1) {
        if (a0 == a1) {
            return true;
        }//from   www.ja  v  a  2  s  .  c  om
        if (a0 != null && a1 == null) {
            return false;
        }
        if (a1 != null && a0 == null) {
            return false;
        }
        if (a0 == null && a1 == null) {
            return true;
        }

        String s0 = a0.toString().trim();
        String s1 = a1.toString().trim();

        if (s0.length() != s1.length()) {
            return false;
        }

        return s0.equalsIgnoreCase(s1);
    }

    public static String toString(AttributeSet a) {
        StringBuilder builder = new StringBuilder("[");
        Enumeration en = a.getAttributeNames();
        do {
            if (!en.hasMoreElements()) {
                break;
            }
            Object name = en.nextElement();
            builder.append(name).append("=").append(a.getAttribute(name));
            if (en.hasMoreElements()) {
                builder.append(", ");
            }
        } while (true);
        builder.append("]");
        return builder.toString();
    }
}

Related Tutorials