All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.qiniu.service.line.MapToJsonFormatter Maven / Gradle / Ivy

There is a newer version: 8.4.8
Show newest version
package com.qiniu.service.line;

import com.google.gson.JsonObject;
import com.qiniu.service.interfaces.IStringFormat;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;

public class MapToJsonFormatter implements IStringFormat> {

    private List rmFields;

    public MapToJsonFormatter(List removeFields) {
        this.rmFields = removeFields == null ? new ArrayList<>() : removeFields;
    }

    public String toFormatString(Map infoMap) {
        JsonObject converted = new JsonObject();
        Set set = infoMap.keySet();
        List keys = new ArrayList(){{
            this.addAll(set);
        }};
        keys.removeAll(rmFields);
        if (keys.contains("key")) {
            converted.addProperty("key", infoMap.get("key"));
            keys.remove("key");
        }
        if (keys.contains("hash")) {
            converted.addProperty("hash", infoMap.get("hash"));
            keys.remove("hash");
        }
        if (keys.contains("fsize")) {
            converted.addProperty("fsize", Long.valueOf(infoMap.get("fsize")));
            keys.remove("fsize");
        }
        if (keys.contains("putTime")) {
            converted.addProperty("putTime", Long.valueOf(infoMap.get("putTime")));
            keys.remove("putTime");
        }
        if (keys.contains("mimeType")) {
            converted.addProperty("mimeType", infoMap.get("mimeType"));
            keys.remove("mimeType");
        }
        if (keys.contains("type")) {
            converted.addProperty("type", Integer.valueOf(infoMap.get("type")));
            keys.remove("type");
        }
        if (keys.contains("status")) {
            converted.addProperty("status", Integer.valueOf(infoMap.get("status")));
            keys.remove("status");
        }
        if (keys.contains("endUser")) {
            converted.addProperty("endUser", infoMap.get("endUser"));
            keys.remove("endUser");
        }
        for (String key : keys) {
            converted.addProperty(key, infoMap.get(key));
        }
        return converted.toString();
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy