Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes to pull request #2 #3

Open
wants to merge 30 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
c1aba95
Push JSR-353-JSON project into repo.
neomatrix369 Feb 9, 2013
f779949
Merge branch 'master' of github.com:neomatrix369/JSR-353-JSON
neomatrix369 Feb 9, 2013
e1c651d
Pom changes & further Json implementations.
neomatrix369 Feb 9, 2013
9c740f7
Pom.xml changes.
neomatrix369 Feb 9, 2013
a43627b
new implementations of Json.
neomatrix369 Feb 9, 2013
254dbb8
JSON Reader, write implementation.
sivajik Feb 9, 2013
147d6dd
JSON Reader, write implementation.
sivajik Feb 9, 2013
3f95fee
Merge pull request #1 from sivajik/master
neomatrix369 Feb 9, 2013
9d8ff3b
Update README.md
neomatrix369 Feb 9, 2013
bc3e970
Update README.md
neomatrix369 Feb 9, 2013
6d6cca8
Update README.md
neomatrix369 Feb 9, 2013
48a2f4e
Tidying up project and stub program.
neomatrix369 Feb 9, 2013
a1ecf63
Merge branch 'master' of github.com:neomatrix369/JSR-353-JSON
neomatrix369 Feb 9, 2013
71ef9ad
Update README.md
neomatrix369 Feb 9, 2013
7c191a6
JsonReader.close() added.
neomatrix369 Feb 10, 2013
c0d7976
Merge branch 'master' of github.com:neomatrix369/JSR-353-JSON
neomatrix369 Feb 10, 2013
f508a9f
synchronized added to a number of methods.
neomatrix369 Feb 11, 2013
a37d107
Revert "synchronized added to a number of methods."
neomatrix369 Feb 11, 2013
f79c00c
some improvements
Mar 14, 2013
c116a40
Fixed issues on pull request #1 via hash e7cccad: volatile, 'e', comm…
neomatrix369 Mar 18, 2013
ea169a7
Remove overkill immutability step, returns object instead.
neomatrix369 Mar 18, 2013
ea3f159
Remove .files from the previous push.
neomatrix369 Mar 18, 2013
94cb9f2
Remove ...~ file from the previous push.
neomatrix369 Mar 18, 2013
571d2ae
Remove .settings from the previous push.
neomatrix369 Mar 18, 2013
d3685b5
Add updated .gitignore file.
neomatrix369 Mar 18, 2013
d7d06b1
Merge branch 'master' of github.com:neomatrix369/JSR-353-JSON
neomatrix369 Mar 22, 2013
6c725f7
Added target folder to .gitignore
neomatrix369 Mar 22, 2013
c6ab0aa
Sync-ed local repo with upstream. To remove 'This pull request cannot…
neomatrix369 Mar 22, 2013
53519e5
Sync-ed local repo with upstream. To remove 'This pull request cannot…
neomatrix369 Mar 22, 2013
7e316c5
Sync-ed local repo with upstream. To remove 'This pull request cannot…
neomatrix369 Mar 22, 2013
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 0 additions & 20 deletions .classpath

This file was deleted.

6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,9 @@
*.jar
*.war
*.ear

# Ignore . & ~ files except .gitignore #
*~
.*
target/
!/.gitignore
23 changes: 0 additions & 23 deletions .project

This file was deleted.

12 changes: 0 additions & 12 deletions .settings/org.eclipse.jdt.core.prefs

This file was deleted.

4 changes: 0 additions & 4 deletions .settings/org.eclipse.m2e.core.prefs

This file was deleted.

13 changes: 7 additions & 6 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,17 @@
</build>

<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.glassfish</groupId>
<artifactId>javax.json</artifactId>
<version>1.0-b02</version>
</dependency>

<!-- <dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>7.0-b72</version>
</dependency> -->
</dependencies>
</project>
50 changes: 24 additions & 26 deletions src/main/java/JSR353/JSON/PricesCacheStore.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,38 +2,36 @@

import java.util.concurrent.ConcurrentHashMap;

public class PricesCacheStore {

private final static PricesCacheStore INSTANCE = new PricesCacheStore();

private PricesCacheStore() {}
private volatile String lastSymboleUpdated;

// will contain Symbols and prices stored and constantly updated
private volatile ConcurrentHashMap<String, Double> pricesCache = new ConcurrentHashMap<>();

public static PricesCacheStore getInstance() {
return INSTANCE;
}

public enum PricesCacheStore {

INSTANCE;

private volatile String lastSymbolUpdated;

// will contain Symbols and prices stored and constantly updated
private ConcurrentHashMap<String, Double> pricesCache = new ConcurrentHashMap<>();

public void addPrice(String symbol, Double price) {
pricesCache.put(symbol, price);
lastSymboleUpdated = symbol;
if (symbol != null && price != null) {
pricesCache.put(symbol, price);
lastSymbolUpdated = symbol;
}
}

public Double getPrice(String symbol) {
if (symbol == null) {
return 0d;
}
Double price = pricesCache.get(symbol);
return price == null ? 0 : price;
return price == null ? 0d : price;
}

// Keep in mind immutability - return a copy of the object
// does not matter if it is static or volatile
// or if its threading is safe
public ConcurrentHashMap<String, Double> getAllPrices() {
return new ConcurrentHashMap<String, Double>(pricesCache);

// Object is threading is safe so can be returned as it is
public ConcurrentHashMap<String, Double> getAllPrices() {
return pricesCache;
}

public String getLastSymbolUpdated() {
return new String(lastSymboleUpdated);
return new String(lastSymbolUpdated);
}
}
Loading