Skip to content

Commit

Permalink
SHRINKRES-215 Fixed putIfAbsent usage
Browse files Browse the repository at this point in the history
  • Loading branch information
kpiwko committed Mar 13, 2015
1 parent 9395693 commit 5ff762e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,11 @@ public static PackagingType of(String typeName) throws IllegalArgumentException
throw new IllegalArgumentException("Packaging type must not be null nor empty.");
}
// return from cache if available
return cache.putIfAbsent(typeName, new PackagingType(typeName));
if(cache.containsKey(typeName)) {
return cache.get(typeName);
}
// this will cause packaging object to register into cache
return new PackagingType(typeName);
}

// we are using only id for hashCode() and equals(Object)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,9 @@ public void par() {
Assert.assertEquals("par", PackagingType.PAR.toString());
}

@Test
public void random() {
Assert.assertEquals("random", PackagingType.of("random").toString());
}

}

0 comments on commit 5ff762e

Please sign in to comment.