All Downloads are FREE. Search and download functionalities are using the official Maven repository.

kieker.analysis.architecture.trace.graph.dot.NodeLabelMapper Maven / Gradle / Ivy

There is a newer version: 2.0.2
Show newest version
/***************************************************************************
 * Copyright 2022 Kieker Project (http://kieker-monitoring.net)
 *
 * 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 kieker.analysis.architecture.trace.graph.dot;

import java.util.Collection;
import java.util.function.Function;
import java.util.stream.Collectors;

import kieker.analysis.generic.graph.INode;

/**
 * This class is a {@link Function} that maps a {@link INode} to a label. The
 * desired format is: container + "::\\n" + "@" + stackDepth + ":" + component +
 * "\\n" + name;
 * {@code ::\\n@:\\n}
 *
 * @author Sören Henning
 *
 * @since 1.14
 *
 */
public class NodeLabelMapper implements Function {

	public NodeLabelMapper() {
		super();
	}

	@Override
	public String apply(final INode vertex) {
		if (vertex.getProperty("artificial") != null) {
			return vertex.getProperty("name").toString();
		}

		final Collection modifiers;

		// BETTER consider check if properties exists

		if (vertex.getProperty("modifiers") instanceof Collection) {
			@SuppressWarnings("unchecked")
			final Collection castedModifiers = (Collection) vertex.getProperty("modifiers");
			modifiers = castedModifiers;
		} else {
			throw new IllegalArgumentException("Vertex property 'modifiers' is not a collection.");
		}

		final Collection parameters;

		if (vertex.getProperty("parameterTypes") instanceof Collection) {
			@SuppressWarnings("unchecked")
			final Collection castedParameters = (Collection) vertex.getProperty("parameterTypes");
			parameters = castedParameters;
		} else {
			throw new IllegalArgumentException("Vertex property 'parameterTypes' is not a collection.");
		}

		// BETTER this could be extracted
		final StringBuilder signature = new StringBuilder();
		signature.append(modifiers.stream().collect(Collectors.joining(" "))).append(' ')
				.append(vertex.getProperty("returnType").toString()).append(' ')
				.append(vertex.getProperty("name").toString()).append('(')
				.append(parameters.stream().collect(Collectors.joining(", "))).append(')');

		final StringBuilder label = new StringBuilder() // NOPMD (.append(<>.toString() + "...") does not make sense)
				.append(vertex.getProperty("deploymentContext").toString()).append("::\\n").append('@')
				.append(vertex.getProperty("stackDepth").toString()).append(':')
				.append(vertex.getProperty("component").toString()).append("\\n").append(signature);

		return label.toString();
	}

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy