Example usage for java.util Map getClass

List of usage examples for java.util Map getClass

Introduction

In this page you can find the example usage for java.util Map getClass.

Prototype

@HotSpotIntrinsicCandidate
public final native Class<?> getClass();

Source Link

Document

Returns the runtime class of this Object .

Usage

From source file:au.edu.unsw.cse.soc.federatedcloud.user.CloudBaseUserInterface.java

/**
 * Init an App./*from w  w  w  .  j  a va 2s.co  m*/
 * Sample command: init aws-s3
 * @param appName
 * @param appAttributes
 */
private void initCloudBase(String appName, String appAttributes) {
    //check if app.json exist in the current directory
    File jsonFile = new File("./" + Constants.FILE_NAME);
    //if app.json does not exist
    if (!jsonFile.exists()) {
        //create an app.json
        try {
            boolean isCreated = jsonFile.createNewFile();

            if (isCreated) {
                Gson gson = new GsonBuilder().setPrettyPrinting().create();

                InputStream inputStream = this.getClass().getClassLoader()
                        .getResourceAsStream(Constants.TEMPLATE_FILE_NAME);
                StringWriter writer = new StringWriter();
                IOUtils.copy(inputStream, writer);
                String fileContent = writer.toString();

                App app = gson.fromJson(fileContent, App.class);

                //Set name
                app.setName(appName);

                //set attributes
                Map<String, String> map = new HashMap<String, String>();
                app.setAttributes((Map<String, String>) gson.fromJson(appAttributes, map.getClass()));

                transformAppToFile(app, jsonFile);

                System.out.println("App:" + app.getName() + " was created");
            } else {
                System.err.println("File was not created");
            }
        } catch (IOException e) {
            System.err.println(e.getMessage());
            e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
        }
    } else {
        System.out.println("File:" + jsonFile.getAbsolutePath() + " already exists.");
    }
}

From source file:com.callidusrobotics.droptables.model.ReportGenerator.java

@JsonProperty("defaultParameters")
@SuppressWarnings("unchecked")
public void setBinding(Map<String, String> binding) throws InstantiationException, IllegalAccessException {
    this.binding = binding.getClass().newInstance();
    this.binding.putAll(binding);
}

From source file:io.dockstore.webservice.helpers.QuayImageRegistry.java

/**
 * Get the map of the given Quay tool/*from   w  w w  .  j ava  2 s  . co  m*/
 * Todo: this should be implemented with the Quay API, but they currently don't have a return model for this call
 * @param tool
 * @return
 */
public Map<String, Object> getQuayInfo(final Tool tool) {
    final String repo = tool.getNamespace() + '/' + tool.getName();
    final String repoUrl = QUAY_URL + "repository/" + repo;
    final Optional<String> asStringBuilds = ResourceUtilities.asString(repoUrl, quayToken.getContent(), client);

    if (asStringBuilds.isPresent()) {
        final String json = asStringBuilds.get();

        Gson gson = new Gson();
        Map<String, Object> map = new HashMap<>();
        map = (Map<String, Object>) gson.fromJson(json, map.getClass());
        return map;

    }
    return null;
}

From source file:com.oracle.coherence.spring.SpringNamespaceHandlerTests.java

/**
 * Test the registration of a bean factory and injection of a backing map.
 *///from   www.j a v a 2 s  . c o  m
@Test
public void testManualRegistration() {
    // this local cache will be used as a backing map
    LocalCache localCache = new LocalCache(100, 0, new AbstractCacheLoader() {
        @Override
        public Object load(Object oKey) {
            return ExternalizableHelper.toBinary("mock");
        }
    });

    // instead of creating a Spring application context, create
    // a simple mock BeanFactory that returns the local cache
    // created above
    BeanFactory factory = mock(BeanFactory.class);

    when(factory.getBean("localBackingMap")).thenReturn(localCache);

    ConfigurableCacheFactory ccf = getFactory();

    // register the mock BeanFactory with the cache factory so that
    // it is used as the backing map (see the cache config file)
    ccf.getResourceRegistry().registerResource(BeanFactory.class, "mock", factory);

    NamedCache namedCache = ccf.ensureCache("CacheCustomBackingMap", null);

    // cache loader always returns the same value
    assertEquals("mock", namedCache.get("key"));

    // assert backing map properties
    Map mapBacking = namedCache.getCacheService().getBackingMapManager().getContext()
            .getBackingMapContext("CacheCustomBackingMap").getBackingMap();

    assertEquals(LocalCache.class, mapBacking.getClass());
    assertEquals(100, ((LocalCache) mapBacking).getHighUnits());
    assertEquals(localCache, mapBacking);
}

From source file:org.pentaho.metaverse.impl.model.kettle.json.TransMetaJsonDeserializer.java

protected void writeJsonAttributes(JsonNode attributes, ObjectMapper mapper, ObjectId stepId)
        throws IOException {
    Map<String, Object> attrs = new HashMap<String, Object>();
    attrs = mapper.readValue(attributes.toString(), attrs.getClass());

    for (String s : attrs.keySet()) {
        Object val = attrs.get(s);
        try {/*w ww . j ava2  s.co m*/
            if (val instanceof Integer) {
                repository.saveStepAttribute(null, stepId, s, (Integer) val);
            } else if (val instanceof Long) {
                repository.saveStepAttribute(null, stepId, s, (Long) val);
            } else if (val instanceof Double) {
                repository.saveStepAttribute(null, stepId, s, (Double) val);
            } else if (val instanceof Boolean) {
                repository.saveStepAttribute(null, stepId, s, (Boolean) val);
            } else {
                repository.saveStepAttribute(null, stepId, s, val == null ? null : (String) val);
            }
        } catch (KettleException e) {
            LOGGER.info(Messages.getString("INFO.Deserialization.Trans.SavingAttributes", s), e);
        }
    }
}

