Example usage for java.util HashMap remove

List of usage examples for java.util HashMap remove

Introduction

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

Prototype

public V remove(Object key) 

Source Link

Document

Removes the mapping for the specified key from this map if present.

Usage

From source file:edu.msu.cme.rdp.readseq.utils.RmDupSeqs.java

public static void filterDuplicates(String inFile, String outFile, int length, boolean debug)
        throws IOException {
    HashMap<String, String> idSet = new HashMap<String, String>();
    IndexedSeqReader reader = new IndexedSeqReader(new File(inFile));
    BufferedWriter outWriter = new BufferedWriter(new FileWriter(new File(outFile)));
    Set<String> allseqIDset = reader.getSeqIdSet();
    Sequence seq;/*w w  w . j a  va2s  .  c  o m*/
    if (debug) {
        System.out.println("ID\tdescription" + "\tcontained_by_ID\tdescription");
    }
    for (String id : allseqIDset) {
        seq = reader.readSeq(id);
        boolean dup = false;
        HashSet<String> tempdupSet = new HashSet<String>();
        for (String exID : idSet.keySet()) {
            String exSeq = idSet.get(exID);
            if (exSeq.length() >= seq.getSeqString().length()) {
                if (exSeq.contains(seq.getSeqString())) {
                    dup = true;
                    if (debug) {
                        Sequence temp = reader.readSeq(exID);
                        System.out.println(id + "\t" + seq.getDesc() + "\t" + exID + "\t" + temp.getDesc());
                    }
                    break;
                }
            } else if (seq.getSeqString().contains(exSeq)) {
                tempdupSet.add(exID);
            }
        }

        if (!dup) {
            idSet.put(id, seq.getSeqString());
        }
        for (String dupid : tempdupSet) {
            idSet.remove(dupid);
            if (debug) {
                Sequence temp = reader.readSeq(dupid);
                System.out.println(dupid + "\t" + temp.getDesc() + "\t" + id + "\t" + seq.getDesc());
            }
        }
    }
    // get the unique seq
    for (String id : idSet.keySet()) {
        seq = reader.readSeq(id);
        if (seq.getSeqString().length() >= length) {
            outWriter.write(">" + id + "\t" + seq.getDesc() + "\n" + seq.getSeqString() + "\n");
        }
    }
    reader.close();
    outWriter.close();
}

From source file:br.mdarte.exemplo.academico.web.geral.detalharCurso.DetalhandoCursoEditaCurso.java

public String particularExecute() throws Exception {
    String casoDeUso = null;//from w  w w.  j a va  2 s . c  o  m
    String urlCasoDeUso = null;
    String modulo = null;

    boolean adicionaBreadCrumb = true;
    casoDeUso = "DetalhaCursoUC";
    urlCasoDeUso = "/DetalhaCursoUC/DetalhandoCursoEditaCurso";

    modulo = "geral";
    Iterator breadCrumbIt = null;
    Boolean aplicacaoPermiteUsoBackBrowser = (Boolean) request.getSession().getServletContext()
            .getAttribute("aplicacaoPermiteUsoBackBrowser");

    if (!aplicacaoPermiteUsoBackBrowser ^ false) {
        if (getInvalidatePageControlCounter(request).get("DetalhaCursoUC.DetalhandoCurso") != null
                && request.getParameter("invalidatePageControlCounter") != null
                && !(((Integer) getInvalidatePageControlCounter(request).get("DetalhaCursoUC.DetalhandoCurso"))
                        .equals(Integer.valueOf(request.getParameter("invalidatePageControlCounter"))))) {
            javax.servlet.http.HttpSession session = request.getSession();
            org.apache.struts.action.ActionMessages messages = (org.apache.struts.action.ActionMessages) session
                    .getAttribute(org.apache.struts.Globals.MESSAGE_KEY);
            if (messages == null) {
                messages = new org.apache.struts.action.ActionMessages();
                session.setAttribute(org.apache.struts.Globals.MESSAGE_KEY, messages);
            }
            messages.add("org.andromda.bpm4struts.errormessages",
                    new org.apache.struts.action.ActionMessage("pagina.expirou"));

            return "forwardAction";
        }
    }

    String forward = null;
    String redirect = "";
    request.getSession().setAttribute(org.apache.struts.Globals.MESSAGE_KEY,
            new org.apache.struts.action.ActionMessages());
    forward = "edita.curso";

    boolean copyParameters = true;

    if (request.getSession().getAttribute(Constantes.COPY_PARAMETERS) != null) {
        copyParameters = (Boolean) request.getSession().getAttribute(Constantes.COPY_PARAMETERS);
        request.getSession().removeAttribute(Constantes.COPY_PARAMETERS);
    }

    DetalhandoCursoEditaCursoFormImpl form = new DetalhandoCursoEditaCursoFormImpl();

    form.setIdCurso(this.idCurso);

    final DetalhandoCursoEditaCursoFormImpl specificForm = (DetalhandoCursoEditaCursoFormImpl) form;

    if (getInvalidatePageControlCounter(request).get("DetalhaCursoUC.DetalhandoCurso") == null)
        getInvalidatePageControlCounter(request).put("DetalhaCursoUC.DetalhandoCurso", 0);
    getInvalidatePageControlCounter(request).put("DetalhaCursoUC.DetalhandoCurso",
            ((Integer) getInvalidatePageControlCounter(request).get("DetalhaCursoUC.DetalhandoCurso"))
                    .intValue() + 1);

    request.getSession().setAttribute("form", form);

    try {

        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/MantemCursoUC/MantemCursoUC.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 = "edita.curso";
        }

    } //fim try
    catch (java.lang.Exception exception) {
        Object formObj = org.andromda.presentation.bpm4struts.PageSessionObjectUtil.getPageForm(request,
                "DetalhaCursoUC.DetalhandoCurso");

        if (formObj != null) {
            try {
                formObj.getClass()
                        .getMethod("resetCheckBoxes",
                                new Class[] { org.apache.struts.action.ActionMapping.class,
                                        javax.servlet.http.HttpServletRequest.class })
                        .invoke(formObj, new Object[] { null, null });
            } catch (Exception e2) {
                // ignoring
            }

            final java.util.Map parameters = new java.util.HashMap();
            for (final java.util.Enumeration names = request.getParameterNames(); names.hasMoreElements();) {
                final String name = String.valueOf(names.nextElement());
                parameters.put(name, request.getParameterValues(name));
            }
            try {
                org.apache.commons.beanutils.BeanUtils.populate(formObj, parameters);
            } catch (java.lang.Exception populateException) {
                // ignore if we have an exception here (we just don't populate).
            }
        }
        throw exception;
    }

    if (request.getAttribute("$forwardKeyModule") != null
            && !request.getAttribute("$forwardKeyModule").equals("geral")) {
        java.util.Enumeration atributosName = request.getSession().getAttributeNames();
        java.util.Map atributos = new java.util.HashMap();

        while (atributosName.hasMoreElements()) {
            String atributo = (String) atributosName.nextElement();
            atributos.put(atributo, request.getSession().getAttribute(atributo));
        }

        org.andromda.presentation.bpm4struts.ShareSessionUtil.saveMapIntoContext(request, response, atributos,
                ServletActionContext.getServletContext().getContext("/sistemaacademico"));
    }

    if (redirect != "") {//troca de modules - to be tested
        response.sendRedirect(redirect);
    }

    request.removeAttribute("$forwardKey");
    request.removeAttribute("$forwardKeyModule");

    return forward;
}

