-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add major/minor version-aware HelpUrl builder
- Loading branch information
Showing
4 changed files
with
99 additions
and
5 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
50 changes: 50 additions & 0 deletions
50
logstash-core/src/main/java/org/logstash/health/HelpUrl.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,50 @@ | ||
package org.logstash.health; | ||
|
||
import org.logstash.Logstash; | ||
|
||
import java.util.Objects; | ||
|
||
public class HelpUrl { | ||
static final String BASE_URL; | ||
static { | ||
final String versionAnchor; | ||
if (Integer.parseInt(Logstash.VERSION_MAJOR) >= 9) { | ||
versionAnchor = "master"; | ||
} else { | ||
versionAnchor = String.format("%s.%s", Logstash.VERSION_MAJOR, Logstash.VERSION_MINOR); | ||
} | ||
BASE_URL = String.format("https://www.elastic.co/guide/en/logstash/%s/", versionAnchor); | ||
} | ||
|
||
public HelpUrl(final String page) { | ||
this(page, null); | ||
} | ||
|
||
public HelpUrl withAnchor(final String anchor) { | ||
return new HelpUrl(this.page, anchor); | ||
} | ||
|
||
private HelpUrl(final String page, final String anchor) { | ||
Objects.requireNonNull(page, "page cannot be null"); | ||
this.page = page; | ||
this.anchor = anchor; | ||
} | ||
|
||
private final String page; | ||
private final String anchor; | ||
|
||
private transient String resolved; | ||
|
||
@Override | ||
public String toString() { | ||
if (resolved == null) { | ||
final StringBuilder sb = new StringBuilder(BASE_URL); | ||
sb.append(page).append(".html"); | ||
if (anchor != null) { | ||
sb.append("#").append(anchor); | ||
} | ||
resolved = sb.toString(); | ||
} | ||
return resolved; | ||
} | ||
} |
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