Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Open Source License 

import android.text.TextUtils;

import java.security.MessageDigest;
import java.util.List;

public class Main {
    public static String md5(String str) {
        if (TextUtils.isEmpty(str)) {
            return null;
        }
        try {
            MessageDigest messageDigest = MessageDigest.getInstance("MD5");
            messageDigest.update(str.getBytes());
            return encodeHex(messageDigest.digest());
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    public static <V> boolean isEmpty(List<V> sourceList) {
        return (sourceList == null || sourceList.size() == 0);
    }

    public static boolean isEmpty(String str) {
        if (TextUtils.isEmpty(str) || str.equals("null")) {
            return true;
        }
        return false;
    }

    private static String encodeHex(byte[] digest) {
        StringBuilder hexString = new StringBuilder();
        String hex = null;
        for (int i = 0; i < digest.length; i++) {
            hex = Integer.toHexString((digest[i] & 0xff));
            if (hex.length() == 1) {
                hex = '0' + hex;
            }
            hexString.append(hex);
        }
        return hexString.toString();
    }
}