From source file:io.dockstore.webservice.helpers.QuayImageRegistry.java

/**
 * For a given tool, update its registry, git, and build information with information from quay.io
 * /* w  ww  .  j  a va 2  s.com*/
 * @param formatter
 * @param mapOfBuilds
 * @param gson
 * @param tool
 * @param repo
 * @param path
 */
private void updateContainersWithBuildInfo(SimpleDateFormat formatter, Map<String, ArrayList<?>> mapOfBuilds,
        Gson gson, Tool tool, String repo, String path) {
    // Get the list of builds from the tool.
    // Builds contain information such as the Git URL and tags
    // TODO: work with quay.io to get a better approach such as only the last build for each tag or at the very least paging
    String urlBuilds = QUAY_URL + "repository/" + repo + "/build/?limit=2147483647";
    Optional<String> asStringBuilds = ResourceUtilities.asString(urlBuilds, quayToken.getContent(), client);
    LOG.info(quayToken.getUsername() + " RESOURCE CALL: {}", urlBuilds);

    String gitURL = "";

    if (asStringBuilds.isPresent()) {
        String json = asStringBuilds.get();

        // parse json using Gson to get the git url of repository and the list of tags
        Map<String, ArrayList> map = new HashMap<>();
        map = (Map<String, ArrayList>) gson.fromJson(json, map.getClass());
        ArrayList builds = map.get("builds");
        if (builds.size() > 0) {

            mapOfBuilds.put(path, builds);

            if (!builds.isEmpty()) {
                Map<String, Map<String, String>> map2 = (Map<String, Map<String, String>>) builds.get(0);

                Map<String, String> triggerMetadata = map2.get("trigger_metadata");

                if (triggerMetadata != null) {
                    gitURL = triggerMetadata.get("git_url");
                }

                Map<String, String> map3 = (Map<String, String>) builds.get(0);
                String lastBuild = map3.get("started");
                LOG.info(quayToken.getUsername() + " : LAST BUILD: {}", lastBuild);

                Date date;
                try {
                    date = formatter.parse(lastBuild);
                    tool.setLastBuild(date);
                } catch (ParseException ex) {
                    LOG.info(quayToken.getUsername() + ": " + quayToken.getUsername()
                            + " Build date did not match format 'EEE, d MMM yyyy HH:mm:ss Z'");
                }
            }
            if (tool.getMode() != ToolMode.MANUAL_IMAGE_PATH) {
                tool.setRegistry(Registry.QUAY_IO);
                tool.setGitUrl(gitURL);
            }
        }
    }
}

From source file:org.apache.ranger.unixusersync.process.FileSourceUserGroupBuilder.java

public Map<String, List<String>> readJSONfile(File jsonFile) throws Exception {
    Map<String, List<String>> ret = new HashMap<String, List<String>>();

    JsonReader jsonReader = new JsonReader(new BufferedReader(new FileReader(jsonFile)));

    Gson gson = new GsonBuilder().create();

    ret = gson.fromJson(jsonReader, ret.getClass());

    return ret;//from  ww w .  j  a va  2s .  c o  m

}

From source file:io.dockstore.webservice.helpers.QuayImageRegistry.java

@Override
public List<Tag> getTags(Tool tool) {
    LOG.info(/*from  ww  w . j  av  a2s.c  o  m*/
            quayToken.getUsername()
                    + " ======================= Getting tags for: {}================================",
            tool.getPath());
    final String repo = tool.getNamespace() + '/' + tool.getName();
    final String repoUrl = QUAY_URL + "repository/" + repo;
    final Optional<String> asStringBuilds = ResourceUtilities.asString(repoUrl, quayToken.getContent(), client);

    final List<Tag> tags = new ArrayList<>();

    if (asStringBuilds.isPresent()) {
        final String json = asStringBuilds.get();
        // LOG.info(json);

        Gson gson = new Gson();
        Map<String, Map<String, Map<String, String>>> map = new HashMap<>();
        map = (Map<String, Map<String, Map<String, String>>>) gson.fromJson(json, map.getClass());

        final Map<String, Map<String, String>> listOfTags = map.get("tags");

        for (Entry<String, Map<String, String>> stringMapEntry : listOfTags.entrySet()) {
            final String s = gson.toJson(stringMapEntry.getValue());
            try {
                final Tag tag = objectMapper.readValue(s, Tag.class);
                tags.add(tag);
                // LOG.info(gson.toJson(tag));
            } catch (IOException ex) {
                LOG.info(quayToken.getUsername() + " Exception: {}", ex);
            }
        }

    }
    return tags;
}

From source file:ome.util.ModelMapper.java

public Map findMap(Map source) {
    if (source == null) {
        return null;
    }/* w  w w  .  ja v a  2  s.co m*/

    Map target = (Map) model2target.get(source);
    if (null == target) {
        try {
            target = source.getClass().newInstance();
            model2target.put(source, target);
        } catch (InstantiationException ie) {
            throw new RuntimeException(ie);
        } catch (IllegalAccessException iae) {
            throw new RuntimeException(iae);
        }
    }
    return target;
}