Example usage for com.google.gson.internal LinkedTreeMap LinkedTreeMap

List of usage examples for com.google.gson.internal LinkedTreeMap LinkedTreeMap

Introduction

In this page you can find the example usage for com.google.gson.internal LinkedTreeMap LinkedTreeMap.

Prototype

@SuppressWarnings("unchecked") 
public LinkedTreeMap() 

Source Link

Document

Create a natural order, empty tree map whose keys must be mutually comparable and non-null.

Usage

From source file:com.magestore.app.pos.api.m1.config.POSConfigDataAccessM1.java

@Override
public Map<String, String> getConfigCCTypes()
        throws DataAccessException, ConnectionException, ParseException, IOException, ParseException {
    if (mConfig == null)
        mConfig = new PosConfigDefault();

    Map<String, Object> cc_types = (Map) mConfig.getValue("cc_types");

    Map<String, String> listCCTypes = new LinkedTreeMap<>();

    for (String key : cc_types.keySet()) {
        if (!key.equals("")) {
            String value = cc_types.get(key).toString();
            listCCTypes.put(key, value);
        }//from w  w w. j a v  a2s. c  o m
    }

    return listCCTypes;
}

From source file:com.magestore.app.pos.api.m1.config.POSConfigDataAccessM1.java

@Override
public Map<String, String> getConfigCCYears()
        throws DataAccessException, ConnectionException, ParseException, IOException, ParseException {
    if (mConfig == null)
        mConfig = new PosConfigDefault();

    Map<String, Object> cc_years = (Map) mConfig.getValue("cc_years");

    Map<String, String> listCCYears = new LinkedTreeMap<>();

    for (String key : cc_years.keySet()) {
        if (!key.equals("0")) {
            double value = (double) cc_years.get(key);
            int intValue = (int) value;
            listCCYears.put(key, String.valueOf(intValue));
        }//w w w . ja  va  2  s. c  om
    }

    return listCCYears;
}

From source file:com.magestore.app.pos.api.m2.config.POSConfigDataAccess.java

/**
 * Ly customer group trong config/* w w w.ja v a 2s. co m*/
 *
 * @return
 * @throws DataAccessException
 * @throws ConnectionException
 * @throws ParseException
 * @throws IOException
 * @throws ParseException
 */
@Override
public Map<String, String> getCustomerGroup()
        throws DataAccessException, ConnectionException, ParseException, IOException, ParseException {
    // nu cha load config, cn khi to ch  default
    if (mConfig == null)
        mConfig = new PosConfigDefault();

    // Chuyn i customer
    List<LinkedTreeMap> customerGroupList = (ArrayList) mConfig.getValue("customerGroup");
    LinkedTreeMap<String, String> returnCustomerGroup = new LinkedTreeMap<String, String>();
    for (LinkedTreeMap customerGroup : customerGroupList) {
        Double id = (Double) customerGroup.get("id");
        returnCustomerGroup.put(String.format("%.0f", id), customerGroup.get("code").toString());
    }
    return returnCustomerGroup;
}

From source file:com.magestore.app.pos.api.m2.config.POSConfigDataAccess.java

/**
 * Ly country trong config//from www. j  av  a2  s .c  o  m
 *
 * @return
 * @throws DataAccessException
 * @throws ConnectionException
 * @throws ParseException
 * @throws IOException
 * @throws ParseException
 */
