List of usage examples for java.util Map getClass
@HotSpotIntrinsicCandidate public final native Class<?> getClass();
From source file:com.bitplan.json.JsonAble.java
/** * get my values a a map/* w w w .ja v a 2s .c o m*/ * @return - the map of values */ @SuppressWarnings("unchecked") default Map<String, Object> asMap() { Map<String, Object> map = new HashMap<String, Object>(); map = (Map<String, Object>) getGson().fromJson(this.asJson(), map.getClass()); return map; }
From source file:io.dockstore.client.cli.CromwellIT.java
@Test public void fileProvisioning() { Main main = new Main(); File workflowFile = new File(ResourceHelpers.resourceFilePath("wdlfileprov.wdl")); File parameterFile = new File(ResourceHelpers.resourceFilePath("wdlfileprov.json")); Bridge bridge = new Bridge(); Map<String, String> wdlInputs = bridge.getInputFiles(workflowFile); WDLFileProvisioning wdlFileProvisioning = new WDLFileProvisioning( ResourceHelpers.resourceFilePath("config_file.txt")); Gson gson = new Gson(); String jsonString = null;//w w w . ja va2 s .c o m try { jsonString = FileUtils.readFileToString(parameterFile); Map<String, Object> map = new HashMap<>(); Map<String, Object> inputJson = gson.fromJson(jsonString, map.getClass()); Map<String, Object> fileMap = wdlFileProvisioning.pullFiles(inputJson, wdlInputs); String newJsonPath = wdlFileProvisioning.createUpdatedInputsJson(inputJson, fileMap); final java.util.List<String> wdlRun = Lists.newArrayList(workflowFile.getAbsolutePath(), newJsonPath); final List<String> wdlRunList = JavaConversions.asScalaBuffer(wdlRun).toList(); // run a workflow final int run = main.run(wdlRunList); Assert.assertTrue(run == 0); } catch (IOException e) { e.printStackTrace(); } }
From source file:yui.classes.YUILoaderTest.java
@Test public void css_data() { logger.info("css_data"); // lame but still better than nothing for now. Map result = loader.css_data(); assertNotNull(result);/*from w w w .j a v a 2s.c o m*/ assertTrue(Map.class.isAssignableFrom(result.getClass())); }
From source file:yui.classes.YUILoaderTest.java
/** * Test of css method, of class YUILoader. *//*from w w w . j a v a2s . c o m*/ @Test public void script_data() { logger.info("script_data"); // lame but still better than nothing for now. Map result = loader.script_data(); assertNotNull(result); assertTrue(Map.class.isAssignableFrom(result.getClass())); }
From source file:io.coala.json.DynaBean.java
/** * @param <T>/*www . j av a 2 s . c o m*/ * @param wrapperType * @return */ static final <T> JsonSerializer<T> createJsonSerializer(final Class<T> type) { return new JsonSerializer<T>() { @Override public void serialize(final T value, final JsonGenerator jgen, final SerializerProvider serializers) throws IOException, JsonProcessingException { // non-Proxy objects get default treatment if (!Proxy.isProxyClass(value.getClass())) { @SuppressWarnings("unchecked") final JsonSerializer<T> ser = (JsonSerializer<T>) serializers .findValueSerializer(value.getClass()); if (ser != this) ser.serialize(value, jgen, serializers); else LOG.warn("Problem serializing: {}", value); return; } // BeanWrapper gets special treatment if (DynaBeanInvocationHandler.class.isInstance(Proxy.getInvocationHandler(value))) { final DynaBeanInvocationHandler handler = (DynaBeanInvocationHandler) Proxy .getInvocationHandler(value); // Wrapper extensions get special treatment if (Wrapper.class.isAssignableFrom(handler.type)) { final Object wrap = handler.bean.get("wrap"); serializers.findValueSerializer(wrap.getClass(), null).serialize(wrap, jgen, serializers); return; } // Config (Accessible) extensions get special treatment else if (Accessible.class.isAssignableFrom(handler.type)) { final Map<String, Object> copy = new HashMap<>(handler.bean.any()); final Accessible config = (Accessible) handler.config; for (String key : config.propertyNames()) copy.put(key, config.getProperty(key)); serializers.findValueSerializer(copy.getClass(), null).serialize(copy, jgen, serializers); return; } else if (Config.class.isAssignableFrom(handler.type)) throw new JsonGenerationException("BeanWrapper should extend " + Accessible.class.getName() + " required for serialization: " + Arrays.asList(handler.type.getInterfaces()), jgen); // BeanWrappers that do not extend OWNER API's Config serializers.findValueSerializer(handler.bean.getClass(), null).serialize(handler.bean, jgen, serializers); return; } // Config (Accessible) gets special treatment if (Accessible.class.isInstance(value)) { final Accessible config = (Accessible) value; final Properties entries = new Properties(); for (String key : config.propertyNames()) entries.put(key, config.getProperty(key)); serializers.findValueSerializer(entries.getClass(), null).serialize(entries, jgen, serializers); return; } if (Config.class.isInstance(value)) throw new JsonGenerationException("Config should extend " + Accessible.class.getName() + " required for serialization: " + Arrays.asList(value.getClass().getInterfaces()), jgen); throw new JsonGenerationException( "No serializer found for proxy of: " + Arrays.asList(value.getClass().getInterfaces()), jgen); } }; }
From source file:com.joyent.manta.util.LookupMap.java
/** * Determines if a given map is of a unmodifiable type. * * @param map map to check//from w w w . j a v a 2s . c o m * @return true if unmodifiable */ private boolean isUnmodifiable(final Map<String, V> map) { return map.getClass().getName().equals("java.util.Collections$UnmodifiableMap") || map.getClass().getName().equals("org.apache.commons.collections4.map.UnmodifiableMap") || map.getClass().getName().equals("com.google.common.collect.ImmutableMap") || map instanceof UnmodifiableMap; }
From source file:ch.caleb.scaffolding.grid.column.IColumnFactory.java
public Map<String, Object> filterForIgnore(Object source, Map<String, Object> input) throws Exception { Map<String, Object> resultMap = new HashMap<String, Object>(); for (String value : input.keySet()) { Method method = input.getClass().getMethod(value); GridMetaData gmd = method.getAnnotation(GridMetaData.class); if (gmd == null || gmd.mode() != GridMetaData.Mode.IGNORE) { resultMap.put(value, input.get(value)); } else {/*from w w w. j a v a 2 s . c o m*/ // is marked ignore } } return resultMap; }
From source file:org.kafka.event.microaggregator.consumer.MicroAggregatorConsumer.java
public void run() { Map<String, Integer> topicCountMap = new HashMap<String, Integer>(); Integer noOfThread = 1;/* ww w . j a va2 s . c o m*/ topicCountMap.put(topic, new Integer(1)); Map<String, List<KafkaStream<byte[], byte[]>>> consumerMap = consumer.createMessageStreams(topicCountMap); KafkaStream<byte[], byte[]> stream = consumerMap.get(topic).get(0); ConsumerIterator<byte[], byte[]> it = stream.iterator(); while (it.hasNext()) { // String message = ExampleUtils.getMessage(it.next()); String message = new String(it.next().message()); Gson gson = new Gson(); Map<String, String> messageMap = new HashMap<String, String>(); try { messageMap = gson.fromJson(message, messageMap.getClass()); } catch (Exception e) { LOG.error("Message Consumer Error: " + e.getMessage()); continue; } // TODO We're only getting raw data now. We'll have to use the // server IP as well for extra information. if (messageMap != null) { updateActivityStream(messageMap); staticAggregation(messageMap); } else { LOG.error("Message Consumer Error messageMap : No data found"); continue; } } }
From source file:au.edu.unsw.cse.soc.federatedcloud.user.CloudBaseUserInterface.java
private Map<String, String> generateAttributesFromJson(String resourceMetadata) { Gson gson = new GsonBuilder().setPrettyPrinting().create(); Map<String, String> map = new HashMap<String, String>(); map = (Map<String, String>) gson.fromJson(resourceMetadata, map.getClass()); return map;//from w w w .j av a 2 s.c o m }
From source file:jef.tools.reflect.ClassEx.java
@SuppressWarnings({ "rawtypes", "unchecked" }) private static Object checkAndConvertMap(Map rawValue, ClassEx container) { Entry<Type, Type> types = GenericUtils.getMapTypes(container.genericType); boolean checkKey = types.getKey() != Object.class; boolean checkValue = types.getValue() != Object.class; if (!checkKey && !checkValue) return rawValue; ClassEx tk = new ClassEx(types.getKey()); ClassEx tv = new ClassEx(types.getValue()); Set<Map.Entry> es = rawValue.entrySet(); Map result;/* w ww.ja v a 2s . c o m*/ try { result = rawValue.getClass().newInstance(); } catch (InstantiationException e1) { throw new IllegalArgumentException(e1); } catch (IllegalAccessException e1) { throw new IllegalArgumentException(e1); } for (Map.Entry e : es) { Object key = e.getKey(); Object value = e.getValue(); if (key != null && checkKey) key = toProperType(key, tk, null); if (value != null && checkValue) value = toProperType(value, tv, null); result.put(key, value); } return result; }