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

org.requirementsascode.Actor Maven / Gradle / Ivy

There is a newer version: 2.0
Show newest version
package org.requirementsascode;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;

/**
 * An actor is a role that a user plays. Actors represent different user groups.
 * They enable to distinguish user rights: only an actor that is connected to a
 * particular step is allowed to cause a system reaction for that step.
 *
 * @author b_muth
 */
public class Actor implements Serializable {
	private static final long serialVersionUID = 2441478758595877661L;

	private String name;
	private Map> useCaseToStepMap;

	/**
	 * Creates an actor with the specified name that is part of the specified use
	 * case model.
	 *
	 * @param name  the name of the actor
	 */
	public Actor(String name) {
		this.name = name;
		this.useCaseToStepMap = new HashMap<>();
	}
	
	/**
	 * Returns the name of the actor.
	 *
	 * @return the name
	 */
	public String getName() {
		return name;
	}

	/**
	 * Returns the use cases this actor is associated with.
	 *
	 * 

* The actor is associated to a use case if it is connected to at least one of * its steps. * * @return the use cases the actor is associated with */ public Set getUseCases() { Set useCases = useCaseToStepMap.keySet(); return Collections.unmodifiableSet(useCases); } /** * Returns the steps this actor is connected with, for the specified use case. * * @param useCase the use case to query for steps the actor is connected with * @return the steps the actor is connected with */ public List getStepsOf(UseCase useCase) { Objects.requireNonNull(useCase); List steps = getModifiableStepsOf(useCase); return Collections.unmodifiableList(steps); } public void connectToStep(Step step) { Objects.requireNonNull(step.getUseCase()); Objects.requireNonNull(step); List steps = getModifiableStepsOf(step.getUseCase()); steps.add(step); } private List getModifiableStepsOf(UseCase useCase) { useCaseToStepMap.putIfAbsent(useCase, new ArrayList<>()); return useCaseToStepMap.get(useCase); } @Override public String toString() { return getName(); } @Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + ((getName() == null) ? 0 : getName().hashCode()); return result; } @Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; Actor other = (Actor) obj; if (getName() == null) { if (other.getName() != null) return false; } else if (!getName().equals(other.getName())) return false; return true; } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy