Skip to content

Commit

Permalink
Closes #88
Browse files Browse the repository at this point in the history
Merge branch 'fix/no-stages' into develop

* fix/no-stages:
  Prevent empty stage changes from happening
  • Loading branch information
7LPdWcaW authored and 7LPdWcaW committed Jun 29, 2019
2 parents 660abd7 + 4ab5716 commit ce9e690
Showing 1 changed file with 31 additions and 16 deletions.
47 changes: 31 additions & 16 deletions app/src/main/java/me/anon/model/Plant.java
Original file line number Diff line number Diff line change
Expand Up @@ -307,8 +307,8 @@ public PlantStage getStage()
}
}

// This should never be reached.
return null;
// Apparently this could be reached
return PlantStage.PLANTED;
}

/**
Expand All @@ -327,6 +327,13 @@ public LinkedHashMap<PlantStage, Action> getStages()
}
}

if (stages.isEmpty())
{
StageChange stageChange = new StageChange(PlantStage.PLANTED);
stageChange.setDate(plantDate);
stages.put(PlantStage.PLANTED, stageChange);
}

return stages;
}

Expand Down Expand Up @@ -371,24 +378,32 @@ else if (lhs.ordinal() > rhs.ordinal())

int stageIndex = 0;
long lastStage = 0;
PlantStage previous = stages.firstKey();
for (PlantStage plantStage : stages.keySet())
if (!stages.isEmpty())
{
long difference = 0;
if (stageIndex == 0)
PlantStage previous = stages.firstKey();
for (PlantStage plantStage : stages.keySet())
{
difference = endDate - stages.get(plantStage);
}
else
{
difference = lastStage - stages.get(plantStage);
}
long difference = 0;
if (stageIndex == 0)
{
difference = endDate - stages.get(plantStage);
}
else
{
difference = lastStage - stages.get(plantStage);
}

previous = plantStage;
lastStage = stages.get(plantStage);
stageIndex++;
previous = plantStage;
lastStage = stages.get(plantStage);
stageIndex++;

stages.put(plantStage, difference);
stages.put(plantStage, difference);
}
}
else
{
PlantStage planted = PlantStage.PLANTED;
stages.put(planted, 0l);
}

return stages;
Expand Down

0 comments on commit ce9e690

Please sign in to comment.