On this page:
Intro
JSON Reminder
Simple Equality
Beyond Simple Equality
Submission
6.12

Lab 7: JSON Equality

Intro

Work in ad-hoc pairs. The two of you will work as a team to solve problems. At any time, one of you will be the Head and the other will be the Hands. The Head does the thinking and the Hands does the typing. Hands type only what the Head tells them to, but you’re free to discuss any issues that pop up. You should switch off during the lab to make sure each of you get practice problem solving, dealing with syntax, and getting finger exercises on the keyboard.

You should start this lab with this project skeleton. Unzip the file into your IdeaProjects directory and open it with IntelliJ to get started. (The file is called Lab12.zip even though this is lab 7, but don’t worry, you’ve got the right material.)

JSON Reminder

Recall the data definition for JSON from last semester (translated a bit to Java):

/* A Json is one of:

 * - new JInt(Integer)

 * - new JStr(String)

 * - LoJson

 * - Assoc

 * Interp: JSON data

 */

 

/* A LoJson is one of:

 * - new Mt()

 * - new Cons(Json first, LoJson rest)

 * Interp: A list of Json data

 */

 

/* An Assoc is one of:

 * - new MtAssoc()

 * - new ConsAssoc(String key, Json value, Assoc rest)

 * Interp: associations between string keys and Json values

 */

We’ll be implementing an isSame structural equality method for the provided JSON classes. The overall structure will be similar to the sameShape method implemented during the last lecture.

Simple Equality

We want to implement the structural equality for each class that extends the abstract class Json.

Following the outline for double dispatch methods that we saw in class, add the necessary method signatures and definitions to all of the JSON classes in order to complete the implementation.

To get you started, we’ve already done the work to implement isSame for JInt.

Ex 1: Design an isSameX methods, one for each of the possible specific arguments in JInt, JStr, Mt, Cons, MtAssoc, and ConsAssoc (replacing X with the appropriate name).

Ex 2: Implement the six isSame methods, one in each of the six JSON classes.

Beyond Simple Equality

In real-world JSON, the order of elements in both regular and association lists does not matter.

Ex 3: Implement an order-independent isSame method for Cons and ConsAssoc. Design any helper methods you may need.

Submission

Submit a zip file of your work at the end of lab.