Example usage for java.util Map remove

List of usage examples for java.util Map remove

Introduction

In this page you can find the example usage for java.util Map remove.

Prototype

V remove(Object key);

Source Link

Document

Removes the mapping for a key from this map if it is present (optional operation).

Usage

From source file:eu.musesproject.windowsclient.contextmonitoring.sensors.DeviceProtectionSensor.java

private boolean identicalContextEvent(ContextEvent oldEvent, ContextEvent newEvent) {
    Map<String, String> oldProperties = oldEvent.getProperties();
    oldProperties.remove(PROPERTY_KEY_ID);
    Map<String, String> newProperties = newEvent.getProperties();
    newProperties.remove(PROPERTY_KEY_ID);
    for (Entry<String, String> set : newProperties.entrySet()) {
        String oldValue = oldProperties.get(set.getKey());
        String newValue = newProperties.get(set.getKey());
        if (!oldValue.equals(newValue)) {
            return false;
        }/* www.  j  a  v a 2s. com*/
    }

    return true;
}

From source file:com.cloudseal.spring.client.userdetails.CloudsealUserAttributes.java

private String removeStringAttribute(Map<String, Collection<XMLObject>> attributes, String name) {
    Collection<XMLObject> list = attributes.remove(name);
    if (list == null || list.isEmpty()) {
        return "";
    }//w ww  .  j  a  v a2  s. c  o m
    StringBuilder builder = new StringBuilder();
    for (XMLObject xmlObject : list) {
        if (XSString.class.isInstance(xmlObject)) {
            if (builder.length() != 0) {
                builder.append(",");
            }
            builder.append(((XSString) xmlObject).getValue());
        }
    }
    return builder.toString();
}

From source file:org.easyj.orm.jpa.SingleJPAEntityDao.java

/**
 * Binds parameter map to the query.//from   www. ja va  2  s.c om
 * 
 * There are two special parameters that is of use:
 * {@link SingleService.PARAM_MAX_RESULTS} used to limit maximum results returned
 * {@link SingleService.PARAM_START_POSITION} used to tell the starting position the result should start
 *
 * @param q query to bind parameters
 * @param params parameter map to bind into the query
 * @return true if all parameters where bound successfully, otherwise false
 */
private boolean setParameters(Query q, Map<String, Object> params) {
    if (q != null && params != null) {
        Integer maxResults = (Integer) params.remove(SingleDao.PARAM_MAX_RESULTS);
        if (maxResults != null && maxResults > 0) {
            q.setMaxResults(maxResults.intValue());
        }

        Integer startPosition = (Integer) params.remove(SingleDao.PARAM_START_POSITION);
        if (startPosition != null && startPosition > -1) {
            q.setFirstResult(startPosition.intValue());
        }

        for (Entry<String, Object> o : params.entrySet()) {
            try {
                q.setParameter(o.getKey().trim(), o.getValue());
            } catch (IllegalArgumentException ex) {
                logger.debug("Illegal Query Parameter", ex);
                return false;
            }
        }
    }
    return true;
}

From source file:edu.lafayette.metadb.web.metadata.UpdateMultipleMetadata.java

