// Copyright 2020 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package com.google.sps.data;

import java.util.Arrays;

public final class Recipe {

  private final String name;
  private final String time;
  private final String calories;
  private final String difficulty;
  private final String[] dietaryRequirements;
  private final String[] ingredients;
  private final String[] instructions;

  public Recipe(
      String name,
      String time,
      String calories,
      String difficulty,
      String[] dietaryRequirements,
      String[] ingredients,
      String[] instructions) {
    this.name = name;
    this.time = time;
    this.calories = calories;
    this.difficulty = difficulty;
    this.dietaryRequirements = dietaryRequirements;
    this.ingredients = ingredients;
    this.instructions = instructions;
  }

  @Override
  public boolean equals(Object other) {
    if (other == this) {
      return true;
    }

    if (!(other instanceof Recipe)) {
      return false;
    }

    Recipe otherRecipe = (Recipe) other;

    return this.name.equals(otherRecipe.name)
        && this.time.equals(otherRecipe.time)
        && this.difficulty.equals(otherRecipe.difficulty)
        && this.calories.equals(otherRecipe.calories)
        && Arrays.equals(this.dietaryRequirements, otherRecipe.dietaryRequirements)
        && Arrays.equals(this.ingredients, otherRecipe.ingredients)
        && Arrays.equals(this.instructions, otherRecipe.instructions);
  }
}

@@ -636,16 +636,42 @@
 .Arrays;
+%0Aimport java.util.Objects;
 %0A%0Apublic
@@ -1444,30 +1444,22 @@
 if (
-o
 th
-er
+is
  == 
+o
 th
-is) %7B%0A     
+er)
  ret
@@ -1472,58 +1472,64 @@
 ue;%0A
-    %7D%0A%0A
     if 
-(!
 (other 
-instanceof Recipe)) %7B%0A     
+== null %7C%7C getClass() != other.getClass())
  ret
@@ -1543,15 +1543,8 @@
 se;%0A
-    %7D%0A%0A
     
@@ -1550,22 +1550,17 @@
  Recipe 
-otherR
+r
 ecipe = 
@@ -1575,17 +1575,16 @@
  other;%0A
-%0A
     retu
@@ -1586,21 +1586,16 @@
  return 
-this.
 name.equ
@@ -1594,30 +1594,25 @@
 name.equals(
-otherR
+r
 ecipe.name)%0A
@@ -1610,16 +1610,19 @@
 pe.name)
+ &&
 %0A       
@@ -1622,24 +1622,20 @@
         
-&& this.
+    
 time.equ
@@ -1634,30 +1634,25 @@
 time.equals(
-otherR
+r
 ecipe.time)%0A
@@ -1650,16 +1650,19 @@
 pe.time)
+ &&
 %0A       
@@ -1666,111 +1666,99 @@
     
-&& this.difficulty.equals(otherRecipe.difficulty)%0A        && this.calories.equals(otherRecipe.calories)
+    calories.equals(recipe.calories) &&%0A            difficulty.equals(recipe.difficulty) &&
 %0A   
@@ -1754,34 +1754,35 @@
 lty) &&%0A        
-&&
+   
  Arrays.equals(t
@@ -1780,21 +1780,16 @@
 .equals(
-this.
 dietaryR
@@ -1797,30 +1797,25 @@
 quirements, 
-otherR
+r
 ecipe.dietar
@@ -1824,24 +1824,27 @@
 equirements)
+ &&
 %0A        && 
@@ -1832,34 +1832,35 @@
 nts) &&%0A        
-&&
+   
  Arrays.equals(t
@@ -1858,21 +1858,16 @@
 .equals(
-this.
 ingredie
@@ -1871,22 +1871,17 @@
 dients, 
-otherR
+r
 ecipe.in
@@ -1890,16 +1890,19 @@
 edients)
+ &&
 %0A       
@@ -1902,18 +1902,19 @@
         
-&&
+   
  Arrays.
@@ -1924,52 +1924,398 @@
 als(
-this.instructions, otherRecipe.instructions)
+instructions, recipe.instructions);%0A  %7D%0A%0A  @Override%0A  public int hashCode() %7B%0A    int multiplier = 31;%0A    int result = Objects.hash(name, time, calories, difficulty);%0A    result = multiplier * result + Arrays.hashCode(dietaryRequirements);%0A    result = multiplier * result + Arrays.hashCode(ingredients);%0A    result = multiplier * result + Arrays.hashCode(instructions);%0A    return result
 ;%0A  

Write hashCode() and equals()