< prev index next >

src/java.desktop/share/classes/java/awt/Font.java

Print this page
rev 14936 : 8160721: Avoid deoptimizations in Font.equals.


1796             }
1797         }
1798         return hash;
1799     }
1800 
1801     /**
1802      * Compares this {@code Font} object to the specified
1803      * {@code Object}.
1804      * @param obj the {@code Object} to compare
1805      * @return {@code true} if the objects are the same
1806      *          or if the argument is a {@code Font} object
1807      *          describing the same font as this object;
1808      *          {@code false} otherwise.
1809      * @since 1.0
1810      */
1811     public boolean equals(Object obj) {
1812         if (obj == this) {
1813             return true;
1814         }
1815 
1816         if (obj != null) {
1817             try {
1818                 Font font = (Font)obj;
1819                 if (size == font.size &&
1820                     style == font.style &&
1821                     nonIdentityTx == font.nonIdentityTx &&
1822                     hasLayoutAttributes == font.hasLayoutAttributes &&
1823                     pointSize == font.pointSize &&
1824                     name.equals(font.name)) {
1825 
1826                     /* 'values' is usually initialized lazily, except when
1827                      * the font is constructed from a Map, or derived using
1828                      * a Map or other values. So if only one font has
1829                      * the field initialized we need to initialize it in
1830                      * the other instance and compare.
1831                      */
1832                     if (values == null) {
1833                         if (font.values == null) {
1834                             return true;
1835                         } else {
1836                             return getAttributeValues().equals(font.values);
1837                         }
1838                     } else {
1839                         return values.equals(font.getAttributeValues());
1840                     }
1841                 }
1842             }
1843             catch (ClassCastException e) {
1844             }
1845         }
1846         return false;
1847     }
1848 
1849     /**
1850      * Converts this {@code Font} object to a {@code String}
1851      * representation.
1852      * @return     a {@code String} representation of this
1853      *          {@code Font} object.
1854      * @since      1.0
1855      */
1856     // NOTE: This method may be called by privileged threads.
1857     //       DO NOT INVOKE CLIENT CODE ON THIS THREAD!
1858     public String toString() {
1859         String  strStyle;
1860 
1861         if (isBold()) {
1862             strStyle = isItalic() ? "bolditalic" : "bold";
1863         } else {




1796             }
1797         }
1798         return hash;
1799     }
1800 
1801     /**
1802      * Compares this {@code Font} object to the specified
1803      * {@code Object}.
1804      * @param obj the {@code Object} to compare
1805      * @return {@code true} if the objects are the same
1806      *          or if the argument is a {@code Font} object
1807      *          describing the same font as this object;
1808      *          {@code false} otherwise.
1809      * @since 1.0
1810      */
1811     public boolean equals(Object obj) {
1812         if (obj == this) {
1813             return true;
1814         }
1815 
1816         if (obj != null && obj instanceof Font) {

1817             Font font = (Font)obj;
1818             if (size == font.size &&
1819                 style == font.style &&
1820                 nonIdentityTx == font.nonIdentityTx &&
1821                 hasLayoutAttributes == font.hasLayoutAttributes &&
1822                 pointSize == font.pointSize &&
1823                 name.equals(font.name)) {
1824 
1825                 /* 'values' is usually initialized lazily, except when
1826                  * the font is constructed from a Map, or derived using
1827                  * a Map or other values. So if only one font has
1828                  * the field initialized we need to initialize it in
1829                  * the other instance and compare.
1830                  */
1831                 if (values == null) {
1832                     if (font.values == null) {
1833                         return true;
1834                     } else {
1835                         return getAttributeValues().equals(font.values);
1836                     }
1837                 } else {
1838                     return values.equals(font.getAttributeValues());
1839                 }



1840             }
1841         }
1842         return false;
1843     }
1844 
1845     /**
1846      * Converts this {@code Font} object to a {@code String}
1847      * representation.
1848      * @return     a {@code String} representation of this
1849      *          {@code Font} object.
1850      * @since      1.0
1851      */
1852     // NOTE: This method may be called by privileged threads.
1853     //       DO NOT INVOKE CLIENT CODE ON THIS THREAD!
1854     public String toString() {
1855         String  strStyle;
1856 
1857         if (isBold()) {
1858             strStyle = isItalic() ? "bolditalic" : "bold";
1859         } else {


< prev index next >