Shadow Read mod

This commit is contained in:
EulPi 2018-04-02 23:50:08 -04:00
parent fc12751b2c
commit 1b8913f5ae
4 changed files with 21 additions and 37 deletions

View file

@ -149,4 +149,7 @@ public class Owner extends Person {
.append("firstName", this.getFirstName()).append("address", this.address)
.append("city", this.city).append("telephone", this.telephone).toString();
}
// for testing
public Owner() {}
}

View file

@ -90,13 +90,6 @@ class OwnerController {
// find owners by last name
Collection<Owner> results = this.owners.findByLastName(owner.getLastName());
for (Owner o : results)
System.out.println(o.toString());
// Shadow Read
compareResults(results, owner.getLastName());
if (results.isEmpty()) {
// no owners found
result.rejectValue("lastName", "notFound", "not found");
@ -112,32 +105,6 @@ class OwnerController {
}
}
private void compareResults(Collection<Owner> results, String lastName) {
String pattern = lastName + "*";
NewOwnerStore newStore = NewOwnerStore.getInstance(owners);
newStore.populateStore();
HashMap<Integer, StaticOwner> storeMap = newStore.getStore();
ArrayList<StaticOwner> newOwners = new ArrayList<>();
for (StaticOwner owner : storeMap.values()) {
if (!Pattern.compile(pattern).matcher(owner.getLastName()).find())
newOwners.add(owner);
}
for (Owner owner : results) {
if (newOwners.contains(owner))
System.out.println("Found. Good");
else {
System.out.println("Not Found. Bad");
newStore.findAndReplace(owner);
}
}
}
@GetMapping("/owners/{ownerId}/edit")
public String initUpdateOwnerForm(@PathVariable("ownerId") int ownerId, Model model) {
Owner owner = this.owners.findById(ownerId);

View file

@ -27,6 +27,13 @@ public class StaticOwner {
this.setTelephone(telephone);
}
public StaticOwner(Integer id, String firstName, String lastName)
{
this.setId(id);
this.setLastName(lastName);
this.setFirstName(firstName);
}
public void setAddress(String address) {
this.address = address;
}
@ -98,5 +105,4 @@ public class StaticOwner {
return new StaticOwner(owner.getId(), owner.getLastName(), owner.getFirstName(),
owner.getAddress(), owner.getCity(), owner.getTelephone());
}
}

View file

@ -68,17 +68,25 @@ public class NewOwnerStoreTest {
int inconsistencies = compareResults(results, "");
assertEquals(inconsistencies, 0);
// Introduce inconsistency
testOwnerStore.getStore().put(1, new StaticOwner(1, "First", "Last"));
inconsistencies = compareResults(results, "");
assertEquals(inconsistencies, 1);
// Inconsistency should be gone
inconsistencies = compareResults(results, "");
assertEquals(inconsistencies, 0);
}
private int compareResults(Collection<Owner> results, String lastName) {
String pattern = "/^" + lastName + "/";
HashMap<Integer, StaticOwner> storeMap = testOwnerStore.getStore();
ArrayList<StaticOwner> staticOwners = new ArrayList<>();
for (StaticOwner owner : storeMap.values()) {
for (StaticOwner owner : ownerStore.values()) {
if (!Pattern.compile(pattern, Pattern.CASE_INSENSITIVE).matcher(owner.getLastName()).find())
staticOwners.add(owner);
}