From source file:br.mdarte.exemplo.academico.web.geral.consultarCurso.ResultadoConsultaDetalhaCurso.java

public String particularExecute() throws Exception {
    String casoDeUso = null;//from   ww w . j a  v a 2  s  .  c  o m
    String urlCasoDeUso = null;
    String modulo = null;

    boolean adicionaBreadCrumb = true;
    casoDeUso = "ConsultaCursoUC";
    urlCasoDeUso = "/ConsultaCursoUC/ResultadoConsultaDetalhaCurso";

    modulo = "geral";
    Iterator breadCrumbIt = null;
    Boolean aplicacaoPermiteUsoBackBrowser = (Boolean) request.getSession().getServletContext()
            .getAttribute("aplicacaoPermiteUsoBackBrowser");

    if (!aplicacaoPermiteUsoBackBrowser ^ false) {
        if (getInvalidatePageControlCounter(request).get("ConsultaCursoUC.ResultadoConsulta") != null
                && request.getParameter("invalidatePageControlCounter") != null
                && !(((Integer) getInvalidatePageControlCounter(request)
                        .get("ConsultaCursoUC.ResultadoConsulta")).equals(
                                Integer.valueOf(request.getParameter("invalidatePageControlCounter"))))) {
            javax.servlet.http.HttpSession session = request.getSession();
            org.apache.struts.action.ActionMessages messages = (org.apache.struts.action.ActionMessages) session
                    .getAttribute(org.apache.struts.Globals.MESSAGE_KEY);
            if (messages == null) {
                messages = new org.apache.struts.action.ActionMessages();
                session.setAttribute(org.apache.struts.Globals.MESSAGE_KEY, messages);
            }
            messages.add("org.andromda.bpm4struts.errormessages",
                    new org.apache.struts.action.ActionMessage("pagina.expirou"));

            return "forwardAction";
        }
    }

    String forward = null;
    String redirect = "";
    request.getSession().setAttribute(org.apache.struts.Globals.MESSAGE_KEY,
            new org.apache.struts.action.ActionMessages());
    forward = "detalha.curso";

    boolean copyParameters = true;

    if (request.getSession().getAttribute(Constantes.COPY_PARAMETERS) != null) {
        copyParameters = (Boolean) request.getSession().getAttribute(Constantes.COPY_PARAMETERS);
        request.getSession().removeAttribute(Constantes.COPY_PARAMETERS);
    }

    ResultadoConsultaDetalhaCursoFormImpl form = new ResultadoConsultaDetalhaCursoFormImpl();

    form.setIdCurso(this.idCurso);

    final ResultadoConsultaDetalhaCursoFormImpl specificForm = (ResultadoConsultaDetalhaCursoFormImpl) form;

    if (getInvalidatePageControlCounter(request).get("ConsultaCursoUC.ResultadoConsulta") == null)
        getInvalidatePageControlCounter(request).put("ConsultaCursoUC.ResultadoConsulta", 0);
    getInvalidatePageControlCounter(request).put("ConsultaCursoUC.ResultadoConsulta",
            ((Integer) getInvalidatePageControlCounter(request).get("ConsultaCursoUC.ResultadoConsulta"))
                    .intValue() + 1);

    request.getSession().setAttribute("form", form);

    try {

        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";
        }

    } //fim try
    catch (java.lang.Exception exception) {
        Object formObj = org.andromda.presentation.bpm4struts.PageSessionObjectUtil.getPageForm(request,
                "ConsultaCursoUC.ResultadoConsulta");

        if (formObj != null) {
            try {
                formObj.getClass()
                        .getMethod("resetCheckBoxes",
                                new Class[] { org.apache.struts.action.ActionMapping.class,
                                        javax.servlet.http.HttpServletRequest.class })
                        .invoke(formObj, new Object[] { null, null });
            } catch (Exception e2) {
                // ignoring
            }

            final java.util.Map parameters = new java.util.HashMap();
            for (final java.util.Enumeration names = request.getParameterNames(); names.hasMoreElements();) {
                final String name = String.valueOf(names.nextElement());
                parameters.put(name, request.getParameterValues(name));
            }
            try {
                org.apache.commons.beanutils.BeanUtils.populate(formObj, parameters);
            } catch (java.lang.Exception populateException) {
                // ignore if we have an exception here (we just don't populate).
            }
        }
        throw exception;
    }

    if (request.getAttribute("$forwardKeyModule") != null
            && !request.getAttribute("$forwardKeyModule").equals("geral")) {
        java.util.Enumeration atributosName = request.getSession().getAttributeNames();
        java.util.Map atributos = new java.util.HashMap();

        while (atributosName.hasMoreElements()) {
            String atributo = (String) atributosName.nextElement();
            atributos.put(atributo, request.getSession().getAttribute(atributo));
        }

        org.andromda.presentation.bpm4struts.ShareSessionUtil.saveMapIntoContext(request, response, atributos,
                ServletActionContext.getServletContext().getContext("/sistemaacademico"));
    }

    if (redirect != "") {//troca de modules - to be tested
        response.sendRedirect(redirect);
    }

    request.removeAttribute("$forwardKey");
    request.removeAttribute("$forwardKeyModule");

    return forward;
}