/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*//*from w ww .  j  a  v  a 2 s.c  om*/
@SuppressWarnings("unchecked")
protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    // TODO Auto-generated method stub
    PrintWriter out = response.getWriter();
    try {
        HttpSession session = request.getSession(false);
        String projname = (String) session.getAttribute(Global.SESSION_PROJECT);
        String type = request.getParameter("type");
        String records = request.getParameter("records");
        JSONArray failed_items = new JSONArray();
        JSONObject output = new JSONObject();
        String message = "";
        String failedRecords = "";
        if (records != null) {
            List<Integer> chosenRecords = null;
            if (records.equals("all"))
                chosenRecords = AdminDescDataDAO.getAdminDescItemNumbers(projname, type);
            else
                chosenRecords = new ArrayList<Integer>(this.filterRecords(records));

            if (chosenRecords != null && !chosenRecords.isEmpty()) {
                Map<String, String[]> attributes = new HashMap<String, String[]>(request.getParameterMap());
                attributes.remove("project-name");
                attributes.remove("type");
                attributes.remove("records");
                //message = type+" Records are updating...\n";
                for (int i = 0; i < chosenRecords.size(); i++) {
                    String userName = (String) session.getAttribute("username");
                    String locker = ItemsDAO.getLocker(projname, chosenRecords.get(i));
                    boolean process = true;
                    if (!(userName.equals(locker) || locker.trim().equals("") || locker == null)) {
                        failedRecords += " " + chosenRecords.get(i);
                        process = false; //Do not touch this record if it is locked.
                    }

                    //Update all the attributes for item i
                    Set keys = attributes.keySet();
                    Iterator itr = keys.iterator();
                    while (itr.hasNext()) {
                        String entry = (String) itr.next();
                        int id = Integer.parseInt(entry);
                        //                     String newData = attributes.get(entry)[0] == null ? "": attributes.get(entry)[0];
                        JSONObject whitelisted = UpdateAdminDescMetadata.whitelist(entry, projname, type,
                                chosenRecords.get(i), request);
                        if (!whitelisted.getBoolean("success")) {
                            //MetaDbHelper.note(whitelisted.toString());
                            //MetaDbHelper.note(entry+" "+projname+" "+type+" "+chosenRecords.get(i));
                            failed_items.put(whitelisted);
                            break;
                        }
                        if (process) {
                            if (!AdminDescDataDAO.updateAdminDescData(projname, chosenRecords.get(i), id,
                                    whitelisted.getString("data")))
                                failedRecords += " " + chosenRecords.get(i); //even if locker check succeeded, could still fail.
                        }
                    }
                }
                message = "Data updates complete.\n";
                if (!(failedRecords.trim().equals("")))
                    message += "The following item(s) could not be updated:" + failedRecords;
            }
        } else
            message = "No attributes in project";
        output.put("failure", failed_items);
        output.put("message", message);
        output.put("type", type);
        out.print(output);
    } catch (Exception e) {
        MetaDbHelper.logEvent(e);
    }
    out.close();
}

From source file:net.testdriven.psiprobe.controllers.system.SysInfoController.java

protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response)
        throws Exception {
    SystemInformation systemInformation = new SystemInformation();
    systemInformation.setAppBase(getContainerWrapper().getTomcatContainer().getAppBase().getAbsolutePath());
    systemInformation.setConfigBase(getContainerWrapper().getTomcatContainer().getConfigBase());

    Map sysProps = new Properties();
    sysProps.putAll(System.getProperties());

    if (!SecurityUtils.hasAttributeValueRole(getServletContext(), request)) {
        for (Object filterOutKey : filterOutKeys) {
            sysProps.remove(filterOutKey);
        }// www . j  av  a 2  s. c  om
    }

    systemInformation.setSystemProperties(sysProps);

    return new ModelAndView(getViewName()).addObject("systemInformation", systemInformation)
            .addObject("runtime", getRuntimeInfoAccessor().getRuntimeInformation())
            .addObject("collectionPeriod", getCollectionPeriod());
}

From source file:org.apache.nifi.processors.standard.RegexAttributesToJSON.java

/**
 * Remove all of the CoreAttributes from the Attributes that will be written to the Flowfile.
 *
 * @param atsToWrite/*www  .ja  v a 2 s . co  m*/
 *  List of Attributes that have already been generated including the CoreAttributes
 *
 * @return
 *  Difference of all attributes minus the CoreAttributes
 */
protected Map<String, String> removeCoreAttributes(Map<String, String> atsToWrite) {
    for (CoreAttributes c : CoreAttributes.values()) {
        atsToWrite.remove(c.key());
    }
    return atsToWrite;
}

From source file:org.saiku.plugin.PentahoSessionService.java

public Map<String, Object> getSession() {
    if (SecurityContextHolder.getContext() != null
            && SecurityContextHolder.getContext().getAuthentication() != null) {
        Object p = SecurityContextHolder.getContext().getAuthentication().getPrincipal();
        if (!sessionHolder.containsKey(p)) {
            populateSession(p);/*from w  w  w.  j  a  v a 2 s  .  c  o  m*/
        }
        Map<String, Object> r = new HashMap<String, Object>();
        r.putAll(sessionHolder.get(p));
        if (r.containsKey("password")) {
            r.remove("password");
        }
        return r;
    }
    return new HashMap<String, Object>();
}

From source file:org.saiku.plugin.PentahoSessionService.java