@Override
public Map<String, ConfigCountry> getCountryGroup()
        throws DataAccessException, ConnectionException, ParseException, IOException, ParseException {
    // nu cha load config, cn khi to ch  default
    if (mConfig == null)
        mConfig = new PosConfigDefault();

    List<LinkedTreeMap> countryList = (ArrayList) mConfig.getValue("country");
    Map<String, ConfigCountry> listConfigCountry = new LinkedTreeMap<>();
    Collections.sort(countryList, new Comparator<LinkedTreeMap>() {
        @Override
        public int compare(LinkedTreeMap linkedTreeMap, LinkedTreeMap linkedTreeMap1) {
            String name = linkedTreeMap.get("country_name").toString();
            String name1 = linkedTreeMap1.get("country_name").toString();
            return name.compareToIgnoreCase(name1);
        }
    });
    for (LinkedTreeMap country : countryList) {
        ConfigCountry configCountry = new PosConfigCountry();
        String country_id = country.get("country_id").toString();
        String country_name = country.get("country_name").toString();
        configCountry.setCountryID(country_id);
        configCountry.setCountryName(country_name);
        List<LinkedTreeMap> regionList = (ArrayList) country.get("regions");
        if (regionList != null) {
            Map<String, ConfigRegion> listConfigRegion = new LinkedTreeMap<>();
            Collections.sort(regionList, new Comparator<LinkedTreeMap>() {
                @Override
                public int compare(LinkedTreeMap linkedTreeMap, LinkedTreeMap linkedTreeMap1) {
                    String name = linkedTreeMap.get("name").toString();
                    String name1 = linkedTreeMap1.get("name").toString();
                    return name.compareToIgnoreCase(name1);
                }
            });
            for (LinkedTreeMap region : regionList) {
                ConfigRegion configRegion = new PosConfigRegion();
                String code = region.get("code").toString();
                String name = region.get("name").toString();
                String id = region.get("id").toString();
                configRegion.setID(id);
                configRegion.setCode(code);
                configRegion.setName(name);
                listConfigRegion.put(id, configRegion);
            }
            configCountry.setRegions(listConfigRegion);
        }
        listConfigCountry.put(country_id, configCountry);
    }
    return listConfigCountry;
}

From source file:com.melchor629.musicote.MainActivity.java

License:Apache License

@Override
public boolean onQueryTextSubmit(String query) {
    DB dbs = new DB(this);
    SQLiteDatabase db = dbs.getReadableDatabase();
    Cursor c = dbs.get(db, query);
    songList.clear();/*from w ww  .  ja  va2  s  .  c  o m*/
    c.moveToFirst();
    if (c.getCount() > 0) {
        do {
            // creating new HashMap
            LinkedTreeMap<String, String> map = new LinkedTreeMap<>();

            long id = c.getLong(c.getColumnIndexOrThrow(DB_entry.COLUMN_CANCIONES_ID));
            String titulo = c.getString(c.getColumnIndexOrThrow(DB_entry.COLUMN_CANCIONES_TITULO));
            String artista = c.getString(c.getColumnIndexOrThrow(DB_entry.COLUMN_CANCIONES_ARTISTA));
            String album = c.getString(c.getColumnIndexOrThrow(DB_entry.COLUMN_CANCIONES_ALBUM));
            String archivo = c.getString(c.getColumnIndexOrThrow(DB_entry.COLUMN_CANCIONES_ARCHIVO));
            String duracion = c.getString(c.getColumnIndexOrThrow(DB_entry.COLUMN_CANCIONES_DURACION));
            String down = c.getString(c.getColumnIndexOrThrow(DB_entry.COLUMN_CANCIONES_DOWNLOADED));
            boolean downloaded = down.equalsIgnoreCase("true");

            // adding each child node to HashMap key => value
            map.put("id", "" + id);
            map.put("titulo", titulo);
            map.put("artista", artista);
            map.put("album", album);
            map.put("archivo", archivo);
            map.put("duracion", duracion);
            map.put("downloaded", downloaded ? "{fa-mobile}" : "{fa-cloud}"); //TODO

            songList.add(map);
        } while (c.moveToNext());
    }
    sis();
    c.close();
    db.close();
    return false;
}

From source file:com.melchor629.musicote.MainActivity.java

License:Apache License