From source file:br.mdarte.exemplo.academico.web.geral.detalharEstudante.DetalhandoEstudanteEditaEstudante.java

public String particularExecute() throws Exception {
    String casoDeUso = null;/*from  ww w  .  j  a va2s .c o  m*/
    String urlCasoDeUso = null;
    String modulo = null;

    boolean adicionaBreadCrumb = true;
    casoDeUso = "DetalhaEstudanteUC";
    urlCasoDeUso = "/DetalhaEstudanteUC/DetalhandoEstudanteEditaEstudante";

    modulo = "geral";
    Iterator breadCrumbIt = null;
    Boolean aplicacaoPermiteUsoBackBrowser = (Boolean) request.getSession().getServletContext()
            .getAttribute("aplicacaoPermiteUsoBackBrowser");

    if (!aplicacaoPermiteUsoBackBrowser ^ false) {
        if (getInvalidatePageControlCounter(request).get("DetalhaEstudanteUC.DetalhandoEstudante") != null
                && request.getParameter("invalidatePageControlCounter") != null
                && !(((Integer) getInvalidatePageControlCounter(request)
                        .get("DetalhaEstudanteUC.DetalhandoEstudante")).equals(
                                Integer.valueOf(request.getParameter("invalidatePageControlCounter"))))) {
            javax.servlet.http.HttpSession session = request.getSession();
            org.apache.struts.action.ActionMessages messages = (org.apache.struts.action.ActionMessages) session
                    .getAttribute(org.apache.struts.Globals.MESSAGE_KEY);
            if (messages == null) {
                messages = new org.apache.struts.action.ActionMessages();
                session.setAttribute(org.apache.struts.Globals.MESSAGE_KEY, messages);
            }
            messages.add("org.andromda.bpm4struts.errormessages",
                    new org.apache.struts.action.ActionMessage("pagina.expirou"));

            return "forwardAction";
        }
    }

    String forward = null;
    String redirect = "";
    request.getSession().setAttribute(org.apache.struts.Globals.MESSAGE_KEY,
            new org.apache.struts.action.ActionMessages());
    forward = "edita.estudante";

    boolean copyParameters = true;

    if (request.getSession().getAttribute(Constantes.COPY_PARAMETERS) != null) {
        copyParameters = (Boolean) request.getSession().getAttribute(Constantes.COPY_PARAMETERS);
        request.getSession().removeAttribute(Constantes.COPY_PARAMETERS);
    }

    DetalhandoEstudanteEditaEstudanteFormImpl form = new DetalhandoEstudanteEditaEstudanteFormImpl();

    form.setIdEstudante(this.idEstudante);

    final DetalhandoEstudanteEditaEstudanteFormImpl specificForm = (DetalhandoEstudanteEditaEstudanteFormImpl) form;

    if (getInvalidatePageControlCounter(request).get("DetalhaEstudanteUC.DetalhandoEstudante") == null)
        getInvalidatePageControlCounter(request).put("DetalhaEstudanteUC.DetalhandoEstudante", 0);
    getInvalidatePageControlCounter(request).put("DetalhaEstudanteUC.DetalhandoEstudante",
            ((Integer) getInvalidatePageControlCounter(request).get("DetalhaEstudanteUC.DetalhandoEstudante"))
                    .intValue() + 1);

    request.getSession().setAttribute("form", form);

    try {

        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/MantemEstudanteUC/MantemEstudanteUC.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 = "edita.estudante";
        }

    } //fim try
    catch (java.lang.Exception exception) {
        Object formObj = org.andromda.presentation.bpm4struts.PageSessionObjectUtil.getPageForm(request,
                "DetalhaEstudanteUC.DetalhandoEstudante");

        if (formObj != null) {
            try {
                formObj.getClass()
                        .getMethod("resetCheckBoxes",
                                new Class[] { org.apache.struts.action.ActionMapping.class,
                                        javax.servlet.http.HttpServletRequest.class })
                        .invoke(formObj, new Object[] { null, null });
            } catch (Exception e2) {
                // ignoring
            }

            final java.util.Map parameters = new java.util.HashMap();
            for (final java.util.Enumeration names = request.getParameterNames(); names.hasMoreElements();) {
                final String name = String.valueOf(names.nextElement());
                parameters.put(name, request.getParameterValues(name));
            }
            try {
                org.apache.commons.beanutils.BeanUtils.populate(formObj, parameters);
            } catch (java.lang.Exception populateException) {
                // ignore if we have an exception here (we just don't populate).
            }
        }
        throw exception;
    }

    if (request.getAttribute("$forwardKeyModule") != null
            && !request.getAttribute("$forwardKeyModule").equals("geral")) {
        java.util.Enumeration atributosName = request.getSession().getAttributeNames();
        java.util.Map atributos = new java.util.HashMap();

        while (atributosName.hasMoreElements()) {
            String atributo = (String) atributosName.nextElement();
            atributos.put(atributo, request.getSession().getAttribute(atributo));
        }

        org.andromda.presentation.bpm4struts.ShareSessionUtil.saveMapIntoContext(request, response, atributos,
                ServletActionContext.getServletContext().getContext("/sistemaacademico"));
    }

    if (redirect != "") {//troca de modules - to be tested
        response.sendRedirect(redirect);
    }

    request.removeAttribute("$forwardKey");
    request.removeAttribute("$forwardKeyModule");

    return forward;
}

