List of usage examples for java.util Map getClass
@HotSpotIntrinsicCandidate public final native Class<?> getClass();
From source file:org.pentaho.platform.repository.runtime.RuntimeElement.java
/** * Sets a map property in the paramMap. Special implementation note - Null values aren't supported in the Map. * So, if a null value is passed in, this implementation will remove the entry from the map. * /*from w w w . j a va 2 s . c om*/ * @param key * The key in the map. * @param value * The map property to set. */ public void setMapProperty(final String key, final Map value) { this.updateOk(); trace(Messages.getInstance().getString("RTREPO.DEBUG_PROPERTY_GETSET", "setMap", key)); //$NON-NLS-1$ //$NON-NLS-2$ checkType(key, value.getClass().getName(), true); Map theMap = getParamMapCPLX(); if (value != null) { theMap.put(key, value); } else { theMap.remove(key); } }
From source file:com.frank.search.solr.core.convert.MappingSolrConverter.java
@SuppressWarnings("unchecked") protected <S extends Object> S read(TypeInformation<S> targetTypeInformation, Map<String, ?> source) { if (source == null) { return null; }// www. ja v a 2 s . com Assert.notNull(targetTypeInformation); Class<S> rawType = targetTypeInformation.getType(); // in case there's a custom conversion for the document if (hasCustomReadTarget(source.getClass(), rawType)) { return convert(source, rawType); } SolrPersistentEntity<S> entity = (SolrPersistentEntity<S>) mappingContext.getPersistentEntity(rawType); return read(entity, source, null); }
From source file:pl.project13.maven.git.GitCommitIdMojoIntegrationTest.java
@Test @Parameters(method = "useNativeGit") public void shouldGenerateCustomPropertiesFileJson(boolean useNativeGit) throws Exception { // given/*from w w w .jav a 2s.c o m*/ mavenSandbox.withParentProject("my-pom-project", "pom").withChildProject("my-jar-module", "jar") .withGitRepoInChild(AvailableGitTestRepo.WITH_ONE_COMMIT_WITH_SPECIAL_CHARACTERS).create(); MavenProject targetProject = mavenSandbox.getChildProject(); String targetFilePath = "target/classes/custom-git.properties"; File expectedFile = new File(targetProject.getBasedir(), targetFilePath); setProjectToExecuteMojoIn(targetProject); alterMojoSettings("generateGitPropertiesFile", true); alterMojoSettings("generateGitPropertiesFilename", targetFilePath); alterMojoSettings("format", "json"); alterMojoSettings("useNativeGit", useNativeGit); // when try { mojo.execute(); // then assertThat(expectedFile).exists(); String json = Files.toString(expectedFile, Charset.forName("UTF-8")); ObjectMapper om = new ObjectMapper(); Map map = new HashMap<>(); map = om.readValue(json, map.getClass()); assertThat(map.size() > 10); } finally { FileUtils.forceDelete(expectedFile); } }
From source file:org.pentaho.platform.engine.services.runtime.SimpleRuntimeElement.java
/** * Sets a map property in the paramMap. Special implementation note - Null values aren't supported in the Map. * So, if a null value is passed in, this implementation will remove the entry from the map. * /*from w w w .ja v a2 s.c o m*/ * @param key * The key in the map. * @param value * The map property to set. */ public void setMapProperty(final String key, final Map value) { this.updateOk(); trace(Messages.getInstance().getString("RTREPO.DEBUG_PROPERTY_GETSET", "setMap", key)); //$NON-NLS-1$ //$NON-NLS-2$ Map theMap = getParamMapCPLX(); if (value != null) { checkType(key, value.getClass().getName(), true); theMap.put(key, value); } else { theMap.remove(key); } }
From source file:com.jkoolcloud.tnt4j.streams.utils.Utils.java
/** * Deserializes JSON data object ({@link String}, {@link java.io.Reader}, {@link java.io.InputStream}) into map * structured data.// w w w. jav a 2 s . co m * * @param jsonData * JSON format data object * @param jsonAsLine * flag indicating that complete JSON data package is single line * @return data map parsed from JSON data object * @throws com.google.gson.JsonSyntaxException * if there was a problem reading from the Reader * @throws com.google.gson.JsonIOException * if json is not a valid representation for an object of type * * @see com.google.gson.Gson#fromJson(String, Class) * @see com.google.gson.Gson#fromJson(java.io.Reader, Class) */ @SuppressWarnings("unchecked") public static Map<String, ?> fromJsonToMap(Object jsonData, boolean jsonAsLine) { Map<String, ?> map = new LinkedTreeMap<String, Object>(); Gson gson = new Gson(); if (jsonAsLine) { try { map = (Map<String, ?>) gson.fromJson(getStringLine(jsonData), map.getClass()); } catch (IOException ioe) { throw new JsonIOException(ioe); } } else { if (jsonData instanceof String) { map = (Map<String, ?>) gson.fromJson((String) jsonData, map.getClass()); } else if (jsonData instanceof byte[]) { map = (Map<String, ?>) gson.fromJson(getString((byte[]) jsonData), map.getClass()); } else if (jsonData instanceof Reader) { map = (Map<String, ?>) gson.fromJson((Reader) jsonData, map.getClass()); } else if (jsonData instanceof InputStream) { map = (Map<String, ?>) gson.fromJson( new BufferedReader(new InputStreamReader((InputStream) jsonData)), map.getClass()); } } return map; }
From source file:com.sinosoft.one.data.jade.statement.SelectQuerier.java
public Object execute(SQLType sqlType, StatementRuntime runtime) { String sql = runtime.getSQL(); Object[] args = runtime.getArgs(); DataAccess dataAccess = new DataAccessImpl(em); List<?> listResult = null; Pageable pageable = null;//from w ww . j a v a 2 s .c o m Sort sort = null; boolean isPage = false; boolean isSort = false; Map<String, Object> paramMap = runtime.getParameters(); for (String key : paramMap.keySet()) { if (paramMap.get(key) instanceof Pageable) { pageable = (Pageable) paramMap.get(key); isPage = true; } else if (paramMap.get(key) instanceof Sort) { sort = (Sort) paramMap.get(key); isSort = true; } } if (isPage && !isSort) { if (returnType == Page.class) { String countSql = parseCountSql(sql); Page<?> page = dataAccess.selectByPage(pageable, sql, countSql, args, rowMapper); return page; } else { try { log.error("The return type[" + returnType + "] must be " + Page.class); throw new Exception("The return type [\"+returnType+\"] is invalid"); } catch (Exception e) { e.printStackTrace(); } } } else if (!isPage && isSort) { return dataAccess.selectBySort(sort, sql, args, rowMapper); } else if (isPage && isSort) { try { log.error("Can not use Params:[" + Pageable.class + " and " + Sort.class + "at the same time."); throw new Exception( "Can not use Params:[" + Pageable.class + " and " + Sort.class + "at the same time."); } catch (Exception e) { e.printStackTrace(); } } else { listResult = dataAccess.select(sql, args, rowMapper); final int sizeResult = listResult.size(); // Result ? if (returnType.isAssignableFrom(List.class)) { // List ? return listResult; } else if (returnType.isArray() && byte[].class != returnType) { Object array = Array.newInstance(returnType.getComponentType(), sizeResult); if (returnType.getComponentType().isPrimitive()) { int len = listResult.size(); for (int i = 0; i < len; i++) { Array.set(array, i, listResult.get(i)); } } else { listResult.toArray((Object[]) array); } return array; } else if (Map.class.isAssignableFrom(returnType)) { // KeyValuePair ?? Map // entry.key?nullHashMap Map<Object, Object> map; if (returnType.isAssignableFrom(HashMap.class)) { map = new HashMap<Object, Object>(listResult.size() * 2); } else if (returnType.isAssignableFrom(Hashtable.class)) { map = new Hashtable<Object, Object>(listResult.size() * 2); } else { throw new Error(returnType.toString()); } for (Object obj : listResult) { if (obj == null) { continue; } Map.Entry<?, ?> entry = (Map.Entry<?, ?>) obj; if (map.getClass() == Hashtable.class && entry.getKey() == null) { continue; } map.put(entry.getKey(), entry.getValue()); } return map; } else if (returnType.isAssignableFrom(HashSet.class)) { // Set ? return new HashSet<Object>(listResult); } else { if (sizeResult == 1) { // ? Bean?Boolean return listResult.get(0); } else if (sizeResult == 0) { // null if (returnType.isPrimitive()) { String msg = "Incorrect result size: expected 1, actual " + sizeResult + ": " + runtime.getMetaData(); throw new EmptyResultDataAccessException(msg, 1); } else { return null; } } else { // IncorrectResultSizeDataAccessException String msg = "Incorrect result size: expected 0 or 1, actual " + sizeResult + ": " + runtime.getMetaData(); throw new IncorrectResultSizeDataAccessException(msg, 1, sizeResult); } } } return listResult; }
From source file:de.javakaffee.kryoserializers.KryoTest.java
@Test(enabled = true) public void testSingletonMap() throws Exception { final Map<?, ?> obj = Collections.singletonMap("foo", "bar"); final Map<?, ?> deserialized = deserialize(serialize(obj), obj.getClass()); assertDeepEquals(deserialized, obj); }
From source file:io.coala.json.DynaBean.java
@SuppressWarnings("unchecked") @Override/*from w w w .ja v a 2 s . c o m*/ protected DynaBean clone() { final Map<String, Object> values = any(); final DynaBean result = new DynaBean(); result.set(JsonUtil.valueOf(JsonUtil.toTree(values), values.getClass())); return result; }
From source file:org.jahia.services.render.scripting.bundle.BundleScriptResolver.java
public void setScriptFactoryMap(Map<String, ScriptFactory> scriptFactoryMap) { if (!(scriptFactoryMap instanceof LinkedHashMap)) { throw new IllegalArgumentException( "Error instantiating BundleScriptResolver: Spring is supposed to create a SortedMap when using a <map> " + "property but didn't. Was: " + scriptFactoryMap.getClass().getName()); }/* w w w .j a va 2s . c om*/ this.scriptFactoryMap = (LinkedHashMap<String, ScriptFactory>) scriptFactoryMap; // record pre-registered extensions preRegisteredExtensions = new HashSet<>(scriptFactoryMap.size()); preRegisteredExtensions.addAll(scriptFactoryMap.keySet()); // record priorities of extensions, each pre-registered extension is assigned a priority of its registration index times 100 extensionPriorities = new HashMap<>(scriptFactoryMap.size()); int i = 0; for (String extension : scriptFactoryMap.keySet()) { extensionPriorities.put(extension, PRIORITY_STAGGER_FACTOR * i); i++; } }
From source file:net.sf.juffrou.reflect.JuffrouTypeConverterDelegate.java
@SuppressWarnings("unchecked") private Map convertToTypedMap(Map original, String propertyName, Class requiredType, TypeDescriptor typeDescriptor) { if (!Map.class.isAssignableFrom(requiredType)) { return original; }/* w w w. j a v a 2s. com*/ boolean approximable = CollectionFactory.isApproximableMapType(requiredType); if (!approximable && !canCreateCopy(requiredType)) { if (logger.isDebugEnabled()) { logger.debug("Custom Map type [" + original.getClass().getName() + "] does not allow for creating a copy - injecting original Map as-is"); } return original; } boolean originalAllowed = requiredType.isInstance(original); typeDescriptor = typeDescriptor.narrow(original); TypeDescriptor keyType = typeDescriptor.getMapKeyTypeDescriptor(); TypeDescriptor valueType = typeDescriptor.getMapValueTypeDescriptor(); if (keyType == null && valueType == null && originalAllowed && !this.propertyEditorRegistry.hasCustomEditorForElement(null, propertyName)) { return original; } Iterator it; try { it = original.entrySet().iterator(); if (it == null) { if (logger.isDebugEnabled()) { logger.debug("Map of type [" + original.getClass().getName() + "] returned null Iterator - injecting original Map as-is"); } return original; } } catch (Throwable ex) { if (logger.isDebugEnabled()) { logger.debug("Cannot access Map of type [" + original.getClass().getName() + "] - injecting original Map as-is: " + ex); } return original; } Map convertedCopy; try { if (approximable) { convertedCopy = CollectionFactory.createApproximateMap(original, original.size()); } else { convertedCopy = (Map) requiredType.newInstance(); } } catch (Throwable ex) { if (logger.isDebugEnabled()) { logger.debug("Cannot create copy of Map type [" + original.getClass().getName() + "] - injecting original Map as-is: " + ex); } return original; } while (it.hasNext()) { Map.Entry entry = (Map.Entry) it.next(); Object key = entry.getKey(); Object value = entry.getValue(); String keyedPropertyName = buildKeyedPropertyName(propertyName, key); Object convertedKey = convertIfNecessary(keyedPropertyName, null, key, (keyType != null ? keyType.getType() : null), keyType); Object convertedValue = convertIfNecessary(keyedPropertyName, null, value, (valueType != null ? valueType.getType() : null), valueType); try { convertedCopy.put(convertedKey, convertedValue); } catch (Throwable ex) { if (logger.isDebugEnabled()) { logger.debug("Map type [" + original.getClass().getName() + "] seems to be read-only - injecting original Map as-is: " + ex); } return original; } originalAllowed = originalAllowed && (key == convertedKey) && (value == convertedValue); } return (originalAllowed ? original : convertedCopy); }