SlideShare a Scribd company logo
1 of 109
Download to read offline
Automated Refactoring of Legacy
Java Software to Enumerated Types*
Raffi Khatchadourian, Jason Sawin, and Atanas Rountev
PRESTO: Program Analyses and Software Tools Research
Group, Ohio State University
* Work supported in part by NSF
Introduction
Introduction
•Java 1.5 introduced a rich set of new features such as
generics, metadata annotations, boxing/unboxing,
and type-safe enumerations.
Introduction
•Java 1.5 introduced a rich set of new features such as
generics, metadata annotations, boxing/unboxing,
and
•Highlight an automated semantics-preserving
approach for migrating legacy Java code to take
advantage of the new language enumerated type
constructs.
Introduction
•Java 1.5 introduced a rich set of new features such as
generics, metadata annotations, boxing/unboxing,
and
•Highlight an automated semantics-preserving
approach for migrating legacy Java code to take
advantage of the new language enumerated type
constructs.
•Present experimental results from research prototype
as an Eclipse IDE plug-in.
Introduction
•Java 1.5 introduced a rich set of new features such as
generics, metadata annotations, boxing/unboxing,
and
•Highlight an automated semantics-preserving
approach for migrating legacy Java code to take
advantage of the new language enumerated type
constructs.
•Present experimental results from research prototype
as an Eclipse IDE plug-in.
•In progress to be included with the standard
distribution of Eclipse.
Motivating Example
class TrafficSignal {
public static final int RED = 0;
public static final int YELLOW = 1;
public static final int GREEN = 2;
/ Current color of the traffic signal, initially red by default /
private int color = RED;
/ Accessor for the light’s current color /
public int getColor() {return this.color;}}
class Automobile {
private static final int IDLE = 0;
private static final int INCREASE_SPEED = 1;
private static final int DECREASE_SPEED = 2;
private static final int STOP = 3;
Motivating Example
Weak Enum
Pattern
class TrafficSignal {
public static final int RED = 0;
public static final int YELLOW = 1;
public static final int GREEN = 2;
/ Current color of the traffic signal, initially red by default /
private int color = RED;
/ Accessor for the light’s current color /
public int getColor() {return this.color;}}
class Automobile {
private static final int IDLE = 0;
private static final int INCREASE_SPEED = 1;
private static final int DECREASE_SPEED = 2;
private static final int STOP = 3;
Motivating Example
Type Safety
class TrafficSignal {
public static final int RED = 0;
public static final int YELLOW = 1;
public static final int GREEN = 2;
/ Current color of the traffic signal, initially red by default /
private int color = RED;
/ Accessor for the light’s current color /
public int getColor() {return this.color;}}
class Automobile {
private static final int IDLE = 0;
private static final int INCREASE_SPEED = 1;
private static final int DECREASE_SPEED = 2;
private static final int STOP = 3;
Motivating Example
class TrafficSignal {
public static final int RED = 0;
public static final int YELLOW = 1;
public static final int GREEN = 2;
/ Current color of the traffic signal, initially red by default /
private int color = RED;
/ Accessor for the light’s current color /
public int getColor() {return this.color;}}
class Automobile {
private static final int IDLE = 0;
private static final int INCREASE_SPEED = 1;
private static final int DECREASE_SPEED = 2;
private static final int STOP = 3;
Manual
Enumeration
Motivating Example
class TrafficSignal {
public static final int RED = 0;
public static final int YELLOW = 1;
public static final int GREEN = 2;
/ Current color of the traffic signal, initially red by default /
private int color = RED;
/ Accessor for the light’s current color /
public int getColor() {return this.color;}}
class Automobile {
private static final int IDLE = 0;
private static final int INCREASE_SPEED = 1;
private static final int DECREASE_SPEED = 2;
private static final int STOP = 3;
Namespacing
Motivating Example
class TrafficSignal {
public static final int RED = 0;
public static final int YELLOW = 1;
public static final int GREEN = 2;
/ Current color of the traffic signal, initially red by default /
private int color = RED;
/ Accessor for the light’s current color /
public int getColor() {return this.color;}}
class Automobile {
private static final int IDLE = 0;
private static final int INCREASE_SPEED = 1;
private static final int DECREASE_SPEED = 2;
private static final int STOP = 3;
Brittle
Motivating Example
class TrafficSignal {
public static final int RED = 0;
public static final int YELLOW = 1;
public static final int GREEN = 2;
/ Current color of the traffic signal, initially red by default /
private int color = RED;
/ Accessor for the light’s current color /
public int getColor() {return this.color;}}
class Automobile {
private static final int IDLE = 0;
private static final int INCREASE_SPEED = 1;
private static final int DECREASE_SPEED = 2;
private static final int STOP = 3;
Motivating Example Revisited
class TrafficSignal {
public static final int RED = 0;
public static final int YELLOW = 1;
public static final int GREEN = 2;
/ Current color of the traffic signal, initially red by default /
private int color = RED;
/ Accessor for the light’s current color /
public int getColor() {return this.color;}}
class Automobile {
private static final int IDLE = 0;
private static final int INCREASE_SPEED = 1;
private static final int DECREASE_SPEED = 2;
private static final int STOP = 3;
class TrafficSignal {
public static final int RED = 0;
public static final int YELLOW = 1;
public static final int GREEN = 2;
/ Current color of the traffic signal, initially red by default /
private int color = RED;
/ Accessor for the light’s current color /
public int getColor() {return this.color;}}
class Automobile {
private static final int IDLE = 0;
private static final int INCREASE_SPEED = 1;
private static final int DECREASE_SPEED = 2;
private static final int STOP = 3;
class TrafficSignal {
public static final int RED = 0;
public static final int YELLOW = 1;
public static final int GREEN = 2;
/ Current color of the traffic signal, initially red by default /
private int color = RED;
/ Accessor for the light’s current color /
public int getColor() {return this.color;}}
class Automobile {
private static final int IDLE = 0;
private static final int INCREASE_SPEED = 1;
private static final int DECREASE_SPEED = 2;
private static final int STOP = 3;
class TrafficSignal {
public static final int RED = 0;
public static final int YELLOW = 1;
public static final int GREEN = 2;
/ Current color of the traffic signal, initially red by default /
private int color = RED;
/ Accessor for the light’s current color /
public int getColor() {return this.color;}}
class Automobile {
private static final int IDLE = 0;
private static final int INCREASE_SPEED = 1;
private static final int DECREASE_SPEED = 2;
private static final int STOP = 3;
class TrafficSignal {
public static final int RED = 0;
public static final int YELLOW = 1;
public static final int GREEN = 2;
/ Current color of the traffic signal, initially red by default /
private int color = RED;
/ Accessor for the light’s current color /
public int getColor() {return this.color;}}
class Automobile {
private static final int IDLE = 0;
private static final int INCREASE_SPEED = 1;
private static final int DECREASE_SPEED = 2;
private static final int STOP = 3;
class TrafficSignal {
public static final int RED = 0;
public static final int YELLOW = 1;
public static final int GREEN = 2;
/ Current color of the traffic signal, initially red by default /
private int color = RED;
/ Accessor for the light’s current color /
public int getColor() {return this.color;}}
class Automobile {
private static final int IDLE = 0;
private static final int INCREASE_SPEED = 1;
private static final int DECREASE_SPEED = 2;
private static final int STOP = 3;
Motivating Example Revisited
class TrafficSignal {
public static final int RED = 0;
public static final int YELLOW = 1;
public static final int GREEN = 2;
/ Current color of the traffic signal, initially red by default /
private int color = RED;
/ Accessor for the light’s current color /
public int getColor() {return this.color;}}
class Automobile {
private static final int IDLE = 0;
private static final int INCREASE_SPEED = 1;
private static final int DECREASE_SPEED = 2;
private static final int STOP = 3;
class TrafficSignal {
public static final int RED = 0;
public static final int YELLOW = 1;
public static final int GREEN = 2;
/ Current color of the traffic signal, initially red by default /
private int color = RED;
/ Accessor for the light’s current color /
public int getColor() {return this.color;}}
class Automobile {
private static final int IDLE = 0;
private static final int INCREASE_SPEED = 1;
private static final int DECREASE_SPEED = 2;
private static final int STOP = 3;
class TrafficSignal {
public enum Color {RED,
YELLOW,
GREEN};
/* Current color of the traffic signal, initially red by default */
private Color color = Color.RED;
/* Accessor for the light’s current color */
public Color getColor() {return this.color;}}
class Automobile {
private enum Action {IDLE,
INCREASE_SPEED,
DECREASE_SPEED,
STOP};
private static final int MAX_SPEED = 140;
class TrafficSignal {
public static final int RED = 0;
public static final int YELLOW = 1;
public static final int GREEN = 2;
/ Current color of the traffic signal, initially red by default /
private int color = RED;
/ Accessor for the light’s current color /
public int getColor() {return this.color;}}
class Automobile {
private static final int IDLE = 0;
private static final int INCREASE_SPEED = 1;
private static final int DECREASE_SPEED = 2;
private static final int STOP = 3;
class TrafficSignal {
public static final int RED = 0;
public static final int YELLOW = 1;
public static final int GREEN = 2;
/ Current color of the traffic signal, initially red by default /
private int color = RED;
/ Accessor for the light’s current color /
public int getColor() {return this.color;}}
class Automobile {
private static final int IDLE = 0;
private static final int INCREASE_SPEED = 1;
private static final int DECREASE_SPEED = 2;
private static final int STOP = 3;
class TrafficSignal {
public static final int RED = 0;
public static final int YELLOW = 1;
public static final int GREEN = 2;
/ Current color of the traffic signal, initially red by default /
private int color = RED;
/ Accessor for the light’s current color /
public int getColor() {return this.color;}}
class Automobile {
private static final int IDLE = 0;
private static final int INCREASE_SPEED = 1;
private static final int DECREASE_SPEED = 2;
private static final int STOP = 3;
Motivating Example Revisited
class TrafficSignal {
public static final int RED = 0;
public static final int YELLOW = 1;
public static final int GREEN = 2;
/ Current color of the traffic signal, initially red by default /
private int color = RED;
/ Accessor for the light’s current color /
public int getColor() {return this.color;}}
class Automobile {
private static final int IDLE = 0;
private static final int INCREASE_SPEED = 1;
private static final int DECREASE_SPEED = 2;
private static final int STOP = 3;
class TrafficSignal {
public enum Color {RED,
YELLOW,
GREEN};
/* Current color of the traffic signal, initially red by default */
private Color color = Color.RED;
/* Accessor for the light’s current color */
public Color getColor() {return this.color;}}
class Automobile {
private enum Action {IDLE,
INCREASE_SPEED,
DECREASE_SPEED,
STOP};
private static final int MAX_SPEED = 140;
class TrafficSignal {
public static final int RED = 0;
public static final int YELLOW = 1;
public static final int GREEN = 2;
/ Current color of the traffic signal, initially red by default /
private int color = RED;
/ Accessor for the light’s current color /
public int getColor() {return this.color;}}
class Automobile {
private static final int IDLE = 0;
private static final int INCREASE_SPEED = 1;
private static final int DECREASE_SPEED = 2;
private static final int STOP = 3;
class TrafficSignal {
public static final int RED = 0;
public static final int YELLOW = 1;
public static final int GREEN = 2;
/ Current color of the traffic signal, initially red by default /
private int color = RED;
/ Accessor for the light’s current color /
public int getColor() {return this.color;}}
class Automobile {
private static final int IDLE = 0;
private static final int INCREASE_SPEED = 1;
private static final int DECREASE_SPEED = 2;
private static final int STOP = 3;
class TrafficSignal {
public static final int RED = 0;
public static final int YELLOW = 1;
public static final int GREEN = 2;
/ Current color of the traffic signal, initially red by default /
private int color = RED;
/ Accessor for the light’s current color /
public int getColor() {return this.color;}}
class Automobile {
private static final int IDLE = 0;
private static final int INCREASE_SPEED = 1;
private static final int DECREASE_SPEED = 2;
private static final int STOP = 3;
class TrafficSignal {
public enum Color {RED,
YELLOW,
GREEN};
/* Current color of the traffic signal, initially red by default */
private Color color = Color.RED;
/* Accessor for the light’s current color */
public Color getColor() {return this.color;}}
class Automobile {
private enum Action {IDLE,
INCREASE_SPEED,
DECREASE_SPEED,
STOP};
Motivating Example Revisited
class TrafficSignal {
public static final int RED = 0;
public static final int YELLOW = 1;
public static final int GREEN = 2;
/ Current color of the traffic signal, initially red by default /
private int color = RED;
/ Accessor for the light’s current color /
public int getColor() {return this.color;}}
class Automobile {
private static final int IDLE = 0;
private static final int INCREASE_SPEED = 1;
private static final int DECREASE_SPEED = 2;
private static final int STOP = 3;
class TrafficSignal {
public enum Color {RED,
YELLOW,
GREEN};
/* Current color of the traffic signal, initially red by default */
private Color color = Color.RED;
/* Accessor for the light’s current color */
public Color getColor() {return this.color;}}
class Automobile {
private enum Action {IDLE,
INCREASE_SPEED,
DECREASE_SPEED,
STOP};
private static final int MAX_SPEED = 140;
class TrafficSignal {
public static final int RED = 0;
public static final int YELLOW = 1;
public static final int GREEN = 2;
/ Current color of the traffic signal, initially red by default /
private int color = RED;
/ Accessor for the light’s current color /
public int getColor() {return this.color;}}
class Automobile {
private static final int IDLE = 0;
private static final int INCREASE_SPEED = 1;
private static final int DECREASE_SPEED = 2;
private static final int STOP = 3;
class TrafficSignal {
public static final int RED = 0;
public static final int YELLOW = 1;
public static final int GREEN = 2;
/ Current color of the traffic signal, initially red by default /
private int color = RED;
/ Accessor for the light’s current color /
public int getColor() {return this.color;}}
class Automobile {
private static final int IDLE = 0;
private static final int INCREASE_SPEED = 1;
private static final int DECREASE_SPEED = 2;
private static final int STOP = 3;
class TrafficSignal {
public enum Color {RED,
YELLOW,
GREEN};
/* Current color of the traffic signal, initially red by default */
private Color color = Color.RED;
/* Accessor for the light’s current color */
public Color getColor() {return this.color;}}
class Automobile {
private enum Action {IDLE,
INCREASE_SPEED,
DECREASE_SPEED,
STOP};
class TrafficSignal {
public enum Color {RED,
YELLOW,
GREEN};
/* Current color of the traffic signal, initially red by default */
private Color color = Color.RED;
/* Accessor for the light’s current color */
public Color getColor() {return this.color;}}
class Automobile {
private enum Action {IDLE,
INCREASE_SPEED,
DECREASE_SPEED,
STOP};
Motivating Example Revisited
class TrafficSignal {
public static final int RED = 0;
public static final int YELLOW = 1;
public static final int GREEN = 2;
/ Current color of the traffic signal, initially red by default /
private int color = RED;
/ Accessor for the light’s current color /
public int getColor() {return this.color;}}
class Automobile {
private static final int IDLE = 0;
private static final int INCREASE_SPEED = 1;
private static final int DECREASE_SPEED = 2;
private static final int STOP = 3;
class TrafficSignal {
public enum Color {RED,
YELLOW,
GREEN};
/* Current color of the traffic signal, initially red by default */
private Color color = Color.RED;
/* Accessor for the light’s current color */
public Color getColor() {return this.color;}}
class Automobile {
private enum Action {IDLE,
INCREASE_SPEED,
DECREASE_SPEED,
STOP};
private static final int MAX_SPEED = 140;
class TrafficSignal {
public enum Color {RED,
YELLOW,
GREEN};
/* Current color of the traffic signal, initially red by default */
private Color color = Color.RED;
/* Accessor for the light’s current color */
public Color getColor() {return this.color;}}
class Automobile {
private enum Action {IDLE,
INCREASE_SPEED,
DECREASE_SPEED,
STOP};
class TrafficSignal {
public enum Color {RED,
YELLOW,
GREEN};
/* Current color of the traffic signal, initially red by default */
private Color color = Color.RED;
/* Accessor for the light’s current color */
public Color getColor() {return this.color;}}
class Automobile {
private enum Action {IDLE,
INCREASE_SPEED,
DECREASE_SPEED,
STOP};
class TrafficSignal {
public static final int RED = 0;
public static final int YELLOW = 1;
public static final int GREEN = 2;
/ Current color of the traffic signal, initially red by default /
private int color = RED;
/ Accessor for the light’s current color /
public int getColor() {return this.color;}}
class Automobile {
private static final int IDLE = 0;
private static final int INCREASE_SPEED = 1;
private static final int DECREASE_SPEED = 2;
private static final int STOP = 3;
class TrafficSignal {
public static final int RED = 0;
public static final int YELLOW = 1;
public static final int GREEN = 2;
/ Current color of the traffic signal, initially red by default /
private int color = RED;
/ Accessor for the light’s current color /
public int getColor() {return this.color;}}
class Automobile {
private static final int IDLE = 0;
private static final int INCREASE_SPEED = 1;
private static final int DECREASE_SPEED = 2;
private static final int STOP = 3;
Motivating Example Revisited
class TrafficSignal {
public static final int RED = 0;
public static final int YELLOW = 1;
public static final int GREEN = 2;
/ Current color of the traffic signal, initially red by default /
private int color = RED;
/ Accessor for the light’s current color /
public int getColor() {return this.color;}}
class Automobile {
private static final int IDLE = 0;
private static final int INCREASE_SPEED = 1;
private static final int DECREASE_SPEED = 2;
private static final int STOP = 3;
class TrafficSignal {
public enum Color {RED,
YELLOW,
GREEN};
/* Current color of the traffic signal, initially red by default */
private Color color = Color.RED;
/* Accessor for the light’s current color */
public Color getColor() {return this.color;}}
class Automobile {
private enum Action {IDLE,
INCREASE_SPEED,
DECREASE_SPEED,
STOP};
private static final int MAX_SPEED = 140;
class TrafficSignal {
public enum Color {RED,
YELLOW,
GREEN};
/* Current color of the traffic signal, initially red by default */
private Color color = Color.RED;
/* Accessor for the light’s current color */
public Color getColor() {return this.color;}}
class Automobile {
private enum Action {IDLE,
INCREASE_SPEED,
DECREASE_SPEED,
STOP};
class TrafficSignal {
public enum Color {RED,
YELLOW,
GREEN};
/* Current color of the traffic signal, initially red by default */
private Color color = Color.RED;
/* Accessor for the light’s current color */
public Color getColor() {return this.color;}}
class Automobile {
private enum Action {IDLE,
INCREASE_SPEED,
DECREASE_SPEED,
STOP};
class TrafficSignal {
public static final int RED = 0;
public static final int YELLOW = 1;
public static final int GREEN = 2;
/ Current color of the traffic signal, initially red by default /
private int color = RED;
/ Accessor for the light’s current color /
public int getColor() {return this.color;}}
class Automobile {
private static final int IDLE = 0;
private static final int INCREASE_SPEED = 1;
private static final int DECREASE_SPEED = 2;
private static final int STOP = 3;
class TrafficSignal {
public static final int RED = 0;
public static final int YELLOW = 1;
public static final int GREEN = 2;
/ Current color of the traffic signal, initially red by default /
private int color = RED;
/ Accessor for the light’s current color /
public int getColor() {return this.color;}}
class Automobile {
private static final int IDLE = 0;
private static final int INCREASE_SPEED = 1;
private static final int DECREASE_SPEED = 2;
private static final int STOP = 3;
Language Enum
Motivating Example Revisited
class TrafficSignal {
public static final int RED = 0;
public static final int YELLOW = 1;
public static final int GREEN = 2;
/ Current color of the traffic signal, initially red by default /
private int color = RED;
/ Accessor for the light’s current color /
public int getColor() {return this.color;}}
class Automobile {
private static final int IDLE = 0;
private static final int INCREASE_SPEED = 1;
private static final int DECREASE_SPEED = 2;
private static final int STOP = 3;
class TrafficSignal {
public enum Color {RED,
YELLOW,
GREEN};
/* Current color of the traffic signal, initially red by default */
private Color color = Color.RED;
/* Accessor for the light’s current color */
public Color getColor() {return this.color;}}
class Automobile {
private enum Action {IDLE,
INCREASE_SPEED,
DECREASE_SPEED,
STOP};
private static final int MAX_SPEED = 140;
class TrafficSignal {
public enum Color {RED,
YELLOW,
GREEN};
/* Current color of the traffic signal, initially red by default */
private Color color = Color.RED;
/* Accessor for the light’s current color */
public Color getColor() {return this.color;}}
class Automobile {
private enum Action {IDLE,
INCREASE_SPEED,
DECREASE_SPEED,
STOP};
class TrafficSignal {
public enum Color {RED,
YELLOW,
GREEN};
/* Current color of the traffic signal, initially red by default */
private Color color = Color.RED;
/* Accessor for the light’s current color */
public Color getColor() {return this.color;}}
class Automobile {
private enum Action {IDLE,
INCREASE_SPEED,
DECREASE_SPEED,
STOP};
class TrafficSignal {
public static final int RED = 0;
public static final int YELLOW = 1;
public static final int GREEN = 2;
/ Current color of the traffic signal, initially red by default /
private int color = RED;
/ Accessor for the light’s current color /
public int getColor() {return this.color;}}
class Automobile {
private static final int IDLE = 0;
private static final int INCREASE_SPEED = 1;
private static final int DECREASE_SPEED = 2;
private static final int STOP = 3;
class TrafficSignal {
public static final int RED = 0;
public static final int YELLOW = 1;
public static final int GREEN = 2;
/ Current color of the traffic signal, initially red by default /
private int color = RED;
/ Accessor for the light’s current color /
public int getColor() {return this.color;}}
class Automobile {
private static final int IDLE = 0;
private static final int INCREASE_SPEED = 1;
private static final int DECREASE_SPEED = 2;
private static final int STOP = 3;
Type Safety
Motivating Example Revisited
class TrafficSignal {
public static final int RED = 0;
public static final int YELLOW = 1;
public static final int GREEN = 2;
/ Current color of the traffic signal, initially red by default /
private int color = RED;
/ Accessor for the light’s current color /
public int getColor() {return this.color;}}
class Automobile {
private static final int IDLE = 0;
private static final int INCREASE_SPEED = 1;
private static final int DECREASE_SPEED = 2;
private static final int STOP = 3;
class TrafficSignal {
public enum Color {RED,
YELLOW,
GREEN};
/* Current color of the traffic signal, initially red by default */
private Color color = Color.RED;
/* Accessor for the light’s current color */
public Color getColor() {return this.color;}}
class Automobile {
private enum Action {IDLE,
INCREASE_SPEED,
DECREASE_SPEED,
STOP};
private static final int MAX_SPEED = 140;
class TrafficSignal {
public enum Color {RED,
YELLOW,
GREEN};
/* Current color of the traffic signal, initially red by default */
private Color color = Color.RED;
/* Accessor for the light’s current color */
public Color getColor() {return this.color;}}
class Automobile {
private enum Action {IDLE,
INCREASE_SPEED,
DECREASE_SPEED,
STOP};
class TrafficSignal {
public enum Color {RED,
YELLOW,
GREEN};
/* Current color of the traffic signal, initially red by default */
private Color color = Color.RED;
/* Accessor for the light’s current color */
public Color getColor() {return this.color;}}
class Automobile {
private enum Action {IDLE,
INCREASE_SPEED,
DECREASE_SPEED,
STOP};
class TrafficSignal {
public static final int RED = 0;
public static final int YELLOW = 1;
public static final int GREEN = 2;
/ Current color of the traffic signal, initially red by default /
private int color = RED;
/ Accessor for the light’s current color /
public int getColor() {return this.color;}}
class Automobile {
private static final int IDLE = 0;
private static final int INCREASE_SPEED = 1;
private static final int DECREASE_SPEED = 2;
private static final int STOP = 3;
class TrafficSignal {
public static final int RED = 0;
public static final int YELLOW = 1;
public static final int GREEN = 2;
/ Current color of the traffic signal, initially red by default /
private int color = RED;
/ Accessor for the light’s current color /
public int getColor() {return this.color;}}
class Automobile {
private static final int IDLE = 0;
private static final int INCREASE_SPEED = 1;
private static final int DECREASE_SPEED = 2;
private static final int STOP = 3;
Singletons in
Natural Order
Motivating Example Revisited
class TrafficSignal {
public static final int RED = 0;
public static final int YELLOW = 1;
public static final int GREEN = 2;
/ Current color of the traffic signal, initially red by default /
private int color = RED;
/ Accessor for the light’s current color /
public int getColor() {return this.color;}}
class Automobile {
private static final int IDLE = 0;
private static final int INCREASE_SPEED = 1;
private static final int DECREASE_SPEED = 2;
private static final int STOP = 3;
class TrafficSignal {
public enum Color {RED,
YELLOW,
GREEN};
/* Current color of the traffic signal, initially red by default */
private Color color = Color.RED;
/* Accessor for the light’s current color */
public Color getColor() {return this.color;}}
class Automobile {
private enum Action {IDLE,
INCREASE_SPEED,
DECREASE_SPEED,
STOP};
private static final int MAX_SPEED = 140;
class TrafficSignal {
public enum Color {RED,
YELLOW,
GREEN};
/* Current color of the traffic signal, initially red by default */
private Color color = Color.RED;
/* Accessor for the light’s current color */
public Color getColor() {return this.color;}}
class Automobile {
private enum Action {IDLE,
INCREASE_SPEED,
DECREASE_SPEED,
STOP};
class TrafficSignal {
public enum Color {RED,
YELLOW,
GREEN};
/* Current color of the traffic signal, initially red by default */
private Color color = Color.RED;
/* Accessor for the light’s current color */
public Color getColor() {return this.color;}}
class Automobile {
private enum Action {IDLE,
INCREASE_SPEED,
DECREASE_SPEED,
STOP};
class TrafficSignal {
public static final int RED = 0;
public static final int YELLOW = 1;
public static final int GREEN = 2;
/ Current color of the traffic signal, initially red by default /
private int color = RED;
/ Accessor for the light’s current color /
public int getColor() {return this.color;}}
class Automobile {
private static final int IDLE = 0;
private static final int INCREASE_SPEED = 1;
private static final int DECREASE_SPEED = 2;
private static final int STOP = 3;
class TrafficSignal {
public static final int RED = 0;
public static final int YELLOW = 1;
public static final int GREEN = 2;
/ Current color of the traffic signal, initially red by default /
private int color = RED;
/ Accessor for the light’s current color /
public int getColor() {return this.color;}}
class Automobile {
private static final int IDLE = 0;
private static final int INCREASE_SPEED = 1;
private static final int DECREASE_SPEED = 2;
private static final int STOP = 3;
Prefixed
Motivating Example Revisited
class TrafficSignal {
public static final int RED = 0;
public static final int YELLOW = 1;
public static final int GREEN = 2;
/ Current color of the traffic signal, initially red by default /
private int color = RED;
/ Accessor for the light’s current color /
public int getColor() {return this.color;}}
class Automobile {
private static final int IDLE = 0;
private static final int INCREASE_SPEED = 1;
private static final int DECREASE_SPEED = 2;
private static final int STOP = 3;
class TrafficSignal {
public enum Color {RED,
YELLOW,
GREEN};
/* Current color of the traffic signal, initially red by default */
private Color color = Color.RED;
/* Accessor for the light’s current color */
public Color getColor() {return this.color;}}
class Automobile {
private enum Action {IDLE,
INCREASE_SPEED,
DECREASE_SPEED,
STOP};
private static final int MAX_SPEED = 140;
class TrafficSignal {
public enum Color {RED,
YELLOW,
GREEN};
/* Current color of the traffic signal, initially red by default */
private Color color = Color.RED;
/* Accessor for the light’s current color */
public Color getColor() {return this.color;}}
class Automobile {
private enum Action {IDLE,
INCREASE_SPEED,
DECREASE_SPEED,
STOP};
class TrafficSignal {
public enum Color {RED,
YELLOW,
GREEN};
/* Current color of the traffic signal, initially red by default */
private Color color = Color.RED;
/* Accessor for the light’s current color */
public Color getColor() {return this.color;}}
class Automobile {
private enum Action {IDLE,
INCREASE_SPEED,
DECREASE_SPEED,
STOP};
class TrafficSignal {
public static final int RED = 0;
public static final int YELLOW = 1;
public static final int GREEN = 2;
/ Current color of the traffic signal, initially red by default /
private int color = RED;
/ Accessor for the light’s current color /
public int getColor() {return this.color;}}
class Automobile {
private static final int IDLE = 0;
private static final int INCREASE_SPEED = 1;
private static final int DECREASE_SPEED = 2;
private static final int STOP = 3;
class TrafficSignal {
public static final int RED = 0;
public static final int YELLOW = 1;
public static final int GREEN = 2;
/ Current color of the traffic signal, initially red by default /
private int color = RED;
/ Accessor for the light’s current color /
public int getColor() {return this.color;}}
class Automobile {
private static final int IDLE = 0;
private static final int INCREASE_SPEED = 1;
private static final int DECREASE_SPEED = 2;
private static final int STOP = 3;
Supports
Separate
Compilation
Motivating Example Revisited
class TrafficSignal {
public static final int RED = 0;
public static final int YELLOW = 1;
public static final int GREEN = 2;
/ Current color of the traffic signal, initially red by default /
private int color = RED;
/ Accessor for the light’s current color /
public int getColor() {return this.color;}}
class Automobile {
private static final int IDLE = 0;
private static final int INCREASE_SPEED = 1;
private static final int DECREASE_SPEED = 2;
private static final int STOP = 3;
class TrafficSignal {
public enum Color {RED,
YELLOW,
GREEN};
/* Current color of the traffic signal, initially red by default */
private Color color = Color.RED;
/* Accessor for the light’s current color */
public Color getColor() {return this.color;}}
class Automobile {
private enum Action {IDLE,
INCREASE_SPEED,
DECREASE_SPEED,
STOP};
private static final int MAX_SPEED = 140;
class TrafficSignal {
public enum Color {RED,
YELLOW,
GREEN};
/* Current color of the traffic signal, initially red by default */
private Color color = Color.RED;
/* Accessor for the light’s current color */
public Color getColor() {return this.color;}}
class Automobile {
private enum Action {IDLE,
INCREASE_SPEED,
DECREASE_SPEED,
STOP};
class TrafficSignal {
public enum Color {RED,
YELLOW,
GREEN};
/* Current color of the traffic signal, initially red by default */
private Color color = Color.RED;
/* Accessor for the light’s current color */
public Color getColor() {return this.color;}}
class Automobile {
private enum Action {IDLE,
INCREASE_SPEED,
DECREASE_SPEED,
STOP};
class TrafficSignal {
public static final int RED = 0;
public static final int YELLOW = 1;
public static final int GREEN = 2;
/ Current color of the traffic signal, initially red by default /
private int color = RED;
/ Accessor for the light’s current color /
public int getColor() {return this.color;}}
class Automobile {
private static final int IDLE = 0;
private static final int INCREASE_SPEED = 1;
private static final int DECREASE_SPEED = 2;
private static final int STOP = 3;
class TrafficSignal {
public static final int RED = 0;
public static final int YELLOW = 1;
public static final int GREEN = 2;
/ Current color of the traffic signal, initially red by default /
private int color = RED;
/ Accessor for the light’s current color /
public int getColor() {return this.color;}}
class Automobile {
private static final int IDLE = 0;
private static final int INCREASE_SPEED = 1;
private static final int DECREASE_SPEED = 2;
private static final int STOP = 3;
Traffic Signal Client
/ The action this automobile is currently performing, idle by default /
private int currentAction = IDLE;
/ The current speed of the automobile, initially 5 mph. /
private int currentSpeed = 5;
private int react(TrafficSignal signal) {
switch(signal.getColor()) {
case TrafficSignal.RED: return STOP;
case TrafficSignal.YELLOW:
// decide whether to stop or go
if (this.shouldGo())
return INCREASE_SPEED;
else return STOP;
case TrafficSignal.GREEN: // no change
return this.currentAction;
default: throw new IllegalArgumentException
("Invalid traffic color");}} // required
public void drive() {
TrafficSignal aSignal = ... ;
int reaction = this.react(aSignal);
private int color = RED;
/ Accessor for the light’s current color /
public int getColor() {return this.color;}}
class Automobile {
private static final int IDLE = 0;
private static final int INCREASE_SPEED = 1;
private static final int DECREASE_SPEED = 2;
private static final int STOP = 3;
private static final int MAX_SPEED = 140;
/ The action this automobile is currently performing, idle by default /
private int currentAction = IDLE;
/ The current speed of the automobile, initially 5 mph. /
private int currentSpeed = 5;
private int react(TrafficSignal signal) {
switch(signal.getColor()) {
case TrafficSignal.RED: return STOP;
case TrafficSignal.YELLOW:
// decide whether to stop or go
if (this.shouldGo())
this.currentAction &&
INCREASE_SPEED ||
tSpeed <= MAX_SPEED))
rmAction(reaction);}
rmAction(int action) {...}}
eger constants for enumerated types.
38 (reacti
39 this.c
40 this.
41
42 private void
(b) Im
Figure 1. Running example: a hypothetical drive-by-w
ch machinery. Third, the weak enum
ogrammer to manually enumerate the
ts, which increases the likelihood of
different enum constants may be unin-
he same internal value. Finally, the
rittle [?]: since the values are com-
at compile time they are inlined into
new constants are added in between
example, in which
by language enum
and Automobile.
ations of these ne
through compile-tim
between the named
ated values. It is als
is an Action, whic
Traffic Signal Client
/ The action this automobile is currently performing, idle by default /
private int currentAction = IDLE;
/ The current speed of the automobile, initially 5 mph. /
private int currentSpeed = 5;
private int react(TrafficSignal signal) {
switch(signal.getColor()) {
case TrafficSignal.RED: return STOP;
case TrafficSignal.YELLOW:
// decide whether to stop or go
if (this.shouldGo())
return INCREASE_SPEED;
else return STOP;
case TrafficSignal.GREEN: // no change
return this.currentAction;
default: throw new IllegalArgumentException
("Invalid traffic color");}} // required
public void drive() {
TrafficSignal aSignal = ... ;
int reaction = this.react(aSignal);
private int color = RED;
/ Accessor for the light’s current color /
public int getColor() {return this.color;}}
class Automobile {
private static final int IDLE = 0;
private static final int INCREASE_SPEED = 1;
private static final int DECREASE_SPEED = 2;
private static final int STOP = 3;
private static final int MAX_SPEED = 140;
/ The action this automobile is currently performing, idle by default /
private int currentAction = IDLE;
/ The current speed of the automobile, initially 5 mph. /
private int currentSpeed = 5;
private int react(TrafficSignal signal) {
switch(signal.getColor()) {
case TrafficSignal.RED: return STOP;
case TrafficSignal.YELLOW:
// decide whether to stop or go
if (this.shouldGo())
this.currentAction &&
INCREASE_SPEED ||
tSpeed <= MAX_SPEED))
rmAction(reaction);}
rmAction(int action) {...}}
eger constants for enumerated types.
38 (reacti
39 this.c
40 this.
41
42 private void
(b) Im
Figure 1. Running example: a hypothetical drive-by-w
ch machinery. Third, the weak enum
ogrammer to manually enumerate the
ts, which increases the likelihood of
different enum constants may be unin-
he same internal value. Finally, the
rittle [?]: since the values are com-
at compile time they are inlined into
new constants are added in between
example, in which
by language enum
and Automobile.
ations of these ne
through compile-tim
between the named
ated values. It is als
is an Action, whic
Traffic Signal Client
/ The action this automobile is currently performing, idle by default /
private int currentAction = IDLE;
/ The current speed of the automobile, initially 5 mph. /
private int currentSpeed = 5;
private int react(TrafficSignal signal) {
switch(signal.getColor()) {
case TrafficSignal.RED: return STOP;
case TrafficSignal.YELLOW:
// decide whether to stop or go
if (this.shouldGo())
return INCREASE_SPEED;
else return STOP;
case TrafficSignal.GREEN: // no change
return this.currentAction;
default: throw new IllegalArgumentException
("Invalid traffic color");}} // required
public void drive() {
TrafficSignal aSignal = ... ;
int reaction = this.react(aSignal);
private int color = RED;
/ Accessor for the light’s current color /
public int getColor() {return this.color;}}
class Automobile {
private static final int IDLE = 0;
private static final int INCREASE_SPEED = 1;
private static final int DECREASE_SPEED = 2;
private static final int STOP = 3;
private static final int MAX_SPEED = 140;
/ The action this automobile is currently performing, idle by default /
private int currentAction = IDLE;
/ The current speed of the automobile, initially 5 mph. /
private int currentSpeed = 5;
private int react(TrafficSignal signal) {
switch(signal.getColor()) {
case TrafficSignal.RED: return STOP;
case TrafficSignal.YELLOW:
// decide whether to stop or go
if (this.shouldGo())
this.currentAction &&
INCREASE_SPEED ||
tSpeed <= MAX_SPEED))
rmAction(reaction);}
rmAction(int action) {...}}
eger constants for enumerated types.
38 (reacti
39 this.c
40 this.
41
42 private void
(b) Im
Figure 1. Running example: a hypothetical drive-by-w
ch machinery. Third, the weak enum
ogrammer to manually enumerate the
ts, which increases the likelihood of
different enum constants may be unin-
he same internal value. Finally, the
rittle [?]: since the values are com-
at compile time they are inlined into
new constants are added in between
example, in which
by language enum
and Automobile.
ations of these ne
through compile-tim
between the named
ated values. It is als
is an Action, whic
Traffic Signal Client
/ The action this automobile is currently performing, idle by default /
private int currentAction = IDLE;
/ The current speed of the automobile, initially 5 mph. /
private int currentSpeed = 5;
private int react(TrafficSignal signal) {
switch(signal.getColor()) {
case TrafficSignal.RED: return STOP;
case TrafficSignal.YELLOW:
// decide whether to stop or go
if (this.shouldGo())
return INCREASE_SPEED;
else return STOP;
case TrafficSignal.GREEN: // no change
return this.currentAction;
default: throw new IllegalArgumentException
("Invalid traffic color");}} // required
public void drive() {
TrafficSignal aSignal = ... ;
int reaction = this.react(aSignal);
private int color = RED;
/ Accessor for the light’s current color /
public int getColor() {return this.color;}}
class Automobile {
private static final int IDLE = 0;
private static final int INCREASE_SPEED = 1;
private static final int DECREASE_SPEED = 2;
private static final int STOP = 3;
private static final int MAX_SPEED = 140;
/ The action this automobile is currently performing, idle by default /
private int currentAction = IDLE;
/ The current speed of the automobile, initially 5 mph. /
private int currentSpeed = 5;
private int react(TrafficSignal signal) {
switch(signal.getColor()) {
case TrafficSignal.RED: return STOP;
case TrafficSignal.YELLOW:
// decide whether to stop or go
if (this.shouldGo())
this.currentAction &&
INCREASE_SPEED ||
tSpeed <= MAX_SPEED))
rmAction(reaction);}
rmAction(int action) {...}}
eger constants for enumerated types.
38 (reacti
39 this.c
40 this.
41
42 private void
(b) Im
Figure 1. Running example: a hypothetical drive-by-w
ch machinery. Third, the weak enum
ogrammer to manually enumerate the
ts, which increases the likelihood of
different enum constants may be unin-
he same internal value. Finally, the
rittle [?]: since the values are com-
at compile time they are inlined into
new constants are added in between
example, in which
by language enum
and Automobile.
ations of these ne
through compile-tim
between the named
ated values. It is als
is an Action, whic
Traffic Signal Client
private int color = RED;
/ Accessor for the light’s current color /
public int getColor() {return this.color;}}
class Automobile {
private static final int IDLE = 0;
private static final int INCREASE_SPEED = 1;
private static final int DECREASE_SPEED = 2;
private static final int STOP = 3;
private static final int MAX_SPEED = 140;
/ The action this automobile is currently performing, idle by default /
private int currentAction = IDLE;
/ The current speed of the automobile, initially 5 mph. /
private int currentSpeed = 5;
private int react(TrafficSignal signal) {
switch(signal.getColor()) {
case TrafficSignal.RED: return STOP;
case TrafficSignal.YELLOW:
// decide whether to stop or go
if (this.shouldGo())
this.currentAction &&
INCREASE_SPEED ||
tSpeed <= MAX_SPEED))
rmAction(reaction);}
rmAction(int action) {...}}
eger constants for enumerated types.
38 (reacti
39 this.c
40 this.
41
42 private void
(b) Im
Figure 1. Running example: a hypothetical drive-by-w
ch machinery. Third, the weak enum
ogrammer to manually enumerate the
ts, which increases the likelihood of
different enum constants may be unin-
he same internal value. Finally, the
rittle [?]: since the values are com-
at compile time they are inlined into
new constants are added in between
example, in which
by language enum
and Automobile.
ations of these ne
through compile-tim
between the named
ated values. It is als
is an Action, whic
private int color = RED;
/ Accessor for the light’s current color /
public int getColor() {return this.color;}}
class Automobile {
private static final int IDLE = 0;
private static final int INCREASE_SPEED = 1;
private static final int DECREASE_SPEED = 2;
private static final int STOP = 3;
private static final int MAX_SPEED = 140;
/ The action this automobile is currently performing, idle by default /
private int currentAction = IDLE;
/ The current speed of the automobile, initially 5 mph. /
private int currentSpeed = 5;
private int react(TrafficSignal signal) {
switch(signal.getColor()) {
case TrafficSignal.RED: return STOP;
case TrafficSignal.YELLOW:
// decide whether to stop or go
Automobile
Action Enum
Traffic Signal Client
private int color = RED;
/ Accessor for the light’s current color /
public int getColor() {return this.color;}}
class Automobile {
private static final int IDLE = 0;
private static final int INCREASE_SPEED = 1;
private static final int DECREASE_SPEED = 2;
private static final int STOP = 3;
private static final int MAX_SPEED = 140;
/ The action this automobile is currently performing, idle by default /
private int currentAction = IDLE;
/ The current speed of the automobile, initially 5 mph. /
private int currentSpeed = 5;
private int react(TrafficSignal signal) {
switch(signal.getColor()) {
case TrafficSignal.RED: return STOP;
case TrafficSignal.YELLOW:
// decide whether to stop or go
if (this.shouldGo())
this.currentAction &&
INCREASE_SPEED ||
tSpeed <= MAX_SPEED))
rmAction(reaction);}
rmAction(int action) {...}}
eger constants for enumerated types.
38 (reacti
39 this.c
40 this.
41
42 private void
(b) Im
Figure 1. Running example: a hypothetical drive-by-w
ch machinery. Third, the weak enum
ogrammer to manually enumerate the
ts, which increases the likelihood of
different enum constants may be unin-
he same internal value. Finally, the
rittle [?]: since the values are com-
at compile time they are inlined into
new constants are added in between
example, in which
by language enum
and Automobile.
ations of these ne
through compile-tim
between the named
ated values. It is als
is an Action, whic
private int color = RED;
/ Accessor for the light’s current color /
public int getColor() {return this.color;}}
class Automobile {
private static final int IDLE = 0;
private static final int INCREASE_SPEED = 1;
private static final int DECREASE_SPEED = 2;
private static final int STOP = 3;
private static final int MAX_SPEED = 140;
/ The action this automobile is currently performing, idle by default /
private int currentAction = IDLE;
/ The current speed of the automobile, initially 5 mph. /
private int currentSpeed = 5;
private int react(TrafficSignal signal) {
switch(signal.getColor()) {
case TrafficSignal.RED: return STOP;
case TrafficSignal.YELLOW:
// decide whether to stop or go
Named-
Constant
Traffic Signal Client
private int color = RED;
/ Accessor for the light’s current color /
public int getColor() {return this.color;}}
class Automobile {
private static final int IDLE = 0;
private static final int INCREASE_SPEED = 1;
private static final int DECREASE_SPEED = 2;
private static final int STOP = 3;
private static final int MAX_SPEED = 140;
/ The action this automobile is currently performing, idle by default /
private int currentAction = IDLE;
/ The current speed of the automobile, initially 5 mph. /
private int currentSpeed = 5;
private int react(TrafficSignal signal) {
switch(signal.getColor()) {
case TrafficSignal.RED: return STOP;
case TrafficSignal.YELLOW:
// decide whether to stop or go
if (this.shouldGo())
this.currentAction &&
INCREASE_SPEED ||
tSpeed <= MAX_SPEED))
rmAction(reaction);}
rmAction(int action) {...}}
eger constants for enumerated types.
38 (reacti
39 this.c
40 this.
41
42 private void
(b) Im
Figure 1. Running example: a hypothetical drive-by-w
ch machinery. Third, the weak enum
ogrammer to manually enumerate the
ts, which increases the likelihood of
different enum constants may be unin-
he same internal value. Finally, the
rittle [?]: since the values are com-
at compile time they are inlined into
new constants are added in between
example, in which
by language enum
and Automobile.
ations of these ne
through compile-tim
between the named
ated values. It is als
is an Action, whic
private int color = RED;
/ Accessor for the light’s current color /
public int getColor() {return this.color;}}
class Automobile {
private static final int IDLE = 0;
private static final int INCREASE_SPEED = 1;
private static final int DECREASE_SPEED = 2;
private static final int STOP = 3;
private static final int MAX_SPEED = 140;
/ The action this automobile is currently performing, idle by default /
private int currentAction = IDLE;
/ The current speed of the automobile, initially 5 mph. /
private int currentSpeed = 5;
private int react(TrafficSignal signal) {
switch(signal.getColor()) {
case TrafficSignal.RED: return STOP;
case TrafficSignal.YELLOW:
// decide whether to stop or go
Promising...
Traffic Signal Client
private int color = RED;
/ Accessor for the light’s current color /
public int getColor() {return this.color;}}
class Automobile {
private static final int IDLE = 0;
private static final int INCREASE_SPEED = 1;
private static final int DECREASE_SPEED = 2;
private static final int STOP = 3;
private static final int MAX_SPEED = 140;
/ The action this automobile is currently performing, idle by default /
private int currentAction = IDLE;
/ The current speed of the automobile, initially 5 mph. /
private int currentSpeed = 5;
private int react(TrafficSignal signal) {
switch(signal.getColor()) {
case TrafficSignal.RED: return STOP;
case TrafficSignal.YELLOW:
// decide whether to stop or go
if (this.shouldGo())
this.currentAction &&
INCREASE_SPEED ||
tSpeed <= MAX_SPEED))
rmAction(reaction);}
rmAction(int action) {...}}
eger constants for enumerated types.
38 (reacti
39 this.c
40 this.
41
42 private void
(b) Im
Figure 1. Running example: a hypothetical drive-by-w
ch machinery. Third, the weak enum
ogrammer to manually enumerate the
ts, which increases the likelihood of
different enum constants may be unin-
he same internal value. Finally, the
rittle [?]: since the values are com-
at compile time they are inlined into
new constants are added in between
example, in which
by language enum
and Automobile.
ations of these ne
through compile-tim
between the named
ated values. It is als
is an Action, whic
private int color = RED;
/ Accessor for the light’s current color /
public int getColor() {return this.color;}}
class Automobile {
private static final int IDLE = 0;
private static final int INCREASE_SPEED = 1;
private static final int DECREASE_SPEED = 2;
private static final int STOP = 3;
private static final int MAX_SPEED = 140;
/ The action this automobile is currently performing, idle by default /
private int currentAction = IDLE;
/ The current speed of the automobile, initially 5 mph. /
private int currentSpeed = 5;
private int react(TrafficSignal signal) {
switch(signal.getColor()) {
case TrafficSignal.RED: return STOP;
case TrafficSignal.YELLOW:
// decide whether to stop or go
Definitely not
enumerizable
Traffic Signal Client
/ The action this automobile is currently performing, idle by default /
private int currentAction = IDLE;
/ The current speed of the automobile, initially 5 mph. /
private int currentSpeed = 5;
private int react(TrafficSignal signal) {
switch(signal.getColor()) {
case TrafficSignal.RED: return STOP;
case TrafficSignal.YELLOW:
// decide whether to stop or go
if (this.shouldGo())
return INCREASE_SPEED;
else return STOP;
case TrafficSignal.GREEN: // no change
return this.currentAction;
default: throw new IllegalArgumentException
("Invalid traffic color");}} // required
public void drive() {
TrafficSignal aSignal = ... ;
int reaction = this.react(aSignal);
private int color = RED;
/ Accessor for the light’s current color /
public int getColor() {return this.color;}}
class Automobile {
private static final int IDLE = 0;
private static final int INCREASE_SPEED = 1;
private static final int DECREASE_SPEED = 2;
private static final int STOP = 3;
private static final int MAX_SPEED = 140;
/ The action this automobile is currently performing, idle by default /
private int currentAction = IDLE;
/ The current speed of the automobile, initially 5 mph. /
private int currentSpeed = 5;
private int react(TrafficSignal signal) {
switch(signal.getColor()) {
case TrafficSignal.RED: return STOP;
case TrafficSignal.YELLOW:
// decide whether to stop or go
if (this.shouldGo())
this.currentAction &&
INCREASE_SPEED ||
tSpeed <= MAX_SPEED))
rmAction(reaction);}
rmAction(int action) {...}}
eger constants for enumerated types.
38 (reacti
39 this.c
40 this.
41
42 private void
(b) Im
Figure 1. Running example: a hypothetical drive-by-w
ch machinery. Third, the weak enum
ogrammer to manually enumerate the
ts, which increases the likelihood of
different enum constants may be unin-
he same internal value. Finally, the
rittle [?]: since the values are com-
at compile time they are inlined into
new constants are added in between
example, in which
by language enum
and Automobile.
ations of these ne
through compile-tim
between the named
ated values. It is als
is an Action, whic
Traffic Signal Client
/ The action this automobile is currently performing, idle by default /
private int currentAction = IDLE;
/ The current speed of the automobile, initially 5 mph. /
private int currentSpeed = 5;
private int react(TrafficSignal signal) {
switch(signal.getColor()) {
case TrafficSignal.RED: return STOP;
case TrafficSignal.YELLOW:
// decide whether to stop or go
if (this.shouldGo())
return INCREASE_SPEED;
else return STOP;
case TrafficSignal.GREEN: // no change
return this.currentAction;
default: throw new IllegalArgumentException
("Invalid traffic color");}} // required
public void drive() {
TrafficSignal aSignal = ... ;
int reaction = this.react(aSignal);
private int color = RED;
/ Accessor for the light’s current color /
public int getColor() {return this.color;}}
class Automobile {
private static final int IDLE = 0;
private static final int INCREASE_SPEED = 1;
private static final int DECREASE_SPEED = 2;
private static final int STOP = 3;
private static final int MAX_SPEED = 140;
/ The action this automobile is currently performing, idle by default /
private int currentAction = IDLE;
/ The current speed of the automobile, initially 5 mph. /
private int currentSpeed = 5;
private int react(TrafficSignal signal) {
switch(signal.getColor()) {
case TrafficSignal.RED: return STOP;
case TrafficSignal.YELLOW:
// decide whether to stop or go
if (this.shouldGo())
this.currentAction &&
INCREASE_SPEED ||
tSpeed <= MAX_SPEED))
rmAction(reaction);}
rmAction(int action) {...}}
eger constants for enumerated types.
38 (reacti
39 this.c
40 this.
41
42 private void
(b) Im
Figure 1. Running example: a hypothetical drive-by-w
ch machinery. Third, the weak enum
ogrammer to manually enumerate the
ts, which increases the likelihood of
different enum constants may be unin-
he same internal value. Finally, the
rittle [?]: since the values are com-
at compile time they are inlined into
new constants are added in between
example, in which
by language enum
and Automobile.
ations of these ne
through compile-tim
between the named
ated values. It is als
is an Action, whic
Traffic Signal Client
/ The action this automobile is currently performing, idle by default /
private int currentAction = IDLE;
/ The current speed of the automobile, initially 5 mph. /
private int currentSpeed = 5;
private int react(TrafficSignal signal) {
switch(signal.getColor()) {
case TrafficSignal.RED: return STOP;
case TrafficSignal.YELLOW:
// decide whether to stop or go
if (this.shouldGo())
return INCREASE_SPEED;
else return STOP;
case TrafficSignal.GREEN: // no change
return this.currentAction;
default: throw new IllegalArgumentException
("Invalid traffic color");}} // required
public void drive() {
TrafficSignal aSignal = ... ;
int reaction = this.react(aSignal);
private int color = RED;
/ Accessor for the light’s current color /
public int getColor() {return this.color;}}
class Automobile {
private static final int IDLE = 0;
private static final int INCREASE_SPEED = 1;
private static final int DECREASE_SPEED = 2;
private static final int STOP = 3;
private static final int MAX_SPEED = 140;
/ The action this automobile is currently performing, idle by default /
private int currentAction = IDLE;
/ The current speed of the automobile, initially 5 mph. /
private int currentSpeed = 5;
private int react(TrafficSignal signal) {
switch(signal.getColor()) {
case TrafficSignal.RED: return STOP;
case TrafficSignal.YELLOW:
// decide whether to stop or go
if (this.shouldGo())
this.currentAction &&
INCREASE_SPEED ||
tSpeed <= MAX_SPEED))
rmAction(reaction);}
rmAction(int action) {...}}
eger constants for enumerated types.
38 (reacti
39 this.c
40 this.
41
42 private void
(b) Im
Figure 1. Running example: a hypothetical drive-by-w
ch machinery. Third, the weak enum
ogrammer to manually enumerate the
ts, which increases the likelihood of
different enum constants may be unin-
he same internal value. Finally, the
rittle [?]: since the values are com-
at compile time they are inlined into
new constants are added in between
example, in which
by language enum
and Automobile.
ations of these ne
through compile-tim
between the named
ated values. It is als
is an Action, whic
/ The action this automobile is currently performing, idle by default /
private int currentAction = IDLE;
/ The current speed of the automobile, initially 5 mph. /
private int currentSpeed = 5;
private int react(TrafficSignal signal) {
switch(signal.getColor()) {
case TrafficSignal.RED: return STOP;
case TrafficSignal.YELLOW:
// decide whether to stop or go
if (this.shouldGo())
return INCREASE_SPEED;
else return STOP;
case TrafficSignal.GREEN: // no change
return this.currentAction;
default: throw new IllegalArgumentException
("Invalid traffic color");}} // required
public void drive() {
TrafficSignal aSignal = ... ;
int reaction = this.react(aSignal);
Traffic Signal Client
private int color = RED;
/ Accessor for the light’s current color /
public int getColor() {return this.color;}}
class Automobile {
private static final int IDLE = 0;
private static final int INCREASE_SPEED = 1;
private static final int DECREASE_SPEED = 2;
private static final int STOP = 3;
private static final int MAX_SPEED = 140;
/ The action this automobile is currently performing, idle by default /
private int currentAction = IDLE;
/ The current speed of the automobile, initially 5 mph. /
private int currentSpeed = 5;
private int react(TrafficSignal signal) {
switch(signal.getColor()) {
case TrafficSignal.RED: return STOP;
case TrafficSignal.YELLOW:
// decide whether to stop or go
if (this.shouldGo())
this.currentAction &&
INCREASE_SPEED ||
tSpeed <= MAX_SPEED))
rmAction(reaction);}
rmAction(int action) {...}}
eger constants for enumerated types.
38 (reacti
39 this.c
40 this.
41
42 private void
(b) Im
Figure 1. Running example: a hypothetical drive-by-w
ch machinery. Third, the weak enum
ogrammer to manually enumerate the
ts, which increases the likelihood of
different enum constants may be unin-
he same internal value. Finally, the
rittle [?]: since the values are com-
at compile time they are inlined into
new constants are added in between
example, in which
by language enum
and Automobile.
ations of these ne
through compile-tim
between the named
ated values. It is als
is an Action, whic
/ The action this automobile is currently performing, idle by default /
private int currentAction = IDLE;
/ The current speed of the automobile, initially 5 mph. /
private int currentSpeed = 5;
private int react(TrafficSignal signal) {
switch(signal.getColor()) {
case TrafficSignal.RED: return STOP;
case TrafficSignal.YELLOW:
// decide whether to stop or go
if (this.shouldGo())
return INCREASE_SPEED;
else return STOP;
case TrafficSignal.GREEN: // no change
return this.currentAction;
default: throw new IllegalArgumentException
("Invalid traffic color");}} // required
public void drive() {
TrafficSignal aSignal = ... ;
int reaction = this.react(aSignal);
/ The action this automobile is currently performing, idle by default /
private int currentAction = IDLE;
/ The current speed of the automobile, initially 5 mph. /
private int currentSpeed = 5;
private int react(TrafficSignal signal) {
switch(signal.getColor()) {
case TrafficSignal.RED: return STOP;
case TrafficSignal.YELLOW:
// decide whether to stop or go
if (this.shouldGo())
return INCREASE_SPEED;
else return STOP;
case TrafficSignal.GREEN: // no change
return this.currentAction;
default: throw new IllegalArgumentException
("Invalid traffic color");}} // required
public void drive() {
TrafficSignal aSignal = ... ;
int reaction = this.react(aSignal);
/ The action this automobile is currently performing, idle by default /
private int currentAction = IDLE;
/ The current speed of the automobile, initially 5 mph. /
private int currentSpeed = 5;
private int react(TrafficSignal signal) {
switch(signal.getColor()) {
case TrafficSignal.RED: return STOP;
case TrafficSignal.YELLOW:
// decide whether to stop or go
if (this.shouldGo())
return INCREASE_SPEED;
else return STOP;
case TrafficSignal.GREEN: // no change
return this.currentAction;
default: throw new IllegalArgumentException
("Invalid traffic color");}} // required
public void drive() {
TrafficSignal aSignal = ... ;
int reaction = this.react(aSignal);
/ The action this automobile is currently performing, idle by default /
private int currentAction = IDLE;
/ The current speed of the automobile, initially 5 mph. /
private int currentSpeed = 5;
private int react(TrafficSignal signal) {
switch(signal.getColor()) {
case TrafficSignal.RED: return STOP;
case TrafficSignal.YELLOW:
// decide whether to stop or go
if (this.shouldGo())
return INCREASE_SPEED;
else return STOP;
case TrafficSignal.GREEN: // no change
return this.currentAction;
default: throw new IllegalArgumentException
("Invalid traffic color");}} // required
public void drive() {
TrafficSignal aSignal = ... ;
int reaction = this.react(aSignal);
/ The action this automobile is currently performing, idle by default /
private int currentAction = IDLE;
/ The current speed of the automobile, initially 5 mph. /
private int currentSpeed = 5;
private int react(TrafficSignal signal) {
switch(signal.getColor()) {
case TrafficSignal.RED: return STOP;
case TrafficSignal.YELLOW:
// decide whether to stop or go
if (this.shouldGo())
return INCREASE_SPEED;
else return STOP;
case TrafficSignal.GREEN: // no change
return this.currentAction;
default: throw new IllegalArgumentException
("Invalid traffic color");}} // required
public void drive() {
TrafficSignal aSignal = ... ;
int reaction = this.react(aSignal);
/ The action this automobile is currently performing, idle by default /
private int currentAction = IDLE;
/ The current speed of the automobile, initially 5 mph. /
private int currentSpeed = 5;
private int react(TrafficSignal signal) {
switch(signal.getColor()) {
case TrafficSignal.RED: return STOP;
case TrafficSignal.YELLOW:
// decide whether to stop or go
if (this.shouldGo())
return INCREASE_SPEED;
else return STOP;
case TrafficSignal.GREEN: // no change
return this.currentAction;
default: throw new IllegalArgumentException
("Invalid traffic color");}} // required
public void drive() {
TrafficSignal aSignal = ... ;
int reaction = this.react(aSignal);
/ The action this automobile is currently performing, idle by default /
private int currentAction = IDLE;
/ The current speed of the automobile, initially 5 mph. /
private int currentSpeed = 5;
private int react(TrafficSignal signal) {
switch(signal.getColor()) {
case TrafficSignal.RED: return STOP;
case TrafficSignal.YELLOW:
// decide whether to stop or go
if (this.shouldGo())
return INCREASE_SPEED;
else return STOP;
case TrafficSignal.GREEN: // no change
return this.currentAction;
default: throw new IllegalArgumentException
("Invalid traffic color");}} // required
public void drive() {
TrafficSignal aSignal = ... ;
int reaction = this.react(aSignal);
/* The action this automobile is currently performing, idle by default */
private Action currentAction = Action.IDLE;
/* The current speed of the automobile, initially 5 mph. */
private int currentSpeed = 5;
private Action react(TrafficSignal signal) {
switch(signal.getColor()) {
case TrafficSignal.RED: return Action.STOP;
case TrafficSignal.YELLOW:
// decide whether to stop or go
if (this.shouldGo())
return Action.INCREASE_SPEED;
else return Action.STOP;
case TrafficSignal.GREEN: // no change
return this.currentAction;
default: throw new IllegalArgumentException
("Invalid traffic color");}} // required
public void drive() {
TrafficSignal aSignal = ... ;
Action reaction = this.react(aSignal);
Traffic Signal Client
private int color = RED;
/ Accessor for the light’s current color /
public int getColor() {return this.color;}}
class Automobile {
private static final int IDLE = 0;
private static final int INCREASE_SPEED = 1;
private static final int DECREASE_SPEED = 2;
private static final int STOP = 3;
private static final int MAX_SPEED = 140;
/ The action this automobile is currently performing, idle by default /
private int currentAction = IDLE;
/ The current speed of the automobile, initially 5 mph. /
private int currentSpeed = 5;
private int react(TrafficSignal signal) {
switch(signal.getColor()) {
case TrafficSignal.RED: return STOP;
case TrafficSignal.YELLOW:
// decide whether to stop or go
if (this.shouldGo())
this.currentAction &&
INCREASE_SPEED ||
tSpeed <= MAX_SPEED))
rmAction(reaction);}
rmAction(int action) {...}}
eger constants for enumerated types.
38 (reacti
39 this.c
40 this.
41
42 private void
(b) Im
Figure 1. Running example: a hypothetical drive-by-w
ch machinery. Third, the weak enum
ogrammer to manually enumerate the
ts, which increases the likelihood of
different enum constants may be unin-
he same internal value. Finally, the
rittle [?]: since the values are com-
at compile time they are inlined into
new constants are added in between
example, in which
by language enum
and Automobile.
ations of these ne
through compile-tim
between the named
ated values. It is als
is an Action, whic
/* The action this automobile is currently performing, idle by default */
private Action currentAction = Action.IDLE;
/* The current speed of the automobile, initially 5 mph. */
private int currentSpeed = 5;
private Action react(TrafficSignal signal) {
switch(signal.getColor()) {
case TrafficSignal.RED: return Action.STOP;
case TrafficSignal.YELLOW:
// decide whether to stop or go
if (this.shouldGo())
return Action.INCREASE_SPEED;
else return Action.STOP;
case TrafficSignal.GREEN: // no change
return this.currentAction;
default: throw new IllegalArgumentException
("Invalid traffic color");}} // required
public void drive() {
TrafficSignal aSignal = ... ;
Action reaction = this.react(aSignal);
/ The action this automobile is currently performing, idle by default /
private int currentAction = IDLE;
/ The current speed of the automobile, initially 5 mph. /
private int currentSpeed = 5;
private int react(TrafficSignal signal) {
switch(signal.getColor()) {
case TrafficSignal.RED: return STOP;
case TrafficSignal.YELLOW:
// decide whether to stop or go
if (this.shouldGo())
return INCREASE_SPEED;
else return STOP;
case TrafficSignal.GREEN: // no change
return this.currentAction;
default: throw new IllegalArgumentException
("Invalid traffic color");}} // required
public void drive() {
TrafficSignal aSignal = ... ;
int reaction = this.react(aSignal);
/ The action this automobile is currently performing, idle by default /
private int currentAction = IDLE;
/ The current speed of the automobile, initially 5 mph. /
private int currentSpeed = 5;
private int react(TrafficSignal signal) {
switch(signal.getColor()) {
case TrafficSignal.RED: return STOP;
case TrafficSignal.YELLOW:
// decide whether to stop or go
if (this.shouldGo())
return INCREASE_SPEED;
else return STOP;
case TrafficSignal.GREEN: // no change
return this.currentAction;
default: throw new IllegalArgumentException
("Invalid traffic color");}} // required
public void drive() {
TrafficSignal aSignal = ... ;
int reaction = this.react(aSignal);
/ The action this automobile is currently performing, idle by default /
private int currentAction = IDLE;
/ The current speed of the automobile, initially 5 mph. /
private int currentSpeed = 5;
private int react(TrafficSignal signal) {
switch(signal.getColor()) {
case TrafficSignal.RED: return STOP;
case TrafficSignal.YELLOW:
// decide whether to stop or go
if (this.shouldGo())
return INCREASE_SPEED;
else return STOP;
case TrafficSignal.GREEN: // no change
return this.currentAction;
default: throw new IllegalArgumentException
("Invalid traffic color");}} // required
public void drive() {
TrafficSignal aSignal = ... ;
int reaction = this.react(aSignal);
/ The action this automobile is currently performing, idle by default /
private int currentAction = IDLE;
/ The current speed of the automobile, initially 5 mph. /
private int currentSpeed = 5;
private int react(TrafficSignal signal) {
switch(signal.getColor()) {
case TrafficSignal.RED: return STOP;
case TrafficSignal.YELLOW:
// decide whether to stop or go
if (this.shouldGo())
return INCREASE_SPEED;
else return STOP;
case TrafficSignal.GREEN: // no change
return this.currentAction;
default: throw new IllegalArgumentException
("Invalid traffic color");}} // required
public void drive() {
TrafficSignal aSignal = ... ;
int reaction = this.react(aSignal);
/ The action this automobile is currently performing, idle by default /
private int currentAction = IDLE;
/ The current speed of the automobile, initially 5 mph. /
private int currentSpeed = 5;
private int react(TrafficSignal signal) {
switch(signal.getColor()) {
case TrafficSignal.RED: return STOP;
case TrafficSignal.YELLOW:
// decide whether to stop or go
if (this.shouldGo())
return INCREASE_SPEED;
else return STOP;
case TrafficSignal.GREEN: // no change
return this.currentAction;
default: throw new IllegalArgumentException
("Invalid traffic color");}} // required
public void drive() {
TrafficSignal aSignal = ... ;
int reaction = this.react(aSignal);
/ The action this automobile is currently performing, idle by default /
private int currentAction = IDLE;
/ The current speed of the automobile, initially 5 mph. /
private int currentSpeed = 5;
private int react(TrafficSignal signal) {
switch(signal.getColor()) {
case TrafficSignal.RED: return STOP;
case TrafficSignal.YELLOW:
// decide whether to stop or go
if (this.shouldGo())
return INCREASE_SPEED;
else return STOP;
case TrafficSignal.GREEN: // no change
return this.currentAction;
default: throw new IllegalArgumentException
("Invalid traffic color");}} // required
public void drive() {
TrafficSignal aSignal = ... ;
int reaction = this.react(aSignal);
/ The action this automobile is currently performing, idle by default /
private int currentAction = IDLE;
/ The current speed of the automobile, initially 5 mph. /
private int currentSpeed = 5;
private int react(TrafficSignal signal) {
switch(signal.getColor()) {
case TrafficSignal.RED: return STOP;
case TrafficSignal.YELLOW:
// decide whether to stop or go
if (this.shouldGo())
return INCREASE_SPEED;
else return STOP;
case TrafficSignal.GREEN: // no change
return this.currentAction;
default: throw new IllegalArgumentException
("Invalid traffic color");}} // required
public void drive() {
TrafficSignal aSignal = ... ;
int reaction = this.react(aSignal);
/* The action this automobile is currently performing, idle by default */
private Action currentAction = Action.IDLE;
/* The current speed of the automobile, initially 5 mph. */
private int currentSpeed = 5;
private Action react(TrafficSignal signal) {
switch(signal.getColor()) {
case TrafficSignal.RED: return Action.STOP;
case TrafficSignal.YELLOW:
// decide whether to stop or go
if (this.shouldGo())
return Action.INCREASE_SPEED;
else return Action.STOP;
case TrafficSignal.GREEN: // no change
return this.currentAction;
default: throw new IllegalArgumentException
("Invalid traffic color");}} // required
public void drive() {
TrafficSignal aSignal = ... ;
Action reaction = this.react(aSignal);
Traffic Signal Client
private int color = RED;
/ Accessor for the light’s current color /
public int getColor() {return this.color;}}
class Automobile {
private static final int IDLE = 0;
private static final int INCREASE_SPEED = 1;
private static final int DECREASE_SPEED = 2;
private static final int STOP = 3;
private static final int MAX_SPEED = 140;
/ The action this automobile is currently performing, idle by default /
private int currentAction = IDLE;
/ The current speed of the automobile, initially 5 mph. /
private int currentSpeed = 5;
private int react(TrafficSignal signal) {
switch(signal.getColor()) {
case TrafficSignal.RED: return STOP;
case TrafficSignal.YELLOW:
// decide whether to stop or go
if (this.shouldGo())
this.currentAction &&
INCREASE_SPEED ||
tSpeed <= MAX_SPEED))
rmAction(reaction);}
rmAction(int action) {...}}
eger constants for enumerated types.
38 (reacti
39 this.c
40 this.
41
42 private void
(b) Im
Figure 1. Running example: a hypothetical drive-by-w
ch machinery. Third, the weak enum
ogrammer to manually enumerate the
ts, which increases the likelihood of
different enum constants may be unin-
he same internal value. Finally, the
rittle [?]: since the values are com-
at compile time they are inlined into
new constants are added in between
example, in which
by language enum
and Automobile.
ations of these ne
through compile-tim
between the named
ated values. It is als
is an Action, whic
/* The action this automobile is currently performing, idle by default */
private Action currentAction = Action.IDLE;
/* The current speed of the automobile, initially 5 mph. */
private int currentSpeed = 5;
private Action react(TrafficSignal signal) {
switch(signal.getColor()) {
case TrafficSignal.RED: return Action.STOP;
case TrafficSignal.YELLOW:
// decide whether to stop or go
if (this.shouldGo())
return Action.INCREASE_SPEED;
else return Action.STOP;
case TrafficSignal.GREEN: // no change
return this.currentAction;
default: throw new IllegalArgumentException
("Invalid traffic color");}} // required
public void drive() {
TrafficSignal aSignal = ... ;
Action reaction = this.react(aSignal);
/ The action this automobile is currently performing, idle by default /
private int currentAction = IDLE;
/ The current speed of the automobile, initially 5 mph. /
private int currentSpeed = 5;
private int react(TrafficSignal signal) {
switch(signal.getColor()) {
case TrafficSignal.RED: return STOP;
case TrafficSignal.YELLOW:
// decide whether to stop or go
if (this.shouldGo())
return INCREASE_SPEED;
else return STOP;
case TrafficSignal.GREEN: // no change
return this.currentAction;
default: throw new IllegalArgumentException
("Invalid traffic color");}} // required
public void drive() {
TrafficSignal aSignal = ... ;
int reaction = this.react(aSignal);
/ The action this automobile is currently performing, idle by default /
private int currentAction = IDLE;
/ The current speed of the automobile, initially 5 mph. /
private int currentSpeed = 5;
private int react(TrafficSignal signal) {
switch(signal.getColor()) {
case TrafficSignal.RED: return STOP;
case TrafficSignal.YELLOW:
// decide whether to stop or go
if (this.shouldGo())
return INCREASE_SPEED;
else return STOP;
case TrafficSignal.GREEN: // no change
return this.currentAction;
default: throw new IllegalArgumentException
("Invalid traffic color");}} // required
public void drive() {
TrafficSignal aSignal = ... ;
int reaction = this.react(aSignal);
/ The action this automobile is currently performing, idle by default /
private int currentAction = IDLE;
/ The current speed of the automobile, initially 5 mph. /
private int currentSpeed = 5;
private int react(TrafficSignal signal) {
switch(signal.getColor()) {
case TrafficSignal.RED: return STOP;
case TrafficSignal.YELLOW:
// decide whether to stop or go
if (this.shouldGo())
return INCREASE_SPEED;
else return STOP;
case TrafficSignal.GREEN: // no change
return this.currentAction;
default: throw new IllegalArgumentException
("Invalid traffic color");}} // required
public void drive() {
TrafficSignal aSignal = ... ;
int reaction = this.react(aSignal);
/ The action this automobile is currently performing, idle by default /
private int currentAction = IDLE;
/ The current speed of the automobile, initially 5 mph. /
private int currentSpeed = 5;
private int react(TrafficSignal signal) {
switch(signal.getColor()) {
case TrafficSignal.RED: return STOP;
case TrafficSignal.YELLOW:
// decide whether to stop or go
if (this.shouldGo())
return INCREASE_SPEED;
else return STOP;
case TrafficSignal.GREEN: // no change
return this.currentAction;
default: throw new IllegalArgumentException
("Invalid traffic color");}} // required
public void drive() {
TrafficSignal aSignal = ... ;
int reaction = this.react(aSignal);
/ The action this automobile is currently performing, idle by default /
private int currentAction = IDLE;
/ The current speed of the automobile, initially 5 mph. /
private int currentSpeed = 5;
private int react(TrafficSignal signal) {
switch(signal.getColor()) {
case TrafficSignal.RED: return STOP;
case TrafficSignal.YELLOW:
// decide whether to stop or go
if (this.shouldGo())
return INCREASE_SPEED;
else return STOP;
case TrafficSignal.GREEN: // no change
return this.currentAction;
default: throw new IllegalArgumentException
("Invalid traffic color");}} // required
public void drive() {
TrafficSignal aSignal = ... ;
int reaction = this.react(aSignal);
/ The action this automobile is currently performing, idle by default /
private int currentAction = IDLE;
/ The current speed of the automobile, initially 5 mph. /
private int currentSpeed = 5;
private int react(TrafficSignal signal) {
switch(signal.getColor()) {
case TrafficSignal.RED: return STOP;
case TrafficSignal.YELLOW:
// decide whether to stop or go
if (this.shouldGo())
return INCREASE_SPEED;
else return STOP;
case TrafficSignal.GREEN: // no change
return this.currentAction;
default: throw new IllegalArgumentException
("Invalid traffic color");}} // required
public void drive() {
TrafficSignal aSignal = ... ;
int reaction = this.react(aSignal);
/* The action this automobile is currently performing, idle by default */
private Action currentAction = Action.IDLE;
/* The current speed of the automobile, initially 5 mph. */
private int currentSpeed = 5;
private Action react(TrafficSignal signal) {
switch(signal.getColor()) {
case TrafficSignal.RED: return Action.STOP;
case TrafficSignal.YELLOW:
// decide whether to stop or go
if (this.shouldGo())
return Action.INCREASE_SPEED;
else return Action.STOP;
case TrafficSignal.GREEN: // no change
return this.currentAction;
default: throw new IllegalArgumentException
("Invalid traffic color");}} // required
public void drive() {
TrafficSignal aSignal = ... ;
Action reaction = this.react(aSignal);
/* The action this automobile is currently performing, idle by default */
private Action currentAction = Action.IDLE;
/* The current speed of the automobile, initially 5 mph. */
private int currentSpeed = 5;
private Action react(TrafficSignal signal) {
switch(signal.getColor()) {
case TrafficSignal.RED: return Action.STOP;
case TrafficSignal.YELLOW:
// decide whether to stop or go
if (this.shouldGo())
return Action.INCREASE_SPEED;
else return Action.STOP;
case TrafficSignal.GREEN: // no change
return this.currentAction;
default: throw new IllegalArgumentException
("Invalid traffic color");}} // required
public void drive() {
TrafficSignal aSignal = ... ;
Action reaction = this.react(aSignal);
/* The action this automobile is currently performing, idle by default */
private Action currentAction = Action.IDLE;
/* The current speed of the automobile, initially 5 mph. */
private int currentSpeed = 5;
private Action react(TrafficSignal signal) {
switch(signal.getColor()) {
case TrafficSignal.RED: return Action.STOP;
case TrafficSignal.YELLOW:
// decide whether to stop or go
if (this.shouldGo())
return Action.INCREASE_SPEED;
else return Action.STOP;
case TrafficSignal.GREEN: // no change
return this.currentAction;
default: throw new IllegalArgumentException
("Invalid traffic color");}} // required
public void drive() {
TrafficSignal aSignal = ... ;
Action reaction = this.react(aSignal);
Traffic Signal Client
private int color = RED;
/ Accessor for the light’s current color /
public int getColor() {return this.color;}}
class Automobile {
private static final int IDLE = 0;
private static final int INCREASE_SPEED = 1;
private static final int DECREASE_SPEED = 2;
private static final int STOP = 3;
private static final int MAX_SPEED = 140;
/ The action this automobile is currently performing, idle by default /
private int currentAction = IDLE;
/ The current speed of the automobile, initially 5 mph. /
private int currentSpeed = 5;
private int react(TrafficSignal signal) {
switch(signal.getColor()) {
case TrafficSignal.RED: return STOP;
case TrafficSignal.YELLOW:
// decide whether to stop or go
if (this.shouldGo())
this.currentAction &&
INCREASE_SPEED ||
tSpeed <= MAX_SPEED))
rmAction(reaction);}
rmAction(int action) {...}}
eger constants for enumerated types.
38 (reacti
39 this.c
40 this.
41
42 private void
(b) Im
Figure 1. Running example: a hypothetical drive-by-w
ch machinery. Third, the weak enum
ogrammer to manually enumerate the
ts, which increases the likelihood of
different enum constants may be unin-
he same internal value. Finally, the
rittle [?]: since the values are com-
at compile time they are inlined into
new constants are added in between
example, in which
by language enum
and Automobile.
ations of these ne
through compile-tim
between the named
ated values. It is als
is an Action, whic
/* The action this automobile is currently performing, idle by default */
private Action currentAction = Action.IDLE;
/* The current speed of the automobile, initially 5 mph. */
private int currentSpeed = 5;
private Action react(TrafficSignal signal) {
switch(signal.getColor()) {
case TrafficSignal.RED: return Action.STOP;
case TrafficSignal.YELLOW:
// decide whether to stop or go
if (this.shouldGo())
return Action.INCREASE_SPEED;
else return Action.STOP;
case TrafficSignal.GREEN: // no change
return this.currentAction;
default: throw new IllegalArgumentException
("Invalid traffic color");}} // required
public void drive() {
TrafficSignal aSignal = ... ;
Action reaction = this.react(aSignal);
/ The action this automobile is currently performing, idle by default /
private int currentAction = IDLE;
/ The current speed of the automobile, initially 5 mph. /
private int currentSpeed = 5;
private int react(TrafficSignal signal) {
switch(signal.getColor()) {
case TrafficSignal.RED: return STOP;
case TrafficSignal.YELLOW:
// decide whether to stop or go
if (this.shouldGo())
return INCREASE_SPEED;
else return STOP;
case TrafficSignal.GREEN: // no change
return this.currentAction;
default: throw new IllegalArgumentException
("Invalid traffic color");}} // required
public void drive() {
TrafficSignal aSignal = ... ;
int reaction = this.react(aSignal);
/ The action this automobile is currently performing, idle by default /
private int currentAction = IDLE;
/ The current speed of the automobile, initially 5 mph. /
private int currentSpeed = 5;
private int react(TrafficSignal signal) {
switch(signal.getColor()) {
case TrafficSignal.RED: return STOP;
case TrafficSignal.YELLOW:
// decide whether to stop or go
if (this.shouldGo())
return INCREASE_SPEED;
else return STOP;
case TrafficSignal.GREEN: // no change
return this.currentAction;
default: throw new IllegalArgumentException
("Invalid traffic color");}} // required
public void drive() {
TrafficSignal aSignal = ... ;
int reaction = this.react(aSignal);
/ The action this automobile is currently performing, idle by default /
private int currentAction = IDLE;
/ The current speed of the automobile, initially 5 mph. /
private int currentSpeed = 5;
private int react(TrafficSignal signal) {
switch(signal.getColor()) {
case TrafficSignal.RED: return STOP;
case TrafficSignal.YELLOW:
// decide whether to stop or go
if (this.shouldGo())
return INCREASE_SPEED;
else return STOP;
case TrafficSignal.GREEN: // no change
return this.currentAction;
default: throw new IllegalArgumentException
("Invalid traffic color");}} // required
public void drive() {
TrafficSignal aSignal = ... ;
int reaction = this.react(aSignal);
/ The action this automobile is currently performing, idle by default /
private int currentAction = IDLE;
/ The current speed of the automobile, initially 5 mph. /
private int currentSpeed = 5;
private int react(TrafficSignal signal) {
switch(signal.getColor()) {
case TrafficSignal.RED: return STOP;
case TrafficSignal.YELLOW:
// decide whether to stop or go
if (this.shouldGo())
return INCREASE_SPEED;
else return STOP;
case TrafficSignal.GREEN: // no change
return this.currentAction;
default: throw new IllegalArgumentException
("Invalid traffic color");}} // required
public void drive() {
TrafficSignal aSignal = ... ;
int reaction = this.react(aSignal);
/ The action this automobile is currently performing, idle by default /
private int currentAction = IDLE;
/ The current speed of the automobile, initially 5 mph. /
private int currentSpeed = 5;
private int react(TrafficSignal signal) {
switch(signal.getColor()) {
case TrafficSignal.RED: return STOP;
case TrafficSignal.YELLOW:
// decide whether to stop or go
if (this.shouldGo())
return INCREASE_SPEED;
else return STOP;
case TrafficSignal.GREEN: // no change
return this.currentAction;
default: throw new IllegalArgumentException
("Invalid traffic color");}} // required
public void drive() {
TrafficSignal aSignal = ... ;
int reaction = this.react(aSignal);
/* The action this automobile is currently performing, idle by default */
private Action currentAction = Action.IDLE;
/* The current speed of the automobile, initially 5 mph. */
private int currentSpeed = 5;
private Action react(TrafficSignal signal) {
switch(signal.getColor()) {
case TrafficSignal.RED: return Action.STOP;
case TrafficSignal.YELLOW:
// decide whether to stop or go
if (this.shouldGo())
return Action.INCREASE_SPEED;
else return Action.STOP;
case TrafficSignal.GREEN: // no change
return this.currentAction;
default: throw new IllegalArgumentException
("Invalid traffic color");}} // required
public void drive() {
TrafficSignal aSignal = ... ;
Action reaction = this.react(aSignal);
/* The action this automobile is currently performing, idle by default */
private Action currentAction = Action.IDLE;
/* The current speed of the automobile, initially 5 mph. */
private int currentSpeed = 5;
private Action react(TrafficSignal signal) {
switch(signal.getColor()) {
case TrafficSignal.RED: return Action.STOP;
case TrafficSignal.YELLOW:
// decide whether to stop or go
if (this.shouldGo())
return Action.INCREASE_SPEED;
else return Action.STOP;
case TrafficSignal.GREEN: // no change
return this.currentAction;
default: throw new IllegalArgumentException
("Invalid traffic color");}} // required
public void drive() {
TrafficSignal aSignal = ... ;
Action reaction = this.react(aSignal);
/* The action this automobile is currently performing, idle by default */
private Action currentAction = Action.IDLE;
/* The current speed of the automobile, initially 5 mph. */
private int currentSpeed = 5;
private Action react(TrafficSignal signal) {
switch(signal.getColor()) {
case TrafficSignal.RED: return Action.STOP;
case TrafficSignal.YELLOW:
// decide whether to stop or go
if (this.shouldGo())
return Action.INCREASE_SPEED;
else return Action.STOP;
case TrafficSignal.GREEN: // no change
return this.currentAction;
default: throw new IllegalArgumentException
("Invalid traffic color");}} // required
public void drive() {
TrafficSignal aSignal = ... ;
Action reaction = this.react(aSignal);
Traffic Signal Client
private int color = RED;
/ Accessor for the light’s current color /
public int getColor() {return this.color;}}
class Automobile {
private static final int IDLE = 0;
private static final int INCREASE_SPEED = 1;
private static final int DECREASE_SPEED = 2;
private static final int STOP = 3;
private static final int MAX_SPEED = 140;
/ The action this automobile is currently performing, idle by default /
private int currentAction = IDLE;
/ The current speed of the automobile, initially 5 mph. /
private int currentSpeed = 5;
private int react(TrafficSignal signal) {
switch(signal.getColor()) {
case TrafficSignal.RED: return STOP;
case TrafficSignal.YELLOW:
// decide whether to stop or go
if (this.shouldGo())
this.currentAction &&
INCREASE_SPEED ||
tSpeed <= MAX_SPEED))
rmAction(reaction);}
rmAction(int action) {...}}
eger constants for enumerated types.
38 (reacti
39 this.c
40 this.
41
42 private void
(b) Im
Figure 1. Running example: a hypothetical drive-by-w
ch machinery. Third, the weak enum
ogrammer to manually enumerate the
ts, which increases the likelihood of
different enum constants may be unin-
he same internal value. Finally, the
rittle [?]: since the values are com-
at compile time they are inlined into
new constants are added in between
example, in which
by language enum
and Automobile.
ations of these ne
through compile-tim
between the named
ated values. It is als
is an Action, whic
/* The action this automobile is currently performing, idle by default */
private Action currentAction = Action.IDLE;
/* The current speed of the automobile, initially 5 mph. */
private int currentSpeed = 5;
private Action react(TrafficSignal signal) {
switch(signal.getColor()) {
case TrafficSignal.RED: return Action.STOP;
case TrafficSignal.YELLOW:
// decide whether to stop or go
if (this.shouldGo())
return Action.INCREASE_SPEED;
else return Action.STOP;
case TrafficSignal.GREEN: // no change
return this.currentAction;
default: throw new IllegalArgumentException
("Invalid traffic color");}} // required
public void drive() {
TrafficSignal aSignal = ... ;
Action reaction = this.react(aSignal);
/ The action this automobile is currently performing, idle by default /
private int currentAction = IDLE;
/ The current speed of the automobile, initially 5 mph. /
private int currentSpeed = 5;
private int react(TrafficSignal signal) {
switch(signal.getColor()) {
case TrafficSignal.RED: return STOP;
case TrafficSignal.YELLOW:
// decide whether to stop or go
if (this.shouldGo())
return INCREASE_SPEED;
else return STOP;
case TrafficSignal.GREEN: // no change
return this.currentAction;
default: throw new IllegalArgumentException
("Invalid traffic color");}} // required
public void drive() {
TrafficSignal aSignal = ... ;
int reaction = this.react(aSignal);
/ The action this automobile is currently performing, idle by default /
private int currentAction = IDLE;
/ The current speed of the automobile, initially 5 mph. /
private int currentSpeed = 5;
private int react(TrafficSignal signal) {
switch(signal.getColor()) {
case TrafficSignal.RED: return STOP;
case TrafficSignal.YELLOW:
// decide whether to stop or go
if (this.shouldGo())
return INCREASE_SPEED;
else return STOP;
case TrafficSignal.GREEN: // no change
return this.currentAction;
default: throw new IllegalArgumentException
("Invalid traffic color");}} // required
public void drive() {
TrafficSignal aSignal = ... ;
int reaction = this.react(aSignal);
/ The action this automobile is currently performing, idle by default /
private int currentAction = IDLE;
/ The current speed of the automobile, initially 5 mph. /
private int currentSpeed = 5;
private int react(TrafficSignal signal) {
switch(signal.getColor()) {
case TrafficSignal.RED: return STOP;
case TrafficSignal.YELLOW:
// decide whether to stop or go
if (this.shouldGo())
return INCREASE_SPEED;
else return STOP;
case TrafficSignal.GREEN: // no change
return this.currentAction;
default: throw new IllegalArgumentException
("Invalid traffic color");}} // required
public void drive() {
TrafficSignal aSignal = ... ;
int reaction = this.react(aSignal);
/ The action this automobile is currently performing, idle by default /
private int currentAction = IDLE;
/ The current speed of the automobile, initially 5 mph. /
private int currentSpeed = 5;
private int react(TrafficSignal signal) {
switch(signal.getColor()) {
case TrafficSignal.RED: return STOP;
case TrafficSignal.YELLOW:
// decide whether to stop or go
if (this.shouldGo())
return INCREASE_SPEED;
else return STOP;
case TrafficSignal.GREEN: // no change
return this.currentAction;
default: throw new IllegalArgumentException
("Invalid traffic color");}} // required
public void drive() {
TrafficSignal aSignal = ... ;
int reaction = this.react(aSignal);
/* The action this automobile is currently performing, idle by default */
private Action currentAction = Action.IDLE;
/* The current speed of the automobile, initially 5 mph. */
private int currentSpeed = 5;
private Action react(TrafficSignal signal) {
switch(signal.getColor()) {
case TrafficSignal.RED: return Action.STOP;
case TrafficSignal.YELLOW:
// decide whether to stop or go
if (this.shouldGo())
return Action.INCREASE_SPEED;
else return Action.STOP;
case TrafficSignal.GREEN: // no change
return this.currentAction;
default: throw new IllegalArgumentException
("Invalid traffic color");}} // required
public void drive() {
TrafficSignal aSignal = ... ;
Action reaction = this.react(aSignal);
/* The action this automobile is currently performing, idle by default */
private Action currentAction = Action.IDLE;
/* The current speed of the automobile, initially 5 mph. */
private int currentSpeed = 5;
private Action react(TrafficSignal signal) {
switch(signal.getColor()) {
case TrafficSignal.RED: return Action.STOP;
case TrafficSignal.YELLOW:
// decide whether to stop or go
if (this.shouldGo())
return Action.INCREASE_SPEED;
else return Action.STOP;
case TrafficSignal.GREEN: // no change
return this.currentAction;
default: throw new IllegalArgumentException
("Invalid traffic color");}} // required
public void drive() {
TrafficSignal aSignal = ... ;
Action reaction = this.react(aSignal);
/* The action this automobile is currently performing, idle by default */
private Action currentAction = Action.IDLE;
/* The current speed of the automobile, initially 5 mph. */
private int currentSpeed = 5;
private Action react(TrafficSignal signal) {
switch(signal.getColor()) {
case TrafficSignal.RED: return Action.STOP;
case TrafficSignal.YELLOW:
// decide whether to stop or go
if (this.shouldGo())
return Action.INCREASE_SPEED;
else return Action.STOP;
case TrafficSignal.GREEN: // no change
return this.currentAction;
default: throw new IllegalArgumentException
("Invalid traffic color");}} // required
public void drive() {
TrafficSignal aSignal = ... ;
Action reaction = this.react(aSignal);
function Enumerizable(C)
1: W ← C /* seed the worklist with the input constants */
2: N ← ∅ /* the non-enumerizable set list, initially empty */
3: for all c ∈ C do
4: MakeSet(c) /* init the union-find data structure */
5: end for
6: while W ̸= ∅ do
7: /* remove an element from the worklist */
8: α ← e | e ∈ W
9: W ← W  {α}
10: for all αctxt ∈ Contexts(α, P) do
11: if ¬isEnumerizableContext(α, αctxt ) then
α variable, eld, method
αctxt context in which α may occur
Figure 2. Formalism notation.
procedure Enumerize(F, P)
1: R ← Enumerizable(F)
2: R ← Unique(R) ∩ Distinct(R) ∩ Consistent(R)
3: for all T ∈ R do
4: Transform(T)
5: end for
Figure 3. Top-level enumerization algorithm.
refactoring. We also assume that we are able to statica
identify all references to candidate elds and transitively d
pendent program entities. This assumption could be inva
dated through the use of reection and custom class loade
Enumerization Approach
function Enumerizable(C)
1: W ← C /* seed the worklist with the input constants */
2: N ← ∅ /* the non-enumerizable set list, initially empty */
3: for all c ∈ C do
4: MakeSet(c) /* init the union-find data structure */
5: end for
6: while W ̸= ∅ do
7: /* remove an element from the worklist */
8: α ← e | e ∈ W
9: W ← W  {α}
10: for all αctxt ∈ Contexts(α, P) do
11: if ¬isEnumerizableContext(α, αctxt ) then
α variable, eld, method
αctxt context in which α may occur
Figure 2. Formalism notation.
procedure Enumerize(F, P)
1: R ← Enumerizable(F)
2: R ← Unique(R) ∩ Distinct(R) ∩ Consistent(R)
3: for all T ∈ R do
4: Transform(T)
5: end for
Figure 3. Top-level enumerization algorithm.
refactoring. We also assume that we are able to statica
identify all references to candidate elds and transitively d
pendent program entities. This assumption could be inva
dated through the use of reection and custom class loade
Subset of static
final fields
Enumerization Approach
function Enumerizable(C)
1: W ← C /* seed the worklist with the input constants */
2: N ← ∅ /* the non-enumerizable set list, initially empty */
3: for all c ∈ C do
4: MakeSet(c) /* init the union-find data structure */
5: end for
6: while W ̸= ∅ do
7: /* remove an element from the worklist */
8: α ← e | e ∈ W
9: W ← W  {α}
10: for all αctxt ∈ Contexts(α, P) do
11: if ¬isEnumerizableContext(α, αctxt ) then
α variable, eld, method
αctxt context in which α may occur
Figure 2. Formalism notation.
procedure Enumerize(F, P)
1: R ← Enumerizable(F)
2: R ← Unique(R) ∩ Distinct(R) ∩ Consistent(R)
3: for all T ∈ R do
4: Transform(T)
5: end for
Figure 3. Top-level enumerization algorithm.
refactoring. We also assume that we are able to statica
identify all references to candidate elds and transitively d
pendent program entities. This assumption could be inva
dated through the use of reection and custom class loade
Abstract Syntax Tree (AST)
Enumerization Approach
function Enumerizable(C)
1: W ← C /* seed the worklist with the input constants */
2: N ← ∅ /* the non-enumerizable set list, initially empty */
3: for all c ∈ C do
4: MakeSet(c) /* init the union-find data structure */
5: end for
6: while W ̸= ∅ do
7: /* remove an element from the worklist */
8: α ← e | e ∈ W
9: W ← W  {α}
10: for all αctxt ∈ Contexts(α, P) do
11: if ¬isEnumerizableContext(α, αctxt ) then
Output:
α variable, eld, method
αctxt context in which α may occur
Figure 2. Formalism notation.
procedure Enumerize(F, P)
1: R ← Enumerizable(F)
2: R ← Unique(R) ∩ Distinct(R) ∩ Consistent(R)
3: for all T ∈ R do
4: Transform(T)
5: end for
Figure 3. Top-level enumerization algorithm.
refactoring. We also assume that we are able to statica
identify all references to candidate elds and transitively d
pendent program entities. This assumption could be inva
dated through the use of reection and custom class loade
Enumerization Approach
• Partitioning of program entities:
• Fields
• Method declarations (return types)
• Local variables (including formal parameters)
function Enumerizable(C)
1: W ← C /* seed the worklist with the input constants */
2: N ← ∅ /* the non-enumerizable set list, initially empty */
3: for all c ∈ C do
4: MakeSet(c) /* init the union-find data structure */
5: end for
6: while W ̸= ∅ do
7: /* remove an element from the worklist */
8: α ← e | e ∈ W
9: W ← W  {α}
10: for all αctxt ∈ Contexts(α, P) do
11: if ¬isEnumerizableContext(α, αctxt ) then
Output:
α variable, eld, method
αctxt context in which α may occur
Figure 2. Formalism notation.
procedure Enumerize(F, P)
1: R ← Enumerizable(F)
2: R ← Unique(R) ∩ Distinct(R) ∩ Consistent(R)
3: for all T ∈ R do
4: Transform(T)
5: end for
Figure 3. Top-level enumerization algorithm.
refactoring. We also assume that we are able to statica
identify all references to candidate elds and transitively d
pendent program entities. This assumption could be inva
dated through the use of reection and custom class loade
Enumerization Approach
Automated Refactoring of Legacy Java Software to Enumerated Types
Automated Refactoring of Legacy Java Software to Enumerated Types
Automated Refactoring of Legacy Java Software to Enumerated Types
Automated Refactoring of Legacy Java Software to Enumerated Types
Automated Refactoring of Legacy Java Software to Enumerated Types
Automated Refactoring of Legacy Java Software to Enumerated Types
Automated Refactoring of Legacy Java Software to Enumerated Types
Automated Refactoring of Legacy Java Software to Enumerated Types
Automated Refactoring of Legacy Java Software to Enumerated Types
Automated Refactoring of Legacy Java Software to Enumerated Types
Automated Refactoring of Legacy Java Software to Enumerated Types
Automated Refactoring of Legacy Java Software to Enumerated Types
Automated Refactoring of Legacy Java Software to Enumerated Types
Automated Refactoring of Legacy Java Software to Enumerated Types
Automated Refactoring of Legacy Java Software to Enumerated Types
Automated Refactoring of Legacy Java Software to Enumerated Types
Automated Refactoring of Legacy Java Software to Enumerated Types
Automated Refactoring of Legacy Java Software to Enumerated Types
Automated Refactoring of Legacy Java Software to Enumerated Types
Automated Refactoring of Legacy Java Software to Enumerated Types
Automated Refactoring of Legacy Java Software to Enumerated Types
Automated Refactoring of Legacy Java Software to Enumerated Types
Automated Refactoring of Legacy Java Software to Enumerated Types
Automated Refactoring of Legacy Java Software to Enumerated Types
Automated Refactoring of Legacy Java Software to Enumerated Types
Automated Refactoring of Legacy Java Software to Enumerated Types
Automated Refactoring of Legacy Java Software to Enumerated Types
Automated Refactoring of Legacy Java Software to Enumerated Types
Automated Refactoring of Legacy Java Software to Enumerated Types
Automated Refactoring of Legacy Java Software to Enumerated Types
Automated Refactoring of Legacy Java Software to Enumerated Types
Automated Refactoring of Legacy Java Software to Enumerated Types
Automated Refactoring of Legacy Java Software to Enumerated Types
Automated Refactoring of Legacy Java Software to Enumerated Types
Automated Refactoring of Legacy Java Software to Enumerated Types
Automated Refactoring of Legacy Java Software to Enumerated Types
Automated Refactoring of Legacy Java Software to Enumerated Types
Automated Refactoring of Legacy Java Software to Enumerated Types
Automated Refactoring of Legacy Java Software to Enumerated Types
Automated Refactoring of Legacy Java Software to Enumerated Types
Automated Refactoring of Legacy Java Software to Enumerated Types
Automated Refactoring of Legacy Java Software to Enumerated Types
Automated Refactoring of Legacy Java Software to Enumerated Types
Automated Refactoring of Legacy Java Software to Enumerated Types
Automated Refactoring of Legacy Java Software to Enumerated Types
Automated Refactoring of Legacy Java Software to Enumerated Types
Automated Refactoring of Legacy Java Software to Enumerated Types
Automated Refactoring of Legacy Java Software to Enumerated Types
Automated Refactoring of Legacy Java Software to Enumerated Types
Automated Refactoring of Legacy Java Software to Enumerated Types
Automated Refactoring of Legacy Java Software to Enumerated Types
Automated Refactoring of Legacy Java Software to Enumerated Types
Automated Refactoring of Legacy Java Software to Enumerated Types
Automated Refactoring of Legacy Java Software to Enumerated Types
Automated Refactoring of Legacy Java Software to Enumerated Types
Automated Refactoring of Legacy Java Software to Enumerated Types
Automated Refactoring of Legacy Java Software to Enumerated Types
Automated Refactoring of Legacy Java Software to Enumerated Types
Automated Refactoring of Legacy Java Software to Enumerated Types
Automated Refactoring of Legacy Java Software to Enumerated Types
Automated Refactoring of Legacy Java Software to Enumerated Types
Automated Refactoring of Legacy Java Software to Enumerated Types
Automated Refactoring of Legacy Java Software to Enumerated Types
Automated Refactoring of Legacy Java Software to Enumerated Types

More Related Content

More from Raffi Khatchadourian

Towards Safe Automated Refactoring of Imperative Deep Learning Programs to Gr...
Towards Safe Automated Refactoring of Imperative Deep Learning Programs to Gr...Towards Safe Automated Refactoring of Imperative Deep Learning Programs to Gr...
Towards Safe Automated Refactoring of Imperative Deep Learning Programs to Gr...Raffi Khatchadourian
 
Automated Evolution of Feature Logging Statement Levels Using Git Histories a...
Automated Evolution of Feature Logging Statement Levels Using Git Histories a...Automated Evolution of Feature Logging Statement Levels Using Git Histories a...
Automated Evolution of Feature Logging Statement Levels Using Git Histories a...Raffi Khatchadourian
 
A Tool for Rejuvenating Feature Logging Levels via Git Histories and Degree o...
A Tool for Rejuvenating Feature Logging Levels via Git Histories and Degree o...A Tool for Rejuvenating Feature Logging Levels via Git Histories and Degree o...
A Tool for Rejuvenating Feature Logging Levels via Git Histories and Degree o...Raffi Khatchadourian
 
Challenges in Migrating Imperative Deep Learning Programs to Graph Execution:...
Challenges in Migrating Imperative Deep Learning Programs to Graph Execution:...Challenges in Migrating Imperative Deep Learning Programs to Graph Execution:...
Challenges in Migrating Imperative Deep Learning Programs to Graph Execution:...Raffi Khatchadourian
 
Actor Concurrency Bugs: A Comprehensive Study on Symptoms, Root Causes, API U...
Actor Concurrency Bugs: A Comprehensive Study on Symptoms, Root Causes, API U...Actor Concurrency Bugs: A Comprehensive Study on Symptoms, Root Causes, API U...
Actor Concurrency Bugs: A Comprehensive Study on Symptoms, Root Causes, API U...Raffi Khatchadourian
 
An Empirical Study of Refactorings and Technical Debt in Machine Learning Sys...
An Empirical Study of Refactorings and Technical Debt in Machine Learning Sys...An Empirical Study of Refactorings and Technical Debt in Machine Learning Sys...
An Empirical Study of Refactorings and Technical Debt in Machine Learning Sys...Raffi Khatchadourian
 
Automated Evolution of Feature Logging Statement Levels Using Git Histories a...
Automated Evolution of Feature Logging Statement Levels Using Git Histories a...Automated Evolution of Feature Logging Statement Levels Using Git Histories a...
Automated Evolution of Feature Logging Statement Levels Using Git Histories a...Raffi Khatchadourian
 
An Empirical Study on the Use and Misuse of Java 8 Streams
An Empirical Study on the Use and Misuse of Java 8 StreamsAn Empirical Study on the Use and Misuse of Java 8 Streams
An Empirical Study on the Use and Misuse of Java 8 StreamsRaffi Khatchadourian
 
Safe Automated Refactoring for Intelligent Parallelization of Java 8 Streams
Safe Automated Refactoring for Intelligent Parallelization of Java 8 StreamsSafe Automated Refactoring for Intelligent Parallelization of Java 8 Streams
Safe Automated Refactoring for Intelligent Parallelization of Java 8 StreamsRaffi Khatchadourian
 
Safe Automated Refactoring for Intelligent Parallelization of Java 8 Streams
Safe Automated Refactoring for Intelligent Parallelization of Java 8 StreamsSafe Automated Refactoring for Intelligent Parallelization of Java 8 Streams
Safe Automated Refactoring for Intelligent Parallelization of Java 8 StreamsRaffi Khatchadourian
 
A Brief Introduction to Type Constraints
A Brief Introduction to Type ConstraintsA Brief Introduction to Type Constraints
A Brief Introduction to Type ConstraintsRaffi Khatchadourian
 
Safe Automated Refactoring for Intelligent Parallelization of Java 8 Streams ...
Safe Automated Refactoring for Intelligent Parallelization of Java 8 Streams ...Safe Automated Refactoring for Intelligent Parallelization of Java 8 Streams ...
Safe Automated Refactoring for Intelligent Parallelization of Java 8 Streams ...Raffi Khatchadourian
 
A Tool for Optimizing Java 8 Stream Software via Automated Refactoring
A Tool for Optimizing Java 8 Stream Software via Automated RefactoringA Tool for Optimizing Java 8 Stream Software via Automated Refactoring
A Tool for Optimizing Java 8 Stream Software via Automated RefactoringRaffi Khatchadourian
 
Porting the NetBeans Java 8 Enhanced For Loop Lambda Expression Refactoring t...
Porting the NetBeans Java 8 Enhanced For Loop Lambda Expression Refactoring t...Porting the NetBeans Java 8 Enhanced For Loop Lambda Expression Refactoring t...
Porting the NetBeans Java 8 Enhanced For Loop Lambda Expression Refactoring t...Raffi Khatchadourian
 
Towards Safe Refactoring for Intelligent Parallelization of Java 8 Streams
Towards Safe Refactoring for Intelligent Parallelization of Java 8 StreamsTowards Safe Refactoring for Intelligent Parallelization of Java 8 Streams
Towards Safe Refactoring for Intelligent Parallelization of Java 8 StreamsRaffi Khatchadourian
 
Proactive Empirical Assessment of New Language Feature Adoption via Automated...
Proactive Empirical Assessment of New Language Feature Adoption via Automated...Proactive Empirical Assessment of New Language Feature Adoption via Automated...
Proactive Empirical Assessment of New Language Feature Adoption via Automated...Raffi Khatchadourian
 
Defaultification Refactoring: A Tool for Automatically Converting Java Method...
Defaultification Refactoring: A Tool for Automatically Converting Java Method...Defaultification Refactoring: A Tool for Automatically Converting Java Method...
Defaultification Refactoring: A Tool for Automatically Converting Java Method...Raffi Khatchadourian
 
Defaultification Refactoring: A Tool for Automatically Converting Java Method...
Defaultification Refactoring: A Tool for Automatically Converting Java Method...Defaultification Refactoring: A Tool for Automatically Converting Java Method...
Defaultification Refactoring: A Tool for Automatically Converting Java Method...Raffi Khatchadourian
 
Automated Refactoring of Legacy Java Software to Default Methods Talk at ICSE...
Automated Refactoring of Legacy Java Software to Default Methods Talk at ICSE...Automated Refactoring of Legacy Java Software to Default Methods Talk at ICSE...
Automated Refactoring of Legacy Java Software to Default Methods Talk at ICSE...Raffi Khatchadourian
 
Poster on Automated Refactoring of Legacy Java Software to Default Methods
Poster on Automated Refactoring of Legacy Java Software to Default MethodsPoster on Automated Refactoring of Legacy Java Software to Default Methods
Poster on Automated Refactoring of Legacy Java Software to Default MethodsRaffi Khatchadourian
 

More from Raffi Khatchadourian (20)

Towards Safe Automated Refactoring of Imperative Deep Learning Programs to Gr...
Towards Safe Automated Refactoring of Imperative Deep Learning Programs to Gr...Towards Safe Automated Refactoring of Imperative Deep Learning Programs to Gr...
Towards Safe Automated Refactoring of Imperative Deep Learning Programs to Gr...
 
Automated Evolution of Feature Logging Statement Levels Using Git Histories a...
Automated Evolution of Feature Logging Statement Levels Using Git Histories a...Automated Evolution of Feature Logging Statement Levels Using Git Histories a...
Automated Evolution of Feature Logging Statement Levels Using Git Histories a...
 
A Tool for Rejuvenating Feature Logging Levels via Git Histories and Degree o...
A Tool for Rejuvenating Feature Logging Levels via Git Histories and Degree o...A Tool for Rejuvenating Feature Logging Levels via Git Histories and Degree o...
A Tool for Rejuvenating Feature Logging Levels via Git Histories and Degree o...
 
Challenges in Migrating Imperative Deep Learning Programs to Graph Execution:...
Challenges in Migrating Imperative Deep Learning Programs to Graph Execution:...Challenges in Migrating Imperative Deep Learning Programs to Graph Execution:...
Challenges in Migrating Imperative Deep Learning Programs to Graph Execution:...
 
Actor Concurrency Bugs: A Comprehensive Study on Symptoms, Root Causes, API U...
Actor Concurrency Bugs: A Comprehensive Study on Symptoms, Root Causes, API U...Actor Concurrency Bugs: A Comprehensive Study on Symptoms, Root Causes, API U...
Actor Concurrency Bugs: A Comprehensive Study on Symptoms, Root Causes, API U...
 
An Empirical Study of Refactorings and Technical Debt in Machine Learning Sys...
An Empirical Study of Refactorings and Technical Debt in Machine Learning Sys...An Empirical Study of Refactorings and Technical Debt in Machine Learning Sys...
An Empirical Study of Refactorings and Technical Debt in Machine Learning Sys...
 
Automated Evolution of Feature Logging Statement Levels Using Git Histories a...
Automated Evolution of Feature Logging Statement Levels Using Git Histories a...Automated Evolution of Feature Logging Statement Levels Using Git Histories a...
Automated Evolution of Feature Logging Statement Levels Using Git Histories a...
 
An Empirical Study on the Use and Misuse of Java 8 Streams
An Empirical Study on the Use and Misuse of Java 8 StreamsAn Empirical Study on the Use and Misuse of Java 8 Streams
An Empirical Study on the Use and Misuse of Java 8 Streams
 
Safe Automated Refactoring for Intelligent Parallelization of Java 8 Streams
Safe Automated Refactoring for Intelligent Parallelization of Java 8 StreamsSafe Automated Refactoring for Intelligent Parallelization of Java 8 Streams
Safe Automated Refactoring for Intelligent Parallelization of Java 8 Streams
 
Safe Automated Refactoring for Intelligent Parallelization of Java 8 Streams
Safe Automated Refactoring for Intelligent Parallelization of Java 8 StreamsSafe Automated Refactoring for Intelligent Parallelization of Java 8 Streams
Safe Automated Refactoring for Intelligent Parallelization of Java 8 Streams
 
A Brief Introduction to Type Constraints
A Brief Introduction to Type ConstraintsA Brief Introduction to Type Constraints
A Brief Introduction to Type Constraints
 
Safe Automated Refactoring for Intelligent Parallelization of Java 8 Streams ...
Safe Automated Refactoring for Intelligent Parallelization of Java 8 Streams ...Safe Automated Refactoring for Intelligent Parallelization of Java 8 Streams ...
Safe Automated Refactoring for Intelligent Parallelization of Java 8 Streams ...
 
A Tool for Optimizing Java 8 Stream Software via Automated Refactoring
A Tool for Optimizing Java 8 Stream Software via Automated RefactoringA Tool for Optimizing Java 8 Stream Software via Automated Refactoring
A Tool for Optimizing Java 8 Stream Software via Automated Refactoring
 
Porting the NetBeans Java 8 Enhanced For Loop Lambda Expression Refactoring t...
Porting the NetBeans Java 8 Enhanced For Loop Lambda Expression Refactoring t...Porting the NetBeans Java 8 Enhanced For Loop Lambda Expression Refactoring t...
Porting the NetBeans Java 8 Enhanced For Loop Lambda Expression Refactoring t...
 
Towards Safe Refactoring for Intelligent Parallelization of Java 8 Streams
Towards Safe Refactoring for Intelligent Parallelization of Java 8 StreamsTowards Safe Refactoring for Intelligent Parallelization of Java 8 Streams
Towards Safe Refactoring for Intelligent Parallelization of Java 8 Streams
 
Proactive Empirical Assessment of New Language Feature Adoption via Automated...
Proactive Empirical Assessment of New Language Feature Adoption via Automated...Proactive Empirical Assessment of New Language Feature Adoption via Automated...
Proactive Empirical Assessment of New Language Feature Adoption via Automated...
 
Defaultification Refactoring: A Tool for Automatically Converting Java Method...
Defaultification Refactoring: A Tool for Automatically Converting Java Method...Defaultification Refactoring: A Tool for Automatically Converting Java Method...
Defaultification Refactoring: A Tool for Automatically Converting Java Method...
 
Defaultification Refactoring: A Tool for Automatically Converting Java Method...
Defaultification Refactoring: A Tool for Automatically Converting Java Method...Defaultification Refactoring: A Tool for Automatically Converting Java Method...
Defaultification Refactoring: A Tool for Automatically Converting Java Method...
 
Automated Refactoring of Legacy Java Software to Default Methods Talk at ICSE...
Automated Refactoring of Legacy Java Software to Default Methods Talk at ICSE...Automated Refactoring of Legacy Java Software to Default Methods Talk at ICSE...
Automated Refactoring of Legacy Java Software to Default Methods Talk at ICSE...
 
Poster on Automated Refactoring of Legacy Java Software to Default Methods
Poster on Automated Refactoring of Legacy Java Software to Default MethodsPoster on Automated Refactoring of Legacy Java Software to Default Methods
Poster on Automated Refactoring of Legacy Java Software to Default Methods
 

Recently uploaded

Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVshikhaohhpro
 
why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfjoe51371421
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...kellynguyen01
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsAndolasoft Inc
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfkalichargn70th171
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsAlberto González Trastoy
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantAxelRicardoTrocheRiq
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdfWave PLM
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...MyIntelliSource, Inc.
 
What is Binary Language? Computer Number Systems
What is Binary Language?  Computer Number SystemsWhat is Binary Language?  Computer Number Systems
What is Binary Language? Computer Number SystemsJheuzeDellosa
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AIABDERRAOUF MEHENNI
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...gurkirankumar98700
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxbodapatigopi8531
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsArshad QA
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...soniya singh
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️anilsa9823
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...MyIntelliSource, Inc.
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionSolGuruz
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...harshavardhanraghave
 

Recently uploaded (20)

Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
Exploring iOS App Development: Simplifying the Process
Exploring iOS App Development: Simplifying the ProcessExploring iOS App Development: Simplifying the Process
Exploring iOS App Development: Simplifying the Process
 
why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdf
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.js
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service Consultant
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
 
What is Binary Language? Computer Number Systems
What is Binary Language?  Computer Number SystemsWhat is Binary Language?  Computer Number Systems
What is Binary Language? Computer Number Systems
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptx
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with Precision
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 

Automated Refactoring of Legacy Java Software to Enumerated Types

  • 1. Automated Refactoring of Legacy Java Software to Enumerated Types* Raffi Khatchadourian, Jason Sawin, and Atanas Rountev PRESTO: Program Analyses and Software Tools Research Group, Ohio State University * Work supported in part by NSF
  • 3. Introduction •Java 1.5 introduced a rich set of new features such as generics, metadata annotations, boxing/unboxing, and type-safe enumerations.
  • 4. Introduction •Java 1.5 introduced a rich set of new features such as generics, metadata annotations, boxing/unboxing, and •Highlight an automated semantics-preserving approach for migrating legacy Java code to take advantage of the new language enumerated type constructs.
  • 5. Introduction •Java 1.5 introduced a rich set of new features such as generics, metadata annotations, boxing/unboxing, and •Highlight an automated semantics-preserving approach for migrating legacy Java code to take advantage of the new language enumerated type constructs. •Present experimental results from research prototype as an Eclipse IDE plug-in.
  • 6. Introduction •Java 1.5 introduced a rich set of new features such as generics, metadata annotations, boxing/unboxing, and •Highlight an automated semantics-preserving approach for migrating legacy Java code to take advantage of the new language enumerated type constructs. •Present experimental results from research prototype as an Eclipse IDE plug-in. •In progress to be included with the standard distribution of Eclipse.
  • 7. Motivating Example class TrafficSignal { public static final int RED = 0; public static final int YELLOW = 1; public static final int GREEN = 2; / Current color of the traffic signal, initially red by default / private int color = RED; / Accessor for the light’s current color / public int getColor() {return this.color;}} class Automobile { private static final int IDLE = 0; private static final int INCREASE_SPEED = 1; private static final int DECREASE_SPEED = 2; private static final int STOP = 3;
  • 8. Motivating Example Weak Enum Pattern class TrafficSignal { public static final int RED = 0; public static final int YELLOW = 1; public static final int GREEN = 2; / Current color of the traffic signal, initially red by default / private int color = RED; / Accessor for the light’s current color / public int getColor() {return this.color;}} class Automobile { private static final int IDLE = 0; private static final int INCREASE_SPEED = 1; private static final int DECREASE_SPEED = 2; private static final int STOP = 3;
  • 9. Motivating Example Type Safety class TrafficSignal { public static final int RED = 0; public static final int YELLOW = 1; public static final int GREEN = 2; / Current color of the traffic signal, initially red by default / private int color = RED; / Accessor for the light’s current color / public int getColor() {return this.color;}} class Automobile { private static final int IDLE = 0; private static final int INCREASE_SPEED = 1; private static final int DECREASE_SPEED = 2; private static final int STOP = 3;
  • 10. Motivating Example class TrafficSignal { public static final int RED = 0; public static final int YELLOW = 1; public static final int GREEN = 2; / Current color of the traffic signal, initially red by default / private int color = RED; / Accessor for the light’s current color / public int getColor() {return this.color;}} class Automobile { private static final int IDLE = 0; private static final int INCREASE_SPEED = 1; private static final int DECREASE_SPEED = 2; private static final int STOP = 3; Manual Enumeration
  • 11. Motivating Example class TrafficSignal { public static final int RED = 0; public static final int YELLOW = 1; public static final int GREEN = 2; / Current color of the traffic signal, initially red by default / private int color = RED; / Accessor for the light’s current color / public int getColor() {return this.color;}} class Automobile { private static final int IDLE = 0; private static final int INCREASE_SPEED = 1; private static final int DECREASE_SPEED = 2; private static final int STOP = 3; Namespacing
  • 12. Motivating Example class TrafficSignal { public static final int RED = 0; public static final int YELLOW = 1; public static final int GREEN = 2; / Current color of the traffic signal, initially red by default / private int color = RED; / Accessor for the light’s current color / public int getColor() {return this.color;}} class Automobile { private static final int IDLE = 0; private static final int INCREASE_SPEED = 1; private static final int DECREASE_SPEED = 2; private static final int STOP = 3; Brittle
  • 13. Motivating Example class TrafficSignal { public static final int RED = 0; public static final int YELLOW = 1; public static final int GREEN = 2; / Current color of the traffic signal, initially red by default / private int color = RED; / Accessor for the light’s current color / public int getColor() {return this.color;}} class Automobile { private static final int IDLE = 0; private static final int INCREASE_SPEED = 1; private static final int DECREASE_SPEED = 2; private static final int STOP = 3;
  • 14. Motivating Example Revisited class TrafficSignal { public static final int RED = 0; public static final int YELLOW = 1; public static final int GREEN = 2; / Current color of the traffic signal, initially red by default / private int color = RED; / Accessor for the light’s current color / public int getColor() {return this.color;}} class Automobile { private static final int IDLE = 0; private static final int INCREASE_SPEED = 1; private static final int DECREASE_SPEED = 2; private static final int STOP = 3; class TrafficSignal { public static final int RED = 0; public static final int YELLOW = 1; public static final int GREEN = 2; / Current color of the traffic signal, initially red by default / private int color = RED; / Accessor for the light’s current color / public int getColor() {return this.color;}} class Automobile { private static final int IDLE = 0; private static final int INCREASE_SPEED = 1; private static final int DECREASE_SPEED = 2; private static final int STOP = 3; class TrafficSignal { public static final int RED = 0; public static final int YELLOW = 1; public static final int GREEN = 2; / Current color of the traffic signal, initially red by default / private int color = RED; / Accessor for the light’s current color / public int getColor() {return this.color;}} class Automobile { private static final int IDLE = 0; private static final int INCREASE_SPEED = 1; private static final int DECREASE_SPEED = 2; private static final int STOP = 3; class TrafficSignal { public static final int RED = 0; public static final int YELLOW = 1; public static final int GREEN = 2; / Current color of the traffic signal, initially red by default / private int color = RED; / Accessor for the light’s current color / public int getColor() {return this.color;}} class Automobile { private static final int IDLE = 0; private static final int INCREASE_SPEED = 1; private static final int DECREASE_SPEED = 2; private static final int STOP = 3; class TrafficSignal { public static final int RED = 0; public static final int YELLOW = 1; public static final int GREEN = 2; / Current color of the traffic signal, initially red by default / private int color = RED; / Accessor for the light’s current color / public int getColor() {return this.color;}} class Automobile { private static final int IDLE = 0; private static final int INCREASE_SPEED = 1; private static final int DECREASE_SPEED = 2; private static final int STOP = 3; class TrafficSignal { public static final int RED = 0; public static final int YELLOW = 1; public static final int GREEN = 2; / Current color of the traffic signal, initially red by default / private int color = RED; / Accessor for the light’s current color / public int getColor() {return this.color;}} class Automobile { private static final int IDLE = 0; private static final int INCREASE_SPEED = 1; private static final int DECREASE_SPEED = 2; private static final int STOP = 3;
  • 15. Motivating Example Revisited class TrafficSignal { public static final int RED = 0; public static final int YELLOW = 1; public static final int GREEN = 2; / Current color of the traffic signal, initially red by default / private int color = RED; / Accessor for the light’s current color / public int getColor() {return this.color;}} class Automobile { private static final int IDLE = 0; private static final int INCREASE_SPEED = 1; private static final int DECREASE_SPEED = 2; private static final int STOP = 3; class TrafficSignal { public static final int RED = 0; public static final int YELLOW = 1; public static final int GREEN = 2; / Current color of the traffic signal, initially red by default / private int color = RED; / Accessor for the light’s current color / public int getColor() {return this.color;}} class Automobile { private static final int IDLE = 0; private static final int INCREASE_SPEED = 1; private static final int DECREASE_SPEED = 2; private static final int STOP = 3; class TrafficSignal { public enum Color {RED, YELLOW, GREEN}; /* Current color of the traffic signal, initially red by default */ private Color color = Color.RED; /* Accessor for the light’s current color */ public Color getColor() {return this.color;}} class Automobile { private enum Action {IDLE, INCREASE_SPEED, DECREASE_SPEED, STOP}; private static final int MAX_SPEED = 140; class TrafficSignal { public static final int RED = 0; public static final int YELLOW = 1; public static final int GREEN = 2; / Current color of the traffic signal, initially red by default / private int color = RED; / Accessor for the light’s current color / public int getColor() {return this.color;}} class Automobile { private static final int IDLE = 0; private static final int INCREASE_SPEED = 1; private static final int DECREASE_SPEED = 2; private static final int STOP = 3; class TrafficSignal { public static final int RED = 0; public static final int YELLOW = 1; public static final int GREEN = 2; / Current color of the traffic signal, initially red by default / private int color = RED; / Accessor for the light’s current color / public int getColor() {return this.color;}} class Automobile { private static final int IDLE = 0; private static final int INCREASE_SPEED = 1; private static final int DECREASE_SPEED = 2; private static final int STOP = 3; class TrafficSignal { public static final int RED = 0; public static final int YELLOW = 1; public static final int GREEN = 2; / Current color of the traffic signal, initially red by default / private int color = RED; / Accessor for the light’s current color / public int getColor() {return this.color;}} class Automobile { private static final int IDLE = 0; private static final int INCREASE_SPEED = 1; private static final int DECREASE_SPEED = 2; private static final int STOP = 3;
  • 16. Motivating Example Revisited class TrafficSignal { public static final int RED = 0; public static final int YELLOW = 1; public static final int GREEN = 2; / Current color of the traffic signal, initially red by default / private int color = RED; / Accessor for the light’s current color / public int getColor() {return this.color;}} class Automobile { private static final int IDLE = 0; private static final int INCREASE_SPEED = 1; private static final int DECREASE_SPEED = 2; private static final int STOP = 3; class TrafficSignal { public enum Color {RED, YELLOW, GREEN}; /* Current color of the traffic signal, initially red by default */ private Color color = Color.RED; /* Accessor for the light’s current color */ public Color getColor() {return this.color;}} class Automobile { private enum Action {IDLE, INCREASE_SPEED, DECREASE_SPEED, STOP}; private static final int MAX_SPEED = 140; class TrafficSignal { public static final int RED = 0; public static final int YELLOW = 1; public static final int GREEN = 2; / Current color of the traffic signal, initially red by default / private int color = RED; / Accessor for the light’s current color / public int getColor() {return this.color;}} class Automobile { private static final int IDLE = 0; private static final int INCREASE_SPEED = 1; private static final int DECREASE_SPEED = 2; private static final int STOP = 3; class TrafficSignal { public static final int RED = 0; public static final int YELLOW = 1; public static final int GREEN = 2; / Current color of the traffic signal, initially red by default / private int color = RED; / Accessor for the light’s current color / public int getColor() {return this.color;}} class Automobile { private static final int IDLE = 0; private static final int INCREASE_SPEED = 1; private static final int DECREASE_SPEED = 2; private static final int STOP = 3; class TrafficSignal { public static final int RED = 0; public static final int YELLOW = 1; public static final int GREEN = 2; / Current color of the traffic signal, initially red by default / private int color = RED; / Accessor for the light’s current color / public int getColor() {return this.color;}} class Automobile { private static final int IDLE = 0; private static final int INCREASE_SPEED = 1; private static final int DECREASE_SPEED = 2; private static final int STOP = 3; class TrafficSignal { public enum Color {RED, YELLOW, GREEN}; /* Current color of the traffic signal, initially red by default */ private Color color = Color.RED; /* Accessor for the light’s current color */ public Color getColor() {return this.color;}} class Automobile { private enum Action {IDLE, INCREASE_SPEED, DECREASE_SPEED, STOP};
  • 17. Motivating Example Revisited class TrafficSignal { public static final int RED = 0; public static final int YELLOW = 1; public static final int GREEN = 2; / Current color of the traffic signal, initially red by default / private int color = RED; / Accessor for the light’s current color / public int getColor() {return this.color;}} class Automobile { private static final int IDLE = 0; private static final int INCREASE_SPEED = 1; private static final int DECREASE_SPEED = 2; private static final int STOP = 3; class TrafficSignal { public enum Color {RED, YELLOW, GREEN}; /* Current color of the traffic signal, initially red by default */ private Color color = Color.RED; /* Accessor for the light’s current color */ public Color getColor() {return this.color;}} class Automobile { private enum Action {IDLE, INCREASE_SPEED, DECREASE_SPEED, STOP}; private static final int MAX_SPEED = 140; class TrafficSignal { public static final int RED = 0; public static final int YELLOW = 1; public static final int GREEN = 2; / Current color of the traffic signal, initially red by default / private int color = RED; / Accessor for the light’s current color / public int getColor() {return this.color;}} class Automobile { private static final int IDLE = 0; private static final int INCREASE_SPEED = 1; private static final int DECREASE_SPEED = 2; private static final int STOP = 3; class TrafficSignal { public static final int RED = 0; public static final int YELLOW = 1; public static final int GREEN = 2; / Current color of the traffic signal, initially red by default / private int color = RED; / Accessor for the light’s current color / public int getColor() {return this.color;}} class Automobile { private static final int IDLE = 0; private static final int INCREASE_SPEED = 1; private static final int DECREASE_SPEED = 2; private static final int STOP = 3; class TrafficSignal { public enum Color {RED, YELLOW, GREEN}; /* Current color of the traffic signal, initially red by default */ private Color color = Color.RED; /* Accessor for the light’s current color */ public Color getColor() {return this.color;}} class Automobile { private enum Action {IDLE, INCREASE_SPEED, DECREASE_SPEED, STOP}; class TrafficSignal { public enum Color {RED, YELLOW, GREEN}; /* Current color of the traffic signal, initially red by default */ private Color color = Color.RED; /* Accessor for the light’s current color */ public Color getColor() {return this.color;}} class Automobile { private enum Action {IDLE, INCREASE_SPEED, DECREASE_SPEED, STOP};
  • 18. Motivating Example Revisited class TrafficSignal { public static final int RED = 0; public static final int YELLOW = 1; public static final int GREEN = 2; / Current color of the traffic signal, initially red by default / private int color = RED; / Accessor for the light’s current color / public int getColor() {return this.color;}} class Automobile { private static final int IDLE = 0; private static final int INCREASE_SPEED = 1; private static final int DECREASE_SPEED = 2; private static final int STOP = 3; class TrafficSignal { public enum Color {RED, YELLOW, GREEN}; /* Current color of the traffic signal, initially red by default */ private Color color = Color.RED; /* Accessor for the light’s current color */ public Color getColor() {return this.color;}} class Automobile { private enum Action {IDLE, INCREASE_SPEED, DECREASE_SPEED, STOP}; private static final int MAX_SPEED = 140; class TrafficSignal { public enum Color {RED, YELLOW, GREEN}; /* Current color of the traffic signal, initially red by default */ private Color color = Color.RED; /* Accessor for the light’s current color */ public Color getColor() {return this.color;}} class Automobile { private enum Action {IDLE, INCREASE_SPEED, DECREASE_SPEED, STOP}; class TrafficSignal { public enum Color {RED, YELLOW, GREEN}; /* Current color of the traffic signal, initially red by default */ private Color color = Color.RED; /* Accessor for the light’s current color */ public Color getColor() {return this.color;}} class Automobile { private enum Action {IDLE, INCREASE_SPEED, DECREASE_SPEED, STOP}; class TrafficSignal { public static final int RED = 0; public static final int YELLOW = 1; public static final int GREEN = 2; / Current color of the traffic signal, initially red by default / private int color = RED; / Accessor for the light’s current color / public int getColor() {return this.color;}} class Automobile { private static final int IDLE = 0; private static final int INCREASE_SPEED = 1; private static final int DECREASE_SPEED = 2; private static final int STOP = 3; class TrafficSignal { public static final int RED = 0; public static final int YELLOW = 1; public static final int GREEN = 2; / Current color of the traffic signal, initially red by default / private int color = RED; / Accessor for the light’s current color / public int getColor() {return this.color;}} class Automobile { private static final int IDLE = 0; private static final int INCREASE_SPEED = 1; private static final int DECREASE_SPEED = 2; private static final int STOP = 3;
  • 19. Motivating Example Revisited class TrafficSignal { public static final int RED = 0; public static final int YELLOW = 1; public static final int GREEN = 2; / Current color of the traffic signal, initially red by default / private int color = RED; / Accessor for the light’s current color / public int getColor() {return this.color;}} class Automobile { private static final int IDLE = 0; private static final int INCREASE_SPEED = 1; private static final int DECREASE_SPEED = 2; private static final int STOP = 3; class TrafficSignal { public enum Color {RED, YELLOW, GREEN}; /* Current color of the traffic signal, initially red by default */ private Color color = Color.RED; /* Accessor for the light’s current color */ public Color getColor() {return this.color;}} class Automobile { private enum Action {IDLE, INCREASE_SPEED, DECREASE_SPEED, STOP}; private static final int MAX_SPEED = 140; class TrafficSignal { public enum Color {RED, YELLOW, GREEN}; /* Current color of the traffic signal, initially red by default */ private Color color = Color.RED; /* Accessor for the light’s current color */ public Color getColor() {return this.color;}} class Automobile { private enum Action {IDLE, INCREASE_SPEED, DECREASE_SPEED, STOP}; class TrafficSignal { public enum Color {RED, YELLOW, GREEN}; /* Current color of the traffic signal, initially red by default */ private Color color = Color.RED; /* Accessor for the light’s current color */ public Color getColor() {return this.color;}} class Automobile { private enum Action {IDLE, INCREASE_SPEED, DECREASE_SPEED, STOP}; class TrafficSignal { public static final int RED = 0; public static final int YELLOW = 1; public static final int GREEN = 2; / Current color of the traffic signal, initially red by default / private int color = RED; / Accessor for the light’s current color / public int getColor() {return this.color;}} class Automobile { private static final int IDLE = 0; private static final int INCREASE_SPEED = 1; private static final int DECREASE_SPEED = 2; private static final int STOP = 3; class TrafficSignal { public static final int RED = 0; public static final int YELLOW = 1; public static final int GREEN = 2; / Current color of the traffic signal, initially red by default / private int color = RED; / Accessor for the light’s current color / public int getColor() {return this.color;}} class Automobile { private static final int IDLE = 0; private static final int INCREASE_SPEED = 1; private static final int DECREASE_SPEED = 2; private static final int STOP = 3; Language Enum
  • 20. Motivating Example Revisited class TrafficSignal { public static final int RED = 0; public static final int YELLOW = 1; public static final int GREEN = 2; / Current color of the traffic signal, initially red by default / private int color = RED; / Accessor for the light’s current color / public int getColor() {return this.color;}} class Automobile { private static final int IDLE = 0; private static final int INCREASE_SPEED = 1; private static final int DECREASE_SPEED = 2; private static final int STOP = 3; class TrafficSignal { public enum Color {RED, YELLOW, GREEN}; /* Current color of the traffic signal, initially red by default */ private Color color = Color.RED; /* Accessor for the light’s current color */ public Color getColor() {return this.color;}} class Automobile { private enum Action {IDLE, INCREASE_SPEED, DECREASE_SPEED, STOP}; private static final int MAX_SPEED = 140; class TrafficSignal { public enum Color {RED, YELLOW, GREEN}; /* Current color of the traffic signal, initially red by default */ private Color color = Color.RED; /* Accessor for the light’s current color */ public Color getColor() {return this.color;}} class Automobile { private enum Action {IDLE, INCREASE_SPEED, DECREASE_SPEED, STOP}; class TrafficSignal { public enum Color {RED, YELLOW, GREEN}; /* Current color of the traffic signal, initially red by default */ private Color color = Color.RED; /* Accessor for the light’s current color */ public Color getColor() {return this.color;}} class Automobile { private enum Action {IDLE, INCREASE_SPEED, DECREASE_SPEED, STOP}; class TrafficSignal { public static final int RED = 0; public static final int YELLOW = 1; public static final int GREEN = 2; / Current color of the traffic signal, initially red by default / private int color = RED; / Accessor for the light’s current color / public int getColor() {return this.color;}} class Automobile { private static final int IDLE = 0; private static final int INCREASE_SPEED = 1; private static final int DECREASE_SPEED = 2; private static final int STOP = 3; class TrafficSignal { public static final int RED = 0; public static final int YELLOW = 1; public static final int GREEN = 2; / Current color of the traffic signal, initially red by default / private int color = RED; / Accessor for the light’s current color / public int getColor() {return this.color;}} class Automobile { private static final int IDLE = 0; private static final int INCREASE_SPEED = 1; private static final int DECREASE_SPEED = 2; private static final int STOP = 3; Type Safety
  • 21. Motivating Example Revisited class TrafficSignal { public static final int RED = 0; public static final int YELLOW = 1; public static final int GREEN = 2; / Current color of the traffic signal, initially red by default / private int color = RED; / Accessor for the light’s current color / public int getColor() {return this.color;}} class Automobile { private static final int IDLE = 0; private static final int INCREASE_SPEED = 1; private static final int DECREASE_SPEED = 2; private static final int STOP = 3; class TrafficSignal { public enum Color {RED, YELLOW, GREEN}; /* Current color of the traffic signal, initially red by default */ private Color color = Color.RED; /* Accessor for the light’s current color */ public Color getColor() {return this.color;}} class Automobile { private enum Action {IDLE, INCREASE_SPEED, DECREASE_SPEED, STOP}; private static final int MAX_SPEED = 140; class TrafficSignal { public enum Color {RED, YELLOW, GREEN}; /* Current color of the traffic signal, initially red by default */ private Color color = Color.RED; /* Accessor for the light’s current color */ public Color getColor() {return this.color;}} class Automobile { private enum Action {IDLE, INCREASE_SPEED, DECREASE_SPEED, STOP}; class TrafficSignal { public enum Color {RED, YELLOW, GREEN}; /* Current color of the traffic signal, initially red by default */ private Color color = Color.RED; /* Accessor for the light’s current color */ public Color getColor() {return this.color;}} class Automobile { private enum Action {IDLE, INCREASE_SPEED, DECREASE_SPEED, STOP}; class TrafficSignal { public static final int RED = 0; public static final int YELLOW = 1; public static final int GREEN = 2; / Current color of the traffic signal, initially red by default / private int color = RED; / Accessor for the light’s current color / public int getColor() {return this.color;}} class Automobile { private static final int IDLE = 0; private static final int INCREASE_SPEED = 1; private static final int DECREASE_SPEED = 2; private static final int STOP = 3; class TrafficSignal { public static final int RED = 0; public static final int YELLOW = 1; public static final int GREEN = 2; / Current color of the traffic signal, initially red by default / private int color = RED; / Accessor for the light’s current color / public int getColor() {return this.color;}} class Automobile { private static final int IDLE = 0; private static final int INCREASE_SPEED = 1; private static final int DECREASE_SPEED = 2; private static final int STOP = 3; Singletons in Natural Order
  • 22. Motivating Example Revisited class TrafficSignal { public static final int RED = 0; public static final int YELLOW = 1; public static final int GREEN = 2; / Current color of the traffic signal, initially red by default / private int color = RED; / Accessor for the light’s current color / public int getColor() {return this.color;}} class Automobile { private static final int IDLE = 0; private static final int INCREASE_SPEED = 1; private static final int DECREASE_SPEED = 2; private static final int STOP = 3; class TrafficSignal { public enum Color {RED, YELLOW, GREEN}; /* Current color of the traffic signal, initially red by default */ private Color color = Color.RED; /* Accessor for the light’s current color */ public Color getColor() {return this.color;}} class Automobile { private enum Action {IDLE, INCREASE_SPEED, DECREASE_SPEED, STOP}; private static final int MAX_SPEED = 140; class TrafficSignal { public enum Color {RED, YELLOW, GREEN}; /* Current color of the traffic signal, initially red by default */ private Color color = Color.RED; /* Accessor for the light’s current color */ public Color getColor() {return this.color;}} class Automobile { private enum Action {IDLE, INCREASE_SPEED, DECREASE_SPEED, STOP}; class TrafficSignal { public enum Color {RED, YELLOW, GREEN}; /* Current color of the traffic signal, initially red by default */ private Color color = Color.RED; /* Accessor for the light’s current color */ public Color getColor() {return this.color;}} class Automobile { private enum Action {IDLE, INCREASE_SPEED, DECREASE_SPEED, STOP}; class TrafficSignal { public static final int RED = 0; public static final int YELLOW = 1; public static final int GREEN = 2; / Current color of the traffic signal, initially red by default / private int color = RED; / Accessor for the light’s current color / public int getColor() {return this.color;}} class Automobile { private static final int IDLE = 0; private static final int INCREASE_SPEED = 1; private static final int DECREASE_SPEED = 2; private static final int STOP = 3; class TrafficSignal { public static final int RED = 0; public static final int YELLOW = 1; public static final int GREEN = 2; / Current color of the traffic signal, initially red by default / private int color = RED; / Accessor for the light’s current color / public int getColor() {return this.color;}} class Automobile { private static final int IDLE = 0; private static final int INCREASE_SPEED = 1; private static final int DECREASE_SPEED = 2; private static final int STOP = 3; Prefixed
  • 23. Motivating Example Revisited class TrafficSignal { public static final int RED = 0; public static final int YELLOW = 1; public static final int GREEN = 2; / Current color of the traffic signal, initially red by default / private int color = RED; / Accessor for the light’s current color / public int getColor() {return this.color;}} class Automobile { private static final int IDLE = 0; private static final int INCREASE_SPEED = 1; private static final int DECREASE_SPEED = 2; private static final int STOP = 3; class TrafficSignal { public enum Color {RED, YELLOW, GREEN}; /* Current color of the traffic signal, initially red by default */ private Color color = Color.RED; /* Accessor for the light’s current color */ public Color getColor() {return this.color;}} class Automobile { private enum Action {IDLE, INCREASE_SPEED, DECREASE_SPEED, STOP}; private static final int MAX_SPEED = 140; class TrafficSignal { public enum Color {RED, YELLOW, GREEN}; /* Current color of the traffic signal, initially red by default */ private Color color = Color.RED; /* Accessor for the light’s current color */ public Color getColor() {return this.color;}} class Automobile { private enum Action {IDLE, INCREASE_SPEED, DECREASE_SPEED, STOP}; class TrafficSignal { public enum Color {RED, YELLOW, GREEN}; /* Current color of the traffic signal, initially red by default */ private Color color = Color.RED; /* Accessor for the light’s current color */ public Color getColor() {return this.color;}} class Automobile { private enum Action {IDLE, INCREASE_SPEED, DECREASE_SPEED, STOP}; class TrafficSignal { public static final int RED = 0; public static final int YELLOW = 1; public static final int GREEN = 2; / Current color of the traffic signal, initially red by default / private int color = RED; / Accessor for the light’s current color / public int getColor() {return this.color;}} class Automobile { private static final int IDLE = 0; private static final int INCREASE_SPEED = 1; private static final int DECREASE_SPEED = 2; private static final int STOP = 3; class TrafficSignal { public static final int RED = 0; public static final int YELLOW = 1; public static final int GREEN = 2; / Current color of the traffic signal, initially red by default / private int color = RED; / Accessor for the light’s current color / public int getColor() {return this.color;}} class Automobile { private static final int IDLE = 0; private static final int INCREASE_SPEED = 1; private static final int DECREASE_SPEED = 2; private static final int STOP = 3; Supports Separate Compilation
  • 24. Motivating Example Revisited class TrafficSignal { public static final int RED = 0; public static final int YELLOW = 1; public static final int GREEN = 2; / Current color of the traffic signal, initially red by default / private int color = RED; / Accessor for the light’s current color / public int getColor() {return this.color;}} class Automobile { private static final int IDLE = 0; private static final int INCREASE_SPEED = 1; private static final int DECREASE_SPEED = 2; private static final int STOP = 3; class TrafficSignal { public enum Color {RED, YELLOW, GREEN}; /* Current color of the traffic signal, initially red by default */ private Color color = Color.RED; /* Accessor for the light’s current color */ public Color getColor() {return this.color;}} class Automobile { private enum Action {IDLE, INCREASE_SPEED, DECREASE_SPEED, STOP}; private static final int MAX_SPEED = 140; class TrafficSignal { public enum Color {RED, YELLOW, GREEN}; /* Current color of the traffic signal, initially red by default */ private Color color = Color.RED; /* Accessor for the light’s current color */ public Color getColor() {return this.color;}} class Automobile { private enum Action {IDLE, INCREASE_SPEED, DECREASE_SPEED, STOP}; class TrafficSignal { public enum Color {RED, YELLOW, GREEN}; /* Current color of the traffic signal, initially red by default */ private Color color = Color.RED; /* Accessor for the light’s current color */ public Color getColor() {return this.color;}} class Automobile { private enum Action {IDLE, INCREASE_SPEED, DECREASE_SPEED, STOP}; class TrafficSignal { public static final int RED = 0; public static final int YELLOW = 1; public static final int GREEN = 2; / Current color of the traffic signal, initially red by default / private int color = RED; / Accessor for the light’s current color / public int getColor() {return this.color;}} class Automobile { private static final int IDLE = 0; private static final int INCREASE_SPEED = 1; private static final int DECREASE_SPEED = 2; private static final int STOP = 3; class TrafficSignal { public static final int RED = 0; public static final int YELLOW = 1; public static final int GREEN = 2; / Current color of the traffic signal, initially red by default / private int color = RED; / Accessor for the light’s current color / public int getColor() {return this.color;}} class Automobile { private static final int IDLE = 0; private static final int INCREASE_SPEED = 1; private static final int DECREASE_SPEED = 2; private static final int STOP = 3;
  • 25. Traffic Signal Client / The action this automobile is currently performing, idle by default / private int currentAction = IDLE; / The current speed of the automobile, initially 5 mph. / private int currentSpeed = 5; private int react(TrafficSignal signal) { switch(signal.getColor()) { case TrafficSignal.RED: return STOP; case TrafficSignal.YELLOW: // decide whether to stop or go if (this.shouldGo()) return INCREASE_SPEED; else return STOP; case TrafficSignal.GREEN: // no change return this.currentAction; default: throw new IllegalArgumentException ("Invalid traffic color");}} // required public void drive() { TrafficSignal aSignal = ... ; int reaction = this.react(aSignal); private int color = RED; / Accessor for the light’s current color / public int getColor() {return this.color;}} class Automobile { private static final int IDLE = 0; private static final int INCREASE_SPEED = 1; private static final int DECREASE_SPEED = 2; private static final int STOP = 3; private static final int MAX_SPEED = 140; / The action this automobile is currently performing, idle by default / private int currentAction = IDLE; / The current speed of the automobile, initially 5 mph. / private int currentSpeed = 5; private int react(TrafficSignal signal) { switch(signal.getColor()) { case TrafficSignal.RED: return STOP; case TrafficSignal.YELLOW: // decide whether to stop or go if (this.shouldGo()) this.currentAction && INCREASE_SPEED || tSpeed <= MAX_SPEED)) rmAction(reaction);} rmAction(int action) {...}} eger constants for enumerated types. 38 (reacti 39 this.c 40 this. 41 42 private void (b) Im Figure 1. Running example: a hypothetical drive-by-w ch machinery. Third, the weak enum ogrammer to manually enumerate the ts, which increases the likelihood of different enum constants may be unin- he same internal value. Finally, the rittle [?]: since the values are com- at compile time they are inlined into new constants are added in between example, in which by language enum and Automobile. ations of these ne through compile-tim between the named ated values. It is als is an Action, whic
  • 26. Traffic Signal Client / The action this automobile is currently performing, idle by default / private int currentAction = IDLE; / The current speed of the automobile, initially 5 mph. / private int currentSpeed = 5; private int react(TrafficSignal signal) { switch(signal.getColor()) { case TrafficSignal.RED: return STOP; case TrafficSignal.YELLOW: // decide whether to stop or go if (this.shouldGo()) return INCREASE_SPEED; else return STOP; case TrafficSignal.GREEN: // no change return this.currentAction; default: throw new IllegalArgumentException ("Invalid traffic color");}} // required public void drive() { TrafficSignal aSignal = ... ; int reaction = this.react(aSignal); private int color = RED; / Accessor for the light’s current color / public int getColor() {return this.color;}} class Automobile { private static final int IDLE = 0; private static final int INCREASE_SPEED = 1; private static final int DECREASE_SPEED = 2; private static final int STOP = 3; private static final int MAX_SPEED = 140; / The action this automobile is currently performing, idle by default / private int currentAction = IDLE; / The current speed of the automobile, initially 5 mph. / private int currentSpeed = 5; private int react(TrafficSignal signal) { switch(signal.getColor()) { case TrafficSignal.RED: return STOP; case TrafficSignal.YELLOW: // decide whether to stop or go if (this.shouldGo()) this.currentAction && INCREASE_SPEED || tSpeed <= MAX_SPEED)) rmAction(reaction);} rmAction(int action) {...}} eger constants for enumerated types. 38 (reacti 39 this.c 40 this. 41 42 private void (b) Im Figure 1. Running example: a hypothetical drive-by-w ch machinery. Third, the weak enum ogrammer to manually enumerate the ts, which increases the likelihood of different enum constants may be unin- he same internal value. Finally, the rittle [?]: since the values are com- at compile time they are inlined into new constants are added in between example, in which by language enum and Automobile. ations of these ne through compile-tim between the named ated values. It is als is an Action, whic
  • 27. Traffic Signal Client / The action this automobile is currently performing, idle by default / private int currentAction = IDLE; / The current speed of the automobile, initially 5 mph. / private int currentSpeed = 5; private int react(TrafficSignal signal) { switch(signal.getColor()) { case TrafficSignal.RED: return STOP; case TrafficSignal.YELLOW: // decide whether to stop or go if (this.shouldGo()) return INCREASE_SPEED; else return STOP; case TrafficSignal.GREEN: // no change return this.currentAction; default: throw new IllegalArgumentException ("Invalid traffic color");}} // required public void drive() { TrafficSignal aSignal = ... ; int reaction = this.react(aSignal); private int color = RED; / Accessor for the light’s current color / public int getColor() {return this.color;}} class Automobile { private static final int IDLE = 0; private static final int INCREASE_SPEED = 1; private static final int DECREASE_SPEED = 2; private static final int STOP = 3; private static final int MAX_SPEED = 140; / The action this automobile is currently performing, idle by default / private int currentAction = IDLE; / The current speed of the automobile, initially 5 mph. / private int currentSpeed = 5; private int react(TrafficSignal signal) { switch(signal.getColor()) { case TrafficSignal.RED: return STOP; case TrafficSignal.YELLOW: // decide whether to stop or go if (this.shouldGo()) this.currentAction && INCREASE_SPEED || tSpeed <= MAX_SPEED)) rmAction(reaction);} rmAction(int action) {...}} eger constants for enumerated types. 38 (reacti 39 this.c 40 this. 41 42 private void (b) Im Figure 1. Running example: a hypothetical drive-by-w ch machinery. Third, the weak enum ogrammer to manually enumerate the ts, which increases the likelihood of different enum constants may be unin- he same internal value. Finally, the rittle [?]: since the values are com- at compile time they are inlined into new constants are added in between example, in which by language enum and Automobile. ations of these ne through compile-tim between the named ated values. It is als is an Action, whic
  • 28. Traffic Signal Client / The action this automobile is currently performing, idle by default / private int currentAction = IDLE; / The current speed of the automobile, initially 5 mph. / private int currentSpeed = 5; private int react(TrafficSignal signal) { switch(signal.getColor()) { case TrafficSignal.RED: return STOP; case TrafficSignal.YELLOW: // decide whether to stop or go if (this.shouldGo()) return INCREASE_SPEED; else return STOP; case TrafficSignal.GREEN: // no change return this.currentAction; default: throw new IllegalArgumentException ("Invalid traffic color");}} // required public void drive() { TrafficSignal aSignal = ... ; int reaction = this.react(aSignal); private int color = RED; / Accessor for the light’s current color / public int getColor() {return this.color;}} class Automobile { private static final int IDLE = 0; private static final int INCREASE_SPEED = 1; private static final int DECREASE_SPEED = 2; private static final int STOP = 3; private static final int MAX_SPEED = 140; / The action this automobile is currently performing, idle by default / private int currentAction = IDLE; / The current speed of the automobile, initially 5 mph. / private int currentSpeed = 5; private int react(TrafficSignal signal) { switch(signal.getColor()) { case TrafficSignal.RED: return STOP; case TrafficSignal.YELLOW: // decide whether to stop or go if (this.shouldGo()) this.currentAction && INCREASE_SPEED || tSpeed <= MAX_SPEED)) rmAction(reaction);} rmAction(int action) {...}} eger constants for enumerated types. 38 (reacti 39 this.c 40 this. 41 42 private void (b) Im Figure 1. Running example: a hypothetical drive-by-w ch machinery. Third, the weak enum ogrammer to manually enumerate the ts, which increases the likelihood of different enum constants may be unin- he same internal value. Finally, the rittle [?]: since the values are com- at compile time they are inlined into new constants are added in between example, in which by language enum and Automobile. ations of these ne through compile-tim between the named ated values. It is als is an Action, whic
  • 29. Traffic Signal Client private int color = RED; / Accessor for the light’s current color / public int getColor() {return this.color;}} class Automobile { private static final int IDLE = 0; private static final int INCREASE_SPEED = 1; private static final int DECREASE_SPEED = 2; private static final int STOP = 3; private static final int MAX_SPEED = 140; / The action this automobile is currently performing, idle by default / private int currentAction = IDLE; / The current speed of the automobile, initially 5 mph. / private int currentSpeed = 5; private int react(TrafficSignal signal) { switch(signal.getColor()) { case TrafficSignal.RED: return STOP; case TrafficSignal.YELLOW: // decide whether to stop or go if (this.shouldGo()) this.currentAction && INCREASE_SPEED || tSpeed <= MAX_SPEED)) rmAction(reaction);} rmAction(int action) {...}} eger constants for enumerated types. 38 (reacti 39 this.c 40 this. 41 42 private void (b) Im Figure 1. Running example: a hypothetical drive-by-w ch machinery. Third, the weak enum ogrammer to manually enumerate the ts, which increases the likelihood of different enum constants may be unin- he same internal value. Finally, the rittle [?]: since the values are com- at compile time they are inlined into new constants are added in between example, in which by language enum and Automobile. ations of these ne through compile-tim between the named ated values. It is als is an Action, whic private int color = RED; / Accessor for the light’s current color / public int getColor() {return this.color;}} class Automobile { private static final int IDLE = 0; private static final int INCREASE_SPEED = 1; private static final int DECREASE_SPEED = 2; private static final int STOP = 3; private static final int MAX_SPEED = 140; / The action this automobile is currently performing, idle by default / private int currentAction = IDLE; / The current speed of the automobile, initially 5 mph. / private int currentSpeed = 5; private int react(TrafficSignal signal) { switch(signal.getColor()) { case TrafficSignal.RED: return STOP; case TrafficSignal.YELLOW: // decide whether to stop or go Automobile Action Enum
  • 30. Traffic Signal Client private int color = RED; / Accessor for the light’s current color / public int getColor() {return this.color;}} class Automobile { private static final int IDLE = 0; private static final int INCREASE_SPEED = 1; private static final int DECREASE_SPEED = 2; private static final int STOP = 3; private static final int MAX_SPEED = 140; / The action this automobile is currently performing, idle by default / private int currentAction = IDLE; / The current speed of the automobile, initially 5 mph. / private int currentSpeed = 5; private int react(TrafficSignal signal) { switch(signal.getColor()) { case TrafficSignal.RED: return STOP; case TrafficSignal.YELLOW: // decide whether to stop or go if (this.shouldGo()) this.currentAction && INCREASE_SPEED || tSpeed <= MAX_SPEED)) rmAction(reaction);} rmAction(int action) {...}} eger constants for enumerated types. 38 (reacti 39 this.c 40 this. 41 42 private void (b) Im Figure 1. Running example: a hypothetical drive-by-w ch machinery. Third, the weak enum ogrammer to manually enumerate the ts, which increases the likelihood of different enum constants may be unin- he same internal value. Finally, the rittle [?]: since the values are com- at compile time they are inlined into new constants are added in between example, in which by language enum and Automobile. ations of these ne through compile-tim between the named ated values. It is als is an Action, whic private int color = RED; / Accessor for the light’s current color / public int getColor() {return this.color;}} class Automobile { private static final int IDLE = 0; private static final int INCREASE_SPEED = 1; private static final int DECREASE_SPEED = 2; private static final int STOP = 3; private static final int MAX_SPEED = 140; / The action this automobile is currently performing, idle by default / private int currentAction = IDLE; / The current speed of the automobile, initially 5 mph. / private int currentSpeed = 5; private int react(TrafficSignal signal) { switch(signal.getColor()) { case TrafficSignal.RED: return STOP; case TrafficSignal.YELLOW: // decide whether to stop or go Named- Constant
  • 31. Traffic Signal Client private int color = RED; / Accessor for the light’s current color / public int getColor() {return this.color;}} class Automobile { private static final int IDLE = 0; private static final int INCREASE_SPEED = 1; private static final int DECREASE_SPEED = 2; private static final int STOP = 3; private static final int MAX_SPEED = 140; / The action this automobile is currently performing, idle by default / private int currentAction = IDLE; / The current speed of the automobile, initially 5 mph. / private int currentSpeed = 5; private int react(TrafficSignal signal) { switch(signal.getColor()) { case TrafficSignal.RED: return STOP; case TrafficSignal.YELLOW: // decide whether to stop or go if (this.shouldGo()) this.currentAction && INCREASE_SPEED || tSpeed <= MAX_SPEED)) rmAction(reaction);} rmAction(int action) {...}} eger constants for enumerated types. 38 (reacti 39 this.c 40 this. 41 42 private void (b) Im Figure 1. Running example: a hypothetical drive-by-w ch machinery. Third, the weak enum ogrammer to manually enumerate the ts, which increases the likelihood of different enum constants may be unin- he same internal value. Finally, the rittle [?]: since the values are com- at compile time they are inlined into new constants are added in between example, in which by language enum and Automobile. ations of these ne through compile-tim between the named ated values. It is als is an Action, whic private int color = RED; / Accessor for the light’s current color / public int getColor() {return this.color;}} class Automobile { private static final int IDLE = 0; private static final int INCREASE_SPEED = 1; private static final int DECREASE_SPEED = 2; private static final int STOP = 3; private static final int MAX_SPEED = 140; / The action this automobile is currently performing, idle by default / private int currentAction = IDLE; / The current speed of the automobile, initially 5 mph. / private int currentSpeed = 5; private int react(TrafficSignal signal) { switch(signal.getColor()) { case TrafficSignal.RED: return STOP; case TrafficSignal.YELLOW: // decide whether to stop or go Promising...
  • 32. Traffic Signal Client private int color = RED; / Accessor for the light’s current color / public int getColor() {return this.color;}} class Automobile { private static final int IDLE = 0; private static final int INCREASE_SPEED = 1; private static final int DECREASE_SPEED = 2; private static final int STOP = 3; private static final int MAX_SPEED = 140; / The action this automobile is currently performing, idle by default / private int currentAction = IDLE; / The current speed of the automobile, initially 5 mph. / private int currentSpeed = 5; private int react(TrafficSignal signal) { switch(signal.getColor()) { case TrafficSignal.RED: return STOP; case TrafficSignal.YELLOW: // decide whether to stop or go if (this.shouldGo()) this.currentAction && INCREASE_SPEED || tSpeed <= MAX_SPEED)) rmAction(reaction);} rmAction(int action) {...}} eger constants for enumerated types. 38 (reacti 39 this.c 40 this. 41 42 private void (b) Im Figure 1. Running example: a hypothetical drive-by-w ch machinery. Third, the weak enum ogrammer to manually enumerate the ts, which increases the likelihood of different enum constants may be unin- he same internal value. Finally, the rittle [?]: since the values are com- at compile time they are inlined into new constants are added in between example, in which by language enum and Automobile. ations of these ne through compile-tim between the named ated values. It is als is an Action, whic private int color = RED; / Accessor for the light’s current color / public int getColor() {return this.color;}} class Automobile { private static final int IDLE = 0; private static final int INCREASE_SPEED = 1; private static final int DECREASE_SPEED = 2; private static final int STOP = 3; private static final int MAX_SPEED = 140; / The action this automobile is currently performing, idle by default / private int currentAction = IDLE; / The current speed of the automobile, initially 5 mph. / private int currentSpeed = 5; private int react(TrafficSignal signal) { switch(signal.getColor()) { case TrafficSignal.RED: return STOP; case TrafficSignal.YELLOW: // decide whether to stop or go Definitely not enumerizable
  • 33. Traffic Signal Client / The action this automobile is currently performing, idle by default / private int currentAction = IDLE; / The current speed of the automobile, initially 5 mph. / private int currentSpeed = 5; private int react(TrafficSignal signal) { switch(signal.getColor()) { case TrafficSignal.RED: return STOP; case TrafficSignal.YELLOW: // decide whether to stop or go if (this.shouldGo()) return INCREASE_SPEED; else return STOP; case TrafficSignal.GREEN: // no change return this.currentAction; default: throw new IllegalArgumentException ("Invalid traffic color");}} // required public void drive() { TrafficSignal aSignal = ... ; int reaction = this.react(aSignal); private int color = RED; / Accessor for the light’s current color / public int getColor() {return this.color;}} class Automobile { private static final int IDLE = 0; private static final int INCREASE_SPEED = 1; private static final int DECREASE_SPEED = 2; private static final int STOP = 3; private static final int MAX_SPEED = 140; / The action this automobile is currently performing, idle by default / private int currentAction = IDLE; / The current speed of the automobile, initially 5 mph. / private int currentSpeed = 5; private int react(TrafficSignal signal) { switch(signal.getColor()) { case TrafficSignal.RED: return STOP; case TrafficSignal.YELLOW: // decide whether to stop or go if (this.shouldGo()) this.currentAction && INCREASE_SPEED || tSpeed <= MAX_SPEED)) rmAction(reaction);} rmAction(int action) {...}} eger constants for enumerated types. 38 (reacti 39 this.c 40 this. 41 42 private void (b) Im Figure 1. Running example: a hypothetical drive-by-w ch machinery. Third, the weak enum ogrammer to manually enumerate the ts, which increases the likelihood of different enum constants may be unin- he same internal value. Finally, the rittle [?]: since the values are com- at compile time they are inlined into new constants are added in between example, in which by language enum and Automobile. ations of these ne through compile-tim between the named ated values. It is als is an Action, whic
  • 34. Traffic Signal Client / The action this automobile is currently performing, idle by default / private int currentAction = IDLE; / The current speed of the automobile, initially 5 mph. / private int currentSpeed = 5; private int react(TrafficSignal signal) { switch(signal.getColor()) { case TrafficSignal.RED: return STOP; case TrafficSignal.YELLOW: // decide whether to stop or go if (this.shouldGo()) return INCREASE_SPEED; else return STOP; case TrafficSignal.GREEN: // no change return this.currentAction; default: throw new IllegalArgumentException ("Invalid traffic color");}} // required public void drive() { TrafficSignal aSignal = ... ; int reaction = this.react(aSignal); private int color = RED; / Accessor for the light’s current color / public int getColor() {return this.color;}} class Automobile { private static final int IDLE = 0; private static final int INCREASE_SPEED = 1; private static final int DECREASE_SPEED = 2; private static final int STOP = 3; private static final int MAX_SPEED = 140; / The action this automobile is currently performing, idle by default / private int currentAction = IDLE; / The current speed of the automobile, initially 5 mph. / private int currentSpeed = 5; private int react(TrafficSignal signal) { switch(signal.getColor()) { case TrafficSignal.RED: return STOP; case TrafficSignal.YELLOW: // decide whether to stop or go if (this.shouldGo()) this.currentAction && INCREASE_SPEED || tSpeed <= MAX_SPEED)) rmAction(reaction);} rmAction(int action) {...}} eger constants for enumerated types. 38 (reacti 39 this.c 40 this. 41 42 private void (b) Im Figure 1. Running example: a hypothetical drive-by-w ch machinery. Third, the weak enum ogrammer to manually enumerate the ts, which increases the likelihood of different enum constants may be unin- he same internal value. Finally, the rittle [?]: since the values are com- at compile time they are inlined into new constants are added in between example, in which by language enum and Automobile. ations of these ne through compile-tim between the named ated values. It is als is an Action, whic
  • 35. Traffic Signal Client / The action this automobile is currently performing, idle by default / private int currentAction = IDLE; / The current speed of the automobile, initially 5 mph. / private int currentSpeed = 5; private int react(TrafficSignal signal) { switch(signal.getColor()) { case TrafficSignal.RED: return STOP; case TrafficSignal.YELLOW: // decide whether to stop or go if (this.shouldGo()) return INCREASE_SPEED; else return STOP; case TrafficSignal.GREEN: // no change return this.currentAction; default: throw new IllegalArgumentException ("Invalid traffic color");}} // required public void drive() { TrafficSignal aSignal = ... ; int reaction = this.react(aSignal); private int color = RED; / Accessor for the light’s current color / public int getColor() {return this.color;}} class Automobile { private static final int IDLE = 0; private static final int INCREASE_SPEED = 1; private static final int DECREASE_SPEED = 2; private static final int STOP = 3; private static final int MAX_SPEED = 140; / The action this automobile is currently performing, idle by default / private int currentAction = IDLE; / The current speed of the automobile, initially 5 mph. / private int currentSpeed = 5; private int react(TrafficSignal signal) { switch(signal.getColor()) { case TrafficSignal.RED: return STOP; case TrafficSignal.YELLOW: // decide whether to stop or go if (this.shouldGo()) this.currentAction && INCREASE_SPEED || tSpeed <= MAX_SPEED)) rmAction(reaction);} rmAction(int action) {...}} eger constants for enumerated types. 38 (reacti 39 this.c 40 this. 41 42 private void (b) Im Figure 1. Running example: a hypothetical drive-by-w ch machinery. Third, the weak enum ogrammer to manually enumerate the ts, which increases the likelihood of different enum constants may be unin- he same internal value. Finally, the rittle [?]: since the values are com- at compile time they are inlined into new constants are added in between example, in which by language enum and Automobile. ations of these ne through compile-tim between the named ated values. It is als is an Action, whic
  • 36. / The action this automobile is currently performing, idle by default / private int currentAction = IDLE; / The current speed of the automobile, initially 5 mph. / private int currentSpeed = 5; private int react(TrafficSignal signal) { switch(signal.getColor()) { case TrafficSignal.RED: return STOP; case TrafficSignal.YELLOW: // decide whether to stop or go if (this.shouldGo()) return INCREASE_SPEED; else return STOP; case TrafficSignal.GREEN: // no change return this.currentAction; default: throw new IllegalArgumentException ("Invalid traffic color");}} // required public void drive() { TrafficSignal aSignal = ... ; int reaction = this.react(aSignal); Traffic Signal Client private int color = RED; / Accessor for the light’s current color / public int getColor() {return this.color;}} class Automobile { private static final int IDLE = 0; private static final int INCREASE_SPEED = 1; private static final int DECREASE_SPEED = 2; private static final int STOP = 3; private static final int MAX_SPEED = 140; / The action this automobile is currently performing, idle by default / private int currentAction = IDLE; / The current speed of the automobile, initially 5 mph. / private int currentSpeed = 5; private int react(TrafficSignal signal) { switch(signal.getColor()) { case TrafficSignal.RED: return STOP; case TrafficSignal.YELLOW: // decide whether to stop or go if (this.shouldGo()) this.currentAction && INCREASE_SPEED || tSpeed <= MAX_SPEED)) rmAction(reaction);} rmAction(int action) {...}} eger constants for enumerated types. 38 (reacti 39 this.c 40 this. 41 42 private void (b) Im Figure 1. Running example: a hypothetical drive-by-w ch machinery. Third, the weak enum ogrammer to manually enumerate the ts, which increases the likelihood of different enum constants may be unin- he same internal value. Finally, the rittle [?]: since the values are com- at compile time they are inlined into new constants are added in between example, in which by language enum and Automobile. ations of these ne through compile-tim between the named ated values. It is als is an Action, whic / The action this automobile is currently performing, idle by default / private int currentAction = IDLE; / The current speed of the automobile, initially 5 mph. / private int currentSpeed = 5; private int react(TrafficSignal signal) { switch(signal.getColor()) { case TrafficSignal.RED: return STOP; case TrafficSignal.YELLOW: // decide whether to stop or go if (this.shouldGo()) return INCREASE_SPEED; else return STOP; case TrafficSignal.GREEN: // no change return this.currentAction; default: throw new IllegalArgumentException ("Invalid traffic color");}} // required public void drive() { TrafficSignal aSignal = ... ; int reaction = this.react(aSignal); / The action this automobile is currently performing, idle by default / private int currentAction = IDLE; / The current speed of the automobile, initially 5 mph. / private int currentSpeed = 5; private int react(TrafficSignal signal) { switch(signal.getColor()) { case TrafficSignal.RED: return STOP; case TrafficSignal.YELLOW: // decide whether to stop or go if (this.shouldGo()) return INCREASE_SPEED; else return STOP; case TrafficSignal.GREEN: // no change return this.currentAction; default: throw new IllegalArgumentException ("Invalid traffic color");}} // required public void drive() { TrafficSignal aSignal = ... ; int reaction = this.react(aSignal); / The action this automobile is currently performing, idle by default / private int currentAction = IDLE; / The current speed of the automobile, initially 5 mph. / private int currentSpeed = 5; private int react(TrafficSignal signal) { switch(signal.getColor()) { case TrafficSignal.RED: return STOP; case TrafficSignal.YELLOW: // decide whether to stop or go if (this.shouldGo()) return INCREASE_SPEED; else return STOP; case TrafficSignal.GREEN: // no change return this.currentAction; default: throw new IllegalArgumentException ("Invalid traffic color");}} // required public void drive() { TrafficSignal aSignal = ... ; int reaction = this.react(aSignal); / The action this automobile is currently performing, idle by default / private int currentAction = IDLE; / The current speed of the automobile, initially 5 mph. / private int currentSpeed = 5; private int react(TrafficSignal signal) { switch(signal.getColor()) { case TrafficSignal.RED: return STOP; case TrafficSignal.YELLOW: // decide whether to stop or go if (this.shouldGo()) return INCREASE_SPEED; else return STOP; case TrafficSignal.GREEN: // no change return this.currentAction; default: throw new IllegalArgumentException ("Invalid traffic color");}} // required public void drive() { TrafficSignal aSignal = ... ; int reaction = this.react(aSignal); / The action this automobile is currently performing, idle by default / private int currentAction = IDLE; / The current speed of the automobile, initially 5 mph. / private int currentSpeed = 5; private int react(TrafficSignal signal) { switch(signal.getColor()) { case TrafficSignal.RED: return STOP; case TrafficSignal.YELLOW: // decide whether to stop or go if (this.shouldGo()) return INCREASE_SPEED; else return STOP; case TrafficSignal.GREEN: // no change return this.currentAction; default: throw new IllegalArgumentException ("Invalid traffic color");}} // required public void drive() { TrafficSignal aSignal = ... ; int reaction = this.react(aSignal); / The action this automobile is currently performing, idle by default / private int currentAction = IDLE; / The current speed of the automobile, initially 5 mph. / private int currentSpeed = 5; private int react(TrafficSignal signal) { switch(signal.getColor()) { case TrafficSignal.RED: return STOP; case TrafficSignal.YELLOW: // decide whether to stop or go if (this.shouldGo()) return INCREASE_SPEED; else return STOP; case TrafficSignal.GREEN: // no change return this.currentAction; default: throw new IllegalArgumentException ("Invalid traffic color");}} // required public void drive() { TrafficSignal aSignal = ... ; int reaction = this.react(aSignal); / The action this automobile is currently performing, idle by default / private int currentAction = IDLE; / The current speed of the automobile, initially 5 mph. / private int currentSpeed = 5; private int react(TrafficSignal signal) { switch(signal.getColor()) { case TrafficSignal.RED: return STOP; case TrafficSignal.YELLOW: // decide whether to stop or go if (this.shouldGo()) return INCREASE_SPEED; else return STOP; case TrafficSignal.GREEN: // no change return this.currentAction; default: throw new IllegalArgumentException ("Invalid traffic color");}} // required public void drive() { TrafficSignal aSignal = ... ; int reaction = this.react(aSignal); /* The action this automobile is currently performing, idle by default */ private Action currentAction = Action.IDLE; /* The current speed of the automobile, initially 5 mph. */ private int currentSpeed = 5; private Action react(TrafficSignal signal) { switch(signal.getColor()) { case TrafficSignal.RED: return Action.STOP; case TrafficSignal.YELLOW: // decide whether to stop or go if (this.shouldGo()) return Action.INCREASE_SPEED; else return Action.STOP; case TrafficSignal.GREEN: // no change return this.currentAction; default: throw new IllegalArgumentException ("Invalid traffic color");}} // required public void drive() { TrafficSignal aSignal = ... ; Action reaction = this.react(aSignal);
  • 37. Traffic Signal Client private int color = RED; / Accessor for the light’s current color / public int getColor() {return this.color;}} class Automobile { private static final int IDLE = 0; private static final int INCREASE_SPEED = 1; private static final int DECREASE_SPEED = 2; private static final int STOP = 3; private static final int MAX_SPEED = 140; / The action this automobile is currently performing, idle by default / private int currentAction = IDLE; / The current speed of the automobile, initially 5 mph. / private int currentSpeed = 5; private int react(TrafficSignal signal) { switch(signal.getColor()) { case TrafficSignal.RED: return STOP; case TrafficSignal.YELLOW: // decide whether to stop or go if (this.shouldGo()) this.currentAction && INCREASE_SPEED || tSpeed <= MAX_SPEED)) rmAction(reaction);} rmAction(int action) {...}} eger constants for enumerated types. 38 (reacti 39 this.c 40 this. 41 42 private void (b) Im Figure 1. Running example: a hypothetical drive-by-w ch machinery. Third, the weak enum ogrammer to manually enumerate the ts, which increases the likelihood of different enum constants may be unin- he same internal value. Finally, the rittle [?]: since the values are com- at compile time they are inlined into new constants are added in between example, in which by language enum and Automobile. ations of these ne through compile-tim between the named ated values. It is als is an Action, whic /* The action this automobile is currently performing, idle by default */ private Action currentAction = Action.IDLE; /* The current speed of the automobile, initially 5 mph. */ private int currentSpeed = 5; private Action react(TrafficSignal signal) { switch(signal.getColor()) { case TrafficSignal.RED: return Action.STOP; case TrafficSignal.YELLOW: // decide whether to stop or go if (this.shouldGo()) return Action.INCREASE_SPEED; else return Action.STOP; case TrafficSignal.GREEN: // no change return this.currentAction; default: throw new IllegalArgumentException ("Invalid traffic color");}} // required public void drive() { TrafficSignal aSignal = ... ; Action reaction = this.react(aSignal); / The action this automobile is currently performing, idle by default / private int currentAction = IDLE; / The current speed of the automobile, initially 5 mph. / private int currentSpeed = 5; private int react(TrafficSignal signal) { switch(signal.getColor()) { case TrafficSignal.RED: return STOP; case TrafficSignal.YELLOW: // decide whether to stop or go if (this.shouldGo()) return INCREASE_SPEED; else return STOP; case TrafficSignal.GREEN: // no change return this.currentAction; default: throw new IllegalArgumentException ("Invalid traffic color");}} // required public void drive() { TrafficSignal aSignal = ... ; int reaction = this.react(aSignal); / The action this automobile is currently performing, idle by default / private int currentAction = IDLE; / The current speed of the automobile, initially 5 mph. / private int currentSpeed = 5; private int react(TrafficSignal signal) { switch(signal.getColor()) { case TrafficSignal.RED: return STOP; case TrafficSignal.YELLOW: // decide whether to stop or go if (this.shouldGo()) return INCREASE_SPEED; else return STOP; case TrafficSignal.GREEN: // no change return this.currentAction; default: throw new IllegalArgumentException ("Invalid traffic color");}} // required public void drive() { TrafficSignal aSignal = ... ; int reaction = this.react(aSignal); / The action this automobile is currently performing, idle by default / private int currentAction = IDLE; / The current speed of the automobile, initially 5 mph. / private int currentSpeed = 5; private int react(TrafficSignal signal) { switch(signal.getColor()) { case TrafficSignal.RED: return STOP; case TrafficSignal.YELLOW: // decide whether to stop or go if (this.shouldGo()) return INCREASE_SPEED; else return STOP; case TrafficSignal.GREEN: // no change return this.currentAction; default: throw new IllegalArgumentException ("Invalid traffic color");}} // required public void drive() { TrafficSignal aSignal = ... ; int reaction = this.react(aSignal); / The action this automobile is currently performing, idle by default / private int currentAction = IDLE; / The current speed of the automobile, initially 5 mph. / private int currentSpeed = 5; private int react(TrafficSignal signal) { switch(signal.getColor()) { case TrafficSignal.RED: return STOP; case TrafficSignal.YELLOW: // decide whether to stop or go if (this.shouldGo()) return INCREASE_SPEED; else return STOP; case TrafficSignal.GREEN: // no change return this.currentAction; default: throw new IllegalArgumentException ("Invalid traffic color");}} // required public void drive() { TrafficSignal aSignal = ... ; int reaction = this.react(aSignal); / The action this automobile is currently performing, idle by default / private int currentAction = IDLE; / The current speed of the automobile, initially 5 mph. / private int currentSpeed = 5; private int react(TrafficSignal signal) { switch(signal.getColor()) { case TrafficSignal.RED: return STOP; case TrafficSignal.YELLOW: // decide whether to stop or go if (this.shouldGo()) return INCREASE_SPEED; else return STOP; case TrafficSignal.GREEN: // no change return this.currentAction; default: throw new IllegalArgumentException ("Invalid traffic color");}} // required public void drive() { TrafficSignal aSignal = ... ; int reaction = this.react(aSignal); / The action this automobile is currently performing, idle by default / private int currentAction = IDLE; / The current speed of the automobile, initially 5 mph. / private int currentSpeed = 5; private int react(TrafficSignal signal) { switch(signal.getColor()) { case TrafficSignal.RED: return STOP; case TrafficSignal.YELLOW: // decide whether to stop or go if (this.shouldGo()) return INCREASE_SPEED; else return STOP; case TrafficSignal.GREEN: // no change return this.currentAction; default: throw new IllegalArgumentException ("Invalid traffic color");}} // required public void drive() { TrafficSignal aSignal = ... ; int reaction = this.react(aSignal); / The action this automobile is currently performing, idle by default / private int currentAction = IDLE; / The current speed of the automobile, initially 5 mph. / private int currentSpeed = 5; private int react(TrafficSignal signal) { switch(signal.getColor()) { case TrafficSignal.RED: return STOP; case TrafficSignal.YELLOW: // decide whether to stop or go if (this.shouldGo()) return INCREASE_SPEED; else return STOP; case TrafficSignal.GREEN: // no change return this.currentAction; default: throw new IllegalArgumentException ("Invalid traffic color");}} // required public void drive() { TrafficSignal aSignal = ... ; int reaction = this.react(aSignal); /* The action this automobile is currently performing, idle by default */ private Action currentAction = Action.IDLE; /* The current speed of the automobile, initially 5 mph. */ private int currentSpeed = 5; private Action react(TrafficSignal signal) { switch(signal.getColor()) { case TrafficSignal.RED: return Action.STOP; case TrafficSignal.YELLOW: // decide whether to stop or go if (this.shouldGo()) return Action.INCREASE_SPEED; else return Action.STOP; case TrafficSignal.GREEN: // no change return this.currentAction; default: throw new IllegalArgumentException ("Invalid traffic color");}} // required public void drive() { TrafficSignal aSignal = ... ; Action reaction = this.react(aSignal);
  • 38. Traffic Signal Client private int color = RED; / Accessor for the light’s current color / public int getColor() {return this.color;}} class Automobile { private static final int IDLE = 0; private static final int INCREASE_SPEED = 1; private static final int DECREASE_SPEED = 2; private static final int STOP = 3; private static final int MAX_SPEED = 140; / The action this automobile is currently performing, idle by default / private int currentAction = IDLE; / The current speed of the automobile, initially 5 mph. / private int currentSpeed = 5; private int react(TrafficSignal signal) { switch(signal.getColor()) { case TrafficSignal.RED: return STOP; case TrafficSignal.YELLOW: // decide whether to stop or go if (this.shouldGo()) this.currentAction && INCREASE_SPEED || tSpeed <= MAX_SPEED)) rmAction(reaction);} rmAction(int action) {...}} eger constants for enumerated types. 38 (reacti 39 this.c 40 this. 41 42 private void (b) Im Figure 1. Running example: a hypothetical drive-by-w ch machinery. Third, the weak enum ogrammer to manually enumerate the ts, which increases the likelihood of different enum constants may be unin- he same internal value. Finally, the rittle [?]: since the values are com- at compile time they are inlined into new constants are added in between example, in which by language enum and Automobile. ations of these ne through compile-tim between the named ated values. It is als is an Action, whic /* The action this automobile is currently performing, idle by default */ private Action currentAction = Action.IDLE; /* The current speed of the automobile, initially 5 mph. */ private int currentSpeed = 5; private Action react(TrafficSignal signal) { switch(signal.getColor()) { case TrafficSignal.RED: return Action.STOP; case TrafficSignal.YELLOW: // decide whether to stop or go if (this.shouldGo()) return Action.INCREASE_SPEED; else return Action.STOP; case TrafficSignal.GREEN: // no change return this.currentAction; default: throw new IllegalArgumentException ("Invalid traffic color");}} // required public void drive() { TrafficSignal aSignal = ... ; Action reaction = this.react(aSignal); / The action this automobile is currently performing, idle by default / private int currentAction = IDLE; / The current speed of the automobile, initially 5 mph. / private int currentSpeed = 5; private int react(TrafficSignal signal) { switch(signal.getColor()) { case TrafficSignal.RED: return STOP; case TrafficSignal.YELLOW: // decide whether to stop or go if (this.shouldGo()) return INCREASE_SPEED; else return STOP; case TrafficSignal.GREEN: // no change return this.currentAction; default: throw new IllegalArgumentException ("Invalid traffic color");}} // required public void drive() { TrafficSignal aSignal = ... ; int reaction = this.react(aSignal); / The action this automobile is currently performing, idle by default / private int currentAction = IDLE; / The current speed of the automobile, initially 5 mph. / private int currentSpeed = 5; private int react(TrafficSignal signal) { switch(signal.getColor()) { case TrafficSignal.RED: return STOP; case TrafficSignal.YELLOW: // decide whether to stop or go if (this.shouldGo()) return INCREASE_SPEED; else return STOP; case TrafficSignal.GREEN: // no change return this.currentAction; default: throw new IllegalArgumentException ("Invalid traffic color");}} // required public void drive() { TrafficSignal aSignal = ... ; int reaction = this.react(aSignal); / The action this automobile is currently performing, idle by default / private int currentAction = IDLE; / The current speed of the automobile, initially 5 mph. / private int currentSpeed = 5; private int react(TrafficSignal signal) { switch(signal.getColor()) { case TrafficSignal.RED: return STOP; case TrafficSignal.YELLOW: // decide whether to stop or go if (this.shouldGo()) return INCREASE_SPEED; else return STOP; case TrafficSignal.GREEN: // no change return this.currentAction; default: throw new IllegalArgumentException ("Invalid traffic color");}} // required public void drive() { TrafficSignal aSignal = ... ; int reaction = this.react(aSignal); / The action this automobile is currently performing, idle by default / private int currentAction = IDLE; / The current speed of the automobile, initially 5 mph. / private int currentSpeed = 5; private int react(TrafficSignal signal) { switch(signal.getColor()) { case TrafficSignal.RED: return STOP; case TrafficSignal.YELLOW: // decide whether to stop or go if (this.shouldGo()) return INCREASE_SPEED; else return STOP; case TrafficSignal.GREEN: // no change return this.currentAction; default: throw new IllegalArgumentException ("Invalid traffic color");}} // required public void drive() { TrafficSignal aSignal = ... ; int reaction = this.react(aSignal); / The action this automobile is currently performing, idle by default / private int currentAction = IDLE; / The current speed of the automobile, initially 5 mph. / private int currentSpeed = 5; private int react(TrafficSignal signal) { switch(signal.getColor()) { case TrafficSignal.RED: return STOP; case TrafficSignal.YELLOW: // decide whether to stop or go if (this.shouldGo()) return INCREASE_SPEED; else return STOP; case TrafficSignal.GREEN: // no change return this.currentAction; default: throw new IllegalArgumentException ("Invalid traffic color");}} // required public void drive() { TrafficSignal aSignal = ... ; int reaction = this.react(aSignal); / The action this automobile is currently performing, idle by default / private int currentAction = IDLE; / The current speed of the automobile, initially 5 mph. / private int currentSpeed = 5; private int react(TrafficSignal signal) { switch(signal.getColor()) { case TrafficSignal.RED: return STOP; case TrafficSignal.YELLOW: // decide whether to stop or go if (this.shouldGo()) return INCREASE_SPEED; else return STOP; case TrafficSignal.GREEN: // no change return this.currentAction; default: throw new IllegalArgumentException ("Invalid traffic color");}} // required public void drive() { TrafficSignal aSignal = ... ; int reaction = this.react(aSignal); /* The action this automobile is currently performing, idle by default */ private Action currentAction = Action.IDLE; /* The current speed of the automobile, initially 5 mph. */ private int currentSpeed = 5; private Action react(TrafficSignal signal) { switch(signal.getColor()) { case TrafficSignal.RED: return Action.STOP; case TrafficSignal.YELLOW: // decide whether to stop or go if (this.shouldGo()) return Action.INCREASE_SPEED; else return Action.STOP; case TrafficSignal.GREEN: // no change return this.currentAction; default: throw new IllegalArgumentException ("Invalid traffic color");}} // required public void drive() { TrafficSignal aSignal = ... ; Action reaction = this.react(aSignal); /* The action this automobile is currently performing, idle by default */ private Action currentAction = Action.IDLE; /* The current speed of the automobile, initially 5 mph. */ private int currentSpeed = 5; private Action react(TrafficSignal signal) { switch(signal.getColor()) { case TrafficSignal.RED: return Action.STOP; case TrafficSignal.YELLOW: // decide whether to stop or go if (this.shouldGo()) return Action.INCREASE_SPEED; else return Action.STOP; case TrafficSignal.GREEN: // no change return this.currentAction; default: throw new IllegalArgumentException ("Invalid traffic color");}} // required public void drive() { TrafficSignal aSignal = ... ; Action reaction = this.react(aSignal);
  • 39. /* The action this automobile is currently performing, idle by default */ private Action currentAction = Action.IDLE; /* The current speed of the automobile, initially 5 mph. */ private int currentSpeed = 5; private Action react(TrafficSignal signal) { switch(signal.getColor()) { case TrafficSignal.RED: return Action.STOP; case TrafficSignal.YELLOW: // decide whether to stop or go if (this.shouldGo()) return Action.INCREASE_SPEED; else return Action.STOP; case TrafficSignal.GREEN: // no change return this.currentAction; default: throw new IllegalArgumentException ("Invalid traffic color");}} // required public void drive() { TrafficSignal aSignal = ... ; Action reaction = this.react(aSignal); Traffic Signal Client private int color = RED; / Accessor for the light’s current color / public int getColor() {return this.color;}} class Automobile { private static final int IDLE = 0; private static final int INCREASE_SPEED = 1; private static final int DECREASE_SPEED = 2; private static final int STOP = 3; private static final int MAX_SPEED = 140; / The action this automobile is currently performing, idle by default / private int currentAction = IDLE; / The current speed of the automobile, initially 5 mph. / private int currentSpeed = 5; private int react(TrafficSignal signal) { switch(signal.getColor()) { case TrafficSignal.RED: return STOP; case TrafficSignal.YELLOW: // decide whether to stop or go if (this.shouldGo()) this.currentAction && INCREASE_SPEED || tSpeed <= MAX_SPEED)) rmAction(reaction);} rmAction(int action) {...}} eger constants for enumerated types. 38 (reacti 39 this.c 40 this. 41 42 private void (b) Im Figure 1. Running example: a hypothetical drive-by-w ch machinery. Third, the weak enum ogrammer to manually enumerate the ts, which increases the likelihood of different enum constants may be unin- he same internal value. Finally, the rittle [?]: since the values are com- at compile time they are inlined into new constants are added in between example, in which by language enum and Automobile. ations of these ne through compile-tim between the named ated values. It is als is an Action, whic /* The action this automobile is currently performing, idle by default */ private Action currentAction = Action.IDLE; /* The current speed of the automobile, initially 5 mph. */ private int currentSpeed = 5; private Action react(TrafficSignal signal) { switch(signal.getColor()) { case TrafficSignal.RED: return Action.STOP; case TrafficSignal.YELLOW: // decide whether to stop or go if (this.shouldGo()) return Action.INCREASE_SPEED; else return Action.STOP; case TrafficSignal.GREEN: // no change return this.currentAction; default: throw new IllegalArgumentException ("Invalid traffic color");}} // required public void drive() { TrafficSignal aSignal = ... ; Action reaction = this.react(aSignal); / The action this automobile is currently performing, idle by default / private int currentAction = IDLE; / The current speed of the automobile, initially 5 mph. / private int currentSpeed = 5; private int react(TrafficSignal signal) { switch(signal.getColor()) { case TrafficSignal.RED: return STOP; case TrafficSignal.YELLOW: // decide whether to stop or go if (this.shouldGo()) return INCREASE_SPEED; else return STOP; case TrafficSignal.GREEN: // no change return this.currentAction; default: throw new IllegalArgumentException ("Invalid traffic color");}} // required public void drive() { TrafficSignal aSignal = ... ; int reaction = this.react(aSignal); / The action this automobile is currently performing, idle by default / private int currentAction = IDLE; / The current speed of the automobile, initially 5 mph. / private int currentSpeed = 5; private int react(TrafficSignal signal) { switch(signal.getColor()) { case TrafficSignal.RED: return STOP; case TrafficSignal.YELLOW: // decide whether to stop or go if (this.shouldGo()) return INCREASE_SPEED; else return STOP; case TrafficSignal.GREEN: // no change return this.currentAction; default: throw new IllegalArgumentException ("Invalid traffic color");}} // required public void drive() { TrafficSignal aSignal = ... ; int reaction = this.react(aSignal); / The action this automobile is currently performing, idle by default / private int currentAction = IDLE; / The current speed of the automobile, initially 5 mph. / private int currentSpeed = 5; private int react(TrafficSignal signal) { switch(signal.getColor()) { case TrafficSignal.RED: return STOP; case TrafficSignal.YELLOW: // decide whether to stop or go if (this.shouldGo()) return INCREASE_SPEED; else return STOP; case TrafficSignal.GREEN: // no change return this.currentAction; default: throw new IllegalArgumentException ("Invalid traffic color");}} // required public void drive() { TrafficSignal aSignal = ... ; int reaction = this.react(aSignal); / The action this automobile is currently performing, idle by default / private int currentAction = IDLE; / The current speed of the automobile, initially 5 mph. / private int currentSpeed = 5; private int react(TrafficSignal signal) { switch(signal.getColor()) { case TrafficSignal.RED: return STOP; case TrafficSignal.YELLOW: // decide whether to stop or go if (this.shouldGo()) return INCREASE_SPEED; else return STOP; case TrafficSignal.GREEN: // no change return this.currentAction; default: throw new IllegalArgumentException ("Invalid traffic color");}} // required public void drive() { TrafficSignal aSignal = ... ; int reaction = this.react(aSignal); / The action this automobile is currently performing, idle by default / private int currentAction = IDLE; / The current speed of the automobile, initially 5 mph. / private int currentSpeed = 5; private int react(TrafficSignal signal) { switch(signal.getColor()) { case TrafficSignal.RED: return STOP; case TrafficSignal.YELLOW: // decide whether to stop or go if (this.shouldGo()) return INCREASE_SPEED; else return STOP; case TrafficSignal.GREEN: // no change return this.currentAction; default: throw new IllegalArgumentException ("Invalid traffic color");}} // required public void drive() { TrafficSignal aSignal = ... ; int reaction = this.react(aSignal); /* The action this automobile is currently performing, idle by default */ private Action currentAction = Action.IDLE; /* The current speed of the automobile, initially 5 mph. */ private int currentSpeed = 5; private Action react(TrafficSignal signal) { switch(signal.getColor()) { case TrafficSignal.RED: return Action.STOP; case TrafficSignal.YELLOW: // decide whether to stop or go if (this.shouldGo()) return Action.INCREASE_SPEED; else return Action.STOP; case TrafficSignal.GREEN: // no change return this.currentAction; default: throw new IllegalArgumentException ("Invalid traffic color");}} // required public void drive() { TrafficSignal aSignal = ... ; Action reaction = this.react(aSignal); /* The action this automobile is currently performing, idle by default */ private Action currentAction = Action.IDLE; /* The current speed of the automobile, initially 5 mph. */ private int currentSpeed = 5; private Action react(TrafficSignal signal) { switch(signal.getColor()) { case TrafficSignal.RED: return Action.STOP; case TrafficSignal.YELLOW: // decide whether to stop or go if (this.shouldGo()) return Action.INCREASE_SPEED; else return Action.STOP; case TrafficSignal.GREEN: // no change return this.currentAction; default: throw new IllegalArgumentException ("Invalid traffic color");}} // required public void drive() { TrafficSignal aSignal = ... ; Action reaction = this.react(aSignal);
  • 40. /* The action this automobile is currently performing, idle by default */ private Action currentAction = Action.IDLE; /* The current speed of the automobile, initially 5 mph. */ private int currentSpeed = 5; private Action react(TrafficSignal signal) { switch(signal.getColor()) { case TrafficSignal.RED: return Action.STOP; case TrafficSignal.YELLOW: // decide whether to stop or go if (this.shouldGo()) return Action.INCREASE_SPEED; else return Action.STOP; case TrafficSignal.GREEN: // no change return this.currentAction; default: throw new IllegalArgumentException ("Invalid traffic color");}} // required public void drive() { TrafficSignal aSignal = ... ; Action reaction = this.react(aSignal); Traffic Signal Client private int color = RED; / Accessor for the light’s current color / public int getColor() {return this.color;}} class Automobile { private static final int IDLE = 0; private static final int INCREASE_SPEED = 1; private static final int DECREASE_SPEED = 2; private static final int STOP = 3; private static final int MAX_SPEED = 140; / The action this automobile is currently performing, idle by default / private int currentAction = IDLE; / The current speed of the automobile, initially 5 mph. / private int currentSpeed = 5; private int react(TrafficSignal signal) { switch(signal.getColor()) { case TrafficSignal.RED: return STOP; case TrafficSignal.YELLOW: // decide whether to stop or go if (this.shouldGo()) this.currentAction && INCREASE_SPEED || tSpeed <= MAX_SPEED)) rmAction(reaction);} rmAction(int action) {...}} eger constants for enumerated types. 38 (reacti 39 this.c 40 this. 41 42 private void (b) Im Figure 1. Running example: a hypothetical drive-by-w ch machinery. Third, the weak enum ogrammer to manually enumerate the ts, which increases the likelihood of different enum constants may be unin- he same internal value. Finally, the rittle [?]: since the values are com- at compile time they are inlined into new constants are added in between example, in which by language enum and Automobile. ations of these ne through compile-tim between the named ated values. It is als is an Action, whic /* The action this automobile is currently performing, idle by default */ private Action currentAction = Action.IDLE; /* The current speed of the automobile, initially 5 mph. */ private int currentSpeed = 5; private Action react(TrafficSignal signal) { switch(signal.getColor()) { case TrafficSignal.RED: return Action.STOP; case TrafficSignal.YELLOW: // decide whether to stop or go if (this.shouldGo()) return Action.INCREASE_SPEED; else return Action.STOP; case TrafficSignal.GREEN: // no change return this.currentAction; default: throw new IllegalArgumentException ("Invalid traffic color");}} // required public void drive() { TrafficSignal aSignal = ... ; Action reaction = this.react(aSignal); / The action this automobile is currently performing, idle by default / private int currentAction = IDLE; / The current speed of the automobile, initially 5 mph. / private int currentSpeed = 5; private int react(TrafficSignal signal) { switch(signal.getColor()) { case TrafficSignal.RED: return STOP; case TrafficSignal.YELLOW: // decide whether to stop or go if (this.shouldGo()) return INCREASE_SPEED; else return STOP; case TrafficSignal.GREEN: // no change return this.currentAction; default: throw new IllegalArgumentException ("Invalid traffic color");}} // required public void drive() { TrafficSignal aSignal = ... ; int reaction = this.react(aSignal); / The action this automobile is currently performing, idle by default / private int currentAction = IDLE; / The current speed of the automobile, initially 5 mph. / private int currentSpeed = 5; private int react(TrafficSignal signal) { switch(signal.getColor()) { case TrafficSignal.RED: return STOP; case TrafficSignal.YELLOW: // decide whether to stop or go if (this.shouldGo()) return INCREASE_SPEED; else return STOP; case TrafficSignal.GREEN: // no change return this.currentAction; default: throw new IllegalArgumentException ("Invalid traffic color");}} // required public void drive() { TrafficSignal aSignal = ... ; int reaction = this.react(aSignal); / The action this automobile is currently performing, idle by default / private int currentAction = IDLE; / The current speed of the automobile, initially 5 mph. / private int currentSpeed = 5; private int react(TrafficSignal signal) { switch(signal.getColor()) { case TrafficSignal.RED: return STOP; case TrafficSignal.YELLOW: // decide whether to stop or go if (this.shouldGo()) return INCREASE_SPEED; else return STOP; case TrafficSignal.GREEN: // no change return this.currentAction; default: throw new IllegalArgumentException ("Invalid traffic color");}} // required public void drive() { TrafficSignal aSignal = ... ; int reaction = this.react(aSignal); / The action this automobile is currently performing, idle by default / private int currentAction = IDLE; / The current speed of the automobile, initially 5 mph. / private int currentSpeed = 5; private int react(TrafficSignal signal) { switch(signal.getColor()) { case TrafficSignal.RED: return STOP; case TrafficSignal.YELLOW: // decide whether to stop or go if (this.shouldGo()) return INCREASE_SPEED; else return STOP; case TrafficSignal.GREEN: // no change return this.currentAction; default: throw new IllegalArgumentException ("Invalid traffic color");}} // required public void drive() { TrafficSignal aSignal = ... ; int reaction = this.react(aSignal); /* The action this automobile is currently performing, idle by default */ private Action currentAction = Action.IDLE; /* The current speed of the automobile, initially 5 mph. */ private int currentSpeed = 5; private Action react(TrafficSignal signal) { switch(signal.getColor()) { case TrafficSignal.RED: return Action.STOP; case TrafficSignal.YELLOW: // decide whether to stop or go if (this.shouldGo()) return Action.INCREASE_SPEED; else return Action.STOP; case TrafficSignal.GREEN: // no change return this.currentAction; default: throw new IllegalArgumentException ("Invalid traffic color");}} // required public void drive() { TrafficSignal aSignal = ... ; Action reaction = this.react(aSignal); /* The action this automobile is currently performing, idle by default */ private Action currentAction = Action.IDLE; /* The current speed of the automobile, initially 5 mph. */ private int currentSpeed = 5; private Action react(TrafficSignal signal) { switch(signal.getColor()) { case TrafficSignal.RED: return Action.STOP; case TrafficSignal.YELLOW: // decide whether to stop or go if (this.shouldGo()) return Action.INCREASE_SPEED; else return Action.STOP; case TrafficSignal.GREEN: // no change return this.currentAction; default: throw new IllegalArgumentException ("Invalid traffic color");}} // required public void drive() { TrafficSignal aSignal = ... ; Action reaction = this.react(aSignal); /* The action this automobile is currently performing, idle by default */ private Action currentAction = Action.IDLE; /* The current speed of the automobile, initially 5 mph. */ private int currentSpeed = 5; private Action react(TrafficSignal signal) { switch(signal.getColor()) { case TrafficSignal.RED: return Action.STOP; case TrafficSignal.YELLOW: // decide whether to stop or go if (this.shouldGo()) return Action.INCREASE_SPEED; else return Action.STOP; case TrafficSignal.GREEN: // no change return this.currentAction; default: throw new IllegalArgumentException ("Invalid traffic color");}} // required public void drive() { TrafficSignal aSignal = ... ; Action reaction = this.react(aSignal);
  • 41. function Enumerizable(C) 1: W ← C /* seed the worklist with the input constants */ 2: N ← ∅ /* the non-enumerizable set list, initially empty */ 3: for all c ∈ C do 4: MakeSet(c) /* init the union-find data structure */ 5: end for 6: while W ̸= ∅ do 7: /* remove an element from the worklist */ 8: α ← e | e ∈ W 9: W ← W {α} 10: for all αctxt ∈ Contexts(α, P) do 11: if ¬isEnumerizableContext(α, αctxt ) then α variable, eld, method αctxt context in which α may occur Figure 2. Formalism notation. procedure Enumerize(F, P) 1: R ← Enumerizable(F) 2: R ← Unique(R) ∩ Distinct(R) ∩ Consistent(R) 3: for all T ∈ R do 4: Transform(T) 5: end for Figure 3. Top-level enumerization algorithm. refactoring. We also assume that we are able to statica identify all references to candidate elds and transitively d pendent program entities. This assumption could be inva dated through the use of reection and custom class loade Enumerization Approach
  • 42. function Enumerizable(C) 1: W ← C /* seed the worklist with the input constants */ 2: N ← ∅ /* the non-enumerizable set list, initially empty */ 3: for all c ∈ C do 4: MakeSet(c) /* init the union-find data structure */ 5: end for 6: while W ̸= ∅ do 7: /* remove an element from the worklist */ 8: α ← e | e ∈ W 9: W ← W {α} 10: for all αctxt ∈ Contexts(α, P) do 11: if ¬isEnumerizableContext(α, αctxt ) then α variable, eld, method αctxt context in which α may occur Figure 2. Formalism notation. procedure Enumerize(F, P) 1: R ← Enumerizable(F) 2: R ← Unique(R) ∩ Distinct(R) ∩ Consistent(R) 3: for all T ∈ R do 4: Transform(T) 5: end for Figure 3. Top-level enumerization algorithm. refactoring. We also assume that we are able to statica identify all references to candidate elds and transitively d pendent program entities. This assumption could be inva dated through the use of reection and custom class loade Subset of static final fields Enumerization Approach
  • 43. function Enumerizable(C) 1: W ← C /* seed the worklist with the input constants */ 2: N ← ∅ /* the non-enumerizable set list, initially empty */ 3: for all c ∈ C do 4: MakeSet(c) /* init the union-find data structure */ 5: end for 6: while W ̸= ∅ do 7: /* remove an element from the worklist */ 8: α ← e | e ∈ W 9: W ← W {α} 10: for all αctxt ∈ Contexts(α, P) do 11: if ¬isEnumerizableContext(α, αctxt ) then α variable, eld, method αctxt context in which α may occur Figure 2. Formalism notation. procedure Enumerize(F, P) 1: R ← Enumerizable(F) 2: R ← Unique(R) ∩ Distinct(R) ∩ Consistent(R) 3: for all T ∈ R do 4: Transform(T) 5: end for Figure 3. Top-level enumerization algorithm. refactoring. We also assume that we are able to statica identify all references to candidate elds and transitively d pendent program entities. This assumption could be inva dated through the use of reection and custom class loade Abstract Syntax Tree (AST) Enumerization Approach
  • 44. function Enumerizable(C) 1: W ← C /* seed the worklist with the input constants */ 2: N ← ∅ /* the non-enumerizable set list, initially empty */ 3: for all c ∈ C do 4: MakeSet(c) /* init the union-find data structure */ 5: end for 6: while W ̸= ∅ do 7: /* remove an element from the worklist */ 8: α ← e | e ∈ W 9: W ← W {α} 10: for all αctxt ∈ Contexts(α, P) do 11: if ¬isEnumerizableContext(α, αctxt ) then Output: α variable, eld, method αctxt context in which α may occur Figure 2. Formalism notation. procedure Enumerize(F, P) 1: R ← Enumerizable(F) 2: R ← Unique(R) ∩ Distinct(R) ∩ Consistent(R) 3: for all T ∈ R do 4: Transform(T) 5: end for Figure 3. Top-level enumerization algorithm. refactoring. We also assume that we are able to statica identify all references to candidate elds and transitively d pendent program entities. This assumption could be inva dated through the use of reection and custom class loade Enumerization Approach
  • 45. • Partitioning of program entities: • Fields • Method declarations (return types) • Local variables (including formal parameters) function Enumerizable(C) 1: W ← C /* seed the worklist with the input constants */ 2: N ← ∅ /* the non-enumerizable set list, initially empty */ 3: for all c ∈ C do 4: MakeSet(c) /* init the union-find data structure */ 5: end for 6: while W ̸= ∅ do 7: /* remove an element from the worklist */ 8: α ← e | e ∈ W 9: W ← W {α} 10: for all αctxt ∈ Contexts(α, P) do 11: if ¬isEnumerizableContext(α, αctxt ) then Output: α variable, eld, method αctxt context in which α may occur Figure 2. Formalism notation. procedure Enumerize(F, P) 1: R ← Enumerizable(F) 2: R ← Unique(R) ∩ Distinct(R) ∩ Consistent(R) 3: for all T ∈ R do 4: Transform(T) 5: end for Figure 3. Top-level enumerization algorithm. refactoring. We also assume that we are able to statica identify all references to candidate elds and transitively d pendent program entities. This assumption could be inva dated through the use of reection and custom class loade Enumerization Approach