org.nuiton.eugene.java.extension.AnnotationsManager Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of eugene Show documentation
Show all versions of eugene Show documentation
Efficient Universal Generator.
/*
* #%L
* EUGene :: EUGene
*
* $Id: AnnotationsManager.java 1286 2013-07-11 13:53:23Z tchemit $
* $HeadURL: https://svn.nuiton.org/eugene/tags/eugene-2.10/eugene/src/main/java/org/nuiton/eugene/java/extension/AnnotationsManager.java $
* %%
* Copyright (C) 2004 - 2010 CodeLutin
* %%
* This program 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 3 of the
* License, or (at your option) any later version.
*
* This program 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 General Lesser Public License for more details.
*
* You should have received a copy of the GNU General Lesser Public
* License along with this program. If not, see
* .
* #L%
*/
package org.nuiton.eugene.java.extension;
import org.nuiton.eugene.models.object.ObjectModelElement;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* To manage annotations for any {@link ObjectModelElement} of a classifier.
*
* Created: 17 déc. 2009
*
* @author tchemit
* @version $Revision: 1286 $
* @since 2.0.0
*/
public class AnnotationsManager {
// private static final String[] EMPTY_STRING_ARRAY = new String[]{};
protected Map> annotations;
/**
* Add the {@code annotation} for the given {@code element} of
* the classifier.
*
* @param element the element where to register the annotation
* @param annotation the annotation to register
*/
public void addAnnotation(ObjectModelElement element,
ObjectModelAnnotation annotation) {
Map> map = getAnnotations();
List list = map.get(element);
if (list == null) {
list = new ArrayList();
map.put(element, list);
}
list.add(annotation);
}
/**
* Obtain the array of annotations registred for a given element of
* the classifier.
*
* @param element the element where to search for annotations
* @return the annotations for the element (empty arry if none found
*/
public List getAnnotations(ObjectModelElement element) {
Map> map = getAnnotations();
List list = map.get(element);
return list == null ? Collections.emptyList() : list;
}
protected Map> getAnnotations() {
if (annotations == null) {
annotations = new HashMap>();
}
return annotations;
}
}