InvalidJid.java

  1/*
  2 * Copyright (c) 2018, Daniel Gultsch All rights reserved.
  3 *
  4 * Redistribution and use in source and binary forms, with or without modification,
  5 * are permitted provided that the following conditions are met:
  6 *
  7 * 1. Redistributions of source code must retain the above copyright notice, this
  8 * list of conditions and the following disclaimer.
  9 *
 10 * 2. Redistributions in binary form must reproduce the above copyright notice,
 11 * this list of conditions and the following disclaimer in the documentation and/or
 12 * other materials provided with the distribution.
 13 *
 14 * 3. Neither the name of the copyright holder nor the names of its contributors
 15 * may be used to endorse or promote products derived from this software without
 16 * specific prior written permission.
 17 *
 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
 19 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 20 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 21 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
 22 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 23 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 24 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
 25 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 27 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 28 */
 29
 30package eu.siacs.conversations.xmpp;
 31
 32import android.support.annotation.NonNull;
 33
 34import rocks.xmpp.addr.Jid;
 35
 36public class InvalidJid implements Jid {
 37
 38	private final String value;
 39
 40	public InvalidJid(String jid) {
 41		this.value = jid;
 42	}
 43
 44	@Override
 45	@NonNull
 46	public String toString() {
 47		return value;
 48	}
 49
 50	@Override
 51	public boolean isFullJid() {
 52		throw new AssertionError("Not implemented");
 53	}
 54
 55	@Override
 56	public boolean isBareJid() {
 57		throw new AssertionError("Not implemented");
 58	}
 59
 60	@Override
 61	public Jid asBareJid() {
 62		throw new AssertionError("Not implemented");
 63	}
 64
 65	@Override
 66	public Jid withLocal(CharSequence charSequence) {
 67		throw new AssertionError("Not implemented");
 68	}
 69
 70	@Override
 71	public Jid withResource(CharSequence charSequence) {
 72		throw new AssertionError("Not implemented");
 73	}
 74
 75	@Override
 76	public Jid atSubdomain(CharSequence charSequence) {
 77		throw new AssertionError("Not implemented");
 78	}
 79
 80	@Override
 81	public String getLocal() {
 82		throw new AssertionError("Not implemented");
 83	}
 84
 85	@Override
 86	public String getEscapedLocal() {
 87		throw new AssertionError("Not implemented");
 88	}
 89
 90	@Override
 91	public String getDomain() {
 92		throw new AssertionError("Not implemented");
 93	}
 94
 95	@Override
 96	public String getResource() {
 97		throw new AssertionError("Not implemented");
 98	}
 99
100	@Override
101	public String toEscapedString() {
102		throw new AssertionError("Not implemented");
103	}
104
105	@Override
106	public int length() {
107		return value.length();
108	}
109
110	@Override
111	public char charAt(int index) {
112		return value.charAt(index);
113	}
114
115	@Override
116	public CharSequence subSequence(int start, int end) {
117		return value.subSequence(start, end);
118	}
119
120	@Override
121	public int compareTo(@NonNull Jid o) {
122		throw new AssertionError("Not implemented");
123	}
124
125	public static Jid getNullForInvalid(Jid jid) {
126		if (jid != null && jid instanceof InvalidJid) {
127			return null;
128		} else {
129			return jid;
130		}
131	}
132
133	public static boolean isValid(Jid jid) {
134		if (jid != null && jid instanceof InvalidJid) {
135			return false;
136		} else {
137			return true;
138		}
139	}
140}