/** Carga desde la base de datos */
private void cursordb(SQLiteDatabase db) {
    // Define a projection that specifies which columns from the database
    // you will actually use after this query.
    String[] projection = { DB_entry.COLUMN_CANCIONES_ID, DB_entry.COLUMN_CANCIONES_TITULO,
            DB_entry.COLUMN_CANCIONES_ARTISTA, DB_entry.COLUMN_CANCIONES_ALBUM,
            DB_entry.COLUMN_CANCIONES_DURACION, DB_entry.COLUMN_CANCIONES_ARCHIVO,
            DB_entry.COLUMN_CANCIONES_DOWNLOADED };

    // How you want the results sorted in the resulting Cursor
    String sortOrder = DB_entry.COLUMN_CANCIONES_ID + " ASC";

    Cursor c = db.query(DB_entry.TABLE_CANCIONES, // The table to query
            projection, // The columns to return
            null, // The columns for the WHERE clause
            null, // The values for the WHERE clause
            null, // don't group the rows
            null, // don't filter by row groups
            sortOrder // The sort order
    );/*from   w  ww  . j ava2s.  co m*/
    if (songList != null)
        songList.clear();
    else
        songList = new ArrayList<>();

    c.moveToFirst();
    try {
        do {
            // creating new HashMap
            LinkedTreeMap<String, String> map = new LinkedTreeMap<>();

            long id = c.getLong(c.getColumnIndexOrThrow(DB_entry.COLUMN_CANCIONES_ID));
            String titulo = c.getString(c.getColumnIndexOrThrow(DB_entry.COLUMN_CANCIONES_TITULO));
            String artista = c.getString(c.getColumnIndexOrThrow(DB_entry.COLUMN_CANCIONES_ARTISTA));
            String album = c.getString(c.getColumnIndexOrThrow(DB_entry.COLUMN_CANCIONES_ALBUM));
            String archivo = c.getString(c.getColumnIndexOrThrow(DB_entry.COLUMN_CANCIONES_ARCHIVO));
            String duracion = c.getString(c.getColumnIndexOrThrow(DB_entry.COLUMN_CANCIONES_DURACION));
            String downloaded = "false";//c.getString(c.getColumnIndexOrThrow(DB_entry.COLUMN_CANCIONES_DOWNLOADED));

            // adding each child node to HashMap key => value
            map.put("id", "" + id);
            map.put("titulo", titulo);
            map.put("artista", artista);
            map.put("album", album);
            map.put("archivo", archivo);
            map.put("duracion", duracion);
            map.put("downloaded", downloaded.equalsIgnoreCase("true") ? "{fa-mobile}" : "{fa-cloud}"); //TODO

            songList.add(map);
        } while (c.moveToNext());
    } catch (CursorIndexOutOfBoundsException e) {
        db.execSQL(DB_entry.DELETE_CANCIONES);
        Log.e("DB", "Mala integridad de la BD");
    }
    c.close();
    sis();
}

From source file:com.qmetry.qaf.automation.gson.GsonObjectDeserializer.java

License:Open Source License

public static Object read(JsonElement in) {

    if (in.isJsonArray()) {
        List<Object> list = new ArrayList<Object>();
        JsonArray arr = in.getAsJsonArray();
        for (JsonElement anArr : arr) {
            list.add(read(anArr));//from  w w w.  j a va2  s. c o m
        }
        return list;
    } else if (in.isJsonObject()) {
        Map<String, Object> map = new LinkedTreeMap<String, Object>();
        JsonObject obj = in.getAsJsonObject();
        Set<Map.Entry<String, JsonElement>> entitySet = obj.entrySet();
        for (Map.Entry<String, JsonElement> entry : entitySet) {
            map.put(entry.getKey(), read(entry.getValue()));
        }
        return map;
    } else if (in.isJsonPrimitive()) {
        JsonPrimitive prim = in.getAsJsonPrimitive();
        if (prim.isBoolean()) {
            return prim.getAsBoolean();
        } else if (prim.isString()) {
            return prim.getAsString();
        } else if (prim.isNumber()) {
            if (prim.getAsString().contains("."))
                return prim.getAsDouble();
            else {
                return prim.getAsLong();
            }
        }
    }
    return null;
}

From source file:ddf.catalog.source.solr.rest.SolrRest.java

License:Open Source License

