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

Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionIntroducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionOnePlan Solutions
 
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
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Modelsaagamshah0812
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech studentsHimanshiGarg82
 
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...kalichargn70th171
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsJhone kinadey
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrainmasabamasaba
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfonteinmasabamasaba
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisamasabamasaba
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...SelfMade bd
 
ManageIQ - Sprint 236 Review - Slide Deck
ManageIQ - Sprint 236 Review - Slide DeckManageIQ - Sprint 236 Review - Slide Deck
ManageIQ - Sprint 236 Review - Slide DeckManageIQ
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...ICS
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfonteinmasabamasaba
 
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...Jittipong Loespradit
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfkalichargn70th171
 
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdfAzure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdfryanfarris8
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsArshad QA
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...Health
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplatePresentation.STUDIO
 

Recently uploaded (20)

Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionIntroducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
 
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
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students
 
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
 
ManageIQ - Sprint 236 Review - Slide Deck
ManageIQ - Sprint 236 Review - Slide DeckManageIQ - Sprint 236 Review - Slide Deck
ManageIQ - Sprint 236 Review - Slide Deck
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
 
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdfAzure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 

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