001/* =========================================================== 002 * JFreeChart : a free chart library for the Java(tm) platform 003 * =========================================================== 004 * 005 * (C) Copyright 2000-2020, by Object Refinery Limited and Contributors. 006 * 007 * Project Info: http://www.jfree.org/jfreechart/index.html 008 * 009 * This library is free software; you can redistribute it and/or modify it 010 * under the terms of the GNU Lesser General Public License as published by 011 * the Free Software Foundation; either version 2.1 of the License, or 012 * (at your option) any later version. 013 * 014 * This library is distributed in the hope that it will be useful, but 015 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 016 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 017 * License for more details. 018 * 019 * You should have received a copy of the GNU Lesser General Public 020 * License along with this library; if not, write to the Free Software 021 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 022 * USA. 023 * 024 * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. 025 * Other names may be trademarks of their respective owners.] 026 * 027 * ---------------------- 028 * AxisLabelLocation.java 029 * ---------------------- 030 * (C) Copyright 2013-2020, by Object Refinery Limited and Contributors. 031 * 032 * Original Author: David Gilbert (for Object Refinery Limited); 033 * Contributor(s): -; 034 * 035 */ 036 037package org.jfree.chart.axis; 038 039import java.io.ObjectStreamException; 040import java.io.Serializable; 041 042/** 043 * Used to indicate the location of an axis label. 044 * 045 * @since 1.0.16 046 */ 047public final class AxisLabelLocation implements Serializable { 048 049 /** For serialization. */ 050 private static final long serialVersionUID = 1L; 051 052 /** Axis label at the top. */ 053 public static final AxisLabelLocation HIGH_END = new AxisLabelLocation( 054 "HIGH_END"); 055 056 /** Axis label at the middle. */ 057 public static final AxisLabelLocation MIDDLE = new AxisLabelLocation( 058 "MIDDLE"); 059 060 /** Axis label at the bottom. */ 061 public static final AxisLabelLocation LOW_END = new AxisLabelLocation( 062 "LOW_END"); 063 064 /** The name. */ 065 private String name; 066 067 /** 068 * Private constructor. 069 * 070 * @param name the name. 071 */ 072 private AxisLabelLocation(String name) { 073 this.name = name; 074 } 075 076 /** 077 * Returns a string representing the object. 078 * 079 * @return The string. 080 */ 081 @Override 082 public String toString() { 083 return this.name; 084 } 085 086 /** 087 * Returns {@code true} if this object is equal to the specified 088 * object, and {@code false} otherwise. 089 * 090 * @param obj the other object ({@code null} permitted). 091 * 092 * @return A boolean. 093 */ 094 @Override 095 public boolean equals(Object obj) { 096 if (this == obj) { 097 return true; 098 } 099 if (!(obj instanceof AxisLabelLocation)) { 100 return false; 101 } 102 AxisLabelLocation location = (AxisLabelLocation) obj; 103 if (!this.name.equals(location.toString())) { 104 return false; 105 } 106 return true; 107 } 108 109 /** 110 * Returns a hash code for this instance. 111 * 112 * @return A hash code. 113 */ 114 @Override 115 public int hashCode() { 116 int hash = 5; 117 hash = 83 * hash + this.name.hashCode(); 118 return hash; 119 } 120 121 /** 122 * Ensures that serialization returns the unique instances. 123 * 124 * @return The object. 125 * 126 * @throws ObjectStreamException if there is a problem. 127 */ 128 private Object readResolve() throws ObjectStreamException { 129 if (this.equals(AxisLabelLocation.HIGH_END)) { 130 return AxisLabelLocation.HIGH_END; 131 } 132 if (this.equals(AxisLabelLocation.MIDDLE)) { 133 return AxisLabelLocation.MIDDLE; 134 } 135 if (this.equals(AxisLabelLocation.LOW_END)) { 136 return AxisLabelLocation.LOW_END; 137 } 138 139 return null; 140 } 141 142}