/**
 *
 * 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.impl;

import org.jxmpp.jid.BareJid;
import org.jxmpp.jid.FullJid;
import org.jxmpp.stringprep.XmppStringPrepUtil;
import org.jxmpp.stringprep.XmppStringprepException;
import org.jxmpp.util.XmppStringUtils;


public class LocalDomainAndResourcepartJid extends LocalAndDomainpartJid implements FullJid {

	private final String resource;

	private String cache;
	private String unescapedCache;

	public LocalDomainAndResourcepartJid(String localpart, String domain, String resource) throws XmppStringprepException {
		super(localpart, domain);
		resource = XmppStringPrepUtil.resourceprep(resource);
		assertNotLongerThen1023BytesOrEmpty(resource);
		this.resource = resource;
	}

	public final String getResource() {
		return resource;
	}

	@Override
	public String toString() {
		if (cache != null) {
			return cache;
		}
		cache = super.toString() + '/' + resource;
		return cache;
	}

	@Override
	public String asUnescapedString() {
		if (unescapedCache != null) {
			return unescapedCache;
		}
		unescapedCache = super.asUnescapedString() + '@' + super.toString();
		return unescapedCache;
	}

	@Override
	public boolean isBareJid() {
		return false;
	}

	@Override
	public boolean isFullJid() {
		return true;
	}

	@Override
	public boolean hasOnlyDomainpart() {
		return false;
	}

	@Override
	public boolean hasResource() {
		return true;
	}

	@Override
	public boolean hasLocalpart() {
		return true;
	}

	@Override
	public BareJid asBareJid() {
		try {
			return JidCreate.bareFrom(XmppStringUtils.completeJidFrom(localpart, domain));
		} catch (XmppStringprepException e) {
			throw new IllegalStateException(e);
		}
	}
}

@@ -1011,16 +1011,47 @@
 edCache;
+%0A%09private BareJid bareJidCache;
 %0A%0A%09publi
@@ -2110,23 +2110,63 @@
 %7B%0A%09%09
-try %7B%0A%09%09%09return
+if (bareJidCache == null) %7B%0A%09%09%09try %7B%0A%09%09%09%09bareJidCache =
  Jid
@@ -2196,16 +2196,23 @@
 ingUtils
+%0A%09%09%09%09%09%09
 .complet
@@ -2241,16 +2241,17 @@
 main));%0A
+%09
 %09%09%7D catc
@@ -2278,24 +2278,25 @@
 eption e) %7B%0A
+%09
 %09%09%09throw new
@@ -2324,15 +2324,43 @@
 n(e);%0A%09%09
-%7D
+%09%7D%0A%09%09%7D%0A%09%09return bareJidCache;
 %0A%09%7D%0A%7D%0A

Add bareJidCache