public Map<String, Object> getAllSessionObjects() {
    if (SecurityContextHolder.getContext() != null
            && SecurityContextHolder.getContext().getAuthentication() != null) {
        Object p = SecurityContextHolder.getContext().getAuthentication().getPrincipal();
        if (!sessionHolder.containsKey(p)) {
            populateSession(p);/*from   w  ww .  j  av  a  2s  .c  o m*/
        }
        Map<String, Object> r = new HashMap<String, Object>();
        r.putAll(sessionHolder.get(p));
        if (r.containsKey("password")) {
            r.remove("password");
        }
        return r;
    }
    return new HashMap<String, Object>();
}

From source file:com.bisone.saiku.security.replace.SessionService.java

public Map<String, Object> getSession() throws Exception {
    if (SecurityContextHolder.getContext() != null
            && SecurityContextHolder.getContext().getAuthentication() != null) {
        Authentication auth = SecurityContextHolder.getContext().getAuthentication();
        Object p = auth.getPrincipal();
        if (sessionHolder.containsKey(p)) {
            Map<String, Object> r = new HashMap<String, Object>();
            r.putAll(sessionHolder.get(p));
            r.remove("password");
            return r;
        }/*from  ww  w  .j a va2 s  .  c  o  m*/

    }
    return new HashMap<String, Object>();
}

From source file:com.hpe.application.automation.tools.octane.executor.UftTestDiscoveryDispatcher.java

/**
 * This method check whether discovered test are already exist on server, and instead of creation - those tests will be updated
 * Go over discovered and octane tests/*from   w  ww . j  a v a  2  s  .c  om*/
 * 1.if test doesn't exist on octane - this is new test
 * 2.if test exist
 * 2.1 if test different from discovered - this is test for update
 * 2.2 if tests are equal - skip test
 * 3. all tests that are found in Octane but not discovered - those deleted tests and they will be turned to not executable
 *
 * @return true if there were changes comparing to discoverede results
 */
private static boolean validateTestDiscoveryForFullDetection(MqmRestClient client,
        UFTTestDetectionResult detectionResult) {
    boolean hasDiff = false;
    Map<String, Entity> octaneTestsMap = getTestsFromServer(client,
            Long.parseLong(detectionResult.getWorkspaceId()),
            Long.parseLong(detectionResult.getScmRepositoryId()), null);

    List<AutomatedTest> discoveredTests = new ArrayList(detectionResult.getNewTests());
    detectionResult.getNewTests().clear();
    for (AutomatedTest discoveredTest : discoveredTests) {
        String key = createKey(discoveredTest.getPackage(), discoveredTest.getName());
        Entity octaneTest = octaneTestsMap.remove(key);

        if (octaneTest == null) {
            detectionResult.getNewTests().add(discoveredTest);
        } else {
            hasDiff = true;//if we get here - there is diff with discovered tests
            //the only fields that might be different is description and executable
            boolean octaneExecutable = octaneTest.getBooleanValue(OctaneConstants.Tests.EXECUTABLE_FIELD);
            String octaneDescription = octaneTest.getStringValue(OctaneConstants.Tests.DESCRIPTION_FIELD);
            boolean descriptionEquals = ((StringUtils.isEmpty(octaneDescription)
                    || "null".equals(octaneDescription)) && discoveredTest.getDescription() == null)
                    || octaneDescription.contains(discoveredTest.getDescription());
            boolean testsEqual = (octaneExecutable && descriptionEquals);
            if (!testsEqual) { //if equal - skip
                discoveredTest.setId(octaneTest.getId());
                detectionResult.getUpdatedTests().add(discoveredTest);
            }
        }
    }

    //go over executable tests that exist in Octane but not discovered and disable them
    for (Entity octaneTest : octaneTestsMap.values()) {
        hasDiff = true;//if some test exist - there is diff with discovered tests
        boolean octaneExecutable = octaneTest.getBooleanValue(OctaneConstants.Tests.EXECUTABLE_FIELD);
        if (octaneExecutable) {
            AutomatedTest test = new AutomatedTest();
            test.setId(octaneTest.getId());
            test.setExecutable(false);
            test.setName(octaneTest.getName());
            test.setPackage(octaneTest.getStringValue(OctaneConstants.Tests.PACKAGE_FIELD));
            detectionResult.getDeletedTests().add(test);
        }
    }

    return hasDiff;
}