Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//  use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of

import android.util.Log;

import java.security.spec.InvalidParameterSpecException;

import java.util.LinkedHashMap;

import java.util.Map;

public class Main {
    /**
     * Builds map from list of strings
     *
     * @param args key-value pairs for build a map. Must be a multiple of 2
     * @return Result map. If args not multiple of 2, last argument will be ignored
     */
    public static Map<String, Object> mapFrom(Object... args) {
        if (args.length % 2 != 0) {
            Log.w("VKUtil", "Params must be paired. Last one is ignored");
        }
        LinkedHashMap<String, Object> result = new LinkedHashMap<String, Object>(args.length / 2);
        for (int i = 0; i + 1 < args.length; i += 2) {
            if (!(args[i] instanceof String))
                Log.e("VK SDK", "Error while using mapFrom",
                        new InvalidParameterSpecException("Key must be string"));
            result.put((String) args[i], args[i + 1]);
        }
        return result;
    }
}