- 
                Notifications
    You must be signed in to change notification settings 
- Fork 33
Add UserAgents.of(UserAgent, Iterable<Agent>) #902
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
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| type: improvement | ||
| improvement: | ||
| description: Add UserAgents.of(UserAgent, Iterable<Agent>) | ||
| links: | ||
| - https://github.com/palantir/conjure-java-runtime-api/pull/902 | 
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
|  | @@ -16,6 +16,7 @@ | |
|  | ||
| package com.palantir.conjure.java.api.config.service; | ||
|  | ||
| import com.palantir.conjure.java.api.config.service.UserAgent.Agent; | ||
| import com.palantir.logsafe.Preconditions; | ||
| import com.palantir.logsafe.SafeArg; | ||
| import com.palantir.logsafe.exceptions.SafeIllegalArgumentException; | ||
|  | @@ -46,6 +47,16 @@ public final class UserAgents { | |
|  | ||
| private UserAgents() {} | ||
|  | ||
| /** | ||
| * Returns a user agent with the given base agent combined with specified additional informational agents. | ||
| */ | ||
| public static UserAgent of(UserAgent base, Iterable<Agent> additional) { | ||
| return ImmutableUserAgent.builder() | ||
| .from(base) | ||
| .addAllInformational(additional) | ||
| .build(); | ||
| } | ||
|          | ||
|  | ||
| /** Returns the canonical string format for the given {@link UserAgent}. */ | ||
| public static String format(UserAgent userAgent) { | ||
| StringBuilder formatted = new StringBuilder(64); // preallocate larger buffer for longer agents | ||
|  | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should probably update this to use immutables params and avoid the Agent.Builder altogether