Skip to content

Commit

Permalink
add toString(), use enum for clarity
Browse files Browse the repository at this point in the history
I want toString() to get a nice representation during debugging. Enums are
much clearer than integers when debugging, as well.
  • Loading branch information
garfieldnate committed May 1, 2024
1 parent 23a90cd commit 06b02b6
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 30 deletions.
6 changes: 3 additions & 3 deletions Java/Debugger/src/edu/umich/soar/debugger/doc/Document.java
Original file line number Diff line number Diff line change
Expand Up @@ -1128,21 +1128,21 @@ protected synchronized void fireSoarConnectionChanged()
protected synchronized void fireAgentAdded(Agent agent)
{
m_SoarChangeGenerator.fireAgentListChanged(this,
SoarAgentEvent.kAgentAdded, agent);
SoarAgentEvent.EventType.AGENT_ADDED, agent);
}

protected synchronized void fireAgentRemoved(Agent agent)
{
m_SoarChangeGenerator.fireAgentListChanged(this,
SoarAgentEvent.kAgentRemoved, agent);
SoarAgentEvent.EventType.AGENT_REMOVED, agent);
}

// More generic than agent added/removed. Use the more specific form if you
// can.
protected synchronized void fireAgentListChanged()
{
m_SoarChangeGenerator.fireAgentListChanged(this,
SoarAgentEvent.kListChanged, null);
SoarAgentEvent.EventType.LIST_CHANGED, null);
}

public String sendAgentCommand(Agent agent, String commandLine)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,48 +18,42 @@
* Used to report a change to an agent (added, removed etc.)
*
************************************************************************/
public class SoarAgentEvent extends java.util.EventObject
{
public class SoarAgentEvent extends java.util.EventObject {
private static final long serialVersionUID = -1073490020065002122L;

public static final int kAgentAdded = 1;

public static final int kAgentRemoved = 2;

public static final int kListChanged = 3; // More generic -- just says the list
// isn't the same now (use the more
// specific event if you can)
public enum EventType {
AGENT_ADDED,
AGENT_REMOVED,
// More generic -- just says the list
// isn't the same now (use the more
// specific event if you can)
LIST_CHANGED;
}

private final int m_Type;
private final EventType m_Type;

private final Agent m_Agent;

public SoarAgentEvent(Object source, int type, Agent agent)
{
public SoarAgentEvent(Object source, EventType type, Agent agent) {
super(source);

m_Type = type;
m_Agent = agent;
}

public boolean isAgentAdded()
{
return m_Type == kAgentAdded;
public boolean isAgentAdded() {
return m_Type.equals(EventType.AGENT_ADDED);
}

public boolean isAgentRemoved()
{
return m_Type == kAgentRemoved;
public boolean isAgentRemoved() {
return m_Type.equals(EventType.AGENT_REMOVED);
}

public boolean isAgentListChanged()
{
return m_Type == kAgentAdded || m_Type == kAgentRemoved
|| m_Type == kListChanged;
public boolean isAgentListChanged() {
return isAgentAdded() || isAgentRemoved() || m_Type.equals(EventType.LIST_CHANGED);
}

public Agent getAgent()
{
public Agent getAgent() {
return m_Agent;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,8 @@ public synchronized void fireSoarConnectionChanged(Object source,
}
}

public synchronized void fireAgentListChanged(Object source, int type,
Agent agent)
{
public synchronized void fireAgentListChanged(Object source, SoarAgentEvent.EventType type,
Agent agent) {
SoarAgentEvent event = new SoarAgentEvent(source, type, agent);

for (SoarChangeListener current : m_Listeners) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1536,4 +1536,10 @@ public void loadFromXML(MainFrame frame,
updateButtonState();
}
}

@Override
public String toString() {
Agent agent = getAgentFocus();
return "FoldingTextView, agent=" + (agent == null ? "null" : agent.GetAgentName());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
********************************************************************************************/
package edu.umich.soar.debugger.modules;

import sml.Agent;

/************************************************************************
*
* This version of the BaseCommandView updates at the end of each run and clears
Expand Down Expand Up @@ -38,4 +40,11 @@ public String getModuleBaseName()
{
return "update";
}

@Override
public String toString() {
Agent agent = getAgentFocus();
return "UpdateCommandView, command=" + (m_CurrentCommand == null ? "null" : m_CurrentCommand) +
", agent=" + (agent == null ? "null" : agent.GetAgentName());
}
}

0 comments on commit 06b02b6

Please sign in to comment.