public void init() {
    String username = getUsername();
    String password = getPassword();
    if (StringUtils.isNotBlank(solrBaseUrl)) {
        if (StringUtils.isBlank(username) || StringUtils.isBlank(password)) {
            solrCatalogSchemaClientFactory = clientFactoryFactory
                    .getSecureCxfClientFactory(getSolrCatalogSchemaUrl(), SolrRestClient.class);
            solrCatalogUpdateClientFactory = clientFactoryFactory
                    .getSecureCxfClientFactory(getSolrCatalogUpdateUrl(), SolrUpdateClient.class);
            solrMetacardCacheSchemaClientFactory = clientFactoryFactory
                    .getSecureCxfClientFactory(getSolrMetacardCacheSchemaUrl(), SolrRestClient.class);
            solrMetacardCacheUpdateClientFactory = clientFactoryFactory
                    .getSecureCxfClientFactory(getSolrMetacardCacheUpdateUrl(), SolrUpdateClient.class);
        } else {//w w  w . j av a2 s .c  om
            solrCatalogSchemaClientFactory = clientFactoryFactory.getSecureCxfClientFactory(
                    getSolrCatalogSchemaUrl(), SolrRestClient.class, username, password);
            solrCatalogUpdateClientFactory = clientFactoryFactory.getSecureCxfClientFactory(
                    getSolrCatalogUpdateUrl(), SolrUpdateClient.class, username, password);
            solrMetacardCacheSchemaClientFactory = clientFactoryFactory.getSecureCxfClientFactory(
                    getSolrMetacardCacheSchemaUrl(), SolrRestClient.class, username, password);
            solrMetacardCacheUpdateClientFactory = clientFactoryFactory.getSecureCxfClientFactory(
                    getSolrMetacardCacheUpdateUrl(), SolrUpdateClient.class, username, password);
        }

        similarityFormat = new LinkedTreeMap<>();
        similarityFormat.put("class", "solr.BM25SimilarityFactory");
        similarityFormat.put(K1_PROPERTY, k1);
        similarityFormat.put(B_PROPERTY, b);

        getProperties();
        setSimilarities();
    }
}

From source file:ddf.catalog.source.solr.rest.SolrRest.java

License:Open Source License

private void setSimilarities() {
    if (CollectionUtils.isNotEmpty(fieldTypes)) {
        LinkedTreeMap<String, Object> replaceField = new LinkedTreeMap<>();
        for (Object fieldType : fieldTypes) {
            LinkedTreeMap<String, Object> objectLinkedTreeMap = (LinkedTreeMap<String, Object>) fieldType;
            Object nameObj = objectLinkedTreeMap.get("name");
            if (nameObj instanceof String) {
                String name = (String) nameObj;
                if (name.contains("suggest")) {
                    LOGGER.trace("Skipping suggest field");
                    continue;
                }/*from  w  w  w  .j  ava  2  s  . co  m*/
            }

            objectLinkedTreeMap.put("similarity", similarityFormat);
            replaceField.put("replace-field-type", objectLinkedTreeMap);

            if (LOGGER.isTraceEnabled()) {
                LOGGER.trace("Replacing field: {}", gson.toJson(replaceField));
            }

            String response = solrCatalogSchemaClientFactory.getClient()
                    .replaceField(gson.toJson(replaceField));
            LOGGER.trace("Catalog Configuration update response: {}", response);

            response = solrMetacardCacheSchemaClientFactory.getClient().replaceField(gson.toJson(replaceField));
            LOGGER.trace("Metacard Cache Configuration update response: {}", response);
        }
    }
}

From source file:io.dockstore.webservice.languages.CWLHandler.java

License:Apache License

