Android Open Source - baracus-framework String Util






From Project

Back to project page baracus-framework.

License

The source code is released under:

Apache License

If you think the Android project baracus-framework 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 net.mantucon.baracus.util;
/*w  w  w . j  a  v a  2s .  c  om*/
import android.text.format.DateFormat;
import android.widget.TextView;
import net.mantucon.baracus.context.BaracusApplicationContext;

import java.util.Date;

/**
 * Created with IntelliJ IDEA.
 * User: marcus
 * Date: 09.04.13
 * Time: 20:14
 * To change this template use File | Settings | File Templates.
 */
public class StringUtil {
    private StringUtil() {
    }

    public static String firstByteToLower(String instring) {
        return instring.substring(0, 1).toLowerCase() + instring.substring(1, instring.length());
    }

    /**
     * checks, if the passed TextView contains some text
     *
     * @param view - the TextView
     * @return true, if a non-null, non-blank string is found inside of the text view
     */
    public static boolean isEmpty(TextView view) {
        if (view != null && view.getText() != null) {
            return getString(view).length() == 0;
        }
        return false;
    }

    /**
     * extract the trimmed string value out of the passed TextView
     *
     * @param view - the view to read from
     * @return the trimmed string value from the view
     */
    public static String getString(TextView view) {
        return view.getText().toString().trim();
    }

    /**
     * extract an Integer out of a TextView
     *
     * @param view - the view to read from
     * @return the Integer value or NULL in case of a non-parseable String
     */
    public static Integer getNumber(TextView view) {
        Integer result;
        if (!isEmpty(view)) {
            try {
                result = Integer.parseInt(getString(view));
            } catch (Exception e) {
                result = null;
            }
        } else {
            result = null;
        }
        return result;
    }

    /**
     * extract an Double out of a TextView
     *
     * @param view - the view to read from
     * @return the Double value or NULL in case of a non-parseable String
     */
    public static Double getDouble(TextView view) {
        Double result;
        if (!isEmpty(view)) {
            try {
                result = Double.parseDouble(getString(view));
            } catch (Exception e) {
                result = null;
            }
        } else {
            result = null;
        }
        return result;
    }

    /**
     * make a one-sized array out of the passed string
     *
     * @param input - the string
     * @return an array sized 1 containing the string
     */
    public static String[] toArray(String input) {
        if (input != null && input.length() > 0) {
            String[] result = new String[1];
            result[0] = input;
            return result;
        } else {
            return new String[0];
        }
    }

    /**
     * make a comma seperated string out a passed list/set of strings
     *
     * @param strings - the string collection
     * @return the comma seperated string
     */
    public static String join(Iterable<String> strings) {
        StringBuilder builder = new StringBuilder();
        for (String s : strings) {
            builder.append(s).append(", ");
        }
        String result = builder.toString();
        return result.substring(1, result.length() - 2);
    }

    /**
     * split a string into an array and trim the strings
     *
     * @param s     - the string to split
     * @param delim - the delimiter
     * @return - the array containing all strings trimmed
     */
    public static String[] splitPurified(String s, String delim) {
        String[] result = null;
        if (s != null && s.length() > 0) {
            String[] input = s.split(delim);
            result = new String[input.length];
            int i = 0;
            for (String v : input) {
                result[i] = v != null ? v.trim() : "";
                i++;
            }
        }
        return result;
    }

    /**
     * formats a date to a string using the system's defined dateformat
     *
     * @param date - the date
     * @return a String containing the formatted date
     */
    public static String formatDate(Date date) {
        return DateFormat.getDateFormat(BaracusApplicationContext.getContext()).format(date);
    }

    /**
     * reverts a date string back into a date usign the system's date format
     *
     * @param date - the date string
     * @return the parsed date
     */
    public static Date parseDate(String date) {
        return DateUtil.toDate(date);
    }

}




Java Source Code List

