mirror of
https://github.com/vanitasvitae/Smack.git
synced 2024-11-20 11:02:05 +01:00
Delete ModelUtil in smack-legacy
and use StringUtils where possible.
This commit is contained in:
parent
0382581237
commit
f19ab5f9a4
5 changed files with 17 additions and 341 deletions
|
@ -17,9 +17,9 @@
|
|||
|
||||
package org.jivesoftware.smackx.workgroup.settings;
|
||||
|
||||
import org.jivesoftware.smackx.workgroup.util.ModelUtil;
|
||||
import org.jivesoftware.smack.packet.IQ;
|
||||
import org.jivesoftware.smack.provider.IQProvider;
|
||||
import org.jivesoftware.smack.util.StringUtils;
|
||||
import org.xmlpull.v1.XmlPullParser;
|
||||
import org.xmlpull.v1.XmlPullParserException;
|
||||
|
||||
|
@ -67,7 +67,7 @@ public class GenericSettings extends IQ {
|
|||
@Override
|
||||
protected IQChildElementXmlStringBuilder getIQChildElementBuilder(IQChildElementXmlStringBuilder buf) {
|
||||
buf.append('>');
|
||||
if (ModelUtil.hasLength(getQuery())) {
|
||||
if (StringUtils.isNotEmpty(getQuery())) {
|
||||
buf.append("<query>" + getQuery() + "</query>");
|
||||
}
|
||||
return buf;
|
||||
|
|
|
@ -19,9 +19,9 @@ package org.jivesoftware.smackx.workgroup.settings;
|
|||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.jivesoftware.smackx.workgroup.util.ModelUtil;
|
||||
import org.jivesoftware.smack.packet.SimpleIQ;
|
||||
import org.jivesoftware.smack.provider.IQProvider;
|
||||
import org.jivesoftware.smack.util.StringUtils;
|
||||
import org.xmlpull.v1.XmlPullParser;
|
||||
import org.xmlpull.v1.XmlPullParserException;
|
||||
|
||||
|
@ -33,7 +33,7 @@ public class OfflineSettings extends SimpleIQ {
|
|||
private String subject;
|
||||
|
||||
public String getRedirectURL() {
|
||||
if (!ModelUtil.hasLength(redirectURL)) {
|
||||
if (!StringUtils.isNotEmpty(redirectURL)) {
|
||||
return "";
|
||||
}
|
||||
return redirectURL;
|
||||
|
@ -44,7 +44,7 @@ public class OfflineSettings extends SimpleIQ {
|
|||
}
|
||||
|
||||
public String getOfflineText() {
|
||||
if (!ModelUtil.hasLength(offlineText)) {
|
||||
if (!StringUtils.isNotEmpty(offlineText)) {
|
||||
return "";
|
||||
}
|
||||
return offlineText;
|
||||
|
@ -55,7 +55,7 @@ public class OfflineSettings extends SimpleIQ {
|
|||
}
|
||||
|
||||
public String getEmailAddress() {
|
||||
if (!ModelUtil.hasLength(emailAddress)) {
|
||||
if (!StringUtils.isNotEmpty(emailAddress)) {
|
||||
return "";
|
||||
}
|
||||
return emailAddress;
|
||||
|
@ -66,7 +66,7 @@ public class OfflineSettings extends SimpleIQ {
|
|||
}
|
||||
|
||||
public String getSubject() {
|
||||
if (!ModelUtil.hasLength(subject)) {
|
||||
if (!StringUtils.isNotEmpty(subject)) {
|
||||
return "";
|
||||
}
|
||||
return subject;
|
||||
|
@ -77,13 +77,13 @@ public class OfflineSettings extends SimpleIQ {
|
|||
}
|
||||
|
||||
public boolean redirects() {
|
||||
return (ModelUtil.hasLength(getRedirectURL()));
|
||||
return (StringUtils.isNotEmpty(getRedirectURL()));
|
||||
}
|
||||
|
||||
public boolean isConfigured(){
|
||||
return ModelUtil.hasLength(getEmailAddress()) &&
|
||||
ModelUtil.hasLength(getSubject()) &&
|
||||
ModelUtil.hasLength(getOfflineText());
|
||||
return StringUtils.isNotEmpty(getEmailAddress()) &&
|
||||
StringUtils.isNotEmpty(getSubject()) &&
|
||||
StringUtils.isNotEmpty(getOfflineText());
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -18,9 +18,9 @@ package org.jivesoftware.smackx.workgroup.settings;
|
|||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.jivesoftware.smackx.workgroup.util.ModelUtil;
|
||||
import org.jivesoftware.smack.packet.SimpleIQ;
|
||||
import org.jivesoftware.smack.provider.IQProvider;
|
||||
import org.jivesoftware.smack.util.StringUtils;
|
||||
import org.xmlpull.v1.XmlPullParser;
|
||||
import org.xmlpull.v1.XmlPullParserException;
|
||||
|
||||
|
@ -29,7 +29,7 @@ public class SearchSettings extends SimpleIQ {
|
|||
private String kbLocation;
|
||||
|
||||
public boolean isSearchEnabled() {
|
||||
return ModelUtil.hasLength(getForumsLocation()) && ModelUtil.hasLength(getKbLocation());
|
||||
return StringUtils.isNotEmpty(getForumsLocation()) && StringUtils.isNotEmpty(getKbLocation());
|
||||
}
|
||||
|
||||
public String getForumsLocation() {
|
||||
|
@ -49,11 +49,11 @@ public class SearchSettings extends SimpleIQ {
|
|||
}
|
||||
|
||||
public boolean hasKB(){
|
||||
return ModelUtil.hasLength(getKbLocation());
|
||||
return StringUtils.isNotEmpty(getKbLocation());
|
||||
}
|
||||
|
||||
public boolean hasForums(){
|
||||
return ModelUtil.hasLength(getForumsLocation());
|
||||
return StringUtils.isNotEmpty(getForumsLocation());
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -19,9 +19,9 @@ package org.jivesoftware.smackx.workgroup.settings;
|
|||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.jivesoftware.smackx.workgroup.util.ModelUtil;
|
||||
import org.jivesoftware.smack.packet.IQ;
|
||||
import org.jivesoftware.smack.provider.IQProvider;
|
||||
import org.jivesoftware.smack.util.StringUtils;
|
||||
import org.xmlpull.v1.XmlPullParser;
|
||||
import org.xmlpull.v1.XmlPullParserException;
|
||||
|
||||
|
@ -81,7 +81,7 @@ public class WorkgroupProperties extends IQ {
|
|||
|
||||
@Override
|
||||
protected IQChildElementXmlStringBuilder getIQChildElementBuilder(IQChildElementXmlStringBuilder buf) {
|
||||
if (ModelUtil.hasLength(getJid())) {
|
||||
if (StringUtils.isNotEmpty(getJid())) {
|
||||
buf.append("jid=\"" + getJid() + "\" ");
|
||||
}
|
||||
buf.setEmptyElement();
|
||||
|
|
|
@ -1,324 +0,0 @@
|
|||
/**
|
||||
*
|
||||
* Copyright 2003-2007 Jive Software.
|
||||
*
|
||||
* 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.jivesoftware.smackx.workgroup.util;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.ListIterator;
|
||||
|
||||
/**
|
||||
* Utility methods frequently used by data classes and design-time
|
||||
* classes.
|
||||
*/
|
||||
public final class ModelUtil {
|
||||
private ModelUtil() {
|
||||
// Prevents instantiation.
|
||||
}
|
||||
|
||||
/**
|
||||
* This is a utility method that compares two objects when one or
|
||||
* both of the objects might be <CODE>null</CODE> The result of
|
||||
* this method is determined as follows:
|
||||
* <OL>
|
||||
* <LI>If <CODE>o1</CODE> and <CODE>o2</CODE> are the same object
|
||||
* according to the <CODE>==</CODE> operator, return
|
||||
* <CODE>true</CODE>.
|
||||
* <LI>Otherwise, if either <CODE>o1</CODE> or <CODE>o2</CODE> is
|
||||
* <CODE>null</CODE>, return <CODE>false</CODE>.
|
||||
* <LI>Otherwise, return <CODE>o1.equals(o2)</CODE>.
|
||||
* </OL>
|
||||
* <p/>
|
||||
* This method produces the exact logically inverted result as the
|
||||
* {@link #areDifferent(Object, Object)} method.<P>
|
||||
* <p/>
|
||||
* For array types, one of the <CODE>equals</CODE> methods in
|
||||
* {@link java.util.Arrays} should be used instead of this method.
|
||||
* Note that arrays with more than one dimension will require some
|
||||
* custom code in order to implement <CODE>equals</CODE> properly.
|
||||
*/
|
||||
public static final boolean areEqual(Object o1, Object o2) {
|
||||
if (o1 == o2) {
|
||||
return true;
|
||||
}
|
||||
else if (o1 == null || o2 == null) {
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
return o1.equals(o2);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This is a utility method that compares two Booleans when one or
|
||||
* both of the objects might be <CODE>null</CODE> The result of
|
||||
* this method is determined as follows:
|
||||
* <OL>
|
||||
* <LI>If <CODE>b1</CODE> and <CODE>b2</CODE> are both TRUE or
|
||||
* neither <CODE>b1</CODE> nor <CODE>b2</CODE> is TRUE,
|
||||
* return <CODE>true</CODE>.
|
||||
* <LI>Otherwise, return <CODE>false</CODE>.
|
||||
* </OL>
|
||||
* <p/>
|
||||
*/
|
||||
public static final boolean areBooleansEqual(Boolean b1, Boolean b2) {
|
||||
// !jwetherb treat NULL the same as Boolean.FALSE
|
||||
return (b1 == Boolean.TRUE && b2 == Boolean.TRUE) ||
|
||||
(b1 != Boolean.TRUE && b2 != Boolean.TRUE);
|
||||
}
|
||||
|
||||
/**
|
||||
* This is a utility method that compares two objects when one or
|
||||
* both of the objects might be <CODE>null</CODE>. The result
|
||||
* returned by this method is determined as follows:
|
||||
* <OL>
|
||||
* <LI>If <CODE>o1</CODE> and <CODE>o2</CODE> are the same object
|
||||
* according to the <CODE>==</CODE> operator, return
|
||||
* <CODE>false</CODE>.
|
||||
* <LI>Otherwise, if either <CODE>o1</CODE> or <CODE>o2</CODE> is
|
||||
* <CODE>null</CODE>, return <CODE>true</CODE>.
|
||||
* <LI>Otherwise, return <CODE>!o1.equals(o2)</CODE>.
|
||||
* </OL>
|
||||
* <p/>
|
||||
* This method produces the exact logically inverted result as the
|
||||
* {@link #areEqual(Object, Object)} method.<P>
|
||||
* <p/>
|
||||
* For array types, one of the <CODE>equals</CODE> methods in
|
||||
* {@link java.util.Arrays} should be used instead of this method.
|
||||
* Note that arrays with more than one dimension will require some
|
||||
* custom code in order to implement <CODE>equals</CODE> properly.
|
||||
*/
|
||||
public static final boolean areDifferent(Object o1, Object o2) {
|
||||
return !areEqual(o1, o2);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* This is a utility method that compares two Booleans when one or
|
||||
* both of the objects might be <CODE>null</CODE> The result of
|
||||
* this method is determined as follows:
|
||||
* <OL>
|
||||
* <LI>If <CODE>b1</CODE> and <CODE>b2</CODE> are both TRUE or
|
||||
* neither <CODE>b1</CODE> nor <CODE>b2</CODE> is TRUE,
|
||||
* return <CODE>false</CODE>.
|
||||
* <LI>Otherwise, return <CODE>true</CODE>.
|
||||
* </OL>
|
||||
* <p/>
|
||||
* This method produces the exact logically inverted result as the
|
||||
* {@link #areBooleansEqual(Boolean, Boolean)} method.<P>
|
||||
*/
|
||||
public static final boolean areBooleansDifferent(Boolean b1, Boolean b2) {
|
||||
return !areBooleansEqual(b1, b2);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns <CODE>true</CODE> if the specified array is not null
|
||||
* and contains a non-null element. Returns <CODE>false</CODE>
|
||||
* if the array is null or if all the array elements are null.
|
||||
*/
|
||||
public static final boolean hasNonNullElement(Object[] array) {
|
||||
if (array != null) {
|
||||
final int n = array.length;
|
||||
for (int i = 0; i < n; i++) {
|
||||
if (array[i] != null) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a single string that is the concatenation of all the
|
||||
* strings in the specified string array. A single space is
|
||||
* put between each string array element. Null array elements
|
||||
* are skipped. If the array itself is null, the empty string
|
||||
* is returned. This method is guaranteed to return a non-null
|
||||
* value, if no expections are thrown.
|
||||
*/
|
||||
public static final String concat(String[] strs) {
|
||||
return concat(strs, " "); //NOTRANS
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a single string that is the concatenation of all the
|
||||
* strings in the specified string array. The strings are separated
|
||||
* by the specified delimiter. Null array elements are skipped. If
|
||||
* the array itself is null, the empty string is returned. This
|
||||
* method is guaranteed to return a non-null value, if no expections
|
||||
* are thrown.
|
||||
*/
|
||||
public static final String concat(String[] strs, String delim) {
|
||||
if (strs != null) {
|
||||
final StringBuilder buf = new StringBuilder();
|
||||
final int n = strs.length;
|
||||
for (int i = 0; i < n; i++) {
|
||||
final String str = strs[i];
|
||||
if (str != null) {
|
||||
buf.append(str).append(delim);
|
||||
}
|
||||
}
|
||||
final int length = buf.length();
|
||||
if (length > 0) {
|
||||
// Trim trailing space.
|
||||
buf.setLength(length - 1);
|
||||
}
|
||||
return buf.toString();
|
||||
}
|
||||
else {
|
||||
return ""; // NOTRANS
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns <CODE>true</CODE> if the specified {@link String} is not
|
||||
* <CODE>null</CODE> and has a length greater than zero. This is
|
||||
* a very frequently occurring check.
|
||||
*/
|
||||
public static final boolean hasLength(String s) {
|
||||
return (s != null && s.length() > 0);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns <CODE>null</CODE> if the specified string is empty or
|
||||
* <CODE>null</CODE>. Otherwise the string itself is returned.
|
||||
*/
|
||||
public static final String nullifyIfEmpty(String s) {
|
||||
return ModelUtil.hasLength(s) ? s : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns <CODE>null</CODE> if the specified object is null
|
||||
* or if its <CODE>toString()</CODE> representation is empty.
|
||||
* Otherwise, the <CODE>toString()</CODE> representation of the
|
||||
* object itself is returned.
|
||||
*/
|
||||
public static final String nullifyingToString(Object o) {
|
||||
return o != null ? nullifyIfEmpty(o.toString()) : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if a string has been changed.
|
||||
*
|
||||
* @param oldString is the initial value of the String
|
||||
* @param newString is the new value of the String
|
||||
* @return true If both oldString and newString are null or if they are
|
||||
* both not null and equal to each other. Otherwise returns false.
|
||||
*/
|
||||
public static boolean hasStringChanged(String oldString, String newString) {
|
||||
if (oldString == null && newString == null) {
|
||||
return false;
|
||||
}
|
||||
else if ((oldString == null && newString != null)
|
||||
|| (oldString != null && newString == null)) {
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
return !oldString.equals(newString);
|
||||
}
|
||||
}
|
||||
|
||||
public static String getTimeFromLong(long diff) {
|
||||
final String HOURS = "h";
|
||||
final String MINUTES = "min";
|
||||
final String SECONDS = "sec";
|
||||
|
||||
final long MS_IN_A_DAY = 1000 * 60 * 60 * 24;
|
||||
final long MS_IN_AN_HOUR = 1000 * 60 * 60;
|
||||
final long MS_IN_A_MINUTE = 1000 * 60;
|
||||
final long MS_IN_A_SECOND = 1000;
|
||||
diff = diff % MS_IN_A_DAY;
|
||||
long numHours = diff / MS_IN_AN_HOUR;
|
||||
diff = diff % MS_IN_AN_HOUR;
|
||||
long numMinutes = diff / MS_IN_A_MINUTE;
|
||||
diff = diff % MS_IN_A_MINUTE;
|
||||
long numSeconds = diff / MS_IN_A_SECOND;
|
||||
diff = diff % MS_IN_A_SECOND;
|
||||
|
||||
StringBuilder buf = new StringBuilder();
|
||||
if (numHours > 0) {
|
||||
buf.append(numHours + " " + HOURS + ", ");
|
||||
}
|
||||
|
||||
if (numMinutes > 0) {
|
||||
buf.append(numMinutes + " " + MINUTES + ", ");
|
||||
}
|
||||
|
||||
buf.append(numSeconds + " " + SECONDS);
|
||||
|
||||
String result = buf.toString();
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Build a List of all elements in an Iterator.
|
||||
*/
|
||||
public static <T> List<T> iteratorAsList(Iterator<T> i) {
|
||||
ArrayList<T> list = new ArrayList<T>(10);
|
||||
while (i.hasNext()) {
|
||||
list.add(i.next());
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an Iterator that is the reverse of a ListIterator.
|
||||
*/
|
||||
public static <T> Iterator<T> reverseListIterator(ListIterator<T> i) {
|
||||
return new ReverseListIterator<T>(i);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* An Iterator that is the reverse of a ListIterator.
|
||||
*/
|
||||
class ReverseListIterator<T> implements Iterator<T> {
|
||||
private ListIterator<T> _i;
|
||||
|
||||
ReverseListIterator(ListIterator<T> i) {
|
||||
_i = i;
|
||||
while (_i.hasNext())
|
||||
_i.next();
|
||||
}
|
||||
|
||||
public boolean hasNext() {
|
||||
return _i.hasPrevious();
|
||||
}
|
||||
|
||||
public T next() {
|
||||
return _i.previous();
|
||||
}
|
||||
|
||||
public void remove() {
|
||||
_i.remove();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
Loading…
Reference in a new issue