forked from datahub-project/datahub
-
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.
fix(uri): marks uri field as deprecated, removes problem code, and ad…
…ds coercer for usages of URI typeref (datahub-project#7093)
- Loading branch information
1 parent
6de7507
commit 3c31c6b
Showing
4 changed files
with
58 additions
and
3 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
38 changes: 38 additions & 0 deletions
38
li-utils/src/main/javaPegasus/com/linkedin/common/uri/Uri.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,38 @@ | ||
package com.linkedin.common.uri; | ||
|
||
import java.net.URI; | ||
import java.net.URISyntaxException; | ||
|
||
public class Uri { | ||
private final String _uri; | ||
|
||
public Uri(String url) { | ||
if (url == null) { | ||
throw new NullPointerException("URL must be non-null"); | ||
} | ||
_uri = url; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return _uri; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object obj) { | ||
if (!(obj instanceof Uri)) { | ||
return false; | ||
} else { | ||
return _uri.equals(((Uri) obj)._uri); | ||
} | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return _uri.hashCode(); | ||
} | ||
|
||
public URI toURI() throws URISyntaxException { | ||
return new URI(_uri); | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
li-utils/src/main/javaPegasus/com/linkedin/common/uri/UriCoercer.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,19 @@ | ||
package com.linkedin.common.uri; | ||
|
||
import com.linkedin.data.template.Custom; | ||
import com.linkedin.data.template.DirectCoercer; | ||
import com.linkedin.data.template.TemplateOutputCastException; | ||
|
||
public class UriCoercer implements DirectCoercer<Uri> { | ||
private static final boolean REGISTER_COERCER = Custom.registerCoercer(new UriCoercer(), Uri.class); | ||
|
||
@Override | ||
public Object coerceInput(Uri object) throws ClassCastException { | ||
return object.toString(); | ||
} | ||
|
||
@Override | ||
public Uri coerceOutput(Object object) throws TemplateOutputCastException { | ||
return new Uri((String) object); | ||
} | ||
} |
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