Android Open Source - Helpers Strings






From Project

Back to project page Helpers.

License

The source code is released under:

MIT License

If you think the Android project Helpers listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package at.wrdlbrnft.helpers;
/* ww w.  j av  a 2  s .  c  om*/

import android.widget.TextView;

import java.util.Collection;
import java.util.List;

/**
 * Created with Android Studio.
 * User: Xaver
 * Date: 29.06.13
 * Time: 02:18
 */
public class Strings {

    public static final String EMPTY = "";

    public static <T> String format(String separator, List<T> list) {
        if (list == null) {
            return "";
        }

        StringBuilder builder = new StringBuilder();
        int formattedCount = 0;
        for (T item : list) {
            if (item == null) {
                continue;
            }

            if (formattedCount > 0) {
                builder.append(separator);
            }
            builder.append(item.toString());
            formattedCount++;
        }
        return builder.toString();
    }

    public static String format(String separator, Object... list) {
        if (list == null) {
            return "";
        }

        StringBuilder builder = new StringBuilder();
        int formattedCount = 0;
        for (Object obj : list) {
            if (obj == null) {
                continue;
            }

            if (formattedCount > 0) {
                builder.append(separator);
            }
            builder.append(obj.toString());
            formattedCount++;
        }
        return builder.toString();
    }

    public static String trim(String string) {
        if(string != null) {
            return string.trim();
        }
        return null;
    }

    public static <T> String[] toArray(T[] array) {
        if(array == null) {
            return null;
        }

        final int count = array.length;
        final String[] output = new String[count];
        for(int i = 0; i < count; i++) {
            output[i] = String.valueOf(array[i]);
        }
        return output;
    }

    public static <T> String[] toArray(Collection<T> collection) {
        if(collection == null) {
            return null;
        }

        final int count = collection.size();
        final String[] output = new String[count];

        int i = 0;
        for (T item : collection) {
            output[i++] = String.valueOf(item);
        }
        return output;
    }

    public static String[] array(Object... objects) {
        if(objects == null) {
            return new String[0];
        }

        final int count = objects.length;
        final String[] output = new String[count];
        for(int i = 0; i < count; i++) {
            output[i] = String.valueOf(objects[i]);
        }

        return output;
    }

    public static String from(TextView textView) {
        if(textView != null) {
            return String.valueOf(textView.getText());
        }
        return "";
    }

    public static boolean nullOrEmpty(String string) {
        return string == null || string.isEmpty();

    }

    public static boolean notNullOrEmpty(String string) {
        return string != null && !string.isEmpty();

    }
}




Java Source Code List

at.wrdlbrnft.helpers.ApplicationTest.java
at.wrdlbrnft.helpers.AssetHelper.java
at.wrdlbrnft.helpers.Base64Coder.java
at.wrdlbrnft.helpers.BitHelper.java
at.wrdlbrnft.helpers.BitmapHelper.java
at.wrdlbrnft.helpers.Bundles.java
at.wrdlbrnft.helpers.CanvasHelper.java
at.wrdlbrnft.helpers.Container.java
at.wrdlbrnft.helpers.Containers.java
at.wrdlbrnft.helpers.Dates.java
at.wrdlbrnft.helpers.ExtrasBuilder.java
at.wrdlbrnft.helpers.IntentHelper.java
at.wrdlbrnft.helpers.LayoutHelper.java
at.wrdlbrnft.helpers.LogHelper.java
at.wrdlbrnft.helpers.Maps.java
at.wrdlbrnft.helpers.NetworkHelper.java
at.wrdlbrnft.helpers.Numbers.java
at.wrdlbrnft.helpers.PackageHelper.java
at.wrdlbrnft.helpers.ReflectionHelper.java
at.wrdlbrnft.helpers.SerializationHelper.java
at.wrdlbrnft.helpers.Sets.java
at.wrdlbrnft.helpers.StreamHelper.java
at.wrdlbrnft.helpers.Strings.java
at.wrdlbrnft.helpers.TypeHelper.java
at.wrdlbrnft.helpers.ViewHelper.java
at.wrdlbrnft.helpers.credentials.CredentialsFactory.java
at.wrdlbrnft.helpers.credentials.Credentials.java
at.wrdlbrnft.helpers.lists.Difference.java
at.wrdlbrnft.helpers.lists.Lists.java
at.wrdlbrnft.helpers.lists.UniqueIdProvider.java
at.wrdlbrnft.helpers.lists.UpdateInfo.java
at.wrdlbrnft.helpers.lists.UpdateValueContainer.java
at.wrdlbrnft.helpers.time.Time.java
at.wrdlbrnft.helpers.time.Times.java