1 42 43 package org.jfree.util; 44 45 import java.text.AttributedCharacterIterator ; 46 import java.text.AttributedString ; 47 import java.text.CharacterIterator ; 48 import java.util.Map ; 49 50 55 public class AttributedStringUtilities { 56 57 60 private AttributedStringUtilities() { 61 } 62 63 73 public static boolean equal(AttributedString s1, AttributedString s2) { 74 if (s1 == null) { 75 return (s2 == null); 76 } 77 if (s2 == null) { 78 return false; 79 } 80 AttributedCharacterIterator it1 = s1.getIterator(); 81 AttributedCharacterIterator it2 = s2.getIterator(); 82 char c1 = it1.first(); 83 char c2 = it2.first(); 84 int start = 0; 85 while (c1 != CharacterIterator.DONE) { 86 int limit1 = it1.getRunLimit(); 87 int limit2 = it2.getRunLimit(); 88 if (limit1 != limit2) { 89 return false; 90 } 91 Map m1 = it1.getAttributes(); 93 Map m2 = it2.getAttributes(); 94 if (!m1.equals(m2)) { 95 return false; 96 } 97 for (int i = start; i < limit1; i++) { 99 if (c1 != c2) { 100 return false; 101 } 102 c1 = it1.next(); 103 c2 = it2.next(); 104 } 105 start = limit1; 106 } 107 return c2 == CharacterIterator.DONE; 108 } 109 110 } 111 | Popular Tags |