From source file:br.mdarte.exemplo.academico.web.geral.detalharCurso.DetalhandoCursoVoltar.java

public String particularExecute() throws Exception {
    String casoDeUso = null;//  ww  w.  j av a 2  s.c o  m
    String urlCasoDeUso = null;
    String modulo = null;

    boolean adicionaBreadCrumb = true;
    casoDeUso = "DetalhaCursoUC";
    urlCasoDeUso = "/DetalhaCursoUC/DetalhandoCursoVoltar";

    modulo = "geral";
    Iterator breadCrumbIt = null;
    Boolean aplicacaoPermiteUsoBackBrowser = (Boolean) request.getSession().getServletContext()
            .getAttribute("aplicacaoPermiteUsoBackBrowser");

    if (!aplicacaoPermiteUsoBackBrowser ^ false) {
        if (getInvalidatePageControlCounter(request).get("DetalhaCursoUC.DetalhandoCurso") != null
                && request.getParameter("invalidatePageControlCounter") != null
                && !(((Integer) getInvalidatePageControlCounter(request).get("DetalhaCursoUC.DetalhandoCurso"))
                        .equals(Integer.valueOf(request.getParameter("invalidatePageControlCounter"))))) {
            javax.servlet.http.HttpSession session = request.getSession();
            org.apache.struts.action.ActionMessages messages = (org.apache.struts.action.ActionMessages) session
                    .getAttribute(org.apache.struts.Globals.MESSAGE_KEY);
            if (messages == null) {
                messages = new org.apache.struts.action.ActionMessages();
                session.setAttribute(org.apache.struts.Globals.MESSAGE_KEY, messages);
            }
            messages.add("org.andromda.bpm4struts.errormessages",
                    new org.apache.struts.action.ActionMessage("pagina.expirou"));

            return "forwardAction";
        }
    }

    String forward = null;
    String redirect = "";
    request.getSession().setAttribute(org.apache.struts.Globals.MESSAGE_KEY,
            new org.apache.struts.action.ActionMessages());
    forward = "voltar";

    boolean copyParameters = true;

    if (request.getSession().getAttribute(Constantes.COPY_PARAMETERS) != null) {
        copyParameters = (Boolean) request.getSession().getAttribute(Constantes.COPY_PARAMETERS);
        request.getSession().removeAttribute(Constantes.COPY_PARAMETERS);
    }

    DetalhandoCursoVoltarFormImpl form = new DetalhandoCursoVoltarFormImpl();

    form.setCodigo(this.codigo);
    form.setNome(this.nome);

    final DetalhandoCursoVoltarFormImpl specificForm = (DetalhandoCursoVoltarFormImpl) form;

    if (getInvalidatePageControlCounter(request).get("DetalhaCursoUC.DetalhandoCurso") == null)
        getInvalidatePageControlCounter(request).put("DetalhaCursoUC.DetalhandoCurso", 0);
    getInvalidatePageControlCounter(request).put("DetalhaCursoUC.DetalhandoCurso",
            ((Integer) getInvalidatePageControlCounter(request).get("DetalhaCursoUC.DetalhandoCurso"))
                    .intValue() + 1);

    request.getSession().setAttribute("form", form);

    try {

        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/ConsultaCursoUC/ConsultaCursoUC.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 = "voltar";
        }

    } //fim try
    catch (java.lang.Exception exception) {
        Object formObj = org.andromda.presentation.bpm4struts.PageSessionObjectUtil.getPageForm(request,
                "DetalhaCursoUC.DetalhandoCurso");

        if (formObj != null) {
            try {
                formObj.getClass()
                        .getMethod("resetCheckBoxes",
                                new Class[] { org.apache.struts.action.ActionMapping.class,
                                        javax.servlet.http.HttpServletRequest.class })
                        .invoke(formObj, new Object[] { null, null });
            } catch (Exception e2) {
                // ignoring
            }

            final java.util.Map parameters = new java.util.HashMap();
            for (final java.util.Enumeration names = request.getParameterNames(); names.hasMoreElements();) {
                final String name = String.valueOf(names.nextElement());
                parameters.put(name, request.getParameterValues(name));
            }
            try {
                org.apache.commons.beanutils.BeanUtils.populate(formObj, parameters);
            } catch (java.lang.Exception populateException) {
                // ignore if we have an exception here (we just don't populate).
            }
        }
        throw exception;
    }

    if (request.getAttribute("$forwardKeyModule") != null
            && !request.getAttribute("$forwardKeyModule").equals("geral")) {
        java.util.Enumeration atributosName = request.getSession().getAttributeNames();
        java.util.Map atributos = new java.util.HashMap();

        while (atributosName.hasMoreElements()) {
            String atributo = (String) atributosName.nextElement();
            atributos.put(atributo, request.getSession().getAttribute(atributo));
        }

        org.andromda.presentation.bpm4struts.ShareSessionUtil.saveMapIntoContext(request, response, atributos,
                ServletActionContext.getServletContext().getContext("/sistemaacademico"));
    }

    if (redirect != "") {//troca de modules - to be tested
        response.sendRedirect(redirect);
    }

    request.removeAttribute("$forwardKey");
    request.removeAttribute("$forwardKeyModule");

    return forward;
}

