SafeHtmlString class
A string wrapped as an object of type {@link SafeHtml}.
This class is package-private and intended for internal use by the {@link com.google.gwt.safehtml} package.
All implementors must implement .equals and .hashCode so that they operate just like String.equals() and String.hashCode().
class SafeHtmlString implements SafeHtml {
String _html;
/**
* Constructs a {@link SafeHtmlString} from a string. Callers are responsible
* for ensuring that the string passed as the argument to this constructor
* satisfies the constraints of the contract imposed by the {@link SafeHtml}
* interface.
*
* @param html the string to be wrapped as a {@link SafeHtml}
*/
SafeHtmlString(String html) {
if (html == null) {
throw new Exception("html is null");
}
this._html = html;
}
// /**
// * No-arg constructor for compatibility with GWT serialization.
// */
// @SuppressWarnings("unused")
// private SafeHtmlString() {
// }
/**
* {@inheritDoc}
*/
String asString() {
return _html;
}
/**
* Compares this string to the specified object.
*/
bool operator ==(Object obj) {
if (!(obj is SafeHtml)) {
return false;
}
return _html == (obj as SafeHtml).asString();
}
/**
* Returns a hash code for this string.
*/
int get hashCode => _html.hashCode;
}
Implements
Constructors
new SafeHtmlString(String html) #
Constructs a {@link SafeHtmlString} from a string. Callers are responsible for ensuring that the string passed as the argument to this constructor satisfies the constraints of the contract imposed by the {@link SafeHtml} interface.
@param html the string to be wrapped as a {@link SafeHtml}
SafeHtmlString(String html) {
if (html == null) {
throw new Exception("html is null");
}
this._html = html;
}
Properties
final int hashCode #
Returns a hash code for this string.
int get hashCode => _html.hashCode;
Operators
bool operator ==(Object obj) #
Compares this string to the specified object.
bool operator ==(Object obj) {
if (!(obj is SafeHtml)) {
return false;
}
return _html == (obj as SafeHtml).asString();
}
Methods
String asString() #
{@inheritDoc}
String asString() {
return _html;
}