List of usage examples for java.util HashMap remove
public V remove(Object key)
From source file:org.cloudata.core.common.testhelper.FaultManager.java
private void internalClear(Class<?> c, String methodName) { synchronized (classFaultMap) { HashMap<String, Fault> faultMap = findFaultMap(c); if (faultMap != null) { faultMap.remove(methodName); if (faultMap.isEmpty()) { classFaultMap.remove(c); }/* w w w.ja v a 2 s .co m*/ } classFaultMap.notifyAll(); } }
From source file:org.kuali.rice.krad.web.controller.LookupController.java
/** * Invoked from the UI to return the selected lookup results lines, parameters are collected to build a URL to * the caller and then a redirect is performed * * @param lookupForm - lookup form instance containing the selected results and lookup configuration *//* ww w . j ava2 s . c o m*/ @RequestMapping(method = RequestMethod.POST, params = "methodToCall=returnSelected") public String returnSelected(@ModelAttribute("KualiForm") LookupForm lookupForm, BindingResult result, HttpServletRequest request, HttpServletResponse response, final RedirectAttributes redirectAttributes) { Properties parameters = new Properties(); // build string of select line identifiers String selectedLineValues = ""; Set<String> selectedLines = lookupForm.getSelectedCollectionLines().get(UifPropertyPaths.LOOKUP_RESULTS); if (selectedLines != null) { for (String selectedLine : selectedLines) { selectedLineValues += selectedLine + ","; } selectedLineValues = StringUtils.removeEnd(selectedLineValues, ","); } //check to see what the redirect URL length would be parameters.put(UifParameters.SELECTED_LINE_VALUES, selectedLineValues); parameters.putAll(lookupForm.getInitialRequestParameters()); String redirectUrl = UrlFactory.parameterizeUrl(lookupForm.getReturnLocation(), parameters); boolean lookupCameFromDifferentServer = areDifferentDomains(lookupForm.getReturnLocation(), lookupForm.getRequestUrl()); if (redirectUrl.length() > RiceConstants.MAXIMUM_URL_LENGTH && !lookupCameFromDifferentServer) { redirectAttributes.addFlashAttribute(UifParameters.SELECTED_LINE_VALUES, selectedLineValues); } if (redirectUrl.length() > RiceConstants.MAXIMUM_URL_LENGTH && lookupCameFromDifferentServer) { HashMap<String, String> parms = (HashMap<String, String>) lookupForm.getInitialRequestParameters(); parms.remove(UifParameters.RETURN_FORM_KEY); //add an error message to display to the user redirectAttributes.mergeAttributes(parms); redirectAttributes.addAttribute(UifParameters.MESSAGE_TO_DISPLAY, RiceKeyConstants.INFO_LOOKUP_RESULTS_MV_RETURN_EXCEEDS_LIMIT); String formKeyParam = request.getParameter(UifParameters.FORM_KEY); redirectAttributes.addAttribute(UifParameters.FORM_KEY, formKeyParam); return UifConstants.REDIRECT_PREFIX + lookupForm.getRequestUrl(); } if (redirectUrl.length() < RiceConstants.MAXIMUM_URL_LENGTH) { redirectAttributes.addAttribute(UifParameters.SELECTED_LINE_VALUES, selectedLineValues); } redirectAttributes.addAttribute(KRADConstants.DISPATCH_REQUEST_PARAMETER, KRADConstants.RETURN_METHOD_TO_CALL); if (StringUtils.isNotBlank(lookupForm.getReturnFormKey())) { redirectAttributes.addAttribute(UifParameters.FORM_KEY, lookupForm.getReturnFormKey()); } redirectAttributes.addAttribute(KRADConstants.REFRESH_CALLER, lookupForm.getView().getId()); redirectAttributes.addAttribute(KRADConstants.REFRESH_CALLER_TYPE, UifConstants.RefreshCallerTypes.MULTI_VALUE_LOOKUP); redirectAttributes.addAttribute(KRADConstants.REFRESH_DATA_OBJECT_CLASS, lookupForm.getDataObjectClassName()); if (StringUtils.isNotBlank(lookupForm.getDocNum())) { redirectAttributes.addAttribute(UifParameters.DOC_NUM, lookupForm.getDocNum()); } if (StringUtils.isNotBlank(lookupForm.getLookupCollectionName())) { redirectAttributes.addAttribute(UifParameters.LOOKUP_COLLECTION_NAME, lookupForm.getLookupCollectionName()); } if (StringUtils.isNotBlank(lookupForm.getReferencesToRefresh())) { redirectAttributes.addAttribute(KRADConstants.REFERENCES_TO_REFRESH, lookupForm.getReferencesToRefresh()); } // clear current form from session GlobalVariables.getUifFormManager().removeSessionForm(lookupForm); return UifConstants.REDIRECT_PREFIX + lookupForm.getReturnLocation(); }
From source file:br.mdarte.exemplo.academico.web.geral.manterCurso.AlterandoCursoSalvaCurso.java
/** * /*from w w w . j a v a 2s. c om*/ */ private String _salvandoCurso(org.apache.struts.validator.ValidatorForm form) throws java.lang.Exception { String forward = null; String redirect = ""; request.getSession().setAttribute(org.apache.struts.Globals.MESSAGE_KEY, new org.apache.struts.action.ActionMessages()); MantemCursoControleFactory.getMantemCursoControleInstance().salvaCurso( (AlterandoCursoSalvaCursoFormImpl) form, new Struts2ViewContainer(this, request, response)); java.util.HashMap map = new java.util.HashMap(); if (request.getSession().getAttribute(Constantes.MODO_OPERACAO) != null) map = (java.util.HashMap) request.getSession().getAttribute(Constantes.MODO_OPERACAO); map.remove("geral/DetalhaCursoUC/DetalhaCursoUC.action"); request.getSession().setAttribute(Constantes.MODO_OPERACAO, map); if (request.getSession().getAttribute("tableNameList") != null) { java.util.Collection tableNameList = (java.util.Collection) request.getSession() .getAttribute("tableNameList"); for (java.util.Iterator it = tableNameList.iterator(); it.hasNext();) { String tableName = (String) it.next(); request.getSession().removeAttribute(tableName); } request.getSession().removeAttribute("tableNameList"); } if (request.getAttribute("$forwardKey") != null) { forward = (String) request.getAttribute("$forwardKey"); } else { forward = "detalha.curso"; } return forward; }
From source file:br.mdarte.exemplo.academico.web.geral.manterEstudante.AlterandoEstudanteSalvaEstudante.java
/** * /*from w w w .j av a2s. co m*/ */ private String _salvandoEstudante(org.apache.struts.validator.ValidatorForm form) throws java.lang.Exception { String forward = null; String redirect = ""; request.getSession().setAttribute(org.apache.struts.Globals.MESSAGE_KEY, new org.apache.struts.action.ActionMessages()); MantemEstudanteControleFactory.getMantemEstudanteControleInstance().salvaEstudante( (AlterandoEstudanteSalvaEstudanteFormImpl) form, new Struts2ViewContainer(this, request, response)); java.util.HashMap map = new java.util.HashMap(); if (request.getSession().getAttribute(Constantes.MODO_OPERACAO) != null) map = (java.util.HashMap) request.getSession().getAttribute(Constantes.MODO_OPERACAO); map.remove("geral/DetalhaEstudanteUC/DetalhaEstudanteUC.action"); request.getSession().setAttribute(Constantes.MODO_OPERACAO, map); if (request.getSession().getAttribute("tableNameList") != null) { java.util.Collection tableNameList = (java.util.Collection) request.getSession() .getAttribute("tableNameList"); for (java.util.Iterator it = tableNameList.iterator(); it.hasNext();) { String tableName = (String) it.next(); request.getSession().removeAttribute(tableName); } request.getSession().removeAttribute("tableNameList"); } if (request.getAttribute("$forwardKey") != null) { forward = (String) request.getAttribute("$forwardKey"); } else { forward = "detalha.estudante"; } return forward; }
From source file:fi.elfcloud.sci.Client.java
/** * Creates a meta header for {@link DataItem} using old meta header. * @param existingMeta old meta header//from w ww. j a v a2 s .c om * @return new meta header * @throws ECEncryptionException */ public String createMeta(String existingMeta) throws ECEncryptionException { HashMap<String, String> map = new HashMap<String, String>(); if (existingMeta != null) { map = Utils.metaToMap(existingMeta); map.remove("v"); map.remove("ENC"); map.remove("KHA"); } map.put("v", "v" + Integer.toString(metaVersion)); String mode = ""; switch (getEncryptionMode()) { case NONE: mode = "NONE"; break; case AES_128: mode = "AES128"; break; case AES_192: mode = "AES192"; break; case AES_256: mode = "AES256"; break; default: throw new ECEncryptionException(1, "Invalid encryption mode"); } map.put("ENC", mode); if (!getEncryptionMode().equals(ENC.NONE)) { map.put("KHA", DataStream.getKeyHash()); } return Utils.metaToString(map); }
From source file:com.edmunds.zookeeper.treewatcher.ZooKeeperTreeState.java
private ZooKeeperTreeNode createParent(ZooKeeperTreeNode parent, Collection<ZooKeeperTreeNode> deletedNodes, Collection<ZooKeeperTreeNode> insertedNodes, boolean dataConsistent, boolean childListConsistent, boolean checkConsistent) { final HashMap<String, ZooKeeperTreeNode> children = Maps.newHashMap(parent.getChildren()); // Remove any deleted nodes. for (ZooKeeperTreeNode deletedNode : deletedNodes) { children.remove(deletedNode.getName()); }//from ww w. ja v a2 s .c om // Add any inserted nodes. for (ZooKeeperTreeNode insertedNode : insertedNodes) { children.put(insertedNode.getName(), insertedNode); } return createNode(parent, children, parent.getData(), dataConsistent, childListConsistent, checkConsistent); }
From source file:Main.java
public static HashMap<Integer, HashMap<Integer, Integer>> getAvailableTime(HashMap<Date, Date> bookedTimes, Date date) {/*from www . j a v a 2 s. c o m*/ HashMap<Integer, HashMap<Integer, Integer>> availableTime = createFullAvailableTime(); HashMap<Date, Date> bookedTimeInOneDate = getBookedTimeInOneDate(bookedTimes, date); Calendar startCalendar = Calendar.getInstance(); Calendar endCalendar = Calendar.getInstance(); for (Date keyBooked : bookedTimeInOneDate.keySet()) { startCalendar.setTime(keyBooked); int startHour = startCalendar.get(Calendar.HOUR_OF_DAY); for (int hourIndex = 0; hourIndex < 24; hourIndex++) { if (hourIndex == startHour) { int startMinute = startCalendar.get(Calendar.MINUTE); int endMinute; endCalendar.setTime(bookedTimeInOneDate.get(keyBooked)); int endHour = endCalendar.get(Calendar.HOUR_OF_DAY); //startHour = endHour = hourIndex if (endHour == hourIndex) { endMinute = endCalendar.get(Calendar.MINUTE); removeMinute(startMinute, endMinute, hourIndex, availableTime); } //startHour = hourIndex != endHour else { for (int i = hourIndex; i < endHour + 1; i++) { if (i == hourIndex) { if (startMinute == 0) { availableTime.remove(startHour); } else { removeMinute(startMinute, 59, hourIndex, availableTime); } } else if (i == endHour) { endMinute = endCalendar.get(Calendar.MINUTE); if (endMinute == 59) { availableTime.remove(endHour); } else { removeMinute(0, endMinute, endHour, availableTime); } } else { availableTime.remove(i); } } } } } } return availableTime; }
From source file:ub.botiga.ServletDispatcher.java
private void showCistell(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { HttpSession session = request.getSession(); User u = (User) session.getAttribute("user"); if (u == null) { response.sendRedirect("/Botiga/"); return;/*from w w w. j a va 2s .c om*/ } HashMap<String, Product> cistell = getCistell(request); HashMap<String, Product> historial = u.getProducts(); for (Product p : historial.values()) { cistell.remove(p.getName()); } session.setAttribute("cistell", cistell); if (u.getCredits() - getPreuCistell(request) < 0) { request.setAttribute("creditsuficient", false); } else { request.setAttribute("creditsuficient", true); } request.setAttribute("cistell", cistell.values()); DecimalFormat df = new DecimalFormat(); df.setMaximumFractionDigits(2); DecimalFormatSymbols dfs = new DecimalFormatSymbols(); dfs.setDecimalSeparator('.'); df.setDecimalFormatSymbols(dfs); request.setAttribute("preucistell", df.format(getPreuCistell(request))); showPage(request, response, "cistell.jsp"); }
From source file:org.opensilk.music.library.mediastore.util.FilesUtil.java
@NonNull public static List<File> filterAudioFiles(Context context, List<File> files) { if (files.size() == 0) { return Collections.emptyList(); }/*from w ww .ja v a2 s. c o m*/ //Map for cursor final HashMap<String, File> pathMap = new HashMap<>(); //The returned list final List<File> audioFiles = new ArrayList<>(); //Build the selection final int size = files.size(); final StringBuilder selection = new StringBuilder(); selection.append(MediaStore.Files.FileColumns.DATA + " IN ("); for (int i = 0; i < size; i++) { final File f = files.get(i); final String path = f.getAbsolutePath(); pathMap.put(path, f); //Add file to map while where iterating //TODO it would probably be better to use selectionArgs selection.append("'").append(StringUtils.replace(path, "'", "''")).append("'"); if (i < size - 1) { selection.append(","); } } selection.append(")"); Cursor c = null; try { c = context.getContentResolver().query(MediaStore.Files.getContentUri("external"), Projections.MEDIA_TYPE_PROJECTION, selection.toString(), null, null); if (c != null && c.moveToFirst()) { do { final int mediaType = c.getInt(0); final String path = c.getString(1); final File f = pathMap.remove(path); if (f != null && mediaType == MediaStore.Files.FileColumns.MEDIA_TYPE_AUDIO) { audioFiles.add(f); } //else throw away } while (c.moveToNext()); } //either the query failed or the cursor didn't contain all the files we asked for. if (!pathMap.isEmpty()) { Timber.w("%d files weren't found in mediastore. Best guessing mime type", pathMap.size()); for (File f : pathMap.values()) { final String mime = guessMimeType(f); if (StringUtils.contains(mime, "audio") || "application/ogg".equals(mime)) { audioFiles.add(f); } } } } catch (Exception e) { if (FilesUtil.DUMPSTACKS) Timber.e(e, "filterAudioFiles"); } finally { closeQuietly(c); } return audioFiles; }
From source file:com.example.android.nfcprovisioning.ProvisioningValuesLoader.java
private void gatherAdminExtras(HashMap<String, String> values) { HashMap<String, String> newMap = new HashMap<String, String>(); Properties props = new Properties(); Set<String> keys = new HashSet(values.keySet()); for (String key : keys) { if (key.startsWith("android.app.extra")) { continue; }//from w ww . jav a 2 s. c om props.put(key, values.get(key)); values.remove(key); } StringWriter sw = new StringWriter(); try { props.store(sw, "admin extras bundle"); values.put(DevicePolicyManager.EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE, sw.toString()); Log.d(TAG, "Admin extras bundle=" + values.get(DevicePolicyManager.EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE)); } catch (IOException e) { Log.e(TAG, "Unable to build admin extras bundle"); } }