/** * Returns true if CharSequence is not null and is not empty, false otherwise. * Examples: * isNotEmpty(null) - false * isNotEmpty("") - false * isNotEmpty(" ") - true * isNotEmpty("empty") - true * * @param cs checked CharSequence * @return true if string is not null and is not empty, false otherwise */ public static boolean isNotEmpty(CharSequence cs) { return !isNullOrEmpty(cs); }
/** * Returns true if all given CharSequences are not empty. * * @param css the CharSequences to test. * @return true if all given CharSequences are not empty. */ public static boolean isNotEmpty(CharSequence... css) { for (CharSequence cs : css) { if (StringUtils.isNullOrEmpty(cs)) { return false; } } return true; }
public StableAndUniqueIdElement(String id) { if (StringUtils.isNullOrEmpty(id)) { throw new IllegalArgumentException("Argument 'id' cannot be null or empty."); } this.id = id; } }
public AlternativeSession(String sessionId) { super(Reason.alternative_session); if (StringUtils.isNullOrEmpty(sessionId)) { throw new NullPointerException("SessionID must not be null or empty."); } this.sessionId = sessionId; }
private static void validate(String elementName, String namespace) { if (StringUtils.isNullOrEmpty(elementName)) { throw new IllegalArgumentException("elementName must not be null or empty"); } if (StringUtils.isNullOrEmpty(namespace)) { throw new IllegalArgumentException("namespace must not be null or empty"); } } }
/** * Require a {@link CharSequence} to be neither null, nor empty. * * @param cs CharSequence * @param message error message * @param <CS> CharSequence type * @return cs */ public static <CS extends CharSequence> CS requireNotNullNorEmpty(CS cs, String message) { if (isNullOrEmpty(cs)) { throw new IllegalArgumentException(message); } return cs; }
public static String getRequiredAttribute(XmlPullParser parser, String name) throws IOException { String value = parser.getAttributeValue("", name); if (StringUtils.isNullOrEmpty(value)) { throw new IOException("Attribute " + name + " is null or empty (" + value + ')'); } return value; }
public static NodeInfo parse(XmlPullParser parser) { String nodeId = parser.getAttributeValue(null, "nodeId"); String sourceId = parser.getAttributeValue(null, "sourceId"); String cacheType = parser.getAttributeValue(null, "cacheType"); if (isNullOrEmpty(nodeId) && isNullOrEmpty(sourceId) && isNullOrEmpty(cacheType)) { return NodeInfo.EMPTY; } return new NodeInfo(nodeId, sourceId, cacheType); } }
public StreamError(Condition condition, String conditionText, Map<String, String> descriptiveTexts, List<ExtensionElement> extensions) { super(descriptiveTexts, extensions); // Some implementations may send the condition as non-empty element containing the empty string, that is // <condition xmlns='foo'></condition>, in this case the parser may calls this constructor with the empty string // as conditionText, therefore reset it to null if it's the empty string if (StringUtils.isNullOrEmpty(conditionText)) { conditionText = null; } if (conditionText != null) { switch (condition) { case see_other_host: break; default: throw new IllegalArgumentException("The given condition '" + condition + "' can not contain a conditionText"); } } this.condition = condition; this.conditionText = conditionText; }
private OnceForThisStanza(XMPPTCPConnection connection, Stanza packet) { this.connection = connection; this.id = packet.getStanzaId(); if (StringUtils.isNullOrEmpty(id)) { throw new IllegalArgumentException("Stanza ID must be set"); } }
public static String getRequiredNextText(XmlPullParser parser) throws XmlPullParserException, IOException { String text = parser.nextText(); if (StringUtils.isNullOrEmpty(text)) { throw new IOException("Next text is null or empty (" + text + ')'); } return text; }
public XmlStringBuilder optXmlLangAttribute(String lang) { if (!StringUtils.isNullOrEmpty(lang)) { xmllangAttribute(lang); } return this; }
public static ItemType fromString(String string) { if (StringUtils.isNullOrEmpty(string)) { return none; } return ItemType.valueOf(string.toLowerCase(Locale.US)); }
/** * Create a new SpoilerElement with a hint about a content and a language attribute. * * @param language language of the hint. * @param hint hint about the content. */ public SpoilerElement(String language, String hint) { if (StringUtils.isNotEmpty(language) && StringUtils.isNullOrEmpty(hint)) { throw new IllegalArgumentException("Hint cannot be null or empty if language is not empty."); } this.language = language; this.hint = hint; }
@Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append("Presence Stanza ["); logCommonAttributes(sb); sb.append("type=").append(type).append(','); if (mode != null) { sb.append("mode=").append(mode).append(','); } if (!StringUtils.isNullOrEmpty(status)) { sb.append("status=").append(status).append(','); } if (priority != Integer.MIN_VALUE) { sb.append("prio=").append(priority).append(','); } sb.append(']'); return sb.toString(); }
@Override public boolean accept(Stanza packet) { String otherId = packet.getStanzaId(); if (StringUtils.isNullOrEmpty(otherId)) { return false; } if (id.equals(otherId)) { connection.removeRequestAckPredicate(this); return true; } return false; }
@Override protected byte[] getAuthenticationText() throws SmackException { if (authorizationId != null) { return toBytes(authorizationId.toString()); } if (StringUtils.isNullOrEmpty(authenticationId)) { return null; } return toBytes(XmppStringUtils.completeJidFrom(authenticationId, serviceName)); }
/** * Answer the active privacy list. Returns <code>null</code> if there is no active list. * * @return the privacy list of the active list. * @throws XMPPErrorException * @throws NoResponseException * @throws NotConnectedException * @throws InterruptedException */ public PrivacyList getActiveList() throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { Privacy privacyAnswer = this.getPrivacyWithListNames(); String listName = privacyAnswer.getActiveName(); if (StringUtils.isNullOrEmpty(listName)) { return null; } boolean isDefaultAndActive = listName != null && listName.equals(privacyAnswer.getDefaultName()); return new PrivacyList(true, isDefaultAndActive, listName, getPrivacyListItems(listName)); }
/** * Answer the default privacy list. Returns <code>null</code> if there is no default list. * * @return the privacy list of the default list. * @throws XMPPErrorException * @throws NoResponseException * @throws NotConnectedException * @throws InterruptedException */ public PrivacyList getDefaultList() throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { Privacy privacyAnswer = this.getPrivacyWithListNames(); String listName = privacyAnswer.getDefaultName(); if (StringUtils.isNullOrEmpty(listName)) { return null; } boolean isDefaultAndActive = listName.equals(privacyAnswer.getActiveName()); return new PrivacyList(isDefaultAndActive, true, listName, getPrivacyListItems(listName)); }
/** * Create and return a new message including a delivery receipt extension for the given message. * <p> * If {@code messageWithReceiptRequest} does not have a Stanza ID set, then {@code null} will be returned. * </p> * * @param messageWithReceiptRequest the given message with a receipt request extension. * @return a new message with a receipt or <code>null</code>. * @since 4.1 */ public static Message receiptMessageFor(Message messageWithReceiptRequest) { String stanzaId = messageWithReceiptRequest.getStanzaId(); if (StringUtils.isNullOrEmpty(stanzaId)) { return null; } Message message = new Message(messageWithReceiptRequest.getFrom(), messageWithReceiptRequest.getType()); message.addExtension(new DeliveryReceipt(stanzaId)); return message; } }