Skip to content

Commit 1c26efb

Browse files
committed
GH-2099 - Polishing.
1 parent e110faa commit 1c26efb

File tree

6 files changed

+404
-238
lines changed

6 files changed

+404
-238
lines changed

src/main/java/org/springframework/hateoas/Link.java

+18-11
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,8 @@ private Link(String href, @Nullable UriTemplate template, LinkRelation rel, List
104104
}
105105

106106
Link(LinkRelation rel, String href, @Nullable String hreflang, @Nullable String media, @Nullable String title,
107-
@Nullable String type, @Nullable String deprecation, @Nullable String profile, @Nullable String name,
108-
@Nullable UriTemplate template, List<Affordance> affordances) {
107+
@Nullable String type, @Nullable String deprecation, @Nullable String profile, @Nullable String name,
108+
@Nullable UriTemplate template, List<Affordance> affordances) {
109109

110110
this.rel = rel;
111111
this.href = href;
@@ -383,15 +383,13 @@ public URI toUri() {
383383
* Factory method to easily create {@link Link} instances from RFC-8288 compatible {@link String} representations of a
384384
* link.
385385
*
386-
* @param element an RFC-8288 compatible representation of a link.
386+
* @param source an RFC-8288 compatible representation of a link.
387387
* @throws IllegalArgumentException if a {@link String} was given that does not adhere to RFC-8288.
388388
* @throws IllegalArgumentException if no {@code rel} attribute could be found.
389-
* @return The parsed link
390-
* @deprecated Use {@link Links#parse(String)} instead. This method parses only the first link from a list of links.
389+
* @return will never be {@literal null}.
391390
*/
392-
@Deprecated
393-
public static Link valueOf(String element) {
394-
return LinkParser.parseLink(element, new int[]{0});
391+
public static Link valueOf(String source) {
392+
return LinkParser.parseLink(source, new int[] { 0 });
395393
}
396394

397395
/**
@@ -596,12 +594,15 @@ public int hashCode() {
596594
*/
597595
@Override
598596
public String toString() {
599-
StringBuilder result = new StringBuilder(64);
597+
598+
var result = new StringBuilder(64);
599+
600600
result.append('<')
601601
// We only url-encode the `>`. We expect other special chars to already be escaped. `;` and `,` need not
602602
// be escaped within the URL
603603
.append(href.replace(">", "%3e"))
604604
.append(">;rel=");
605+
605606
quoteParamValue(rel.value(), result);
606607

607608
if (hreflang != null) {
@@ -646,20 +647,26 @@ public String toString() {
646647
* Quotes the given string `s` and appends the result to the `target`. This method appends the start quote, the
647648
* escaped text, and the end quote.
648649
*
649-
* @param s Text to quote
650+
* @param s Text to quote
650651
* @param target StringBuilder to append to
651652
*/
652-
private void quoteParamValue(String s, StringBuilder target) {
653+
private static void quoteParamValue(String s, StringBuilder target) {
654+
653655
// we reserve extra 4 chars: two for the start and end quote, another two are a reserve for potential escaped chars
654656
target.ensureCapacity(target.length() + s.length() + 4);
655657
target.append('"');
658+
656659
for (int i = 0, l = s.length(); i < l; i++) {
660+
657661
char ch = s.charAt(i);
662+
658663
if (ch == '"' || ch == '\\') {
659664
target.append('\\');
660665
}
666+
661667
target.append(ch);
662668
}
669+
663670
target.append('"');
664671
}
665672

0 commit comments

Comments
 (0)