Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Apache License 

import android.util.Base64;
import com.google.gson.Gson;

public class Main {
    private static Gson gson = new Gson();

    public static String generateKey(String key, int position) {
        StringBuilder sb = new StringBuilder();

        sb.append(key);
        sb.append(":");
        sb.append(position);

        return sb.toString();
    }

    public static String generateKey(Object... objects) {

        Object[] args = objects;

        if (args == null) {
            throw new NullPointerException("Cannot generate key with no params!");
        }

        StringBuilder stringBuilder = new StringBuilder();

        for (Object o : args) {
            if (o != null) {
                if (o instanceof String) {
                    stringBuilder.append(o);
                    stringBuilder.append("_");
                } else {
                    String json = gson.toJson(o);
                    stringBuilder.append(json);
                    stringBuilder.append("_");
                }
            }
        }

        return Base64.encodeToString(stringBuilder.toString().getBytes(), Base64.DEFAULT);
    }
}