package com.google.tripmeout.frontend.storage;
 
import com.google.tripmeout.frontend.PlaceVisitModel;
import com.google.tripmeout.frontend.storage.PlaceVisitStorage;
import java.util.List;
 
@Singleton
public class InMemoryPlaceVisitStorage implements PlaceVisitStorage {
  List<PlaceVisitModel> storage = new ArrayList<>();
 
  @Override
  void addPlaceVisit(PlaceVisitModel placeVisit) {
    for (PlaceVisit place: storage) {
      if (place.tripId().equals(placeVisit.tripId()) && place.placeId().equals(placeVisit.placeId())) {
        throw Exception;
      }
    }
    storage.add(placeVisit);
  }

  @Override
  void removePlaceVisit(String tripId, String placeId) {
    for (PlaceVisit place: storage) {
      if (place.tripId().equals(tripId) && place.placeId().equals(placeId)) {
        storage.remove(place);
        return;
      }
    }
    throw Exception;
  }

  @Override
  PlaceVisit getPlaceVisit(String tripId, String placeId) {
    for (PlaceVisit place: storage) {
      if (place.tripId().equals(tripId) && place.placeId().equals(placeId)) {
        return place;
      }
    }
    throw Exception;
  }

  @Override
  void changePlaceVisitStatus(String tripId, String placeId, String newStatus) {
    for (PlaceVisit place: storage) {
      if (place.tripId().equals(tripId) && place.placeId().equals(placeId)) {
        Builder placeValueBuilder = PlaceVisitModel.builder();
        PlaceValueModel updatedPlace = placeValueBuilder
          .setTripId(tripId)
          .setPlaceId(placeId)
          .setName(place.name())
          .setLatitude(place.latitude())
          .setLongitude(place.longitude())
          .setUserMark(newStatus);
        storage.remove(place);
        storage.add(updatedPlace);
        return;
      }
    }
    throw Exception;
  }

  @Override
  List<PlaceVisitModel> getTripPlaceVisits(String tripId) {
    List<PlaceVisitModel> tripPlaceVisits = new ArrayList<>();
    for (PlaceVisit place: storage) {
      if (place.tripId().equals(tripId)) {
        tripPlaceVisits.add(place);
      }
    }
    return tripPlaceVisits;
  }
 
}

@@ -171,157 +171,428 @@
 ort 
-java.util.List;%0A %0A@Singleton%0Apublic class InMemoryPlaceVisitStorage implements PlaceVisitStorage %7B%0A  List%3CPlaceVisitModel%3E storage = new ArrayList%3C%3E(
+com.google.common.collect.Tables;%0Aimport com.google.common.collect.Table;%0Aimport com.google.common.collect.HashBasedTable;%0Aimport java.util.Map;%0Aimport java.util.List;%0Aimport java.util.Collection;%0A %0A@Singleton%0Apublic class InMemoryPlaceVisitStorage implements PlaceVisitStorage %7B%0A  // %3CplaceId, tripId, PlaceVisitModel%3E %0A  Table%3CString, String, PlaceVisitModel%3E storage = Tables.synchronizedTable(HashBasedTable.create()
 );%0A 
@@ -666,32 +666,37 @@
  for (PlaceVisit
+Model
  place: storage)
@@ -853,20 +853,63 @@
 storage.
-add(
+put(placeVisit.placeId(), placeVisit.tripId(), 
 placeVis
@@ -995,181 +995,50 @@
     
-for (PlaceVisit place: storage) %7B%0A      if (place.tripId().equals(tripId) && place.placeId().equals(placeId)) %7B%0A        storage.remove(place);%0A        return;%0A      %7D%0A    %7D%0A
+if (!storage.remove(placeId, tripId)) %7B%0A  
     
@@ -1046,32 +1046,39 @@
 hrow Exception;%0A
+    %7D %0A
   %7D%0A%0A  @Override
@@ -1090,16 +1090,21 @@
 aceVisit
+Model
  getPlac
@@ -1139,37 +1139,32 @@
  placeId) %7B%0A    
-for (
 PlaceVisit place
@@ -1153,39 +1153,45 @@
   PlaceVisit
+Model
  place
-:
+ =
  storage
 ) %7B%0A      if
@@ -1182,92 +1182,48 @@
 rage
-) %7B%0A      if (place.tripId().equals(tripId) && place.placeId().equals
+.get(placeId, tripId);%0A    if 
 (place
-Id)
 ) %7B%0A
-  
     
@@ -1238,24 +1238,16 @@
  place;%0A
-      %7D%0A
     %7D%0A  
@@ -1374,32 +1374,37 @@
  for (PlaceVisit
+Model
  place: storage)
@@ -1496,81 +1496,18 @@
     
-Builder placeValueBuilder = PlaceVisitModel.builder();%0A        PlaceValue
+PlaceVisit
 Mode
@@ -1527,235 +1527,45 @@
 e = 
-p
+P
 laceV
-alueBuilder%0A          .setTripId(tripId)%0A          .setPlaceId(placeId)%0A          .setName(place.name())%0A          .setLatitude(place.latitude())%0A          .setLongitude(place.longitude())%0A          .setUserMark(newStatus
+isitModel.buildFromStatus(place
 );%0A 
@@ -1753,24 +1753,172 @@
 g tripId) %7B%0A
+    Map%3CString, PlaceVisitModel%3E placeIdPlaceMap = storage.column(tripId);%0A    Collection%3CPlaceVisitModel%3E placeVisits = placeIdPlaceMap.values();%0A%0A
     List%3CPla
@@ -1968,16 +1968,21 @@
 st%3C%3E();%0A
+    %0A
     for 
@@ -1992,24 +1992,29 @@
 aceVisit
+Model
  place: 
 storage)
@@ -1997,39 +1997,43 @@
 sitModel place: 
-storage
+placeVisits
 ) %7B%0A      if (pl
@@ -2028,38 +2028,40 @@
       if (place.
-tripId
+userMark
 ().equals(tripId
@@ -2054,22 +2054,26 @@
 .equals(
-tripId
+%22must-see%22
 )) %7B%0A   
@@ -2115,24 +2115,25 @@
     %7D%0A    %7D%0A
+%0A
     return t

change list storage to table storage