-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #86 from magx2/4.0.x
4.0.x
- Loading branch information
Showing
11 changed files
with
293 additions
and
91 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
src/main/java/pl/grzeslowski/jsupla/api/internal/ApiUsageStatisticsCollector.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package pl.grzeslowski.jsupla.api.internal; | ||
|
||
import lombok.NoArgsConstructor; | ||
import lombok.NonNull; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.ToString; | ||
import pl.grzeslowski.jsupla.api.Api; | ||
|
||
import java.util.Optional; | ||
import java.util.concurrent.ConcurrentHashMap; | ||
import java.util.concurrent.ConcurrentMap; | ||
|
||
import static lombok.AccessLevel.PRIVATE; | ||
|
||
@NoArgsConstructor(access = PRIVATE) | ||
final class ApiUsageStatisticsCollector { | ||
static final ApiUsageStatisticsCollector INSTANCE = new ApiUsageStatisticsCollector(); | ||
private final ConcurrentMap<String, Api.ApiUsageStatistics> cache = new ConcurrentHashMap<>(); | ||
|
||
TokenBound newTokenBound(@NonNull String token) { | ||
return new TokenBound(token); | ||
} | ||
|
||
void putStatistics(@NonNull String token, @NonNull Api.ApiUsageStatistics apiUsageStatistics) { | ||
cache.put(token, apiUsageStatistics); | ||
} | ||
|
||
Optional<Api.ApiUsageStatistics> getStatistics(@NonNull String token) { | ||
return Optional.ofNullable(cache.getOrDefault(token, null)); | ||
} | ||
|
||
@ToString | ||
@RequiredArgsConstructor | ||
final class TokenBound implements ApiUsageStatisticsSetter { | ||
@NonNull private final String token; | ||
|
||
@Override | ||
public void setApiUsageStatistics(final Api.ApiUsageStatistics apiUsageStatistics) { | ||
putStatistics(token, apiUsageStatistics); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.