/**
 *
 * Copyright © 2014 Florian Schmaus
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.jxmpp.jid.parts;

public abstract class Part implements CharSequence {

	private final String part;

	protected Part(String part) {
		this.part = part;
	}

	@Override
	public final int length() {
		return part.length();
	}

	@Override
	public final char charAt(int index) {
		return part.charAt(index);
	}

	@Override
	public final CharSequence subSequence(int start, int end) {
		return part.subSequence(start, end);
	}

	@Override
	public final String toString() {
		return part;
	}

	@Override
	public final boolean equals(Object other) {
		if (this == other) {
			return true;
		}
		return part.equals(other.toString());
	}

	@Override
	public final int hashCode() {
		return part.hashCode();
	}

	protected static void assertNotLongerThen1023BytesOrEmpty(String string) {
		char[] bytes = string.toCharArray();
		if (bytes.length > 1023) {
			throw new IllegalArgumentException("Given string '" + string + "' is longer then 1023 bytes");
		} else if (bytes.length == 0) {
			throw new IllegalArgumentException("Argument can't be the empty string");
		}
	}
}

@@ -628,16 +628,70 @@
 parts;%0A%0A
+import org.jxmpp.stringprep.XmppStringprepException;%0A%0A
 public a
@@ -1438,16 +1438,47 @@
  string)
+ throws XmppStringprepException
  %7B%0A%09%09cha
@@ -1515,105 +1515,274 @@
 ();%0A
-%09%09if (bytes.length %3E 1023) %7B%0A%09%09%09throw new IllegalArgumentException(%22Given string '%22 +
+%0A%09%09// Better throw XmppStringprepException instead of IllegalArgumentException here, because users don't expect an%0A%09%09// IAE and it also makes the error handling for users easier.%0A%09%09if (bytes.length %3E 1023) %7B%0A%09%09%09throw new XmppStringprepException(string, %22Given
  string
- + %22'
  is 
@@ -1854,31 +1854,30 @@
 row new 
-IllegalArgument
+XmppStringprep
 Exceptio
@@ -1878,16 +1878,24 @@
 ception(
+string, 
 %22Argumen

Make assertNotLonger… throw XmppStringprepExcpetion