From source file:br.mdarte.exemplo.academico.web.geral.detalharEstudante.DetalhandoEstudanteVoltar.java

public String particularExecute() throws Exception {
    String casoDeUso = null;/*from ww w .  j  a va 2s.c  o m*/
    String urlCasoDeUso = null;
    String modulo = null;

    boolean adicionaBreadCrumb = true;
    casoDeUso = "DetalhaEstudanteUC";
    urlCasoDeUso = "/DetalhaEstudanteUC/DetalhandoEstudanteVoltar";

    modulo = "geral";
    Iterator breadCrumbIt = null;
    Boolean aplicacaoPermiteUsoBackBrowser = (Boolean) request.getSession().getServletContext()
            .getAttribute("aplicacaoPermiteUsoBackBrowser");

    if (!aplicacaoPermiteUsoBackBrowser ^ false) {
        if (getInvalidatePageControlCounter(request).get("DetalhaEstudanteUC.DetalhandoEstudante") != null
                && request.getParameter("invalidatePageControlCounter") != null
                && !(((Integer) getInvalidatePageControlCounter(request)
                        .get("DetalhaEstudanteUC.DetalhandoEstudante")).equals(
                                Integer.valueOf(request.getParameter("invalidatePageControlCounter"))))) {
            javax.servlet.http.HttpSession session = request.getSession();
            org.apache.struts.action.ActionMessages messages = (org.apache.struts.action.ActionMessages) session
                    .getAttribute(org.apache.struts.Globals.MESSAGE_KEY);
            if (messages == null) {
                messages = new org.apache.struts.action.ActionMessages();
                session.setAttribute(org.apache.struts.Globals.MESSAGE_KEY, messages);
            }
            messages.add("org.andromda.bpm4struts.errormessages",
                    new org.apache.struts.action.ActionMessage("pagina.expirou"));

            return "forwardAction";
        }
    }

    String forward = null;
    String redirect = "";
    request.getSession().setAttribute(org.apache.struts.Globals.MESSAGE_KEY,
            new org.apache.struts.action.ActionMessages());
    forward = "voltar";

    boolean copyParameters = true;

    if (request.getSession().getAttribute(Constantes.COPY_PARAMETERS) != null) {
        copyParameters = (Boolean) request.getSession().getAttribute(Constantes.COPY_PARAMETERS);
        request.getSession().removeAttribute(Constantes.COPY_PARAMETERS);
    }

    DetalhandoEstudanteVoltarFormImpl form = new DetalhandoEstudanteVoltarFormImpl();

    form.setNome(this.nome);
    form.setMatricula(this.matricula);

    final DetalhandoEstudanteVoltarFormImpl specificForm = (DetalhandoEstudanteVoltarFormImpl) form;

    if (getInvalidatePageControlCounter(request).get("DetalhaEstudanteUC.DetalhandoEstudante") == null)
        getInvalidatePageControlCounter(request).put("DetalhaEstudanteUC.DetalhandoEstudante", 0);
    getInvalidatePageControlCounter(request).put("DetalhaEstudanteUC.DetalhandoEstudante",
            ((Integer) getInvalidatePageControlCounter(request).get("DetalhaEstudanteUC.DetalhandoEstudante"))
                    .intValue() + 1);

    request.getSession().setAttribute("form", form);

    try {

        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/ConsultaEstudanteUC/ConsultaEstudanteUC.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 = "voltar";
        }

    } //fim try
    catch (java.lang.Exception exception) {
        Object formObj = org.andromda.presentation.bpm4struts.PageSessionObjectUtil.getPageForm(request,
                "DetalhaEstudanteUC.DetalhandoEstudante");

        if (formObj != null) {
            try {
                formObj.getClass()
                        .getMethod("resetCheckBoxes",
                                new Class[] { org.apache.struts.action.ActionMapping.class,
                                        javax.servlet.http.HttpServletRequest.class })
                        .invoke(formObj, new Object[] { null, null });
            } catch (Exception e2) {
                // ignoring
            }

            final java.util.Map parameters = new java.util.HashMap();
            for (final java.util.Enumeration names = request.getParameterNames(); names.hasMoreElements();) {
                final String name = String.valueOf(names.nextElement());
                parameters.put(name, request.getParameterValues(name));
            }
            try {
                org.apache.commons.beanutils.BeanUtils.populate(formObj, parameters);
            } catch (java.lang.Exception populateException) {
                // ignore if we have an exception here (we just don't populate).
            }
        }
        throw exception;
    }

    if (request.getAttribute("$forwardKeyModule") != null
            && !request.getAttribute("$forwardKeyModule").equals("geral")) {
        java.util.Enumeration atributosName = request.getSession().getAttributeNames();
        java.util.Map atributos = new java.util.HashMap();

        while (atributosName.hasMoreElements()) {
            String atributo = (String) atributosName.nextElement();
            atributos.put(atributo, request.getSession().getAttribute(atributo));
        }

        org.andromda.presentation.bpm4struts.ShareSessionUtil.saveMapIntoContext(request, response, atributos,
                ServletActionContext.getServletContext().getContext("/sistemaacademico"));
    }

    if (redirect != "") {//troca de modules - to be tested
        response.sendRedirect(redirect);
    }

    request.removeAttribute("$forwardKey");
    request.removeAttribute("$forwardKeyModule");

    return forward;
}

