forked from Azure/azure-sdk-for-java
-
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.
Add UrlTokenizer and make UrlBuilder use it (Azure#316)
- Loading branch information
Dan Schulte
authored
Dec 6, 2017
1 parent
f9f781c
commit 482df1b
Showing
6 changed files
with
772 additions
and
102 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
76 changes: 76 additions & 0 deletions
76
client-runtime/src/main/java/com/microsoft/rest/v2/http/UrlToken.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,76 @@ | ||
/** | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. See License.txt in the project root for | ||
* license information. | ||
*/ | ||
|
||
package com.microsoft.rest.v2.http; | ||
|
||
class UrlToken { | ||
private final String text; | ||
private final Type type; | ||
|
||
UrlToken(String text, Type type) { | ||
this.text = text; | ||
this.type = type; | ||
} | ||
|
||
String text() { | ||
return text; | ||
} | ||
|
||
Type type() { | ||
return type; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object rhs) { | ||
return rhs instanceof UrlToken && equals((UrlToken) rhs); | ||
} | ||
|
||
public boolean equals(UrlToken rhs) { | ||
return rhs != null && text.equals(rhs.text) && type == rhs.type; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "\"" + text + "\" (" + type + ")"; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return (text == null ? 0 : text.hashCode()) ^ type.hashCode(); | ||
} | ||
|
||
static UrlToken scheme(String text) { | ||
return new UrlToken(text, Type.SCHEME); | ||
} | ||
|
||
static UrlToken host(String text) { | ||
return new UrlToken(text, Type.HOST); | ||
} | ||
|
||
static UrlToken port(String text) { | ||
return new UrlToken(text, Type.PORT); | ||
} | ||
|
||
static UrlToken path(String text) { | ||
return new UrlToken(text, Type.PATH); | ||
} | ||
|
||
static UrlToken query(String text) { | ||
return new UrlToken(text, Type.QUERY); | ||
} | ||
|
||
enum Type { | ||
SCHEME, | ||
|
||
HOST, | ||
|
||
PORT, | ||
|
||
PATH, | ||
|
||
QUERY, | ||
} | ||
} |
Oops, something went wrong.