
br.com.objectos.way.code.AnnotationValueKind Maven / Gradle / Ivy
/*
* Copyright 2014 Objectos, Fábrica de Software LTDA.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package br.com.objectos.way.code;
import java.util.Map;
import java.util.Optional;
/**
* @author [email protected] (Marcio Endo)
*/
public enum AnnotationValueKind {
ARRAY_ANNOTATION,
ARRAY_BOOLEAN,
ARRAY_CHAR,
ARRAY_DOUBLE,
ARRAY_ENUM,
ARRAY_FLOAT,
ARRAY_INT,
ARRAY_LONG,
ARRAY_STRING,
ARRAY_TYPE,
ANNOTATION {
@Override
public AnnotationValueKind toArray() {
return ARRAY_ANNOTATION;
}
},
ENUM {
@Override
public AnnotationValueKind toArray() {
return ARRAY_ENUM;
}
},
PRIMITIVE_BOOLEAN {
@Override
public AnnotationValueKind toArray() {
return ARRAY_BOOLEAN;
}
},
PRIMITIVE_CHAR {
@Override
public AnnotationValueKind toArray() {
return ARRAY_CHAR;
}
},
PRIMITIVE_DOUBLE {
@Override
public AnnotationValueKind toArray() {
return ARRAY_DOUBLE;
}
},
PRIMITIVE_FLOAT {
@Override
public AnnotationValueKind toArray() {
return ARRAY_FLOAT;
}
},
PRIMITIVE_INT {
@Override
public AnnotationValueKind toArray() {
return ARRAY_INT;
}
},
PRIMITIVE_LONG {
@Override
public AnnotationValueKind toArray() {
return ARRAY_LONG;
}
},
STRING {
@Override
public AnnotationValueKind toArray() {
return ARRAY_STRING;
}
},
TYPE {
@Override
public AnnotationValueKind toArray() {
return ARRAY_TYPE;
}
},
UNKNOWN;
public AnnotationValueKind toArray() {
return UNKNOWN;
}
public Optional getIfPresent(Map nameMap, String name) {
if (!nameMap.containsKey(name)) {
return Optional.empty();
}
AnnotationValueInfo value = nameMap.get(name);
AnnotationValueKind kind = value.kind();
if (!kind.equals(this)) {
throw new ClassCastException(kind + " cannot be cast to " + this);
}
@SuppressWarnings("unchecked")
T object = (T) value.value();
return Optional.of(object);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy