-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
6 changed files
with
114 additions
and
17 deletions.
There are no files selected for viewing
57 changes: 57 additions & 0 deletions
57
clients/algoliasearch-client-java-2/algoliasearch-core/com/algolia/utils/UserAgent.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,57 @@ | ||
package com.algolia.utils; | ||
|
||
import java.util.LinkedHashSet; | ||
import java.util.Set; | ||
|
||
public class UserAgent { | ||
|
||
private final Set<String> segments; | ||
|
||
private String finalValue; | ||
|
||
public UserAgent(String clientVersion) { | ||
this.finalValue = String.format("Algolia for Java (%s)", clientVersion); | ||
this.segments = new LinkedHashSet<String>(); | ||
this.addSegment(new Segment("JVM", System.getProperty("java.version"))); | ||
} | ||
|
||
public String addSegment(Segment seg) { | ||
String segment = seg.toString(); | ||
if (segments.contains(segment)) { | ||
return finalValue; | ||
} | ||
segments.add(segment); | ||
finalValue += segment; | ||
return finalValue; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return finalValue; | ||
} | ||
|
||
public static class Segment { | ||
|
||
private final String value; | ||
private final String version; | ||
|
||
public Segment(String value) { | ||
this(value, null); | ||
} | ||
|
||
public Segment(String value, String version) { | ||
this.value = value; | ||
this.version = version; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
StringBuilder sb = new StringBuilder(); | ||
sb.append("; ").append(value); | ||
if (version != null) { | ||
sb.append(" (").append(version).append(")"); | ||
} | ||
return sb.toString(); | ||
} | ||
} | ||
} |
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