-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
37ce510
commit ce6c736
Showing
4 changed files
with
86 additions
and
22 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
69 changes: 69 additions & 0 deletions
69
src/main/java/com/github/natche/gravatarjavaclient/profile/GravatarProfileTokenProvider.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,69 @@ | ||
package com.github.natche.gravatarjavaclient.profile; | ||
|
||
import com.google.common.base.Preconditions; | ||
|
||
import java.util.function.Supplier; | ||
|
||
/** | ||
* An authentication token provider for Gravatar Profile API calls. | ||
*/ | ||
public final class GravatarProfileTokenProvider { | ||
private final Supplier<byte[]> tokenProvider; | ||
private final String source; | ||
|
||
/** | ||
* Constructs a new token provider. | ||
* | ||
* @param tokenProvider the encapsulated provider | ||
* @param source the source/key, this is used for hash and equals comparisons | ||
* @throws NullPointerException if any parameter is null | ||
* @throws IllegalArgumentException if source is empty | ||
*/ | ||
public GravatarProfileTokenProvider(Supplier<byte[]> tokenProvider, String source) { | ||
Preconditions.checkNotNull(tokenProvider); | ||
Preconditions.checkNotNull(source); | ||
Preconditions.checkArgument(!source.trim().isEmpty()); | ||
|
||
this.tokenProvider = tokenProvider; | ||
this.source = source; | ||
} | ||
|
||
public byte[] getToken() { | ||
return tokenProvider.get(); | ||
} | ||
|
||
/** | ||
* Returns a hashcode representation of this object. | ||
* | ||
* @return a hashcode representation of this object | ||
*/ | ||
@Override | ||
public int hashCode() { | ||
return source.hashCode(); | ||
} | ||
|
||
/** | ||
* Returns whether the provided object equals this. | ||
* | ||
* @param o the other object | ||
* @return whether the provided object equals this | ||
*/ | ||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
else if (!(o instanceof GravatarProfileTokenProvider)) return false; | ||
|
||
GravatarProfileTokenProvider other = (GravatarProfileTokenProvider) o; | ||
return source.equals(other.source); | ||
} | ||
|
||
/** | ||
* Returns a string representation of this object. | ||
* | ||
* @return a string representation of this object | ||
*/ | ||
@Override | ||
public String toString() { | ||
return "GravatarProfileTokenProvider{source=\"" + source + "\"}"; | ||
} | ||
} |
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