net.mantucon.baracus.annotations.Bean.java
net.mantucon.baracus.context.AnnotationScanner.java
net.mantucon.baracus.context.BaracusApplicationContext.java
net.mantucon.baracus.context.BeanContainer.java
net.mantucon.baracus.context.Exceptions.java
net.mantucon.baracus.context.ManagedActivity.java
net.mantucon.baracus.context.ManagedFragment.java
net.mantucon.baracus.dao.BaracusOpenHelper.java
net.mantucon.baracus.dao.BaseDao.java
net.mantucon.baracus.dao.ConfigurationDao.java
net.mantucon.baracus.errorhandling.CustomErrorHandler.java
net.mantucon.baracus.errorhandling.ErrorHandler.java
net.mantucon.baracus.errorhandling.ErrorHandlingFactory.java
net.mantucon.baracus.errorhandling.ErrorSeverity.java
net.mantucon.baracus.errorhandling.StandardErrorHandler.java
net.mantucon.baracus.errorhandling.TextEditErrorHandler.java
net.mantucon.baracus.lifecycle.ApplicationContextInitializer.java
net.mantucon.baracus.lifecycle.Destroyable.java
net.mantucon.baracus.lifecycle.Initializeable.java
net.mantucon.baracus.migr8.MigrationStep.java
net.mantucon.baracus.migr8.ModelVersion000.java
net.mantucon.baracus.model.ConfigurationParameter.java
net.mantucon.baracus.orm.AbstractModelBase.java
net.mantucon.baracus.orm.FieldList.java
net.mantucon.baracus.orm.Field.java
net.mantucon.baracus.orm.Identifiable.java
net.mantucon.baracus.orm.LazyCollection.java
net.mantucon.baracus.orm.LazyMorphicCollection.java
net.mantucon.baracus.orm.LazyReference.java
net.mantucon.baracus.orm.LegacyModelBase.java
net.mantucon.baracus.orm.ModelBase.java
net.mantucon.baracus.orm.NullReference.java
net.mantucon.baracus.orm.ObjectReference.java
net.mantucon.baracus.orm.OptimisticLockingModelBase.java
net.mantucon.baracus.orm.OptmisticLocking.java
net.mantucon.baracus.orm.ReferenceLoader.java
net.mantucon.baracus.orm.Reference.java
net.mantucon.baracus.orm.Timestamped.java
net.mantucon.baracus.signalling.ConfigurationChangeListener.java
net.mantucon.baracus.signalling.DataChangeAwareComponent.java
net.mantucon.baracus.signalling.DataSetChangeAwareComponent.java
net.mantucon.baracus.signalling.DeleteAwareComponent.java
net.mantucon.baracus.signalling.GenericEventAwareComponent.java
net.mantucon.baracus.signalling.GenericEvent.java
net.mantucon.baracus.ui.ConstrainedEditText.java
net.mantucon.baracus.ui.ConstrainedSpinner.java
net.mantucon.baracus.ui.ErrorView.java
net.mantucon.baracus.ui.Popup.java
net.mantucon.baracus.util.DBBackup.java
net.mantucon.baracus.util.DataUtil.java
net.mantucon.baracus.util.DateUtil.java
net.mantucon.baracus.util.DayDate.java
net.mantucon.baracus.util.Logger.java
net.mantucon.baracus.util.StringUtil.java
net.mantucon.baracus.validation.AbstractValidator.java
net.mantucon.baracus.validation.ConstrainedView.java
net.mantucon.baracus.validation.ValidatableView.java
net.mantucon.baracus.validation.ValidationFactory.java
net.mantucon.baracus.validation.Validator.java
net.mantucon.baracus.validation.builtins.DateFromNow.java
net.mantucon.baracus.validation.builtins.NumberMustBeGreaterThanZero.java
net.mantucon.baracus.validation.builtins.StringIsNumericDouble.java
net.mantucon.baracus.validation.builtins.StringIsNumericInteger.java
net.mantucon.baracus.validation.builtins.StringNotEmpty.java