public static void pruneAnnotations()

in taverna-workflowmodel-api/src/main/java/org/apache/taverna/workflowmodel/utils/AnnotationTools.java [127:169]


	public static void pruneAnnotations(Annotated<?> annotated, Edits edits) {
		Map<Class<? extends AnnotationBeanSPI>, AnnotationAssertion> remainder = new HashMap<>();
		Set<AnnotationChain> newChains = new HashSet<AnnotationChain>();
		for (AnnotationChain chain : annotated.getAnnotations()) {
			AnnotationChain newChain = edits.createAnnotationChain();
			for (AnnotationAssertion assertion : chain.getAssertions()) {
				AnnotationBeanSPI annotation = assertion.getDetail();
				Class<? extends AnnotationBeanSPI> annotationClass = annotation
						.getClass();
				AppliesTo appliesToAnnotation = (AppliesTo) annotationClass
						.getAnnotation(AppliesTo.class);
				if ((appliesToAnnotation == null) || appliesToAnnotation.many()
						|| !appliesToAnnotation.pruned())
					try {
						edits.getAddAnnotationAssertionEdit(newChain, assertion)
								.doEdit();
					} catch (EditException e) {
						logger.error("Error while pruning annotations", e);
					}
				else if (remainder.containsKey(annotationClass)) {
					AnnotationAssertion currentAssertion = remainder
							.get(annotationClass);
					if (assertion.getCreationDate().compareTo(
							currentAssertion.getCreationDate()) > 0)
						remainder.put(annotationClass, assertion);
				} else
					remainder.put(annotationClass, assertion);
			}
			if (!newChain.getAssertions().isEmpty())
				newChains.add(newChain);
		}
		for (AnnotationAssertion assertion : remainder.values()) {
			AnnotationChain newChain = edits.createAnnotationChain();
			try {
				edits.getAddAnnotationAssertionEdit(newChain, assertion)
						.doEdit();
			} catch (EditException e) {
				logger.error("Error while pruning annotations", e);
			}
			newChains.add(newChain);
		}
		annotated.setAnnotations(newChains);
	}