net.time4j.format.PredefinedKey Maven / Gradle / Ivy
/*
* -----------------------------------------------------------------------
* Copyright © 2013-2015 Meno Hochschild,
* -----------------------------------------------------------------------
* This file (PredefinedKey.java) is part of project Time4J.
*
* Time4J is free software: You can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published
* by the Free Software Foundation, either version 2.1 of the License, or
* (at your option) any later version.
*
* Time4J is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Time4J. If not, see .
* -----------------------------------------------------------------------
*/
package net.time4j.format;
import net.time4j.engine.AttributeKey;
/**
* Repräsentiert einen vordefinierten Attributschlüssel.
*
* @param generic type of associated attribute values
* @author Meno Hochschild
* @doctags.concurrency
*/
final class PredefinedKey
implements AttributeKey {
//~ Instanzvariablen --------------------------------------------------
private final String name;
private final Class type;
//~ Konstruktoren -----------------------------------------------------
private PredefinedKey(
String name,
Class type
) {
super();
if (name == null) {
throw new NullPointerException("Missing name of attribute key.");
} else if (type == null) {
throw new NullPointerException("Missing type of attribute.");
}
this.name = name;
this.type = type;
}
//~ Methoden ----------------------------------------------------------
/**
* Erzeugt einen neuen vordefinierten Attributschlüssel.
*
* @param generic type of associated attribute values
* @param name name of attribute key
* @param type reified type of attribute values
* @return new instance
*/
static PredefinedKey valueOf(
String name,
Class type
) {
return new PredefinedKey(name, type);
}
@Override
public String name() {
return this.name;
}
@Override
public Class type() {
return this.type;
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
} else if (obj instanceof PredefinedKey) {
PredefinedKey> that = (PredefinedKey) obj;
return (this.name.equals(that.name) && this.type.equals(that.type));
} else {
return false;
}
}
@Override
public int hashCode() {
return this.name.hashCode();
}
@Override
public String toString() {
return this.type.getName() + "@" + this.name;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy