List of usage examples for java.util Map isEmpty
boolean isEmpty();
From source file:com.hangum.tadpole.engine.restful.RESTfulAPIUtils.java
/** * Return SQL Paramter/*from w w w .j ava2s. co m*/ * * @param strSQL * @return */ public static String getParameter(String strSQL) { String strArguments = ""; OracleStyleSQLNamedParameterUtil oracleNamedParamUtil = OracleStyleSQLNamedParameterUtil.getInstance(); oracleNamedParamUtil.parse(strSQL); Map<Integer, String> mapIndex = oracleNamedParamUtil.getMapIndexToName(); if (!mapIndex.isEmpty()) { for (String strParam : mapIndex.values()) { strArguments += String.format("%s={%s_value}&", strParam, strParam); } strArguments = StringUtils.removeEnd(strArguments, "&"); } else { strArguments = "";//1={FirstParameter}&2={SecondParameter}"; } return strArguments; }
From source file:com.evolveum.midpoint.schema.result.OperationResultFactory.java
public static OperationResultType createOperationResult(String operation, OperationResultStatusType status, Map<String, Element> params) { OperationResultType result = createOperationResult(operation, status); if (params == null || params.isEmpty()) { return result; }//from ww w .j a va 2 s . co m ObjectFactory factory = new ObjectFactory(); ParamsType paramsType = factory.createParamsType(); result.setParams(paramsType); EntryType entryType; Set<Entry<String, Element>> set = params.entrySet(); for (Entry<String, Element> entry : set) { entryType = factory.createEntryType(); entryType.setKey(entry.getKey()); entryType.setEntryValue(new JAXBElement(EntryType.F_ENTRY_VALUE, Element.class, entry.getValue())); paramsType.getEntry().add(entryType); } return result; }
From source file:com.datumbox.common.dataobjects.MatrixDataset.java
/** * Method used to generate a Dataset to a MatrixDataset and extracts its contents * to Matrixes. It populates the featureIdsReference map with the mappings * between the feature names and the column ids of the matrix. Typically used * to convert the training dataset./*from w w w . j av a 2s. c o m*/ * * @param dataset * @param addConstantColumn * @param featureIdsReference * @return */ public static MatrixDataset newInstance(Dataset dataset, boolean addConstantColumn, Map<Object, Integer> featureIdsReference) { if (!featureIdsReference.isEmpty()) { throw new RuntimeException("The featureIdsReference map should be empty."); } int n = dataset.size(); int d = dataset.getColumnSize(); if (addConstantColumn) { ++d; } MatrixDataset m = new MatrixDataset(new ArrayRealVector(n), new BlockRealMatrix(n, d), featureIdsReference); if (dataset.isEmpty()) { return m; } boolean extractY = (Dataset .value2ColumnType(dataset.iterator().next().getY()) == Dataset.ColumnType.NUMERICAL); int previousFeatureId = 0; if (addConstantColumn) { for (int row = 0; row < n; ++row) { m.X.setEntry(row, previousFeatureId, 1.0); //put the constant in evey row } m.feature2ColumnId.put(Dataset.constantColumnName, previousFeatureId); ++previousFeatureId; } for (Record r : dataset) { int row = r.getId(); if (extractY) { m.Y.setEntry(row, Dataset.toDouble(r.getY())); } for (Map.Entry<Object, Object> entry : r.getX().entrySet()) { Object feature = entry.getKey(); Integer featureId = m.feature2ColumnId.get(feature); if (featureId == null) { featureId = previousFeatureId; m.feature2ColumnId.put(feature, featureId); ++previousFeatureId; } Double value = Dataset.toDouble(entry.getValue()); if (value != null) { m.X.setEntry(row, featureId, value); } else { //else the X matrix maintains the 0.0 default value } } } return m; }
From source file:net.sf.dynamicreports.jasper.base.tableofcontents.JasperTocReport.java
public static void createTocReport(JasperReportDesign jasperReportDesign, JasperPrint jasperPrint) throws DRException, JRException { JasperCustomValues customValues = jasperReportDesign.getCustomValues(); Map<String, JasperTocHeading> headings = customValues.getTocHeadings(); if (headings != null && !headings.isEmpty()) { JasperReportBuilder tocReport = report(); List<JasperTocHeading> headingList = new ArrayList<JasperTocHeading>(); int pageNumber = 1; for (JRPrintPage page : jasperPrint.getPages()) { for (JRPrintElement element : page.getElements()) { addTocHeading(headings, headingList, element, pageNumber); }// ww w. j av a 2 s . c om pageNumber++; } int levels = 0; for (JasperTocHeading heading : headingList) { if (heading.getLevel() > levels) { levels = heading.getLevel(); } } levels++; DRIDesignPage designPage = jasperReportDesign.getReport().getPage(); DRPage tocPage = tocReport.getReport().getPage(); tocPage.setWidth(designPage.getWidth()); tocPage.setHeight(designPage.getHeight()); tocPage.setOrientation(designPage.getOrientation()); DRIDesignMargin designMargin = designPage.getMargin(); MarginBuilder tocMargin = margin(); tocMargin.setTop(designMargin.getTop()); tocMargin.setLeft(designMargin.getLeft()); tocMargin.setBottom(designMargin.getBottom()); tocMargin.setRight(designMargin.getRight()); tocReport.setPageMargin(tocMargin); tocReport.setDataSource(new JRBeanCollectionDataSource(headingList)); DRITableOfContentsCustomizer tableOfContents = jasperReportDesign.getReport() .getTableOfContentsCustomizer(); tableOfContents.setReport(tocReport); tableOfContents.setHeadingList(headingList); tableOfContents.setHeadings(headings.size()); tableOfContents.setLevels(levels); tableOfContents.customize(); TableOfContentsPosition tableOfContentsPosition = tableOfContents.getPosition(); if (tableOfContentsPosition == null) { tableOfContentsPosition = Defaults.getDefaults().getTableOfContentsPosition(); } JasperPrint tocJasperPrint = tocReport.toJasperPrint(); for (int i = 0; i < tocJasperPrint.getPages().size(); i++) { JRPrintPage page = tocJasperPrint.getPages().get(i); switch (tableOfContentsPosition) { case TOP: jasperPrint.addPage(i, page); break; case BOTTOM: jasperPrint.addPage(page); break; default: throw new JasperDesignException( "Table of contents position " + tableOfContentsPosition.name() + " not supported"); } } for (JRStyle style : tocJasperPrint.getStyles()) { jasperPrint.addStyle(style); } } }
From source file:fm.pattern.spin.config.SpinConfiguration.java
private static List<Instance> resolveInstances(Map<String, Map<String, Object>> model) { List<Instance> instances = new ArrayList<>(); for (Map.Entry<String, Map<String, Object>> entry : model.entrySet()) { String name = entry.getKey(); if (name.equals("startup")) { continue; }/*from w ww . j a v a2s .c o m*/ Map<String, Object> map = entry.getValue(); String start = (String) map.get("start"); if (StringUtils.isEmpty(start)) { throw new SpinConfigurationException( "Invalid Spin configuration - 'start' is required attribute for " + name); } String stop = (String) map.get("stop"); if (StringUtils.isEmpty(stop)) { throw new SpinConfigurationException( "Invalid Spin configuration - 'stop' is required attribute for " + name); } String ping = (String) map.get("ping"); if (StringUtils.isBlank(ping)) { throw new SpinConfigurationException( "Invalid Spin configuration - 'ping' is a required attribute for " + name); } Instance instance = new Instance(name, start, stop, ping); String path = (String) map.get("path"); if (StringUtils.isNotBlank(path)) { instance.setPath(path); } Map<String, String> environment = (Map<String, String>) map.get("environment"); if (environment != null && !environment.isEmpty()) { instance.setEnvironment(environment); } instances.add(instance); } return instances; }
From source file:com.google.api.tools.framework.importers.swagger.MultiSwaggerParser.java
/** * Ensures that all files are valid json/yaml and does schema validation on swagger spec. Returns * * <p>the valid swagger file./* ww w .ja v a 2s . c om*/ * * @throws SwaggerConversionException */ private static Map<String, File> validateInputFiles(Map<String, FileWrapper> savedFilePaths) throws SwaggerConversionException { Map<String, File> topLevelSwaggerFiles = getTopLevelSwaggerFiles(savedFilePaths); if (topLevelSwaggerFiles.isEmpty()) { throw new SwaggerConversionException(String .format("Cannot find a valid swagger %s spec in the input files", CURRENT_SWAGGER_VERSION)); } return topLevelSwaggerFiles; }
From source file:com.longtime.ajy.support.weixin.HttpsKit.java
/** * @param url/*from ww w . java 2 s. c o m*/ * @param params * @return */ private static String initParams(String url, Map<String, String> params) { if (null == params || params.isEmpty()) { return url; } StringBuilder sb = new StringBuilder(url); if (url.indexOf("?") == -1) { sb.append("?"); } else { sb.append("&"); } boolean first = true; for (Entry<String, String> entry : params.entrySet()) { if (first) { first = false; } else { sb.append("&"); } String key = entry.getKey(); String value = entry.getValue(); sb.append(key).append("="); if (StringUtils.isNotEmpty(value)) { try { sb.append(URLEncoder.encode(value, DEFAULT_CHARSET)); } catch (UnsupportedEncodingException e) { e.printStackTrace(); logger.error(url, e); } } } return sb.toString(); }
From source file:com.baasbox.service.push.providers.GCMServer.java
public static void validateApiKey(String apikey) throws MalformedURLException, IOException, PushInvalidApiKeyException { Message message = new Message.Builder().addData("message", "validateAPIKEY").build(); Sender sender = new Sender(apikey); List<String> deviceid = new ArrayList<String>(); deviceid.add("ABC"); Map<Object, Object> jsonRequest = new HashMap<Object, Object>(); jsonRequest.put(JSON_REGISTRATION_IDS, deviceid); Map<String, String> payload = message.getData(); if (!payload.isEmpty()) { jsonRequest.put(JSON_PAYLOAD, payload); }//ww w . j a va2 s. c o m String requestBody = JSONValue.toJSONString(jsonRequest); String url = com.google.android.gcm.server.Constants.GCM_SEND_ENDPOINT; HttpURLConnection conn = (HttpURLConnection) new URL(url).openConnection(); byte[] bytes = requestBody.getBytes(); conn.setDoOutput(true); conn.setUseCaches(false); conn.setFixedLengthStreamingMode(bytes.length); conn.setRequestMethod("POST"); conn.setRequestProperty("Content-Type", "application/json"); conn.setRequestProperty("Authorization", "key=" + apikey); OutputStream out = conn.getOutputStream(); out.write(bytes); out.close(); int status = conn.getResponseCode(); if (status != 200) { if (status == 401) { throw new PushInvalidApiKeyException("Wrong api key"); } if (status == 503) { throw new UnknownHostException(); } } }
From source file:se.uu.it.cs.recsys.ruleminer.datastructure.builder.FPTreeHeaderTableBuilder.java
/** * * @param idAndCount item id and count//from w ww. j a va 2 s . c o m * @param threshold, min support * @return non-null HeaderTableItem if the input contains id meets threshold * requirement; otherwise null. */ public static List<HeaderTableItem> build(Map<Integer, Integer> idAndCount, Integer threshold) { List<HeaderTableItem> instance = new ArrayList<>(); Map<Integer, Integer> filteredIdAndCount = Util.filter(idAndCount, threshold); if (filteredIdAndCount.isEmpty()) { LOGGER.debug("Empty map after filtering. Empty list will be returned. Source: {}", idAndCount); return instance; } List<Integer> countList = new ArrayList<>(filteredIdAndCount.values()); Collections.sort(countList); Collections.reverse(countList);// now the count is in DESC order for (int i = 1; i <= filteredIdAndCount.size(); i++) { instance.add(new HeaderTableItem()); // in order to call list.set(idx,elem) } Map<Integer, Set<Integer>> forIdsHavingSameCount = new HashMap<>();//different ids may have same count filteredIdAndCount.entrySet().forEach((entry) -> { Integer courseId = entry.getKey(); Integer count = entry.getValue(); Integer countFrequence = Collections.frequency(countList, count); if (countFrequence == 1) { Integer countIdx = countList.indexOf(count); instance.set(countIdx, new HeaderTableItem(new Item(courseId, count))); } else { // different ids have same count if (!forIdsHavingSameCount.containsKey(count)) { forIdsHavingSameCount.put(count, Util.findDuplicatesIndexes(countList, count)); } Iterator<Integer> itr = forIdsHavingSameCount.get(count).iterator(); Integer idx = itr.next(); itr.remove(); instance.set(idx, new HeaderTableItem(new Item(courseId, count))); } }); // LOGGER.debug("Final built header table: {}", // instance.stream() // .map(headerItem -> headerItem.getItem()).collect(Collectors.toList())); return instance; }
From source file:de.bund.bfr.jung.JungUtils.java
private static double getDenominator(Map<?, Double> values) { if (values == null || values.isEmpty()) { return 1.0; }//from ww w. ja v a 2s .com double max = Collections.max(values.values()); return max != 0.0 ? max : 1.0; }