List of usage examples for java.util Map isEmpty
boolean isEmpty();
From source file:com.vmware.photon.controller.common.dcp.ServiceHostUtils.java
public static <H extends ServiceHost> void deleteAllDocuments(H host, String referrer, long timeout, TimeUnit timeUnit) throws Throwable { QueryTask.Query selfLinkClause = new QueryTask.Query() .setTermPropertyName(ServiceDocument.FIELD_NAME_SELF_LINK).setTermMatchValue("*") .setTermMatchType(QueryTask.QueryTerm.MatchType.WILDCARD); QueryTask.QuerySpecification querySpecification = new QueryTask.QuerySpecification(); querySpecification.query.addBooleanClause(selfLinkClause); QueryTask queryTask = QueryTask.create(querySpecification).setDirect(true); NodeGroupBroadcastResponse queryResponse = ServiceHostUtils.sendBroadcastQueryAndWait(host, referrer, queryTask);//from ww w.j av a 2 s. c o m Set<String> documentLinks = QueryTaskUtils.getBroadcastQueryResults(queryResponse); if (documentLinks == null || documentLinks.size() <= 0) { return; } CountDownLatch latch = new CountDownLatch(1); OperationJoin.JoinedCompletionHandler handler = new OperationJoin.JoinedCompletionHandler() { @Override public void handle(Map<Long, Operation> ops, Map<Long, Throwable> failures) { if (failures != null && !failures.isEmpty()) { for (Throwable e : failures.values()) { logger.error("deleteAllDocuments failed", e); } } latch.countDown(); } }; Collection<Operation> deletes = new LinkedList<>(); for (String documentLink : documentLinks) { Operation deleteOperation = Operation.createDelete(UriUtils.buildUri(host, documentLink)).setBody("{}") .setReferer(UriUtils.buildUri(host, referrer)); deletes.add(deleteOperation); } OperationJoin join = OperationJoin.create(deletes); join.setCompletion(handler); join.sendWith(host); if (!latch.await(timeout, timeUnit)) { throw new TimeoutException(String .format("Deletion of all documents timed out. Timeout:{%s}, TimeUnit:{%s}", timeout, timeUnit)); } }
From source file:com.mywork.framework.util.RemoteHttpUtil.java
/** * ?MultipartHttp??????ContentBody map//from ww w . j av a 2 s . c om */ public static String fetchMultipartHttpResponse(String contentUrl, Map<String, String> headerMap, Map<String, ContentBody> bodyMap) throws IOException { try { HttpPost httpPost = new HttpPost(contentUrl); MultipartEntityBuilder multipartEntityBuilder = MultipartEntityBuilder.create(); if (headerMap != null && !headerMap.isEmpty()) { for (Map.Entry<String, String> m : headerMap.entrySet()) { httpPost.addHeader(m.getKey(), m.getValue()); } } if (bodyMap != null && !bodyMap.isEmpty()) { for (Map.Entry<String, ContentBody> m : bodyMap.entrySet()) { multipartEntityBuilder.addPart(m.getKey(), m.getValue()); } } HttpEntity reqEntity = multipartEntityBuilder.build(); httpPost.setEntity(reqEntity); CloseableHttpResponse response = httpClient.execute(httpPost); try { HttpEntity resEntity = response.getEntity(); String resStr = IOUtils.toString(resEntity.getContent()); return resStr; } catch (Exception e) { // TODO: handle exception } finally { response.close(); } } finally { httpClient.close(); } return null; }
From source file:com.opengamma.web.server.WebView.java
private static SortedMap<Integer, Long> processViewportData(final Map<String, Object> viewportData) { final SortedMap<Integer, Long> result = new TreeMap<Integer, Long>(); if (viewportData.isEmpty()) { return result; }/*from w w w . jav a 2s. c o m*/ final Object[] ids = (Object[]) viewportData.get("rowIds"); final Object[] lastTimes = (Object[]) viewportData.get("lastTimestamps"); for (int i = 0; i < ids.length; i++) { if (ids[i] instanceof Number) { final long jsRowId = (Long) ids[i]; final int rowId = (int) jsRowId; if (lastTimes[i] != null) { final Long lastTime = (Long) lastTimes[i]; result.put(rowId, lastTime); } else { result.put(rowId, null); } } else { throw new OpenGammaRuntimeException("Unexpected type of webId: " + ids[i]); } } return result; }
From source file:de.interactive_instruments.etf.sel.mapping.TestRunCollector.java
/** * Returns true if message is a manual test instruction *//* w w w .java 2s . c o m*/ private static boolean addMessage(final String message, final TestResultCollector collector, final int i) { final int startIndex = message.indexOf("<etfTranslate "); final int endIndex = message.lastIndexOf("</etfTranslate>"); if (startIndex != -1) { final int wi = message.indexOf("what='", startIndex + 14); final boolean singleQ = wi > -1; final int whatIndex = singleQ ? wi : message.indexOf("what=\"", startIndex + 14); if (whatIndex != -1) { final int endWhatIndex = message.indexOf(singleQ ? "'" : "\"", whatIndex + 6); if (whatIndex < endWhatIndex) { final String t = message.substring(whatIndex + 6, endWhatIndex); final String translationTemplate = t.startsWith("TR.") ? t : "TR." + t; final boolean manual = translationTemplate.startsWith("TR.manual."); if (endIndex > 0) { // Check that are no >s in what final int messagesIndex = message.indexOf(">", startIndex + 1); if (whatIndex < messagesIndex && messagesIndex < endIndex) { final Map<String, String> tokenArguments = new TreeMap<>(); parseRec(message, messagesIndex + 1, endIndex, tokenArguments); if (!tokenArguments.isEmpty()) { // if there is only one tokenArgument combination with an INFO token, // change the template to TR.INFO if (tokenArguments.size() == 1 && tokenArguments.containsKey("INFO")) { // Add message with INFO message collector.addMessage("TR.fallbackInfo", tokenArguments); } else { // Add message with token/arguments collector.addMessage(translationTemplate, tokenArguments); } } else { // Add message without tokenArguments collector.addMessage(translationTemplate); } return manual; } } else { collector.addMessage(translationTemplate); return manual; } } } } try { // TODO temporary fallback final Map<String, String> map = new HashMap<String, String>() { { put("INFO", message); } }; collector.addMessage("TR.fallbackInfo", map); collector.saveAttachment(IOUtils.toInputStream(message, "UTF-8"), "Error." + i, "text/plain", "Error"); } catch (IOException e) { collector.internalError(e); } return false; }
From source file:com.erudika.para.utils.Constraint.java
/** * Builds a new constraint from a given name and payload * @param cname the constraint name// w ww . j ava 2s. c o m * @param payload the payload * @return constraint */ public static Constraint build(String cname, Map<String, Object> payload) { if (cname != null && payload != null && !payload.isEmpty()) { if ("required".equals(cname)) { return required(); } else if ("email".equals(cname)) { return email(); } else if ("false".equals(cname)) { return falsy(); } else if ("true".equals(cname)) { return truthy(); } else if ("future".equals(cname)) { return future(); } else if ("past".equals(cname)) { return past(); } else if ("url".equals(cname)) { return url(); } else if ("min".equals(cname) && payload.containsKey("value")) { return min(payload.get("value")); } else if ("max".equals(cname) && payload.containsKey("value")) { return max(payload.get("value")); } else if ("size".equals(cname) && payload.containsKey("min") && payload.containsKey("max")) { return size(payload.get("min"), payload.get("max")); } else if ("digits".equals(cname) && payload.containsKey("integer") && payload.containsKey("fraction")) { return digits(payload.get("integer"), payload.get("fraction")); } else if ("pattern".equals(cname) && payload.containsKey("value")) { return pattern(payload.get("value")); } } return null; }
From source file:io.appium.uiautomator2.utils.AlertHelpers.java
@Nullable private static UiObject2 getRegularAlertButton(AlertAction action, @Nullable String buttonLabel) { final Map<String, UiObject2> alertButtonsMapping = new HashMap<>(); final List<Integer> buttonIndexes = new ArrayList<>(); for (final UiObject2 button : getUiDevice().findObjects(By.res(regularAlertButtonResIdPattern))) { final String resId = button.getResourceName(); alertButtonsMapping.put(resId, button); buttonIndexes.add(Integer.parseInt(resId.substring(regularAlertButtonResIdPrefix.length()))); }//from ww w .j a va 2 s. c o m if (alertButtonsMapping.isEmpty()) { return null; } Log.d(TAG, String.format("Found %d buttons on the alert", alertButtonsMapping.size())); if (buttonLabel == null) { final int minIdx = Collections.min(buttonIndexes); return action == AlertAction.ACCEPT ? alertButtonsMapping.get(buttonResIdByIdx(minIdx)) : alertButtonsMapping .get(buttonResIdByIdx(alertButtonsMapping.size() > 1 ? minIdx + 1 : minIdx)); } return filterButtonByLabel(alertButtonsMapping.values(), buttonLabel); }
From source file:com.egt.core.db.util.Reporter.java
private static Object[] getReportParametersArray(Map parameters) { if (parameters == null || parameters.isEmpty()) { return null; }//from ww w . j a v a 2 s. c om int n = parameters.size(); Object[] args = new Object[n]; Set set = parameters.keySet(); Iterator iterator = set.iterator(); Object key; Object val; String psi; String str; for (int i = 0; i < n && iterator.hasNext(); i++) { key = iterator.next(); val = parameters.get(key); if (val != null) { psi = val instanceof Long ? Global.PREFIJO_STRING_ID_RECURSO : ""; str = StringUtils.trimToEmpty(STP.getString(val)); args[i] = key + "=" + psi + str; Bitacora.trace("args [" + i + "] = " + key + "=(" + val.getClass().getSimpleName() + ")" + str); } } return args; }
From source file:com.espertech.esper.core.start.EPStatementStartMethodCreateTable.java
private static EventType validateExpressionGetEventType(String msgprefix, List<AnnotationDesc> annotations, EventAdapterService eventAdapterService) throws ExprValidationException { Map<String, List<AnnotationDesc>> annos = AnnotationUtil.mapByNameLowerCase(annotations); // check annotations used List<AnnotationDesc> typeAnnos = annos.remove("type"); if (!annos.isEmpty()) { throw new ExprValidationException( msgprefix + " unrecognized annotation '" + annos.keySet().iterator().next() + "'"); }//from w ww . j a va2s. co m // type determination EventType optionalType = null; if (typeAnnos != null) { String typeName = AnnotationUtil.getExpectSingleStringValue(msgprefix, typeAnnos); optionalType = eventAdapterService.getExistsTypeByName(typeName); if (optionalType == null) { throw new ExprValidationException(msgprefix + " failed to find event type '" + typeName + "'"); } } return optionalType; }
From source file:gridool.db.partitioning.csv.CsvHashPartitioningJob.java
private static GridNode mapPrimaryFragment(final byte[] distkey, final Map<GridNode, MutableInt> mappedNodes, final int tablePartitionNo, final GridTaskRouter router) throws GridException { assert (mappedNodes.isEmpty()); GridNode mappedNode = router.selectNode(distkey); if (mappedNode == null) { throw new GridException("Could not find any node in cluster."); }/* w w w.j a v a 2 s . c o m*/ MutableInt newHidden = new MutableInt(tablePartitionNo); mappedNodes.put(mappedNode, newHidden); return mappedNode; }
From source file:com.plugin.excel.util.ExcelFileHelper.java
public static void writeFile(String directory, String fileName, Map<String, List<List<ExcelCell>>> sheets, int headerRowHeight, int commentRowHeight) { if (StringUtils.isNotBlank(directory) && StringUtils.isNotBlank(fileName) && sheets != null && !sheets.isEmpty()) { SXSSFWorkbook workbook = new SXSSFWorkbook(); Font invisibleFont = workbook.createFont(); for (Entry<String, List<List<ExcelCell>>> entry : sheets.entrySet()) { // TODO: remove and logging // log.info("writeFile","Started writing sheet: "+entry.getKey()); SXSSFSheet sheet = (SXSSFSheet) workbook.createSheet(entry.getKey()); int totalColumn = 0; if (entry.getValue() != null && !entry.getValue().isEmpty()) { int rowNumber = 0; Font dataFont = null; for (List<ExcelCell> rows : entry.getValue()) { // Row row = sheet.getRow(rowNumber)!=null ? sheet.getRow(rowNumber) : rowMap.get(rowNumber); Row row = sheet.createRow(rowNumber); int rowHeight = rowNumber == 0 ? headerRowHeight : commentRowHeight; if (rowNumber == 0 || rowNumber == 1) { if (rowHeight > 0) { row.setHeight((short) rowHeight); }/*from ww w . j ava 2 s . co m*/ addDataValidation(rowNumber, sheet); } rowNumber++; if (rows != null && !rows.isEmpty()) { int cellNum = 0; Font font = null; if (rowNumber > 3 && dataFont != null) { font = dataFont; } else { font = workbook.createFont(); dataFont = font; } // as each row requires different syle with separate font Map<IndexedColors, CellStyle> s_cellStyle = new HashMap<IndexedColors, CellStyle>(); for (ExcelCell cellValue : rows) { Cell cell = row.createCell(cellNum); updateCell(cell, cellValue, s_cellStyle, workbook, font, invisibleFont); ++cellNum; } totalColumn = cellNum; } if (rowNumber == 2) {/* * auto size after DOCUMENTATION-ROW (row=2) so, we don't have to do * multiple times */ autoSize(sheet, totalColumn, false); // rowMap = createRows(workbook, sheet, rowNumber+1, excelConfig.getMaxInputRows()); } } } autoSize(sheet, totalColumn, true); } // addMetaSheet(workbook); writeWorkBook(directory, fileName, workbook); } }