List of usage examples for java.util Map isEmpty
boolean isEmpty();
From source file:com.impetus.kundera.utils.KunderaCoreUtils.java
public static boolean isEmptyOrNull(Object o) { if (o == null) { return true; }//from w w w . java 2 s . c o m if (!ProxyHelper.isProxyOrCollection(o)) { if (PropertyAccessorHelper.isCollection(o.getClass())) { Collection c = (Collection) o; if (c.isEmpty()) { return true; } } else if (Map.class.isAssignableFrom(o.getClass())) { Map m = (Map) o; if (m.isEmpty()) { return true; } } } return false; }
From source file:com.streamsets.pipeline.lib.jdbc.multithread.util.OffsetQueryUtil.java
/** * Build query using the lastOffset which is of the form (<column1>=<value1>::<column2>=<value2>::<column3>=<value3>) * * @param tableRuntimeContext Context for the current table. * @param lastOffset the last offset for this particular table * @return A query to execute for the current batch. *///from ww w . j ava 2 s .co m public static Pair<String, List<Pair<Integer, String>>> buildAndReturnQueryAndParamValToSet( TableRuntimeContext tableRuntimeContext, String lastOffset, String quoteChar, TableJdbcELEvalContext tableJdbcELEvalContext) throws ELEvalException { final TableContext tableContext = tableRuntimeContext.getSourceTableContext(); StringBuilder queryBuilder = new StringBuilder(); List<Pair<Integer, String>> paramValueToSet = new ArrayList<>(); queryBuilder.append(buildBaseTableQuery(tableRuntimeContext, quoteChar)); Map<String, String> storedTableToOffset = getColumnsToOffsetMapFromOffsetFormat(lastOffset); final boolean noStoredOffsets = storedTableToOffset.isEmpty(); //Determines whether an initial offset is specified in the config and there is no stored offset. boolean isOffsetOverriden = tableContext.isOffsetOverriden() && noStoredOffsets; OffsetComparison minComparison = OffsetComparison.GREATER_THAN; Map<String, String> offset = null; if (isOffsetOverriden) { //Use the offset in the configuration offset = tableContext.getOffsetColumnToStartOffset(); } else if (tableRuntimeContext.isPartitioned() && noStoredOffsets) { // use partitioned starting offsets offset = tableRuntimeContext.getStartingPartitionOffsets(); minComparison = OffsetComparison.GREATER_THAN_OR_EQUALS; } else { // if offset is available // get the stored offset (which is of the form partitionName=value) and strip off 'offsetColumns=' prefix // else null // offset = storedOffsets; offset = storedTableToOffset; } Map<String, String> maxOffsets = new HashMap<>(); if (tableRuntimeContext.isPartitioned()) { maxOffsets.putAll(tableRuntimeContext.getMaxPartitionOffsets()); } List<String> finalAndConditions = new ArrayList<>(); //Apply last offset conditions if (offset != null && !offset.isEmpty()) { List<String> finalOrConditions = new ArrayList<>(); List<String> preconditions = new ArrayList<>(); List<Pair<Integer, String>> preconditionParamVals = new ArrayList<>(); //For partition columns p1, p2 and p3 with offsets o1, o2 and o3 respectively, the query will look something like //select * from tableName where (p1 > o1) or (p1 = o1 and p2 > o2) or (p1 = o1 and p2 = o2 and p3 > o3) order by p1, p2, p3. for (String partitionColumn : tableContext.getOffsetColumns()) { int partitionSqlType = tableContext.getOffsetColumnType(partitionColumn); String partitionOffset = offset.get(partitionColumn); String thisPartitionColumnMax = null; boolean hasMaxOffset = false; // add max value for partition column (if applicable) if (maxOffsets.containsKey(partitionColumn)) { final String maxOffset = maxOffsets.get(partitionColumn); if (!Strings.isNullOrEmpty(maxOffset)) { Pair<Integer, String> paramValForCurrentOffsetColumnMax = Pair.of(partitionSqlType, maxOffset); // add for current partition column max value paramValueToSet.add(paramValForCurrentOffsetColumnMax); thisPartitionColumnMax = getConditionForPartitionColumn(partitionColumn, OffsetComparison.LESS_THAN, preconditions, quoteChar); hasMaxOffset = true; } } final String thisPartitionColumnMin = getConditionForPartitionColumn(partitionColumn, minComparison, preconditions, quoteChar); String conditionForThisPartitionColumn; if (hasMaxOffset) { conditionForThisPartitionColumn = String.format(AND_CONDITION_FORMAT, // add max condition first, since its param to set was already added thisPartitionColumnMax, thisPartitionColumnMin); } else { conditionForThisPartitionColumn = String.format(CONDITION_FORMAT, thisPartitionColumnMin); } //Add for preconditions (EX: composite keys) paramValueToSet.addAll(new ArrayList<>(preconditionParamVals)); Pair<Integer, String> paramValForCurrentOffsetColumn = Pair.of(partitionSqlType, partitionOffset); //Add for current partition column paramValueToSet.add(paramValForCurrentOffsetColumn); finalOrConditions.add(conditionForThisPartitionColumn); preconditions.add(getConditionForPartitionColumn(partitionColumn, OffsetComparison.EQUALS, Collections.emptyList(), quoteChar)); preconditionParamVals.add(paramValForCurrentOffsetColumn); } finalAndConditions.add(String.format(CONDITION_FORMAT, OR_JOINER.join(finalOrConditions))); } if (!StringUtils.isEmpty(tableContext.getExtraOffsetColumnConditions())) { //Apply extra offset column conditions configured which will be appended as AND on the query String condition = tableJdbcELEvalContext.evaluateAsString("extraOffsetColumnConditions", tableContext.getExtraOffsetColumnConditions()); finalAndConditions.add(String.format(CONDITION_FORMAT, condition)); } if (!finalAndConditions.isEmpty()) { queryBuilder.append(String.format(WHERE_CLAUSE, AND_JOINER.join(finalAndConditions))); } Collection<String> quotedOffsetColumns = tableContext.getOffsetColumns().stream() .map(offsetCol -> String.format(QUOTED_NAME, quoteChar, offsetCol, quoteChar)) .collect(Collectors.toList()); queryBuilder.append(String.format(ORDER_BY_CLAUSE, COMMA_SPACE_JOINER.join(quotedOffsetColumns))); return Pair.of(queryBuilder.toString(), paramValueToSet); }
From source file:com.wso2telco.dep.operatorservice.StoreHostObject.java
public static NativeObject jsFunction_getOperatorApprovedSubscriptionsByApplicationId(Context cx, Scriptable thisObj, Object[] args, Function funObj) throws StoreHostObjectException { NativeObject resultObject = new NativeObject(); NativeArray historyArray = new NativeArray(0); String appId = args[0].toString(); OparatorService oparatorService = new OparatorService(); if (jsFunction_getDeploymentType().equals("hub") || jsFunction_getDeploymentType().equals("external_gateway")) { try {//from w w w . j a v a 2 s . c o m Map<Integer, Map<String, Map<String, String>>> subDetails = oparatorService .getOperatorApprovedSubscriptionsByApplicationId(Integer.parseInt(appId)); log.debug("getOperatorApprovedSubscriptionsByApplicationId : " + subDetails); if (!subDetails.isEmpty()) { int j = 0; for (Map.Entry<Integer, Map<String, Map<String, String>>> sub : subDetails.entrySet()) { Map<String, Map<String, String>> subInfo = sub.getValue(); NativeArray historyDataArray = new NativeArray(0); int z = 0; for (Map.Entry<String, Map<String, String>> sb : subInfo.entrySet()) { String apiName = sb.getKey(); Map<String, String> s = sb.getValue(); NativeObject subData = new NativeObject(); subData.put("apiName", subData, apiName); subData.put("substatus", subData, s.get("substatus")); subData.put("operatorname", subData, s.get("operatorname")); historyDataArray.put(z, historyDataArray, subData); z++; } historyArray.put(j, historyArray, historyDataArray); j++; } } else { log.debug("subscription details unavalible for application id : " + appId); } } catch (Exception e) { log.error("error occurred in getOperatorApprovedSubscriptionsByApplicationId : ", e); handleException(e.getMessage(), e); } } resultObject.put("operatorSubsApprovedHistory", resultObject, historyArray); return resultObject; }
From source file:com.aurel.track.admin.customize.category.filter.tree.design.TreeFilterSaverBL.java
/** * Gather the original tree and the dropdowns in a new tree to be saved * @param qNodeOriginalRoot/*w w w .j a v a 2s . co m*/ * @param filterSelectsTO * @return */ public static QNode createQNodeWithQueryListsTO(QNode qNodeOriginalRoot, FilterUpperTO filterSelectsTO, Locale locale) { QNode qNodeReportBean = createNode(QNode.AND); qNodeReportBean.setChildren(new ArrayList<QNode>()); qNodeReportBean.setType(QNode.AND); QNode qNode = createQueryNodeExpressionWithEqualMatcher(SystemFields.INTEGER_PROJECT, filterSelectsTO.getSelectedProjects()); if (qNode != null) { qNodeReportBean.getChildren().add(qNode); } qNode = createQueryNodeExpressionWithEqualMatcher(SystemFields.INTEGER_RELEASESCHEDULED, filterSelectsTO.getSelectedReleases()); if (qNode != null) { qNodeReportBean.getChildren().add(qNode); //save the closed release flag only if release is specified, otherwise by creating the textual filter expression (for tooltip) confuses the user boolean showClosedReleases = filterSelectsTO.isShowClosedReleases(); if (showClosedReleases) { qNode = createQueryNodeExpressionWithEqualMatcher( Integer.valueOf(FilterUpperTO.PSEUDO_FIELDS.SHOW_CLOSED_RELEASES), Boolean.valueOf(filterSelectsTO.isShowClosedReleases())); qNodeReportBean.getChildren().add(qNode); } //set the release type selector only if release is specified, otherwise by creating the textual filter expression (for tooltip) confuses the user Integer releaseTypeSelector = filterSelectsTO.getReleaseTypeSelector(); if (releaseTypeSelector != null) { qNode = createQueryNodeExpressionWithEqualMatcher( Integer.valueOf(FilterUpperTO.PSEUDO_FIELDS.RELEASE_TYPE_SELECTOR), releaseTypeSelector); qNodeReportBean.getChildren().add(qNode); } } qNode = createQueryNodeExpressionWithEqualMatcher(SystemFields.INTEGER_MANAGER, filterSelectsTO.getSelectedManagers()); if (qNode != null) { qNodeReportBean.getChildren().add(qNode); } qNode = createQueryNodeExpressionWithEqualMatcher(SystemFields.INTEGER_RESPONSIBLE, filterSelectsTO.getSelectedResponsibles()); if (qNode != null) { qNodeReportBean.getChildren().add(qNode); } qNode = createQueryNodeExpressionWithEqualMatcher(SystemFields.INTEGER_ORIGINATOR, filterSelectsTO.getSelectedOriginators()); if (qNode != null) { qNodeReportBean.getChildren().add(qNode); } qNode = createQueryNodeExpressionWithEqualMatcher(SystemFields.INTEGER_CHANGEDBY, filterSelectsTO.getSelectedChangedBys()); if (qNode != null) { qNodeReportBean.getChildren().add(qNode); } qNode = createQueryNodeExpressionWithEqualMatcher(SystemFields.INTEGER_STATE, filterSelectsTO.getSelectedStates()); if (qNode != null) { qNodeReportBean.getChildren().add(qNode); } qNode = createQueryNodeExpressionWithEqualMatcher(SystemFields.INTEGER_ISSUETYPE, filterSelectsTO.getSelectedIssueTypes()); if (qNode != null) { qNodeReportBean.getChildren().add(qNode); } qNode = createQueryNodeExpressionWithEqualMatcher(SystemFields.INTEGER_PRIORITY, filterSelectsTO.getSelectedPriorities()); if (qNode != null) { qNodeReportBean.getChildren().add(qNode); } qNode = createQueryNodeExpressionWithEqualMatcher(SystemFields.INTEGER_SEVERITY, filterSelectsTO.getSelectedSeverities()); if (qNode != null) { qNodeReportBean.getChildren().add(qNode); } //set the consultants/informants qNode = createQueryNodeExpressionWithEqualMatcher( Integer.valueOf(FilterUpperTO.PSEUDO_FIELDS.CONSULTANT_INFORMNAT_FIELD_ID), filterSelectsTO.getSelectedConsultantsInformants()); if (qNode != null) { //at least one consultant or informant is selected qNodeReportBean.getChildren().add(qNode); //the consultant or informant selector only if any watcher is specified, otherwise by creating the textual filter expression (for tooltip) confuses the user Integer watcherSelector = filterSelectsTO.getWatcherSelector(); if (watcherSelector != null) { qNode = createQueryNodeExpressionWithEqualMatcher( Integer.valueOf(FilterUpperTO.PSEUDO_FIELDS.CONSULTANT_OR_INFORMANT_SELECTOR), watcherSelector); qNodeReportBean.getChildren().add(qNode); } } //get the custom selects Map<Integer, String> selectedCustomSelectsMap = filterSelectsTO.getSelectedCustomSelectsStr(); if (selectedCustomSelectsMap != null && !selectedCustomSelectsMap.isEmpty()) for (Integer fieldID : selectedCustomSelectsMap.keySet()) { String selectedCustomSelects = selectedCustomSelectsMap.get(fieldID); if (selectedCustomSelects != null && selectedCustomSelects.length() > 0) { qNode = createQueryNodeExpressionWithEqualMatcher(fieldID, FilterUpperTO.createIntegerArrFromString(selectedCustomSelects)); if (qNode != null) { qNodeReportBean.getChildren().add(qNode); } } } //set the keyword String keyword = filterSelectsTO.getKeyword(); if (keyword != null && keyword.length() > 0) { //make it xml compatible keyword = StringEscapeUtils.escapeXml(keyword); qNode = createQueryNodeExpressionWithEqualMatcher( Integer.valueOf(FilterUpperTO.PSEUDO_FIELDS.KEYWORD_FIELD_ID), keyword); qNodeReportBean.getChildren().add(qNode); } Integer archived = filterSelectsTO.getArchived(); if (archived != null) { qNode = createQueryNodeExpressionWithEqualMatcher( Integer.valueOf(FilterUpperTO.PSEUDO_FIELDS.ARCHIVED_FIELD_ID), archived); qNodeReportBean.getChildren().add(qNode); } Integer deleted = filterSelectsTO.getDeleted(); if (deleted != null) { qNode = createQueryNodeExpressionWithEqualMatcher( Integer.valueOf(FilterUpperTO.PSEUDO_FIELDS.DELETED_FIELD_ID), deleted); qNodeReportBean.getChildren().add(qNode); } String linkTypeFilterSuperset = filterSelectsTO.getLinkTypeFilterSuperset(); if (linkTypeFilterSuperset != null && !"".equals(linkTypeFilterSuperset)) { qNode = createQueryNodeExpressionWithEqualMatcher( Integer.valueOf(FilterUpperTO.PSEUDO_FIELDS.LINKTYPE_FILTER_SUPERSET), linkTypeFilterSuperset); qNodeReportBean.getChildren().add(qNode); } List<FieldExpressionSimpleTO> fieldExpressionSimpleTOList = filterSelectsTO.getFieldExpressionSimpleList(); if (fieldExpressionSimpleTOList != null) { for (FieldExpressionSimpleTO fieldExpressionSimpleTO : fieldExpressionSimpleTOList) { QNodeExpression qNodeExpression = createNodeORsFromFilterExpression(fieldExpressionSimpleTO); if (qNodeExpression != null) { qNodeReportBean.getChildren().add(qNodeExpression); } } } QNode qNewRoot = createNode(QNode.AND); qNewRoot.setChildren(new ArrayList<QNode>()); qNewRoot.getChildren().add(qNodeReportBean); if (qNodeOriginalRoot != null) { qNewRoot.getChildren().add(qNodeOriginalRoot); } return qNewRoot; }
From source file:com.st.maven.debian.DebianPackageMojo.java
private static String formatDependencies(Map<Object, Object> osDependencies) { StringBuilder result = new StringBuilder(); if (osDependencies != null && !osDependencies.isEmpty()) { Iterator<Object> keys = osDependencies.keySet().iterator(); while (keys.hasNext()) { Object key = keys.next(); if (key == null) { continue; }// w w w. j a v a 2s .c o m Object value = osDependencies.get(key); if (result.length() != 0) { result.append(", "); } result.append(key.toString()); if (value != null) { result.append(" (").append(value.toString()).append(")"); } } } return result.toString(); }
From source file:edu.stanford.epad.epadws.queries.Dcm4CheeQueries.java
public static DCM4CHEEStudy getStudy(String studyUID) { Dcm4CheeDatabaseOperations dcm4CheeDatabaseOperations = Dcm4CheeDatabase.getInstance() .getDcm4CheeDatabaseOperations(); Map<String, String> dcm4CheeStudyData = dcm4CheeDatabaseOperations.studySearch(studyUID); if (!dcm4CheeStudyData.isEmpty()) return extractDCM4CHEEStudyFromData(dcm4CheeStudyData); else/*from w w w . j a v a2s .co m*/ return null; }
From source file:com.jms.notify.utils.httpclient.SimpleHttpUtils.java
/** * * @param parameters//from www .j a va2s .c o m * @param charSet * @return */ public static String mapToQueryString(Map parameters, String charSet) { String queryString = ""; if (parameters != null && !parameters.isEmpty()) { Set<Entry> entrySet = parameters.entrySet(); for (Entry entry : entrySet) { try { String key = entry.getKey().toString(); Object value = entry.getValue(); List values = makeStringList(value); for (Object v : values) { queryString += key + "=" + URLEncoder.encode(v == null ? "" : v.toString(), charSet) + "&"; } } catch (UnsupportedEncodingException e) { throw new IllegalArgumentException("invalid charset : " + charSet); } } if (queryString.length() > 0) { queryString = queryString.substring(0, queryString.length() - 1); } } return queryString; }
From source file:com.newatlanta.appengine.datastore.CachingDatastoreService.java
@SuppressWarnings("unchecked") private static void doWriteBehindTask(HttpServletRequest req, HttpServletResponse res) throws IOException { Object payload = null;//from w ww .j av a 2 s . co m try { payload = deserialize(req); if (payload == null) { return; } } catch (Exception e) { log.warning(e.toString()); return; } MemcacheService memcache = getMemcacheService(); List<Key> keys; if (payload instanceof Key) { keys = new ArrayList<Key>(); keys.add((Key) payload); // delete flag that prevents multiple tasks from being queued memcache.delete(keyToString((Key) payload)); } else if (payload instanceof List) { keys = (List) payload; } else { log.warning(payload.getClass().getName()); return; } Map<String, Entity> entityMap = (Map) memcache.getAll((List) keys); if ((entityMap != null) && !entityMap.isEmpty()) { try { if (getDatastoreService().put(entityMap.values()).size() != entityMap.size()) { log.info("failed to write all entities - retrying"); res.sendError(HttpServletResponse.SC_PARTIAL_CONTENT); } } catch (DatastoreTimeoutException e) { // retry task log.info(e.getMessage()); res.sendError(HttpServletResponse.SC_REQUEST_TIMEOUT); } catch (ConcurrentModificationException e) { // retry task log.info(e.getMessage()); res.sendError(HttpServletResponse.SC_CONFLICT); } catch (Exception e) { // don't retry log.warning(e.toString()); } } }
From source file:edu.stanford.epad.epadws.queries.Dcm4CheeQueries.java
public static DCM4CHEESeries getSeries(String seriesUID) { Dcm4CheeDatabaseOperations dcm4CheeDatabaseOperations = Dcm4CheeDatabase.getInstance() .getDcm4CheeDatabaseOperations(); Map<String, String> dcm4CheeSeriesData = dcm4CheeDatabaseOperations.getSeriesData(seriesUID); if (!dcm4CheeSeriesData.isEmpty()) return extractDCM4CHEESeriesFromSeriesData(dcm4CheeSeriesData); else {/*from w ww .j a v a 2 s . c o m*/ log.warning("Could not find series " + seriesUID + " in dcm4chee's database"); return null; } }
From source file:io.github.swagger2markup.MarkdownConverterTest.java
/** * Given a markdown document to search, this checks to see if the specified tables * have all of the expected fields listed. * Match is a "search", and not an "equals" match. * * @param doc markdown document file to inspect * @param fieldsByTable map of table name (header) to field names expected * to be found in that table. * @throws IOException if the markdown document could not be read *//*from w w w . ja v a 2 s . co m*/ private static void verifyMarkdownContainsFieldsInTables(File doc, Map<String, Set<String>> fieldsByTable) throws IOException { //TODO: This method is too complex, split it up in smaller methods to increase readability final List<String> lines = Files.readAllLines(doc.toPath(), Charset.defaultCharset()); final Map<String, Set<String>> fieldsLeftByTable = Maps.newHashMap(); for (Map.Entry<String, Set<String>> entry : fieldsByTable.entrySet()) { fieldsLeftByTable.put(entry.getKey(), Sets.newHashSet(entry.getValue())); } String inTable = null; for (String line : lines) { // If we've found every field we care about, quit early if (fieldsLeftByTable.isEmpty()) { return; } // Transition to a new table if we encounter a header final String currentHeader = getTableHeader(line); if (inTable == null || currentHeader != null) { inTable = currentHeader; } // If we're in a table that we care about, inspect this potential table row if (inTable != null && fieldsLeftByTable.containsKey(inTable)) { // If we're still in a table, read the row and check for the field name // NOTE: If there was at least one pipe, then there's at least 2 fields String[] parts = line.split("\\|"); if (parts.length > 1) { final String fieldName = parts[1]; final Set<String> fieldsLeft = fieldsLeftByTable.get(inTable); // Mark the field as found and if this table has no more fields to find, // remove it from the "fieldsLeftByTable" map to mark the table as done Iterator<String> fieldIt = fieldsLeft.iterator(); while (fieldIt.hasNext()) { String fieldLeft = fieldIt.next(); if (fieldName.contains(fieldLeft)) fieldIt.remove(); } if (fieldsLeft.isEmpty()) { fieldsLeftByTable.remove(inTable); } } } } // After reading the file, if there were still types, fail if (!fieldsLeftByTable.isEmpty()) { fail(String.format("Markdown file '%s' did not contain expected fields (by table): %s", doc, fieldsLeftByTable)); } }