List of usage examples for java.util HashMap isEmpty
public boolean isEmpty()
From source file:configuration.Util.java
/** * IN TEST for Docker/*from w ww . j av a2s.c o m*/ * Compare a table of path from inputs files and return an hashmap of string local<>string in docker * Problem1 to compare canonical path the minimum path is the root and it's useless * Problem2 it probably not the best way to share * => we have choosed to share a folder per inputs connected to a folder in Docker * Added by JG 2017 * @param tab a table of string for files * @param doinputs the inputs path in docker container * @return string of inputs files and the string in docker * */ public static HashMap<String, String> compareTabFilePath(String[] tab, String doInputs) { HashMap<String, Integer> finalFilesPath = new HashMap<String, Integer>(); HashMap<String, String> filesPathName = new HashMap<String, String>(); String[] tabTmp = tab; for (String p : tabTmp) { if (p != "") { String path = getParentOfFile(p); String name = getFileName(p); filesPathName.put(path, name); p = path; } } for (int i = 0; i < tabTmp.length - 1; i++) { for (String path : filesPathName.keySet()) { if (tab[i] != "" && path != "") { String[] r = compareTwoFilePath(tabTmp[i], path); if (r[0] != "") { if (finalFilesPath.isEmpty()) { finalFilesPath.put(r[0], 0); } for (String p : finalFilesPath.keySet()) { String[] r2 = compareTwoFilePath(r[0], p); if (r2[0] != r[0]) { finalFilesPath.remove(r[0]); finalFilesPath.put(r2[0], 0); } } } } } } HashMap<String, String> inputsFilesPath = new HashMap<String, String>(); for (String k : finalFilesPath.keySet()) { inputsFilesPath.put(k, doInputs + Integer.toString(finalFilesPath.get(k)) + "/"); } return inputsFilesPath; }
From source file:it.cnr.icar.eric.common.BindingUtility.java
public SubmitObjectsRequest createSubmitRequest(boolean dontVersion, boolean dontVersionContent, List<RegistryObjectType> ebRegistryObjectTypeList) throws Exception { SubmitObjectsRequest request = lcmFac.createSubmitObjectsRequest(); HashMap<String, String> slotsMap = new HashMap<String, String>(); if (dontVersion) { slotsMap.put(CANONICAL_SLOT_LCM_DONT_VERSION, "true"); }/* ww w.j a va2s . c om*/ if (dontVersionContent) { slotsMap.put(CANONICAL_SLOT_LCM_DONT_VERSION_CONTENT, "true"); } if (!slotsMap.isEmpty()) { addSlotsToRequest(request, slotsMap); } if ((ebRegistryObjectTypeList != null) && (ebRegistryObjectTypeList.size() > 0)) { request.setRegistryObjectList(getRegistryObjectListType(ebRegistryObjectTypeList)); } return request; }
From source file:com.actionbarsherlock.ActionBarSherlock.java
/** * Wrap an activity with an action bar abstraction which will enable the * use of a custom implementation on platforms where a native version does * not exist./*from w w w . ja va 2s . co m*/ * * @param activity Owning activity. * @param flags Option flags to control behavior. * @return Instance to interact with the action bar. */ public static ActionBarSherlock wrap(Activity activity, int flags) { //Create a local implementation map we can modify HashMap<Implementation, Class<? extends ActionBarSherlock>> impls = new HashMap<Implementation, Class<? extends ActionBarSherlock>>( IMPLEMENTATIONS); boolean hasQualfier; /* DPI FILTERING */ hasQualfier = false; for (Implementation key : impls.keySet()) { //Only honor TVDPI as a specific qualifier if (key.dpi() == DisplayMetrics.DENSITY_TV) { hasQualfier = true; break; } } if (hasQualfier) { final boolean isTvDpi = activity.getResources() .getDisplayMetrics().densityDpi == DisplayMetrics.DENSITY_TV; for (Iterator<Implementation> keys = impls.keySet().iterator(); keys.hasNext();) { int keyDpi = keys.next().dpi(); if ((isTvDpi && keyDpi != DisplayMetrics.DENSITY_TV) || (!isTvDpi && keyDpi == DisplayMetrics.DENSITY_TV)) { keys.remove(); } } } /* API FILTERING */ hasQualfier = false; for (Implementation key : impls.keySet()) { if (key.api() != Implementation.DEFAULT_API) { hasQualfier = true; break; } } if (hasQualfier) { final int runtimeApi = Build.VERSION.SDK_INT; int bestApi = 0; for (Iterator<Implementation> keys = impls.keySet().iterator(); keys.hasNext();) { int keyApi = keys.next().api(); if (keyApi > runtimeApi) { keys.remove(); } else if (keyApi > bestApi) { bestApi = keyApi; } } for (Iterator<Implementation> keys = impls.keySet().iterator(); keys.hasNext();) { if (keys.next().api() != bestApi) { keys.remove(); } } } if (impls.size() > 1) { throw new IllegalStateException("More than one implementation matches configuration."); } if (impls.isEmpty()) { throw new IllegalStateException("No implementations match configuration."); } Class<? extends ActionBarSherlock> impl = impls.values().iterator().next(); if (DEBUG) Log.i(TAG, "Using implementation: " + impl.getSimpleName()); try { Constructor<? extends ActionBarSherlock> ctor = impl.getConstructor(CONSTRUCTOR_ARGS); return ctor.newInstance(activity, flags); } catch (NoSuchMethodException e) { throw new RuntimeException(e); } catch (IllegalArgumentException e) { throw new RuntimeException(e); } catch (InstantiationException e) { throw new RuntimeException(e); } catch (IllegalAccessException e) { throw new RuntimeException(e); } catch (InvocationTargetException e) { throw new RuntimeException(e); } }
From source file:se.unlogic.fileuploadutils.MultipartRequest.java
public MultipartRequest(int ramThreshold, long maxSize, Long maxFileSize, File repository, HttpServletRequest req) throws FileUploadException { this.originalRequest = req; factory = new SafeDiskFileItemFactory(ramThreshold, repository); uploadHandler = new ServletFileUpload(factory); uploadHandler.setSizeMax(maxSize);/*from w w w . j av a 2s . c om*/ if (maxFileSize != null) { uploadHandler.setFileSizeMax(maxFileSize); } HashMap<String, List<String>> tempParameterMap = new HashMap<String, List<String>>(); List<FileItem> items; try { items = uploadHandler.parseRequest(req); if (items != null && items.size() > 0) { for (FileItem item : items) { if (item.isFormField()) { Field contentType = item.getClass().getDeclaredField("contentType"); contentType.setAccessible(true); contentType.set(item, "charset=UTF-8;"); List<String> valueList = tempParameterMap.get(item.getFieldName()); if (valueList != null) { valueList.add(item.getString()); } else { valueList = new ArrayList<String>(); valueList.add(item.getString()); tempParameterMap.put(item.getFieldName(), valueList); } } else { List<FileItem> fileItems = fileMap.get(item.getFieldName()); if (fileItems == null) { fileItems = new ArrayList<FileItem>(10); fileMap.put(item.getFieldName(), fileItems); } fileItems.add(item); this.fileItemList.add(item); } } } if (!tempParameterMap.isEmpty()) { for (Entry<String, List<String>> entry : tempParameterMap.entrySet()) { this.parameterMap.put(entry.getKey(), entry.getValue().toArray(new String[entry.getValue().size()])); } } } catch (FileUploadException e) { factory.deleteFiles(); throw e; } catch (IllegalAccessException e) { factory.deleteFiles(); } catch (NoSuchFieldException e) { factory.deleteFiles(); } }
From source file:org.kuali.kfs.module.purap.document.service.impl.CreditMemoServiceImpl.java
/** * @see org.kuali.kfs.module.purap.document.service.CreditMemoCreateService#populateDocumentAfterInit(org.kuali.kfs.module.purap.document.CreditMemoDocument) *//*from ww w .j a va2 s . c o m*/ @Override public void populateDocumentAfterInit(VendorCreditMemoDocument cmDocument) { // make a call to search for expired/closed accounts HashMap<String, ExpiredOrClosedAccountEntry> expiredOrClosedAccountList = accountsPayableService .getExpiredOrClosedAccountList(cmDocument); if (cmDocument.isSourceDocumentPaymentRequest()) { populateDocumentFromPreq(cmDocument, expiredOrClosedAccountList); } else if (cmDocument.isSourceDocumentPurchaseOrder()) { populateDocumentFromPO(cmDocument, expiredOrClosedAccountList); } else { populateDocumentFromVendor(cmDocument); } populateDocumentDescription(cmDocument); // write a note for expired/closed accounts if any exist and add a message stating there were expired/closed accounts at the // top of the document accountsPayableService.generateExpiredOrClosedAccountNote(cmDocument, expiredOrClosedAccountList); // set indicator so a message is displayed for accounts that were replaced due to expired/closed status if (ObjectUtils.isNotNull(expiredOrClosedAccountList) && !expiredOrClosedAccountList.isEmpty()) { cmDocument.setContinuationAccountIndicator(true); } }
From source file:org.shareok.data.sagedata.SageSourceDataHandlerImpl.java
/** * Organize the raw data in order to retrieve the necessary information to * request the metadata Note: this method is closely depending on the excel * file format/*w ww .ja v a 2s. c om*/ */ @Override public void processSourceData() { if (null == data || data.isEmpty()) { readSourceData(); if (null == data || data.isEmpty()) { return; } } try { Set keys = data.keySet(); Iterator it = keys.iterator(); int rowPre = 0; HashMap articleData = new HashMap(); while (it.hasNext()) { String key = (String) it.next(); String value = (String) data.get(key); // the values is composed of "val--datatype": for example, Tom--Str or 0.50--num String[] values = value.split("--"); if (null == values || values.length != 2) { continue; } value = values[0]; String[] rowCol = key.split("-"); if (null == rowCol || rowCol.length != 2) { throw new Exception("The row and column are not specifid!"); } int row = Integer.parseInt(rowCol[0]); int col = Integer.parseInt(rowCol[1]); if (row != rowPre) { rowPre = row; if (null != articleData && !articleData.isEmpty()) { if (null == itemData) { itemData = new ArrayList<HashMap>(); } Object articleDataCopy = articleData.clone(); itemData.add((HashMap) articleDataCopy); articleData.clear(); } } if (0 != row) { switch (col) { case 0: articleData.put("journal", value); break; case 2: articleData.put("title", value); break; case 3: articleData.put("volume", value); break; case 4: articleData.put("issue", value); break; case 5: articleData.put("pages", value); break; case 6: articleData.put("year", value); break; case 7: articleData.put("citation", value); break; case 8: articleData.put("pubdate", value); break; case 9: articleData.put("doi", value); break; case 10: articleData.put("url", value); break; default: break; } } } // Put the last article into itemData: if (null != articleData && !articleData.isEmpty()) { if (null == itemData) { itemData = new ArrayList<HashMap>(); } Object articleDataCopy = articleData.clone(); itemData.add((HashMap) articleDataCopy); articleData.clear(); } } catch (Exception e) { e.printStackTrace(); } }
From source file:org.globus.wsrf.tools.wsdl.WSDLPreprocessor.java
public static Map getResourceProperties(QName resourceProperties, Definition def, Map documentLocations, boolean quiet) throws Exception { HashMap resourcePropertyElements = new HashMap(); if (resourceProperties != null) { Types types = def.getTypes(); if (types == null) { if (!quiet) { log.warn("The " + def.getDocumentBaseURI() + " definition does not have a types section"); }/*from w ww .jav a2 s. c om*/ return resourcePropertyElements; } List elementList = types.getExtensibilityElements(); // assume only on schema element for now if (elementList.size() > 1) { if (!quiet) { System.err.println("WARNING: The types section in " + def.getDocumentBaseURI() + " contains more than one top level element."); } // maybe throw error } Element schema = ((UnknownExtensibilityElement) elementList.get(0)).getElement(); XSModel schemaModel = loadSchema(schema, def); XSElementDeclaration resourcePropertiesElement = schemaModel .getElementDeclaration(resourceProperties.getLocalPart(), resourceProperties.getNamespaceURI()); if (resourcePropertiesElement != null) { XSComplexTypeDecl type = (XSComplexTypeDecl) resourcePropertiesElement.getTypeDefinition(); XSParticle particle = type.getParticle(); XSModelGroup sequence = (XSModelGroup) particle.getTerm(); XSObjectList objectList = sequence.getParticles(); for (int i = 0; i < objectList.getLength(); i++) { XSParticle part = (XSParticle) objectList.item(i); Object term = part.getTerm(); if (term instanceof XSElementDeclaration) { XSElementDeclaration resourceProperty = (XSElementDeclaration) term; resourcePropertyElements .put(new QName(resourceProperty.getNamespace(), resourceProperty.getName()), part); } else { throw new Exception( "Invalid resource properties document " + resourceProperties.toString()); } } } else { Map imports = def.getImports(); Iterator importNSIterator = imports.values().iterator(); while (importNSIterator.hasNext() && resourcePropertyElements.isEmpty()) { Vector importVector = (Vector) importNSIterator.next(); Iterator importIterator = importVector.iterator(); while (importIterator.hasNext() && resourcePropertyElements.isEmpty()) { Import importDef = (Import) importIterator.next(); // process imports resourcePropertyElements.putAll(getResourceProperties(resourceProperties, importDef.getDefinition(), documentLocations, quiet)); } } if (resourcePropertyElements.isEmpty()) { throw new Exception("Unable to resolve resource properties " + resourceProperties.toString()); } } populateLocations(schemaModel, documentLocations, def); } return resourcePropertyElements; }
From source file:com.impetus.ankush.common.service.MonitoringManager.java
/** * Save Technology Service Status.// www . j av a 2 s. com * * @param nodeId * @param agentServiceStatus */ public boolean saveTecnologyServiceStatus(Long nodeId, HashMap<String, Map<String, Boolean>> agentServiceStatus) { boolean status = true; try { // getting the node object. Node node = nodeManager.get(nodeId); // get cluster from nodedId GenericManager<Cluster, Long> clusterManager = AppStoreWrapper.getManager(Constant.Manager.CLUSTER, Cluster.class); // Return if not is not in deployed state if (clusterManager.get(node.getClusterId()).getState() .equalsIgnoreCase(Constant.Cluster.State.REMOVING.toString()) || !node.getState().equalsIgnoreCase(Constant.Node.State.DEPLOYED.toString())) { LOG.error("Cann't save node service status as Cluster or node State is not Deployed."); status = false; } else { // Get the db node monitoring info NodeMonitoring nodeMonitoring = monitoringManager.getByPropertyValueGuarded(NODE_ID, nodeId); // if null create the new node monitoring obj. if (nodeMonitoring == null) { nodeMonitoring = new NodeMonitoring(); // Set initial node monitoring data nodeMonitoring.setNodeId(nodeId); // set service status. nodeMonitoring.setTechnologyServiceStatus(new HashMap<String, Map<String, Boolean>>()); } // Update service into database if it is not empty if (!agentServiceStatus.isEmpty()) { Map<String, Map<String, Boolean>> serviceStatus = nodeMonitoring.getTechnologyServiceStatus(); if (serviceStatus == null) { serviceStatus = new HashMap<String, Map<String, Boolean>>(); } for (String key : agentServiceStatus.keySet()) { if (serviceStatus.containsKey(key)) { serviceStatus.get(key).putAll(agentServiceStatus.get(key)); } else { serviceStatus.put(key, agentServiceStatus.get(key)); } } // set service status. nodeMonitoring .setTechnologyServiceStatus((HashMap<String, Map<String, Boolean>>) serviceStatus); // Set service status into service table DBServiceManager.getManager().setServicesStatus(node.getClusterId(), node.getPublicIp(), agentServiceStatus); } // Set monitoring info in node monitoring info. nodeMonitoring.setUpdateTime(new Date()); // Saving node monitoring info in database. nodeMonitoring = monitoringManager.save(nodeMonitoring); DBEventManager eventManager = new DBEventManager(); eventManager.checkAlertsForService(node.getPublicIp(), node.getClusterId(), agentServiceStatus); } } catch (Exception e) { // Setting log error. LOG.error("Unable to save node service status against nodeId : " + nodeId, e); status = false; } return status; }
From source file:hu.api.SivaPlayerVideoServlet.java
/** * Return available stats for user./*from ww w.j a va 2 s . co m*/ * * @param request * servlet. * @param response * servlet. * @throws IOException */ private void getStats(HttpServletRequest request, HttpServletResponse response) throws IOException { // Check if there is a user specified for getting the stats and abort if // not User user = null; IApiStore apiStore = this.persistenceProvider.getApiStore(); if (request.getParameter("token") != null && !request.getParameter("token").equals("") && !request.getParameter("token").equals("undefined")) { SivaPlayerSession session = apiStore.findSivaPlayerSessionByToken( Integer.parseInt(request.getParameter("token").split("-")[0]), request.getParameter("token").split("-")[1], true); if (session.getUserId() == null) { this.sendError(response, HttpServletResponse.SC_UNAUTHORIZED, "loginRequiredTitle"); return; } user = new User(session.getUserId()); } else if (request.getParameter("email") == null && !request.getParameter("email").equals("")) { this.sendError(response, HttpServletResponse.SC_UNAUTHORIZED, "loginRequiredTitle"); return; } else { user = this.persistenceProvider.getUserStore().findByEmail(request.getParameter("email")); if (user == null || request.getParameter("secret") == null || !user.getSecretKey().equals(request.getParameter("secret"))) { this.sendError(response, HttpServletResponse.SC_FORBIDDEN, "unknownUserCredentials"); return; } } // Get stats and write them to HTTP response HashMap<String, Integer> stats = apiStore.getSivaPlayerSessionDurationByDay(user.getId()); if (stats.isEmpty()) { this.sendError(response, HttpServletResponse.SC_BAD_REQUEST, "notSufficentData"); } else { this.isAJAXRequest = true; this.writeJSON(response, (new JSONObject(stats).toString())); } }
From source file:com.photon.phresco.impl.IPhonePhrescoApplicationProcessor.java
private void storeConfigObjAsPlist(List<Configuration> configuration, String destPlistFile) throws PhrescoException { //FIXME: this logic needs to be revisited and should be fixed with XMLPropertyListConfiguration classes. try {/*from w w w . jav a2 s . c o m*/ XMLPropertyListConfiguration plist = new XMLPropertyListConfiguration(); for (Configuration config : configuration) { if (FEATURES.equalsIgnoreCase(config.getType())) { String rootNode = ""; HashMap<String, Object> valueMap = new HashMap(); Properties properties = config.getProperties(); Enumeration em = properties.keys(); while (em.hasMoreElements()) { HashMap<String, Object> tempMap = new HashMap(); String key = (String) em.nextElement(); String value = properties.getProperty(key); String[] keySplited = key.split("\\."); rootNode = keySplited[0]; int length = keySplited.length; if (value != null && value instanceof String && value.toString().startsWith("[") && value.toString().endsWith("]")) { String arrayListvalue = value.toString().replace("[", "").replace("]", ""); String[] split = arrayListvalue.toString().split(","); Map<String, Object> keyValuePair = new HashMap<String, Object>(); List<String> asList = new ArrayList<String>(); for (String string : split) { asList.add(string.trim()); } String rootKey = ""; String arrayListKey = ""; if (length == 3) { rootKey = keySplited[1]; arrayListKey = keySplited[2]; keyValuePair.put(arrayListKey, asList); if (!valueMap.isEmpty()) { if (valueMap.containsKey(keySplited[1])) { HashMap<String, Object> object = (HashMap) valueMap.get(keySplited[1]); tempMap.put(arrayListKey, asList); for (Map.Entry<String, Object> entry : object.entrySet()) { tempMap.put(entry.getKey(), entry.getValue()); } valueMap.put(rootKey, tempMap); } else { valueMap.put(rootKey, keyValuePair); } } else { valueMap.put(rootKey, keyValuePair); } } else if (length == 2) { valueMap.put(keySplited[1], asList); } } else { String arrayListKey = ""; if (length == 2) { arrayListKey = keySplited[1]; valueMap.put(arrayListKey, value); } else if (length == 3) { HashMap localMap = new HashMap(); localMap.put(keySplited[2], value); if (!valueMap.isEmpty()) { if (valueMap.containsKey(keySplited[1])) { HashMap<String, Object> object = (HashMap) valueMap.get(keySplited[1]); tempMap.put(keySplited[2], value); for (Map.Entry<String, Object> entry : object.entrySet()) { tempMap.put(entry.getKey(), entry.getValue()); } valueMap.put(keySplited[1], tempMap); } else { valueMap.put(keySplited[1], localMap); } } else { valueMap.put(keySplited[1], localMap); } } } } plist.addProperty(rootNode, valueMap); } } plist.save(destPlistFile); } catch (ConfigurationException e) { throw new PhrescoException(e); } }