Repository navigation
Expand file tree
/
Copy pathHUri.java
More file actions
71 lines (61 loc) · 1.57 KB
/
Copy pathHUri.java
File metadata and controls
71 lines (61 loc) · 1.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
//
// Copyright (c) 2011, Brian Frank
// Licensed under the Academic Free License version 3.0
//
// History:
// 09 Jun 2011 Brian Frank Creation
//
package org.projecthaystack;
/**
* HUri models a URI as a string.
*
* @see <a href='http://project-haystack.org/doc/TagModel#tagKinds'>Project Haystack</a>
*/
public class HUri extends HVal
{
/** Construct from string value */
public static HUri make(String val)
{
if (val.length() == 0) return EMPTY;
return new HUri(val);
}
/** Singleton value for empty URI */
private static final HUri EMPTY = new HUri("");
/** Private constructor */
private HUri(String val) { this.val = val; }
/** String value of URI */
public final String val;
/** Hash code is based on string value */
public int hashCode() { return val.hashCode(); }
/** Equals is based on string value */
public boolean equals(Object that)
{
if (!(that instanceof HUri)) return false;
return this.val.equals(((HUri)that).val);
}
/** Return value string. */
public String toString()
{
return val;
}
/** Encode as {@code "u:<val>"} */
public String toJson()
{
return "u:" + val;
}
/** Encode using "`" back ticks */
public String toZinc()
{
StringBuffer s = new StringBuffer();
s.append('`');
for (int i=0; i<val.length(); ++i)
{
int c = val.charAt(i);
if (c < ' ') throw new IllegalArgumentException("Invalid URI char '" + val + "', char='" + (char)c + "'");
if (c == '`') s.append('\\');
s.append((char)c);
}
s.append('`');
return s.toString();
}
}