From source file:org.tolven.security.password.PasswordHolder.java

public boolean isPasswordStoreUpToDate() {
    Passwords initialPasswords = loadPasswords();
    HashMap<String, PasswordInfo> passwordMapCopy = new HashMap<String, PasswordInfo>(getPasswordMap());
    passwordMapCopy.remove(getAdminGroupId());
    if (passwordMapCopy.size() != initialPasswords.getPasswordInfo().size()) {
        return false;
    }//from www .  j  a v a  2 s  . c om
    char[] password = null;
    PasswordInfo passwordInfo = null;
    for (PasswordDetail passwordDetail : initialPasswords.getPasswordInfo()) {
        passwordInfo = passwordMapCopy.get(passwordDetail.getRefId());
        if (passwordInfo == null) {
            return false;
        }
        password = getPassword(passwordInfo.getRefId());
        CharBuffer passwordBuff = CharBuffer.wrap(password);
        if (!passwordBuff.toString().equals(passwordDetail.getPassword()))
            return false;
    }
    return true;
}

From source file:br.mdarte.exemplo.academico.web.geral.consultarEstudante.ResultadoConsultaDetalhaEstudante.java

public String particularExecute() throws Exception {
    String casoDeUso = null;//from   ww w  .j  av  a 2s. c o m
    String urlCasoDeUso = null;
    String modulo = null;

    boolean adicionaBreadCrumb = true;
    casoDeUso = "ConsultaEstudanteUC";
    urlCasoDeUso = "/ConsultaEstudanteUC/ResultadoConsultaDetalhaEstudante";

    modulo = "geral";
    Iterator breadCrumbIt = null;
    ArrayList breadCrumbCollection = new ArrayList();
    breadCrumbCollection.add(
            "<a href='javascript:window.location=getPath()+\"/ForwardAction.do?modulo=ConsultaEstudanteUC&path=/"
                    + casoDeUso + ".action\"'>ConsultaEstudanteUC</a>");

    request.getSession().setAttribute("breadCrumb", breadCrumbCollection);
    request.getSession().setAttribute("nomeDeTela", casoDeUso);

    Boolean aplicacaoPermiteUsoBackBrowser = (Boolean) request.getSession().getServletContext()
            .getAttribute("aplicacaoPermiteUsoBackBrowser");

    if (!aplicacaoPermiteUsoBackBrowser ^ false) {
        if (getInvalidatePageControlCounter(request).get("ConsultaEstudanteUC.ResultadoConsulta") != null
                && request.getParameter("invalidatePageControlCounter") != null
                && !(((Integer) getInvalidatePageControlCounter(request)
                        .get("ConsultaEstudanteUC.ResultadoConsulta")).equals(
                                Integer.valueOf(request.getParameter("invalidatePageControlCounter"))))) {
            javax.servlet.http.HttpSession session = request.getSession();
            org.apache.struts.action.ActionMessages messages = (org.apache.struts.action.ActionMessages) session
                    .getAttribute(org.apache.struts.Globals.MESSAGE_KEY);
            if (messages == null) {
                messages = new org.apache.struts.action.ActionMessages();
                session.setAttribute(org.apache.struts.Globals.MESSAGE_KEY, messages);
            }
            messages.add("org.andromda.bpm4struts.errormessages",
                    new org.apache.struts.action.ActionMessage("pagina.expirou"));

            return "forwardAction";
        }
    }

    String forward = null;
    String redirect = "";
    request.getSession().setAttribute(org.apache.struts.Globals.MESSAGE_KEY,
            new org.apache.struts.action.ActionMessages());
    forward = "detalha.estudante";

    boolean copyParameters = true;

    if (request.getSession().getAttribute(Constantes.COPY_PARAMETERS) != null) {
        copyParameters = (Boolean) request.getSession().getAttribute(Constantes.COPY_PARAMETERS);
        request.getSession().removeAttribute(Constantes.COPY_PARAMETERS);
    }

    ResultadoConsultaDetalhaEstudanteFormImpl form = new ResultadoConsultaDetalhaEstudanteFormImpl();

    form.setIdEstudante(this.idEstudante);

    final ResultadoConsultaDetalhaEstudanteFormImpl specificForm = (ResultadoConsultaDetalhaEstudanteFormImpl) form;

    if (getInvalidatePageControlCounter(request).get("ConsultaEstudanteUC.ResultadoConsulta") == null)
        getInvalidatePageControlCounter(request).put("ConsultaEstudanteUC.ResultadoConsulta", 0);
    getInvalidatePageControlCounter(request).put("ConsultaEstudanteUC.ResultadoConsulta",
            ((Integer) getInvalidatePageControlCounter(request).get("ConsultaEstudanteUC.ResultadoConsulta"))
                    .intValue() + 1);

    request.getSession().setAttribute("form", form);

    try {

        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";
        }

    } //fim try
    catch (java.lang.Exception exception) {
        Object formObj = org.andromda.presentation.bpm4struts.PageSessionObjectUtil.getPageForm(request,
                "ConsultaEstudanteUC.ResultadoConsulta");

        if (formObj != null) {
            try {
                formObj.getClass()
                        .getMethod("resetCheckBoxes",
                                new Class[] { org.apache.struts.action.ActionMapping.class,
                                        javax.servlet.http.HttpServletRequest.class })
                        .invoke(formObj, new Object[] { null, null });
            } catch (Exception e2) {
                // ignoring
            }

            final java.util.Map parameters = new java.util.HashMap();
            for (final java.util.Enumeration names = request.getParameterNames(); names.hasMoreElements();) {
                final String name = String.valueOf(names.nextElement());
                parameters.put(name, request.getParameterValues(name));
            }
            try {
                org.apache.commons.beanutils.BeanUtils.populate(formObj, parameters);
            } catch (java.lang.Exception populateException) {
                // ignore if we have an exception here (we just don't populate).
            }
        }
        throw exception;
    }

    if (request.getAttribute("$forwardKeyModule") != null
            && !request.getAttribute("$forwardKeyModule").equals("geral")) {
        java.util.Enumeration atributosName = request.getSession().getAttributeNames();
        java.util.Map atributos = new java.util.HashMap();

        while (atributosName.hasMoreElements()) {
            String atributo = (String) atributosName.nextElement();
            atributos.put(atributo, request.getSession().getAttribute(atributo));
        }

        org.andromda.presentation.bpm4struts.ShareSessionUtil.saveMapIntoContext(request, response, atributos,
                ServletActionContext.getServletContext().getContext("/sistemaacademico"));
    }

    if (redirect != "") {//troca de modules - to be tested
        response.sendRedirect(redirect);
    }

    request.removeAttribute("$forwardKey");
    request.removeAttribute("$forwardKeyModule");

    return forward;
}

