List of usage examples for java.util Collections EMPTY_MAP
Map EMPTY_MAP
To view the source code for java.util Collections EMPTY_MAP.
Click Source Link
From source file:io.fabric8.kubernetes.api.KubernetesHelper.java
public static Map<String, String> getSelector(Service entity) { Map<String, String> answer = null; if (entity != null) { answer = entity.getSelector();/*from ww w .j a va 2 s .c o m*/ if (answer == null) { // TODO lets look for the spec nested object if its available } /* ServiceSpec spec = entity.getSpec(); if (spec != null) { return spec.getSelector(); } */ } return answer != null ? answer : Collections.EMPTY_MAP; }
From source file:com.feedzai.fos.impl.dummy.DummyManager.java
@Override public Map<UUID, ModelConfig> listModels() { return Collections.EMPTY_MAP; }
From source file:org.apache.tiles.definition.TestUrlDefinitionsFactory.java
/** * Tests the getDefinition method./*from w w w . j ava 2 s . c o m*/ * * @throws Exception If something goes wrong. */ @SuppressWarnings("unchecked") public void testGetDefinition() throws Exception { DefinitionsFactory factory = new UrlDefinitionsFactory(); // Set up multiple data sources. URL url1 = this.getClass().getClassLoader().getResource("org/apache/tiles/config/defs1.xml"); assertNotNull("Could not load defs1 file.", url1); URL url2 = this.getClass().getClassLoader().getResource("org/apache/tiles/config/defs2.xml"); assertNotNull("Could not load defs2 file.", url2); URL url3 = this.getClass().getClassLoader().getResource("org/apache/tiles/config/defs3.xml"); assertNotNull("Could not load defs3 file.", url3); factory.addSource(url1); factory.addSource(url2); factory.addSource(url3); factory.init(Collections.EMPTY_MAP); TilesRequestContext emptyContext = new MockOnlyLocaleTilesContext(null); TilesRequestContext usContext = new MockOnlyLocaleTilesContext(Locale.US); TilesRequestContext frenchContext = new MockOnlyLocaleTilesContext(Locale.FRENCH); TilesRequestContext chinaContext = new MockOnlyLocaleTilesContext(Locale.CHINA); TilesRequestContext canadaFrenchContext = new MockOnlyLocaleTilesContext(Locale.CANADA_FRENCH); assertNotNull("test.def1 definition not found.", factory.getDefinition("test.def1", emptyContext)); assertNotNull("test.def2 definition not found.", factory.getDefinition("test.def2", emptyContext)); assertNotNull("test.def3 definition not found.", factory.getDefinition("test.def3", emptyContext)); assertNotNull("test.common definition not found.", factory.getDefinition("test.common", emptyContext)); assertNotNull("test.common definition in US locale not found.", factory.getDefinition("test.common", usContext)); assertNotNull("test.common definition in FRENCH locale not found.", factory.getDefinition("test.common", frenchContext)); assertNotNull("test.common definition in CHINA locale not found.", factory.getDefinition("test.common", chinaContext)); assertNotNull("test.common.french definition in FRENCH locale not found.", factory.getDefinition("test.common.french", frenchContext)); assertNotNull("test.common.french definition in CANADA_FRENCH locale not found.", factory.getDefinition("test.common.french", canadaFrenchContext)); assertNotNull("test.def.toextend definition not found.", factory.getDefinition("test.def.toextend", emptyContext)); assertNotNull("test.def.overridden definition not found.", factory.getDefinition("test.def.overridden", emptyContext)); assertNotNull("test.def.overridden definition in FRENCH locale not found.", factory.getDefinition("test.def.overridden", frenchContext)); assertEquals("Incorrect default country value", "default", factory.getDefinition("test.def1", emptyContext).getAttribute("country").getValue()); assertEquals("Incorrect US country value", "US", factory.getDefinition("test.def1", usContext).getAttribute("country").getValue()); assertEquals("Incorrect France country value", "France", factory.getDefinition("test.def1", frenchContext).getAttribute("country").getValue()); assertEquals("Incorrect Chinese country value (should be default)", "default", factory.getDefinition("test.def1", chinaContext).getAttribute("country").getValue()); assertEquals("Incorrect default country value", "default", factory.getDefinition("test.def.overridden", emptyContext).getAttribute("country").getValue()); assertEquals("Incorrect default title value", "Definition to be overridden", factory.getDefinition("test.def.overridden", emptyContext).getAttribute("title").getValue()); assertEquals("Incorrect France country value", "France", factory.getDefinition("test.def.overridden", frenchContext).getAttribute("country").getValue()); assertEquals("Incorrect France title value", "Definition to be extended", factory.getDefinition("test.def.overridden", frenchContext).getAttribute("title").getValue()); }
From source file:de.hybris.platform.catalog.jalo.synchronization.ItemCopyCreatorServiceLayerTest.java
@Test public void testExceptionDuringCreation() throws InterruptedException { createConstraint = createCreateConstraint(PRODUCT_FAILING_ON_CREATE); modelService.save(createConstraint); validationService.reloadValidationEngine(); final CatalogVersionSyncCopyContext ctx = new CatalogVersionSyncCopyContext(syncJob, syncCronJob, worker); final Product source = ProductManager.getInstance().createProduct(PRODUCT_FAILING_ON_CREATE + " foo "); final Product target = null; final Collection<String> whiteList = Arrays .asList(Product.CODE/*, Product.NAME, Product.TYPE, Product.PK*/); final Collection<String> blackList = Arrays.asList(Product.MODIFIED_TIME, Product.CREATION_TIME); final Map<String, Object> presets = Collections.EMPTY_MAP; final ItemCopyCreator copyCreator = new ItemCopyCreator(ctx, null, source, target, blackList, whiteList, presets);/*from www. j a va 2s. co m*/ Assert.assertNull(copyCreator.copy()); }
From source file:com.ms.commons.summer.web.util.json.JsonBeanUtils.java
/** * Creates a bean from a JSONObject, with the specific configuration. *//*ww w .j a va 2s. co m*/ public static Object toBean(JSONObject jsonObject, JsonConfig jsonConfig) { if (jsonObject == null || jsonObject.isNullObject()) { return null; } Class beanClass = jsonConfig.getRootClass(); Map classMap = jsonConfig.getClassMap(); if (beanClass == null) { return toBean(jsonObject); } if (classMap == null) { classMap = Collections.EMPTY_MAP; } Object bean = null; try { if (beanClass.isInterface()) { if (!Map.class.isAssignableFrom(beanClass)) { throw new JSONException("beanClass is an interface. " + beanClass); } else { bean = new HashMap(); } } else { bean = jsonConfig.getNewBeanInstanceStrategy().newInstance(beanClass, jsonObject); } } catch (JSONException jsone) { throw jsone; } catch (Exception e) { throw new JSONException(e); } Map props = JSONUtils.getProperties(jsonObject); PropertyFilter javaPropertyFilter = jsonConfig.getJavaPropertyFilter(); for (Iterator entries = jsonObject.names().iterator(); entries.hasNext();) { String name = (String) entries.next(); Class type = (Class) props.get(name); Object value = jsonObject.get(name); if (javaPropertyFilter != null && javaPropertyFilter.apply(bean, name, value)) { continue; } String key = Map.class.isAssignableFrom(beanClass) && jsonConfig.isSkipJavaIdentifierTransformationInMapKeys() ? name : JSONUtils.convertToJavaIdentifier(name, jsonConfig); try { if (Map.class.isAssignableFrom(beanClass)) { // no type info available for conversion if (JSONUtils.isNull(value)) { setProperty(bean, key, value, jsonConfig); } else if (value instanceof JSONArray) { setProperty(bean, key, convertPropertyValueToCollection(key, value, jsonConfig, name, classMap, List.class), jsonConfig); } else if (String.class.isAssignableFrom(type) || JSONUtils.isBoolean(type) || JSONUtils.isNumber(type) || JSONUtils.isString(type) || JSONFunction.class.isAssignableFrom(type)) { if (jsonConfig.isHandleJettisonEmptyElement() && "".equals(value)) { setProperty(bean, key, null, jsonConfig); } else { setProperty(bean, key, value, jsonConfig); } } else { Class targetClass = findTargetClass(key, classMap); targetClass = targetClass == null ? findTargetClass(name, classMap) : targetClass; JsonConfig jsc = jsonConfig.copy(); jsc.setRootClass(targetClass); jsc.setClassMap(classMap); if (targetClass != null) { setProperty(bean, key, toBean((JSONObject) value, jsc), jsonConfig); } else { setProperty(bean, key, toBean((JSONObject) value), jsonConfig); } } } else { PropertyDescriptor pd = PropertyUtils.getPropertyDescriptor(bean, key); if (pd != null && pd.getWriteMethod() == null) { log.warn("Property '" + key + "' has no write method. SKIPPED."); continue; } if (pd != null) { Class targetType = pd.getPropertyType(); if (!JSONUtils.isNull(value)) { if (value instanceof JSONArray) { if (List.class.isAssignableFrom(pd.getPropertyType())) { setProperty(bean, key, convertPropertyValueToCollection(key, value, jsonConfig, name, classMap, pd.getPropertyType()), jsonConfig); } else if (Set.class.isAssignableFrom(pd.getPropertyType())) { setProperty(bean, key, convertPropertyValueToCollection(key, value, jsonConfig, name, classMap, pd.getPropertyType()), jsonConfig); } else { setProperty(bean, key, convertPropertyValueToArray(key, value, targetType, jsonConfig, classMap), jsonConfig); } } else if (String.class.isAssignableFrom(type) || JSONUtils.isBoolean(type) || JSONUtils.isNumber(type) || JSONUtils.isString(type) || JSONFunction.class.isAssignableFrom(type)) { if (pd != null) { if (jsonConfig.isHandleJettisonEmptyElement() && "".equals(value)) { setProperty(bean, key, null, jsonConfig); } else if (!targetType.isInstance(value)) { setProperty(bean, key, morphPropertyValue(key, value, type, targetType), jsonConfig); } else { setProperty(bean, key, value, jsonConfig); } } else if (beanClass == null || bean instanceof Map) { setProperty(bean, key, value, jsonConfig); } else { log.warn("Tried to assign property " + key + ":" + type.getName() + " to bean of class " + bean.getClass().getName()); } } else { if (jsonConfig.isHandleJettisonSingleElementArray()) { JSONArray array = new JSONArray().element(value, jsonConfig); Class newTargetClass = findTargetClass(key, classMap); newTargetClass = newTargetClass == null ? findTargetClass(name, classMap) : newTargetClass; JsonConfig jsc = jsonConfig.copy(); jsc.setRootClass(newTargetClass); jsc.setClassMap(classMap); if (targetType.isArray()) { setProperty(bean, key, JSONArray.toArray(array, jsc), jsonConfig); } else if (JSONArray.class.isAssignableFrom(targetType)) { setProperty(bean, key, array, jsonConfig); } else if (List.class.isAssignableFrom(targetType) || Set.class.isAssignableFrom(targetType)) { jsc.setCollectionType(targetType); setProperty(bean, key, JSONArray.toCollection(array, jsc), jsonConfig); } else { setProperty(bean, key, toBean((JSONObject) value, jsc), jsonConfig); } } else { if (targetType == Object.class) { targetType = findTargetClass(key, classMap); targetType = targetType == null ? findTargetClass(name, classMap) : targetType; } JsonConfig jsc = jsonConfig.copy(); jsc.setRootClass(targetType); jsc.setClassMap(classMap); setProperty(bean, key, toBean((JSONObject) value, jsc), jsonConfig); } } } else { if (type.isPrimitive()) { // assume assigned default value log.warn("Tried to assign null value to " + key + ":" + type.getName()); setProperty(bean, key, JSONUtils.getMorpherRegistry().morph(type, null), jsonConfig); } else { setProperty(bean, key, null, jsonConfig); } } } else { if (!JSONUtils.isNull(value)) { if (value instanceof JSONArray) { setProperty(bean, key, convertPropertyValueToCollection(key, value, jsonConfig, name, classMap, List.class), jsonConfig); } else if (String.class.isAssignableFrom(type) || JSONUtils.isBoolean(type) || JSONUtils.isNumber(type) || JSONUtils.isString(type) || JSONFunction.class.isAssignableFrom(type)) { if (pd != null) { if (jsonConfig.isHandleJettisonEmptyElement() && "".equals(value)) { setProperty(bean, key, null, jsonConfig); } else { setProperty(bean, key, value, jsonConfig); } } else if (beanClass == null || bean instanceof Map) { setProperty(bean, key, value, jsonConfig); } else { log.warn("Tried to assign property " + key + ":" + type.getName() + " to bean of class " + bean.getClass().getName()); } } else { if (jsonConfig.isHandleJettisonSingleElementArray()) { Class newTargetClass = findTargetClass(key, classMap); newTargetClass = newTargetClass == null ? findTargetClass(name, classMap) : newTargetClass; JsonConfig jsc = jsonConfig.copy(); jsc.setRootClass(newTargetClass); jsc.setClassMap(classMap); setProperty(bean, key, toBean((JSONObject) value, jsc), jsonConfig); } else { setProperty(bean, key, value, jsonConfig); } } } else { if (type.isPrimitive()) { // assume assigned default value log.warn("Tried to assign null value to " + key + ":" + type.getName()); setProperty(bean, key, JSONUtils.getMorpherRegistry().morph(type, null), jsonConfig); } else { setProperty(bean, key, null, jsonConfig); } } } } } catch (JSONException jsone) { throw jsone; } catch (Exception e) { throw new JSONException("Error while setting property=" + name + " type " + type, e); } } return bean; }
From source file:fr.inria.atlanmod.neoemf.graph.blueprints.datastore.BlueprintsPersistenceBackendFactoryTest.java
@Test public void testCreatePersistentBackendNoOptionNoConfigFile() throws InvalidDataStoreException { PersistenceBackend persistentBackend = persistenceBackendFactory.createPersistentBackend(testFile, Collections.EMPTY_MAP); assert persistentBackend instanceof BlueprintsPersistenceBackend : "Invalid backend created"; BlueprintsPersistenceBackend graph = (BlueprintsPersistenceBackend) persistentBackend; assert graph.getBaseGraph() instanceof TinkerGraph : "The base graph is not the default TinkerGraph"; }
From source file:de.hybris.platform.catalog.jalo.synchronization.ItemCopyCreatorTest.java
@Test public void testExceptionDuringCreation() throws InterruptedException { final CatalogVersionSyncCopyContext ctx = new CatalogVersionSyncCopyContext(syncJob, syncCronJob, worker) { @Override// w w w . j av a 2 s . c o m SynchronizationPersistenceAdapter getPersistenceAdapter() { return new LegacySynchronizationPersistenceAdapter(this) { @Override public Item create(final ComposedType expectedType, final Map<String, Object> attributes) throws SynchronizationPersistenceException { throw new IllegalStateException("expected exception during creation "); } }; } }; final Product source = ProductManager.getInstance().createProduct(PRODUCT_FAILING_ON_CREATE); final Product target = null; final Collection<String> whiteList = Arrays .asList(Product.CODE/* , Product.NAME, Product.TYPE, Product.PK */); final Collection<String> blackList = Arrays.asList(Product.MODIFIED_TIME, Product.CREATION_TIME); final Map<String, Object> presets = Collections.EMPTY_MAP; final ItemCopyCreator copyCreator = new ItemCopyCreator(ctx, null, source, target, blackList, whiteList, presets); Assert.assertNull(copyCreator.copy()); }
From source file:it.units.malelab.ege.benchmark.mapper.MappingPropertiesFitness.java
@Override public MultiObjectiveFitness<Double> compute(Node<String> mapperRawPhenotype) { Map<Property, double[]> propertyValues = new LinkedHashMap<>(); for (Property property : properties) { propertyValues.put(property, new double[problems.size()]); }/*from www. ja v a 2 s . c o m*/ int i = 0; for (Problem<String, NumericFitness> problem : problems.keySet()) { List<Node<String>> phenotypes = new ArrayList<>(); Multiset<Node<String>> groups = LinkedHashMultiset.create(); //build mapper RecursiveMapper<String> mapper = new RecursiveMapper<>(mapperRawPhenotype, maxMappingDepth, EXPRESSIVENESS_DEPTH, problem.getGrammar()); //map for (BitsGenotype genotype : genotypes) { Node<String> phenotype = Node.EMPTY_TREE; try { phenotype = mapper.map(genotype, Collections.EMPTY_MAP); } catch (MappingException ex) { //ignore } phenotypes.add(phenotype); groups.add(phenotype); } //compute properties if (propertyValues.keySet().contains(Property.REDUNDANCY)) { propertyValues.get(Property.REDUNDANCY)[i] = 1d - (double) groups.elementSet().size() / (double) genotypes.size(); } if (propertyValues.keySet().contains(Property.NON_UNIFORMITY)) { double[] groupSizes = new double[groups.elementSet().size()]; int c = 0; for (Node<String> phenotype : groups.elementSet()) { groupSizes[c] = (double) groups.count(phenotype); c = c + 1; } propertyValues.get(Property.NON_UNIFORMITY)[i] = Math.sqrt(StatUtils.variance(groupSizes)) / StatUtils.mean(groupSizes); } if (propertyValues.keySet().contains(Property.NON_LOCALITY)) { double[] phenotypeDistances = computeDistances(phenotypes, problems.get(problem)); double locality = 1d - (1d + (new PearsonsCorrelation().correlation(genotypeDistances, phenotypeDistances))) / 2d; propertyValues.get(Property.NON_LOCALITY)[i] = Double.isNaN(locality) ? 1d : locality; } i = i + 1; } Double[] meanValues = new Double[properties.length]; for (int j = 0; j < properties.length; j++) { meanValues[j] = StatUtils.mean(propertyValues.get(properties[j])); } MultiObjectiveFitness<Double> mof = new MultiObjectiveFitness<Double>(meanValues); return mof; }
From source file:com.github.lucapino.jira.GenerateReleaseNotesMojo.java
/** * Writes issues to output//from w ww . j av a 2s . co m * * @param issues */ void output(List<JiraIssue> issues) throws IOException, MojoFailureException { Log log = getLog(); if (targetFile == null) { log.warn("No targetFile specified. Ignoring"); return; } if (issues == null) { log.warn("No issues found. File will not be generated."); return; } HashMap<Object, Object> parameters = new HashMap<>(); HashMap<String, List<JiraIssue>> jiraIssues = processIssues(issues); List<JiraIssue> jiraIssuesList = new ArrayList<>(); for (List<JiraIssue> list : jiraIssues.values()) { jiraIssuesList.addAll(list); } parameters.put("issues", jiraIssuesList); parameters.put("issuesMap", jiraIssues); parameters.put("jiraURL", jiraURL); parameters.put("jiraProjectKey", jiraProjectKey); parameters.put("releaseVersion", releaseVersion); if (announceParameters == null) { // empty Map to prevent NPE in velocity execution parameters.put("announceParameters", java.util.Collections.EMPTY_MAP); } else { parameters.put("announceParameters", announceParameters); } boolean useDefault = false; if (templateFile == null || !templateFile.exists()) { useDefault = true; // let's use the default one // it/peng/maven/jira/releaseNotes.vm InputStream defaultTemplate = this.getClass().getClassLoader().getResourceAsStream("releaseNotes.vm"); templateFile = File.createTempFile("releaseNotes.vm", null); FileOutputStream fos = new FileOutputStream(templateFile); IOUtils.copy(defaultTemplate, fos); IOUtils.closeQuietly(defaultTemplate); IOUtils.closeQuietly(fos); } String content = getEvaluator().evaluate(templateFile, parameters); if (useDefault) { // remove the temp file templateFile.delete(); } // this creates the parent folder and the file if they doesn't exist OutputStreamWriter writer = new OutputStreamWriter(FileUtils.openOutputStream(targetFile), "UTF-8"); PrintWriter ps = new PrintWriter(writer); try { if (beforeText != null) { ps.println(beforeText); } ps.println(content); if (afterText != null) { ps.println(afterText); } } finally { ps.flush(); IOUtils.closeQuietly(ps); } }
From source file:grails.plugin.errorpagesfix.PatchedErrorHandlingServlet.java
@Override protected void doDispatch(final HttpServletRequest request, final HttpServletResponse response) throws Exception { int statusCode; if (request.getAttribute("javax.servlet.error.status_code") != null) { statusCode = Integer.parseInt(request.getAttribute("javax.servlet.error.status_code").toString()); } else {//from w w w .j av a 2 s . com statusCode = 500; } Throwable t = null; if (request.getAttribute("javax.servlet.error.exception") != null) { t = (Throwable) request.getAttribute("javax.servlet.error.exception"); if (!(t instanceof GrailsWrappedRuntimeException) && request.getAttribute("exception") == null) { request.setAttribute("exception", new GrailsWrappedRuntimeException(getServletContext(), t)); } } final UrlMappingsHolder urlMappingsHolder = lookupUrlMappings(); UrlMappingInfo matchedInfo = null; if (t != null) { matchedInfo = urlMappingsHolder.matchStatusCode(statusCode, t); if (matchedInfo == null) { matchedInfo = urlMappingsHolder.matchStatusCode(statusCode, GrailsExceptionResolver.getRootCause(t)); } } if (matchedInfo == null) { matchedInfo = urlMappingsHolder.matchStatusCode(statusCode); } final UrlMappingInfo urlMappingInfo = matchedInfo; if (urlMappingInfo != null) { final GrailsWebRequest webRequest = (GrailsWebRequest) RequestContextHolder.getRequestAttributes(); request.setAttribute("com.opensymphony.sitemesh.APPLIED_ONCE", null); urlMappingInfo.configure(webRequest); String viewName = urlMappingInfo.getViewName(); if (viewName == null || viewName.endsWith(GSP_SUFFIX) || viewName.endsWith(JSP_SUFFIX)) { WebUtils.forwardRequestForUrlMappingInfo(request, response, urlMappingInfo, Collections.EMPTY_MAP); } else { ViewResolver viewResolver = WebUtils.lookupViewResolver(getServletContext()); if (viewResolver != null) { View v; try { v = WebUtils.resolveView(request, urlMappingInfo, viewName, viewResolver); IncludeResponseWrapper includeResponse = new IncludeResponseWrapper(response); v.render(Collections.EMPTY_MAP, request, response); } catch (Exception e) { throw new UrlMappingException( "Error mapping onto view [" + viewName + "]: " + e.getMessage(), e); } } } } else { renderDefaultResponse(response, statusCode); } }