@Override
@SuppressWarnings("checkstyle:methodlength")
public String getContent(String mainDescriptorPath, String mainDescriptor,
        Map<String, String> secondaryDescContent, LanguageHandlerInterface.Type type, ToolDAO dao) {
    Yaml yaml = new Yaml();
    if (isValidCwl(mainDescriptor, yaml)) {
        // Initialize data structures for DAG
        Map<String, ToolInfo> toolInfoMap = new HashMap<>(); // Mapping of stepId -> array of dependencies for the step
        List<Pair<String, String>> nodePairs = new ArrayList<>(); // List of pairings of step id and dockerPull url
        Map<String, String> stepToType = new HashMap<>(); // Map of stepId -> type (expression tool, tool, workflow)
        String defaultDockerPath = null;

        // Initialize data structures for Tool table
        Map<String, Triple<String, String, String>> nodeDockerInfo = new HashMap<>(); // map of stepId -> (run path, docker image, docker url)

        // Convert YAML to JSON
        Map<String, Object> mapping = yaml.loadAs(mainDescriptor, Map.class);
        JSONObject cwlJson = new JSONObject(mapping);

        // Other useful variables
        String nodePrefix = "dockstore_";
        String toolType = "tool";
        String workflowType = "workflow";
        String expressionToolType = "expressionTool";

        // Set up GSON for JSON parsing
        Gson gson;/*from w  w w.j a va2 s .  c o m*/
        try {
            gson = io.cwl.avro.CWL.getTypeSafeCWLToolDocument();

            final io.cwl.avro.Workflow workflow = gson.fromJson(cwlJson.toString(), io.cwl.avro.Workflow.class);

            if (workflow == null) {
                LOG.error("The workflow does not seem to conform to CWL specs.");
                return null;
            }

            // Determine default docker path (Check requirement first and then hint)
            defaultDockerPath = getRequirementOrHint(workflow.getRequirements(), workflow.getHints(),
                    defaultDockerPath);

            // Store workflow steps in json and then read it into map <String, WorkflowStep>
            Object steps = workflow.getSteps();
            String stepJson = gson.toJson(steps);
            Map<String, WorkflowStep> workflowStepMap;
            if (steps instanceof ArrayList) {
                ArrayList<WorkflowStep> workflowStepList = gson.fromJson(stepJson,
                        new TypeToken<ArrayList<WorkflowStep>>() {
                        }.getType());
                workflowStepMap = new LinkedTreeMap<>();
                workflowStepList.forEach(
                        workflowStep -> workflowStepMap.put(workflowStep.getId().toString(), workflowStep));
            } else {
                workflowStepMap = gson.fromJson(stepJson, new TypeToken<Map<String, WorkflowStep>>() {
                }.getType());
            }

            if (stepJson == null) {
                LOG.error("Could not find any steps for the workflow.");
                return null;
            }

            if (workflowStepMap == null) {
                LOG.error("Error deserializing workflow steps");
                return null;
            }

            // Iterate through steps to find dependencies and docker requirements
            for (Map.Entry<String, WorkflowStep> entry : workflowStepMap.entrySet()) {
                WorkflowStep workflowStep = entry.getValue();
                String workflowStepId = nodePrefix + entry.getKey();

                ArrayList<String> stepDependencies = new ArrayList<>();

                // Iterate over source and get the dependencies
                if (workflowStep.getIn() != null) {
                    for (WorkflowStepInput workflowStepInput : workflowStep.getIn()) {
                        Object sources = workflowStepInput.getSource();

                        processDependencies(nodePrefix, stepDependencies, sources);
                    }
                    if (stepDependencies.size() > 0) {
                        toolInfoMap.computeIfPresent(workflowStepId, (toolId, toolInfo) -> {
                            toolInfo.toolDependencyList.addAll(stepDependencies);
                            return toolInfo;
                        });
                        toolInfoMap.computeIfAbsent(workflowStepId,
                                toolId -> new ToolInfo(null, stepDependencies));
                    }
                }

                // Check workflow step for docker requirement and hints
                String stepDockerRequirement = defaultDockerPath;
                stepDockerRequirement = getRequirementOrHint(workflowStep.getRequirements(),
                        workflowStep.getHints(), stepDockerRequirement);

                // Check for docker requirement within workflow step file
                String secondaryFile = null;
                Object run = workflowStep.getRun();
                String runAsJson = gson.toJson(gson.toJsonTree(run));

                if (run instanceof String) {
                    secondaryFile = (String) run;
                } else if (isTool(runAsJson, yaml)) {
                    CommandLineTool clTool = gson.fromJson(runAsJson, CommandLineTool.class);
                    stepDockerRequirement = getRequirementOrHint(clTool.getRequirements(), clTool.getHints(),
                            stepDockerRequirement);
                    stepToType.put(workflowStepId, toolType);
                } else if (isWorkflow(runAsJson, yaml)) {
                    io.cwl.avro.Workflow stepWorkflow = gson.fromJson(runAsJson, io.cwl.avro.Workflow.class);
                    stepDockerRequirement = getRequirementOrHint(stepWorkflow.getRequirements(),
                            stepWorkflow.getHints(), stepDockerRequirement);
                    stepToType.put(workflowStepId, workflowType);
                } else if (isExpressionTool(runAsJson, yaml)) {
                    ExpressionTool expressionTool = gson.fromJson(runAsJson, ExpressionTool.class);
                    stepDockerRequirement = getRequirementOrHint(expressionTool.getRequirements(),
                            expressionTool.getHints(), stepDockerRequirement);
                    stepToType.put(workflowStepId, expressionToolType);
                } else if (run instanceof Map) {
                    // must be import or include
                    Object importVal = ((Map) run).get("import");
                    if (importVal != null) {
                        secondaryFile = importVal.toString();
                    }

                    Object includeVal = ((Map) run).get("include");
                    if (includeVal != null) {
                        secondaryFile = includeVal.toString();
                    }
                }

                // Check secondary file for docker pull
                if (secondaryFile != null) {
                    stepDockerRequirement = parseSecondaryFile(stepDockerRequirement,
                            secondaryDescContent.get(secondaryFile), gson, yaml);
                    if (isExpressionTool(secondaryDescContent.get(secondaryFile), yaml)) {
                        stepToType.put(workflowStepId, expressionToolType);
                    } else if (isTool(secondaryDescContent.get(secondaryFile), yaml)) {
                        stepToType.put(workflowStepId, toolType);
                    } else if (isWorkflow(secondaryDescContent.get(secondaryFile), yaml)) {
                        stepToType.put(workflowStepId, workflowType);
                    } else {
                        stepToType.put(workflowStepId, "n/a");
                    }
                }

                String dockerUrl = null;
                if (!stepToType.get(workflowStepId).equals(workflowType)
                        && !Strings.isNullOrEmpty(stepDockerRequirement)) {
                    dockerUrl = getURLFromEntry(stepDockerRequirement, dao);
                }

                if (type == LanguageHandlerInterface.Type.DAG) {
                    nodePairs.add(new MutablePair<>(workflowStepId, dockerUrl));
                }

                if (secondaryFile != null) {
                    nodeDockerInfo.put(workflowStepId,
                            new MutableTriple<>(secondaryFile, stepDockerRequirement, dockerUrl));
                } else {
                    nodeDockerInfo.put(workflowStepId,
                            new MutableTriple<>(mainDescriptorPath, stepDockerRequirement, dockerUrl));
                }

            }

            if (type == LanguageHandlerInterface.Type.DAG) {
                // Determine steps that point to end
                List<String> endDependencies = new ArrayList<>();

                for (WorkflowOutputParameter workflowOutputParameter : workflow.getOutputs()) {
                    Object sources = workflowOutputParameter.getOutputSource();
                    processDependencies(nodePrefix, endDependencies, sources);
                }

                toolInfoMap.put("UniqueEndKey", new ToolInfo(null, endDependencies));
                nodePairs.add(new MutablePair<>("UniqueEndKey", ""));

                // connect start node with them
                for (Pair<String, String> node : nodePairs) {
                    if (toolInfoMap.get(node.getLeft()) == null) {
                        toolInfoMap.put(node.getLeft(),
                                new ToolInfo(null, Lists.newArrayList("UniqueBeginKey")));
                    }
                }
                nodePairs.add(new MutablePair<>("UniqueBeginKey", ""));

                return setupJSONDAG(nodePairs, toolInfoMap, stepToType, nodeDockerInfo);
            } else {
                return getJSONTableToolContent(nodeDockerInfo);
            }
        } catch (JsonParseException ex) {
            LOG.error("The JSON file provided is invalid.", ex);
            return null;
        }
    } else {
        return null;
    }
}