From source file:org.opensilk.music.library.folders.provider.FoldersLibraryProvider.java

public static List<Track> convertAudioFilesToTracks(Context context, File base, List<File> audioFiles) {
    if (audioFiles.size() == 0) {
        return Collections.emptyList();
    }/*  w  w w. jav  a  2  s .  c om*/

    final List<Track> trackList = new ArrayList<>(audioFiles.size());

    Cursor c = null;
    Cursor c2 = null;
    try {
        final HashMap<String, File> pathMap = new HashMap<>();

        //Build the selection
        final int size = audioFiles.size();
        final StringBuilder selection = new StringBuilder();
        selection.append(MediaStore.Audio.AudioColumns.DATA + " IN (");
        for (int i = 0; i < size; i++) {
            final File f = audioFiles.get(i);
            final String path = f.getAbsolutePath();
            pathMap.put(path, f); //Add file to map while where iterating
            selection.append("'").append(StringUtils.replace(path, "'", "''")).append("'");
            if (i < size - 1) {
                selection.append(",");
            }
        }
        selection.append(")");

        //make query
        c = context.getContentResolver().query(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, SONG_PROJECTION,
                selection.toString(), null, null);
        if (c != null && c.moveToFirst()) {
            //track albums for second query
            final HashMap<Long, List<Track.Builder>> albumsMap = new HashMap<>();
            do {
                final File f = pathMap
                        .remove(c.getString(c.getColumnIndexOrThrow(MediaStore.Audio.AudioColumns.DATA)));
                if (f != null) {
                    Track.Builder tb = Track.builder().setIdentity(toRelativePath(base, f))
                            .setName(c.getString(
                                    c.getColumnIndexOrThrow(MediaStore.Audio.AudioColumns.DISPLAY_NAME)))
                            .setArtistName(
                                    c.getString(c.getColumnIndexOrThrow(MediaStore.Audio.AudioColumns.ARTIST)))
                            .setAlbumName(
                                    c.getString(c.getColumnIndexOrThrow(MediaStore.Audio.AudioColumns.ALBUM)))
                            .setAlbumIdentity(c
                                    .getString(c.getColumnIndexOrThrow(MediaStore.Audio.AudioColumns.ALBUM_ID)))
                            .setDuration(
                                    c.getInt(c.getColumnIndexOrThrow(MediaStore.Audio.AudioColumns.DURATION))
                                            / 1000)
                            .setMimeType(c.getString(
                                    c.getColumnIndexOrThrow(MediaStore.Audio.AudioColumns.MIME_TYPE)))
                            .setDataUri(ContentUris.withAppendedId(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,
                                    c.getLong(c.getColumnIndexOrThrow(BaseColumns._ID))))
                            .setArtworkUri(ContentUris.withAppendedId(BASE_ARTWORK_URI,
                                    c.getLong(c.getColumnIndexOrThrow(MediaStore.Audio.Media.ALBUM_ID))));
                    long albumId = c.getLong(c.getColumnIndexOrThrow(MediaStore.Audio.Media.ALBUM_ID));
                    List<Track.Builder> tsForAlbum = albumsMap.get(albumId);
                    if (tsForAlbum == null) {
                        tsForAlbum = new ArrayList<>();
                        albumsMap.put(albumId, tsForAlbum);
                    }
                    tsForAlbum.add(tb);
                }
            } while (c.moveToNext());

            //Get the albumartists
            final Set<Long> albumIds = albumsMap.keySet();
            final int size2 = albumIds.size();
            final StringBuilder selection2 = new StringBuilder();
            selection2.append(BaseColumns._ID + " IN (");
            int i = 0;
            for (long id : albumIds) {
                selection2.append(id);
                if (++i < size2) {
                    selection2.append(",");
                }
            }
            selection2.append(")");
            c2 = context.getContentResolver().query(MediaStore.Audio.Albums.EXTERNAL_CONTENT_URI,
                    SONG_ALBUM_PROJECTION, selection2.toString(), null, null);
            if (c2 != null && c2.moveToFirst()) {
                do {
                    final long id = c2.getLong(0);
                    final String artist = c2.getString(1);
                    List<Track.Builder> albumTracks = albumsMap.remove(id);
                    if (albumTracks != null) {
                        for (Track.Builder tb : albumTracks) {
                            tb.setAlbumArtistName(artist);
                            trackList.add(tb.build());
                        }
                    }
                } while (c2.moveToNext());
            }
            if (!albumsMap.isEmpty()) {
                Timber.w("%d albums didn't make the cursor", albumsMap.size());
                for (List<Track.Builder> tbs : albumsMap.values()) {
                    for (Track.Builder tb : tbs) {
                        trackList.add(tb.build());
                    }
                }
            }
        }
        if (!pathMap.isEmpty()) {
            Timber.w("%d audioFiles didn't make the cursor", pathMap.size());
            for (File f : pathMap.values()) {
                Track t = Track.builder().setIdentity(toRelativePath(base, f)).setName(f.getName())
                        .setMimeType(guessMimeType(f)).setDataUri(Uri.fromFile(f)).build();
                trackList.add(t);
            }
        }
    } catch (Exception e) {
        if (DUMPSTACKS)
            Timber.e(e, "convertAudioFilesToTracks");
    } finally {
        closeQuietly(c);
        closeQuietly(c2);
    }
    return trackList;
}

