001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017:
018: /* $Id: FontTriplet.java 426576 2006-07-28 15:44:37Z jeremias $ */
019:
020: package org.apache.fop.fonts;
021:
022: import java.io.Serializable;
023:
024: /**
025: * FontTriplet contains information on name, style and weight of one font
026: */
027: public class FontTriplet implements Comparable, Serializable {
028:
029: /** serial version UID */
030: private static final long serialVersionUID = 1168991106658033508L;
031:
032: private String name;
033: private String style;
034: private int weight;
035:
036: //This is only a cache
037: private transient String key;
038:
039: /**
040: * Creates a new font triplet.
041: * @param name font name
042: * @param style font style (normal, italic etc.)
043: * @param weight font weight (100, 200, 300...800, 900)
044: */
045: public FontTriplet(String name, String style, int weight) {
046: this .name = name;
047: this .style = style;
048: this .weight = weight;
049: }
050:
051: /** @return the font name */
052: public String getName() {
053: return name;
054: }
055:
056: /** @return the font style */
057: public String getStyle() {
058: return style;
059: }
060:
061: /** @return the font weight */
062: public int getWeight() {
063: return weight;
064: }
065:
066: private String getKey() {
067: if (this .key == null) {
068: //This caches the combined key
069: this .key = getName() + "," + getStyle() + "," + getWeight();
070: }
071: return this .key;
072: }
073:
074: /** @see java.lang.Comparable#compareTo(java.lang.Object) */
075: public int compareTo(Object o) {
076: return getKey().compareTo(((FontTriplet) o).getKey());
077: }
078:
079: /** @see java.lang.Object#hashCode() */
080: public int hashCode() {
081: return toString().hashCode();
082: }
083:
084: /** @see java.lang.Object#equals(java.lang.Object) */
085: public boolean equals(Object obj) {
086: if (obj == null) {
087: return false;
088: } else if (obj == this ) {
089: return true;
090: } else {
091: if (obj instanceof FontTriplet) {
092: FontTriplet other = (FontTriplet) obj;
093: return (getName().equals(other.getName())
094: && getStyle().equals(other.getStyle()) && (getWeight() == other
095: .getWeight()));
096: }
097: }
098: return false;
099: }
100:
101: /** @see java.lang.Object#toString() */
102: public String toString() {
103: return getKey();
104: }
105:
106: }
|