/******************************************************************************* * Copyright (c) 2012-2015 INRIA. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * Generoso Pagano - initial API and implementation ******************************************************************************/ package fr.inria.soctrace.lib.model; import fr.inria.soctrace.lib.model.utils.SoCTraceException; /** * Class representing the EVENT_PRODUCER entity of the data model. * * @author "Generoso Pagano <generoso.pagano@inria.fr>" * */ public class EventProducer implements IModelElement, ISearchable { public static final int NO_PARENT_ID = -1; private final int id; private String type; private String localId; private String name; private int parentId; /** * Constructor * @param id the entity unique id */ public EventProducer(int id) { this.id = id; this.type = ""; this.localId = ""; this.name = ""; this.parentId = NO_PARENT_ID; } /** * @return the type */ public String getType() { return type; } /** * @param type the type to set */ public void setType(String type) { this.type = type; } /** * @return the localId */ public String getLocalId() { return localId; } /** * @param localId the localId to set */ public void setLocalId(String localId) { this.localId = localId; } /** * @return the name */ public String getName() { return name; } /** * @param name the name to set */ public void setName(String name) { this.name = name; } /** * @return the parentId */ public int getParentId() { return parentId; } /** * @param parentId the parentId to set */ public void setParentId(int parentId) { this.parentId = parentId; } /** * @return the id */ public int getId() { return id; } /** * Get the whole name of this producer, * containing also the type and the local id informations. * * @return the whole name of the producer */ public String getWholeName() { return name +" (" + type +":"+localId+")"; } @Override public String toString() { return "EventProducer[(id:" + id + "),(type:\"" + type + "\")," + "(local_id:\"" + localId + "\"),(name:\"" + name + "\")," + "(parent_id:\"" + parentId + "\")]"; } @Override public void accept(IModelVisitor visitor) throws SoCTraceException { visitor.visit(this); } /* (non-Javadoc) * @see java.lang.Object#hashCode() */ @Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + id; result = prime * result + ((localId == null) ? 0 : localId.hashCode()); result = prime * result + ((name == null) ? 0 : name.hashCode()); result = prime * result + parentId; result = prime * result + ((type == null) ? 0 : type.hashCode()); return result; } /* (non-Javadoc) * @see java.lang.Object#equals(java.lang.Object) */ @Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (!(obj instanceof EventProducer)) return false; EventProducer other = (EventProducer) obj; if (id != other.id) return false; if (localId == null) { if (other.localId != null) return false; } else if (!localId.equals(other.localId)) return false; if (name == null) { if (other.name != null) return false; } else if (!name.equals(other.name)) return false; if (parentId != other.parentId) return false; if (type == null) { if (other.type != null) return false; } else if (!type.equals(other.type)) return false; return true; } }