From source file:org.rhwlab.dispim.nucleus.Division.java

static public HashMap<Nucleus, Division> bestDivisions(List<Nucleus> fromList, List<Nucleus> toList) {

    List<Nucleus> possibleParentList = possibleParents(fromList);

    // determine all possible divisions from each possible parent
    HashMap<Nucleus, Set<Division>> possibleFrom = new HashMap<>();
    for (Nucleus possibleParent : possibleParentList) {
        Set<Division> possibleDivs = possibleDivisions(possibleParent, toList.toArray(new Nucleus[0]));
        if (!possibleDivs.isEmpty()) {
            possibleFrom.put(possibleParent, possibleDivs);
        }//from  w w w . j  a  v  a 2  s  .  c  o m
    }

    // determine all the divsions ending on each 'to' nucleus
    HashMap<Nucleus, Set<Division>> possibleTo = new HashMap<>();
    for (Nucleus fromNuc : possibleFrom.keySet()) {
        Set<Division> divs = possibleFrom.get(fromNuc);
        for (Division div : divs) {
            Nucleus to1 = div.child1;
            Nucleus to2 = div.child2;

            Set<Division> toDivs = possibleTo.get(to1);
            if (toDivs == null) {
                toDivs = new HashSet<>();
                possibleTo.put(to1, toDivs);
            }
            toDivs.add(div);

            toDivs = possibleTo.get(to2);
            if (toDivs == null) {
                toDivs = new HashSet<>();
                possibleTo.put(to2, toDivs);
            }
            toDivs.add(div);
        }
    }
    // use the 'best' division for each 'to' nucleus
    HashMap<Nucleus, Division> ret = new HashMap<>();
    while (!possibleTo.isEmpty()) {
        Nucleus first = possibleTo.keySet().iterator().next();
        Set<Division> divs = possibleTo.get(first);
        Division best = bestDivision(divs);
        ret.put(first, best);

        // remove any divisions that are no longer possible
        possibleTo.remove(best.child1);
        possibleTo.remove(best.child2);
    }

    return ret;
}