Example usage for java.util ArrayList set

List of usage examples for java.util ArrayList set

Introduction

In this page you can find the example usage for java.util ArrayList set.

Prototype

public E set(int index, E element) 

Source Link

Document

Replaces the element at the specified position in this list with the specified element.

Usage

From source file:org.apache98.hadoop.conf.Configuration.java

private void loadResources(Properties properties, ArrayList<Resource> resources, boolean quiet) {
    if (loadDefaults) {
        for (String resource : defaultResources) {
            loadResource(properties, new Resource(resource), quiet);
        }//from   w  ww .  j  av a2  s .  c o m

        // support the hadoop-site.xml as a deprecated case
        if (getResource("hadoop-site.xml") != null) {
            loadResource(properties, new Resource("hadoop-site.xml"), quiet);
        }
    }

    for (int i = 0; i < resources.size(); i++) {
        Resource ret = loadResource(properties, resources.get(i), quiet);
        if (ret != null) {
            resources.set(i, ret);
        }
    }
}

From source file:com.vmware.identity.idm.server.config.directory.DirectoryConfigStore.java

/**
 * retrieve ordered AlternativeOCSP list
 * @param connection/*from w ww  . j  a v  a2  s.c o  m*/
 * @param altOcspListDn
 * @return
 */
protected static List<AlternativeOCSP> retrieveAlternativeOCSPsForSite(ILdapConnectionEx connection,
        String altOcspListDn) {
    Collection<TenantAlternativeOCSP> tOcspCollection = retrieveObjectsCollection(connection, altOcspListDn,
            ContainerLdapObject.CONTAINER_OCSPs, TenantAlternativeOCSPLdapObject.getInstance(), null);

    ArrayList<AlternativeOCSP> ocspArray = new ArrayList<AlternativeOCSP>(tOcspCollection.size());
    for (TenantAlternativeOCSP tAlternativeOCSP : tOcspCollection) {
        ocspArray.add(tAlternativeOCSP.getAlternativeOCSP());
    }

    //verify the order by cn
    int index = 0;
    for (TenantAlternativeOCSP tAlternativeOCSP : tOcspCollection) {
        int cn = Integer.parseInt(tAlternativeOCSP.getCn());
        if (cn < tOcspCollection.size()) {
            if (cn != index) {
                ocspArray.set(cn, tAlternativeOCSP.getAlternativeOCSP());
            }
        } else {
            throw new IllegalArgumentException(
                    "Unexpected TenantAlternativeOCSP object has cn value out of index range of the collection.");
        }
        index++;
    }

    return ocspArray;
}

From source file:org.jfree.chart.demo.LeftPanel.java

public LeftPanel(ArrayList<ChartPanel> graphics, ArrayList<Graphic> Grafs, ArrayList<JFreeChart> charts,
        ArrayList<XYSeries> Series) {
    //setBackground(new Color(152 ,134, 202));
    //setBackground(new Color(234 ,247, 202));
    setSize(800, 530);/*  w w w  .j  av a  2  s. co m*/
    setLayout(null);
    setBackground(new Color(176, 199, 246));

    JTabbedPane tabbedPane = new JTabbedPane(JTabbedPane.TOP);
    tabbedPane.setBackground(new Color(174, 250, 127));

    tabbedPane.setFont(new Font("Arial", 15, 16));
    tabbedPane.setOpaque(false);

    tabbedPane.setBounds(7, 6, 750, 505);
    tabbedPane.setAlignmentY(Component.TOP_ALIGNMENT);
    add(tabbedPane);

    JPanel panel = new JPanel();
    panel.setBackground(new Color(176, 199, 246));
    panel.setToolTipText("Graphic 1");
    panel.add(graphics.get(0));
    panel.add(new bottom_slider(new Color(176, 199, 246), charts, Grafs.get(0), 0));
    tabbedPane.addTab("Graphic 1", null, panel, null);
    panel.setLayout(null);

    JPanel panel_2 = new JPanel();
    panel_2.add(graphics.get(1));
    tabbedPane.addTab("Graphic 2", null, panel_2, null);
    panel_2.setLayout(null);
    panel_2.setBackground(new Color(176, 199, 246));
    panel_2.add(new bottom_slider(new Color(176, 199, 246), charts, Grafs.get(1), 1));

    JPanel panel_1 = new JPanel();
    panel_1.add(graphics.get(2));
    tabbedPane.addTab("Graphic 3", null, panel_1, null);
    panel_1.setLayout(null);
    panel_1.setBackground(new Color(176, 199, 246));
    panel_1.add(new bottom_slider(new Color(176, 199, 246), charts, Grafs.get(2), 2));
    panel_1.setBackground(new Color(176, 199, 246));

    JPanel panel_3 = new JPanel();
    panel_3.add(graphics.get(3));
    tabbedPane.addTab("Graphic 4", null, panel_3, null);
    panel_3.setLayout(null);
    panel_3.setBackground(new Color(176, 199, 246));
    panel_3.add(new bottom_slider(new Color(176, 199, 246), charts, Grafs.get(3), 3));

    JPanel panel_4 = new JPanel();
    panel_4.add(graphics.get(4));
    tabbedPane.addTab("Graphic 5 ", null, panel_4, null);
    panel_4.setLayout(null);
    panel_4.setBackground(new Color(176, 199, 246));
    panel_4.add(new bottom_slider(new Color(176, 199, 246), charts, Grafs.get(4), 4));

    JPanel panel_5 = new JPanel();
    panel_5.add(graphics.get(5));
    tabbedPane.addTab("Graphic 6", null, panel_5, null);
    panel_5.setLayout(null);
    panel_5.setBackground(new Color(176, 199, 246));
    panel_5.add(new bottom_slider(new Color(176, 199, 246), charts, Grafs.get(5), 5));

    JPanel panel_6 = new JPanel();
    panel_6.add(graphics.get(6));
    tabbedPane.addTab("Graphic 7", null, panel_6, null);
    panel_6.setLayout(null);
    panel_6.setBackground(new Color(176, 199, 246));
    panel_6.add(new bottom_slider(new Color(176, 199, 246), charts, Grafs.get(6), 6));

    JPanel panel_7 = new JPanel();
    panel_7.add(graphics.get(7));
    tabbedPane.addTab("Graphic 8", null, panel_7, null);
    panel_7.setLayout(null);
    panel_7.setBackground(new Color(176, 199, 246));
    panel_7.add(new bottom_slider(new Color(176, 199, 246), charts, Grafs.get(7), 7));

    JPanel panel_8 = new JPanel();
    panel_8.add(new Bottom_panel(Grafs, Series, 5, 390, 735, 50));
    graphics.set(8, Grafs.get(8).get_ChartPanel(740, 390));
    panel_8.add(graphics.get(8));

    tabbedPane.addTab("Graphic 9", null, panel_8, null);
    panel_8.setLayout(null);
    panel_8.setBackground(new Color(176, 199, 246));

    JPanel panel_9 = new JPanel();
    panel_9.add(graphics.get(9));
    tabbedPane.addTab("Graphic 10", null, panel_9, null);
    panel_9.setLayout(null);
    panel_9.setBackground(new Color(176, 199, 246));

}

From source file:es.pode.catalogadorWeb.presentacion.categoriasAvanzado.metametadatos.MetametadatosControllerImpl.java

private void cambioFormulario(HttpServletRequest request, int longitudIdentificadores, int longitudEsquemas,
        int longitudDescripciones, int longitudContribuciones, int[] longitudTextosDesc,
        int[] longitudEntidadesContrib) throws Exception {
    identificadores = new IdentificadorVO[longitudIdentificadores];
    esquemasMeta = new EsquemaDeMetadatosVO[longitudEsquemas];
    descripciones = new DescripcionVO[longitudDescripciones];
    contribuciones = new Contribucion[longitudContribuciones];
    String[] catalogos = new String[longitudIdentificadores];
    String[] entradas = new String[longitudIdentificadores];
    String[] esquemas = new String[longitudEsquemas];

    ArrayList[] textoDescripciones = new ArrayList[longitudDescripciones];
    ArrayList[] idiomaDescripciones = new ArrayList[longitudDescripciones];
    ArrayList[] nombresEntidades = new ArrayList[longitudContribuciones];
    ArrayList[] orgsEntidades = new ArrayList[longitudContribuciones];
    ArrayList[] correoEntidades = new ArrayList[longitudContribuciones];
    String[] fechasCorta = new String[longitudContribuciones];
    //         String[] anyos = new String[longitudContribuciones];
    //         String[] meses = new String[longitudContribuciones];
    String[] horas = new String[longitudContribuciones];
    String[] minutos = new String[longitudContribuciones];
    String[] segundos1 = new String[longitudContribuciones];
    String[] segundos2 = new String[longitudContribuciones];
    String[] zhHoras = new String[longitudContribuciones];
    String[] zhMinutos = new String[longitudContribuciones];
    String[] roles = new String[longitudContribuciones];
    String[] zonaH = new String[longitudContribuciones];
    String[] meridianosCero = new String[longitudContribuciones];

    for (Enumeration names = request.getParameterNames(); names.hasMoreElements();) {
        String name = String.valueOf(names.nextElement());
        if (name.startsWith("Cont")) {//descripciones           
            String[] namePartido = name.split("_");
            int i = Integer.parseInt(namePartido[0].substring(4, namePartido[0].length()));
            //Descripciones fechas
            if (namePartido[1].startsWith("DesFecTex")) {
                int j = Integer.parseInt(namePartido[1].substring(9, namePartido[1].length()));
                ArrayList lDesc = textoDescripciones[i];
                if (lDesc == null) {
                    lDesc = new ArrayList();
                    for (int k = 0; k < longitudTextosDesc[i]; k++)
                        lDesc.add("");
                }//from www.j a  v a 2s  . c o  m

                lDesc.set(j, request.getParameter(name));
                textoDescripciones[i] = lDesc;
            } else if (namePartido[1].startsWith("DesFecIdio")) {//Idio
                int j = Integer.parseInt(namePartido[1].substring(10, namePartido[1].length()));
                ArrayList lDesc = idiomaDescripciones[i];
                if (lDesc == null) {
                    lDesc = new ArrayList();
                    for (int k = 0; k < longitudTextosDesc[i]; k++)
                        lDesc.add("");
                }

                lDesc.set(j, request.getParameter(name));
                idiomaDescripciones[i] = lDesc;
            }
            // partes de la fecha
            else if (namePartido[1].startsWith("FechaCorta"))
                fechasCorta[i] = request.getParameter(name);
            else if (namePartido[1].startsWith("FechaHora"))
                horas[i] = request.getParameter(name);
            else if (namePartido[1].startsWith("FechaMin"))
                minutos[i] = request.getParameter(name);
            else if (namePartido[1].startsWith("FechaSeg1"))
                segundos1[i] = request.getParameter(name);
            else if (namePartido[1].startsWith("FechaSeg2"))
                segundos2[i] = request.getParameter(name);
            else if (namePartido[1].startsWith("FechaZHHora"))
                zhHoras[i] = request.getParameter(name);
            else if (namePartido[1].startsWith("FechaZHMinutos"))
                zhMinutos[i] = request.getParameter(name);
            else if (namePartido[1].startsWith("FechaZonaH"))
                zonaH[i] = request.getParameter(name);
            else if (namePartido[1].startsWith("Rol"))
                roles[i] = request.getParameter(name);
            //entidades
            else if (namePartido[1].startsWith("Ent")) {
                int j = Integer.parseInt(namePartido[1].substring(3, namePartido[1].length()));
                if (namePartido[2].startsWith("Nom")) {
                    ArrayList lNom = nombresEntidades[i];
                    if (lNom == null) {
                        lNom = new ArrayList();
                        for (int k = 0; k < longitudEntidadesContrib[i]; k++)
                            lNom.add("");
                    }

                    lNom.set(j, request.getParameter(name));
                    nombresEntidades[i] = lNom;
                }
                if (namePartido[2].startsWith("Org")) {
                    ArrayList lOrg = orgsEntidades[i];
                    if (lOrg == null) {
                        lOrg = new ArrayList();
                        for (int k = 0; k < longitudEntidadesContrib[i]; k++)
                            lOrg.add("");
                    }

                    lOrg.set(j, request.getParameter(name));
                    orgsEntidades[i] = lOrg;
                }
                if (namePartido[2].startsWith("Cor")) {
                    ArrayList lCor = correoEntidades[i];
                    if (lCor == null) {
                        lCor = new ArrayList();
                        for (int k = 0; k < longitudEntidadesContrib[i]; k++)
                            lCor.add("");
                    }

                    lCor.set(j, request.getParameter(name));
                    correoEntidades[i] = lCor;
                }

            } else if (namePartido[1].startsWith("meridianoCero")) {
                meridianosCero[i] = request.getParameter(name);
            }
        }

        if (name.startsWith("Id")) {//identificadores
            if (name.startsWith("IdCat")) {
                int i = Integer.parseInt(name.substring(5, name.length()));
                catalogos[i] = request.getParameter(name);
            }
            if (name.startsWith("IdEnt")) {
                int i = Integer.parseInt(name.substring(5, name.length()));
                entradas[i] = request.getParameter(name);
            }
        }
        if (name.startsWith("Esq")) {//esquemas
            int i = Integer.parseInt(name.substring(3, name.length()));
            esquemas[i] = request.getParameter(name);
        }
    }

    //identificadores
    for (int i = 0; i < catalogos.length; i++) {
        IdentificadorVO idVO = new IdentificadorVO();
        idVO.setCatalogo(catalogos[i]);
        idVO.setEntrada(entradas[i]);
        identificadores[i] = idVO;
    }
    //esquemas
    for (int i = 0; i < esquemas.length; i++) {
        EsquemaDeMetadatosVO esqVO = new EsquemaDeMetadatosVO();
        esqVO.setTexto(esquemas[i]);
        esquemasMeta[i] = esqVO;
    }

    //descripciones
    for (int i = 0; i < textoDescripciones.length; i++) {
        DescripcionVO descVO = new DescripcionVO();
        if (textoDescripciones[i] != null) {
            LangStringVO[] aLangDesc = new LangStringVO[textoDescripciones[i].size()];
            for (int j = 0; j < textoDescripciones[i].size(); j++) {
                LangStringVO langDesc = new LangStringVO();
                langDesc.setTexto(textoDescripciones[i].get(j).toString());
                langDesc.setIdioma(idiomaDescripciones[i].get(j).toString());
                aLangDesc[j] = langDesc;
            }
            descVO.setTextos(aLangDesc);
        } else {
            LangStringVO[] aLangString = new LangStringVO[1];
            LangStringVO langString = new LangStringVO();
            langString.setIdioma("");
            langString.setTexto("");
            aLangString[0] = langString;
            descVO.setTextos(aLangString);
        }
        descripciones[i] = descVO;
    }
    //contribuciones
    for (int i = 0; i < longitudContribuciones; i++) {
        Contribucion contribucionAux = new Contribucion();
        //rol
        SourceValueVO rolAux = new SourceValueVO();
        rolAux.setValor(roles[i]);
        //entidad
        Entidad[] entidadesAux = new Entidad[longitudEntidadesContrib[i]];
        for (int j = 0; j < entidadesAux.length; j++) {
            Entidad entidad = new Entidad();
            String correoEntIJ = "";
            if ((correoEntidades[i] != null) && (correoEntidades[i].get(j)) != null) {
                correoEntIJ = correoEntidades[i].get(j).toString();
            }
            entidad.setCorreo(correoEntIJ);
            String nombresEntIJ = "";
            if ((nombresEntidades[i] != null) && (nombresEntidades[i].get(j) != null)) {
                nombresEntIJ = nombresEntidades[i].get(j).toString();
            }
            entidad.setNombre(nombresEntIJ);
            String orgsEntIJ = "";
            if ((orgsEntidades[i] != null) && (orgsEntidades[i].get(j) != null)) {
                orgsEntIJ = orgsEntidades[i].get(j).toString();
            }
            entidad.setOrganizacion(orgsEntIJ);
            entidadesAux[j] = entidad;
        }
        //fecha
        Fecha fechaAux = new Fecha();
        fechaAux.setIdioma(this.getCatalogadorAvSession(request).getIdioma());
        fechaAux.setFechaCorta(fechasCorta[i]);
        fechaAux.setHora(horas[i]);
        fechaAux.setMinutos(minutos[i]);
        fechaAux.setSegundoP1(segundos1[i]);
        fechaAux.setSegundoP2(segundos2[i]);
        fechaAux.setZhHora(zhHoras[i] == null ? "" : zhHoras[i]);
        fechaAux.setZhMinutos(zhMinutos[i] == null ? "" : zhMinutos[i]);
        fechaAux.setMasOmenos(zonaH[i] == null ? "" : zonaH[i]);
        fechaAux.setMeridianoCero(meridianosCero[i]);
        //contribucion
        contribucionAux.setRol(rolAux);
        contribucionAux.setEntidades(entidadesAux);
        contribucionAux.setFecha(fechaAux);
        contribuciones[i] = contribucionAux;
    }

}

From source file:com.chen.mail.browse.SendersView.java

public static void handlePriority(Context context, int maxChars, String messageInfoString,
        ConversationInfo conversationInfo, ArrayList<SpannableString> styledSenders,
        ArrayList<String> displayableSenderNames, ArrayList<String> displayableSenderEmails, String account,
        final TextAppearanceSpan unreadStyleSpan, final CharacterStyle readStyleSpan) {
    boolean shouldAddPhotos = displayableSenderEmails != null;
    int maxPriorityToInclude = -1; // inclusive
    int numCharsUsed = messageInfoString.length(); // draft, number drafts,
                                                   // count
    int numSendersUsed = 0;
    int numCharsToRemovePerWord = 0;
    int maxFoundPriority = 0;
    if (numCharsUsed > maxChars) {
        numCharsToRemovePerWord = numCharsUsed - maxChars;
    }/*from www  .j  a  v a  2  s  .c  o  m*/

    final Map<Integer, Integer> priorityToLength = PRIORITY_LENGTH_MAP_CACHE.get();
    try {
        priorityToLength.clear();
        int senderLength;
        for (MessageInfo info : conversationInfo.messageInfos) {
            senderLength = !TextUtils.isEmpty(info.sender) ? info.sender.length() : 0;
            priorityToLength.put(info.priority, senderLength);
            maxFoundPriority = Math.max(maxFoundPriority, info.priority);
        }
        while (maxPriorityToInclude < maxFoundPriority) {
            if (priorityToLength.containsKey(maxPriorityToInclude + 1)) {
                int length = numCharsUsed + priorityToLength.get(maxPriorityToInclude + 1);
                if (numCharsUsed > 0)
                    length += 2;
                // We must show at least two senders if they exist. If we don't
                // have space for both
                // then we will truncate names.
                if (length > maxChars && numSendersUsed >= 2) {
                    break;
                }
                numCharsUsed = length;
                numSendersUsed++;
            }
            maxPriorityToInclude++;
        }
    } finally {
        PRIORITY_LENGTH_MAP_CACHE.release(priorityToLength);
    }
    // We want to include this entry if
    // 1) The onlyShowUnread flags is not set
    // 2) The above flag is set, and the message is unread
    MessageInfo currentMessage;
    SpannableString spannableDisplay;
    String nameString;
    CharacterStyle style;
    boolean appendedElided = false;
    Map<String, Integer> displayHash = Maps.newHashMap();
    String firstDisplayableSenderEmail = null;
    String firstDisplayableSender = null;
    for (int i = 0; i < conversationInfo.messageInfos.size(); i++) {
        currentMessage = conversationInfo.messageInfos.get(i);
        nameString = !TextUtils.isEmpty(currentMessage.sender) ? currentMessage.sender : "";
        if (nameString.length() == 0) {
            nameString = getMe(context);
        }
        if (numCharsToRemovePerWord != 0) {
            nameString = nameString.substring(0, Math.max(nameString.length() - numCharsToRemovePerWord, 0));
        }
        final int priority = currentMessage.priority;
        style = !currentMessage.read ? getWrappedStyleSpan(unreadStyleSpan)
                : getWrappedStyleSpan(readStyleSpan);
        if (priority <= maxPriorityToInclude) {
            spannableDisplay = new SpannableString(sBidiFormatter.unicodeWrap(nameString));
            // Don't duplicate senders; leave the first instance, unless the
            // current instance is also unread.
            int oldPos = displayHash.containsKey(currentMessage.sender) ? displayHash.get(currentMessage.sender)
                    : DOES_NOT_EXIST;
            // If this sender doesn't exist OR the current message is
            // unread, add the sender.
            if (oldPos == DOES_NOT_EXIST || !currentMessage.read) {
                // If the sender entry already existed, and is right next to the
                // current sender, remove the old entry.
                if (oldPos != DOES_NOT_EXIST && i > 0 && oldPos == i - 1 && oldPos < styledSenders.size()) {
                    // Remove the old one!
                    styledSenders.set(oldPos, null);
                    if (shouldAddPhotos && !TextUtils.isEmpty(currentMessage.senderEmail)) {
                        displayableSenderEmails.remove(currentMessage.senderEmail);
                        displayableSenderNames.remove(currentMessage.sender);
                    }
                }
                displayHash.put(currentMessage.sender, i);
                spannableDisplay.setSpan(style, 0, spannableDisplay.length(), 0);
                styledSenders.add(spannableDisplay);
            }
        } else {
            if (!appendedElided) {
                spannableDisplay = new SpannableString(sElidedString);
                spannableDisplay.setSpan(style, 0, spannableDisplay.length(), 0);
                appendedElided = true;
                styledSenders.add(spannableDisplay);
            }
        }
        if (shouldAddPhotos) {
            String senderEmail = TextUtils.isEmpty(currentMessage.sender) ? account
                    : TextUtils.isEmpty(currentMessage.senderEmail) ? currentMessage.sender
                            : currentMessage.senderEmail;
            if (i == 0) {
                // Always add the first sender!
                firstDisplayableSenderEmail = senderEmail;
                firstDisplayableSender = currentMessage.sender;
            } else {
                if (!Objects.equal(firstDisplayableSenderEmail, senderEmail)) {
                    int indexOf = displayableSenderEmails.indexOf(senderEmail);
                    if (indexOf > -1) {
                        displayableSenderEmails.remove(indexOf);
                        displayableSenderNames.remove(indexOf);
                    }
                    displayableSenderEmails.add(senderEmail);
                    displayableSenderNames.add(currentMessage.sender);
                    if (displayableSenderEmails.size() > DividedImageCanvas.MAX_DIVISIONS) {
                        displayableSenderEmails.remove(0);
                        displayableSenderNames.remove(0);
                    }
                }
            }
        }
    }
    if (shouldAddPhotos && !TextUtils.isEmpty(firstDisplayableSenderEmail)) {
        if (displayableSenderEmails.size() < DividedImageCanvas.MAX_DIVISIONS) {
            displayableSenderEmails.add(0, firstDisplayableSenderEmail);
            displayableSenderNames.add(0, firstDisplayableSender);
        } else {
            displayableSenderEmails.set(0, firstDisplayableSenderEmail);
            displayableSenderNames.set(0, firstDisplayableSender);
        }
    }
}

From source file:edu.mayo.informatics.lexgrid.convert.directConversions.hl7.HL7MapToLexGrid.java

void loadArtificialTopNodes(CodingScheme csclass, Entities concepts, Connection c) {
    messages_.info("Processing code systems into top nodes");
    ResultSet topNode_results = null;
    try {//from  w w  w .j a  v  a 2  s.c om
        // Create an "@" top node.
        Entity rootNode = new Entity();

        // Create and set the concept code for "@"
        String topNodeDesignation = "@";
        rootNode.setEntityCode(topNodeDesignation);
        rootNode.setEntityCodeNamespace(csclass.getCodingSchemeName());
        rootNode.setIsAnonymous(Boolean.TRUE);
        EntityDescription enDesc = new EntityDescription();
        enDesc.setContent("Root node for subclass relations.");
        rootNode.setEntityDescription(enDesc);
        concepts.addEntity(rootNode);

        AssociationSource ai = new AssociationSource();
        ai.setSourceEntityCode(rootNode.getEntityCode());
        ai.setSourceEntityCodeNamespace(csclass.getCodingSchemeName());
        AssociationPredicate parent_assoc = (AssociationPredicate) RelationsUtil
                .resolveAssociationPredicates(csclass, HL72LGConstants.ASSOCIATION_HAS_SUBTYPE).get(0);
        ai = RelationsUtil.subsume(parent_assoc, ai);

        // Get all the code systems except the
        // legacy code system coding scheme in HL7
        PreparedStatement getArtificialTopNodeData = c
                .prepareStatement("select cs.*, code.internalId FROM VCS_code_system AS cs "
                        + "LEFT JOIN  VCS_concept_code_xref AS code "
                        + "ON cs.codeSystemName= code.conceptCode2 "
                        + "where (code.codeSystemId2 = ? OR code.codeSystemId2 is null) AND cs.codesystemid <> ?");
        getArtificialTopNodeData.setString(1, HL72LGConstants.CODE_SYSTEM_OID);
        getArtificialTopNodeData.setString(2, HL72LGConstants.CODE_SYSTEM_OID);
        ResultSet dataResults = getArtificialTopNodeData.executeQuery();
        while (dataResults.next()) {
            Entity topNode = new Entity();
            String nodeName = dataResults.getString("codeSystemName");
            String entityDescription = dataResults.getString("fullName");
            String oid = dataResults.getString("codeSystemId");
            String def = dataResults.getString("description");
            String internalId = dataResults.getString("internalId");
            if (StringUtils.isNotBlank(def)) {
                int begin = def.lastIndexOf("<p>");
                int end = def.lastIndexOf("</p>");
                if (begin > -1) {
                    if (begin + 3 < end)
                        def = def.substring(begin + 3, end);
                }
            }

            if (StringUtils.isNotBlank(internalId)) {
                topNode.setEntityCode(internalId + ":" + nodeName);
            } else {
                topNode.setEntityCode(nodeName + ":" + nodeName);
            }
            topNode.setEntityCodeNamespace(csclass.getCodingSchemeName());

            EntityDescription enD = new EntityDescription();
            enD.setContent(entityDescription);
            topNode.setEntityDescription(enD);
            topNode.setIsActive(true);

            // Set presentation so it's a full fledged concept
            Presentation p = new Presentation();
            Text txt = new Text();
            txt.setContent((String) entityDescription);
            p.setValue(txt);
            p.setIsPreferred(Boolean.TRUE);
            p.setPropertyName(HL72LGConstants.PROPERTY_PRINTNAME);
            p.setPropertyId("T1");
            p.setLanguage(HL72LGConstants.DEFAULT_LANGUAGE_EN);
            topNode.addPresentation(p);

            // Set definition
            if (StringUtils.isNotBlank(def)) {
                Definition definition = new Definition();
                Text defText = new Text();
                defText.setContent(def);
                definition.setValue(defText);
                definition.setPropertyName(HL72LGConstants.PROPERTY_DEFINITION);
                definition.setPropertyId("D1");
                definition.setIsActive(Boolean.TRUE);
                definition.setIsPreferred(Boolean.TRUE);
                definition.setLanguage(HL72LGConstants.DEFAULT_LANGUAGE_EN);
                topNode.addDefinition(definition);
            }

            topNode.addEntityType(EntityTypes.CONCEPT.toString());
            concepts.addEntity(topNode);

            // This coding scheme is attached to an artificial root.
            AssociationTarget at = new AssociationTarget();
            at.setTargetEntityCode(topNode.getEntityCode());
            at.setTargetEntityCodeNamespace(csclass.getCodingSchemeName());
            RelationsUtil.subsume(ai, at);

            // Now find the top nodes of the scheme and subsume them to this
            // scheme's artificial top node.
            // First get a list of all nodes in the scheme.
            // but again exclude the code system nodes.
            ArrayList<String> topNodes = new ArrayList<String>();
            PreparedStatement getSystemCodes = c.prepareStatement(
                    "SELECT DISTINCT (internalId), conceptCode2 FROM VCS_concept_code_xref WHERE codeSystemId2 =? AND codeSystemId2 <> ?");
            getSystemCodes.setString(1, oid);
            getSystemCodes.setString(2, HL72LGConstants.CODE_SYSTEM_OID);
            ResultSet systemCodes = getSystemCodes.executeQuery();
            while (systemCodes.next()) {
                String testCode = systemCodes.getString("internalId");
                if (testCode != null)
                    topNodes.add(testCode);
            }
            if (systemCodes != null)
                systemCodes.close();
            if (getSystemCodes != null)
                getSystemCodes.close();

            // Drop any from the list that aren't top nodes.
            ArrayList<String> nodesToRemove = new ArrayList<String>();
            PreparedStatement checkForTopNode = null;
            for (int i = 0; i < topNodes.size(); i++) {
                checkForTopNode = c.prepareStatement(
                        "SELECT targetInternalId FROM VCS_concept_relationship WHERE targetInternalId =?");
                checkForTopNode.setString(1, (String) topNodes.get(i));
                topNode_results = checkForTopNode.executeQuery();
                if (topNode_results.next()) {
                    if (topNodes.get(i).equals(topNode_results.getString(1))) {
                        nodesToRemove.add(topNodes.get(i));
                    }
                }
                if (topNode_results != null)
                    topNode_results.close();
                if (checkForTopNode != null)
                    checkForTopNode.close();
            }

            for (int i = 0; i < nodesToRemove.size(); i++) {
                topNodes.remove(nodesToRemove.get(i));
            }
            // Get the full concept code for each.
            PreparedStatement getconceptSuffix = null;
            ResultSet conceptCode = null;
            for (int i = 0; i < topNodes.size(); i++) {
                getconceptSuffix = c.prepareStatement(
                        "SELECT conceptCode2 FROM VCS_concept_code_xref where internalId = ?");

                getconceptSuffix.setString(1, (String) topNodes.get(i));
                conceptCode = getconceptSuffix.executeQuery();
                conceptCode.next();
                topNodes.set(i, topNodes.get(i) + ":" + conceptCode.getString(1));
                if (conceptCode != null)
                    conceptCode.close();
                if (getconceptSuffix != null)
                    getconceptSuffix.close();
            }

            // For each top node subsume to the current artificial node for
            // the scheme.
            for (int j = 0; j < topNodes.size(); j++) {
                try {
                    AssociationSource atn = new AssociationSource();
                    atn.setSourceEntityCode(topNode.getEntityCode());
                    atn.setSourceEntityCodeNamespace(csclass.getCodingSchemeName());
                    atn = RelationsUtil.subsume(parent_assoc, atn);

                    AssociationTarget atopNode = new AssociationTarget();
                    atopNode.setTargetEntityCode((String) topNodes.get(j));
                    atopNode.setTargetEntityCodeNamespace(csclass.getCodingSchemeName());
                    RelationsUtil.subsume(atn, atopNode);
                } catch (Exception e) {
                    messages_.error("Failed while processing HL7 psuedo top node hierarchy", e);
                    e.printStackTrace();
                }
            }
        }
        dataResults.close();
        messages_.info("Top node processing complete");
    } catch (Exception e) {
        messages_.error("Top node processing failed", e);
        e.printStackTrace();
    }

}

From source file:gov.nih.nci.evs.browser.utils.DataUtils.java

public static void sortArray(ArrayList list) {
    String tmp;/*from   w w  w  . j a v a2 s.c o m*/
    if (list.size() <= 1)
        return;
    for (int i = 0; i < list.size(); i++) {
        String s1 = (String) list.get(i);
        for (int j = i + 1; j < list.size(); j++) {
            String s2 = (String) list.get(j);
            if (s1.compareToIgnoreCase(s2) > 0) {
                tmp = s1;
                list.set(i, s2);
                list.set(j, tmp);
            }
        }
    }
}

From source file:com.chinamobile.bcbsp.comm.MessageQueuesForDisk.java

/**
 * Load bucket from disk.//from www  . j a v  a  2 s .  c  o  m
 * @param queuesBuckets
 * @param bucketIndex
 * @param queuePath
 * @throws IOException
 */
private void loadBucket(ArrayList<BucketMeta> queuesBuckets, int bucketIndex, String queuePath)
        throws IOException {
    LOG.info("[MessageQueuesForDisk] is loading the [" + queuePath + " Bucket-" + bucketIndex + "] <<< size = "
            + queuesBuckets.get(bucketIndex).count + ".");
    long start = System.currentTimeMillis();
    /** Clock */
    File messagesDataFileBucket;
    FileReader frMessagesData;
    BufferedReader brMessagesData;
    messagesDataFileBucket = new File(this.messagesDataFile + "/" + queuePath + "/" + "bucket-" + bucketIndex);
    if (!messagesDataFileBucket.exists()) {
        throw new IOException("Bucket file" + messagesDataFileBucket + " does not exit!");
    }
    // Open file readers.
    frMessagesData = new FileReader(messagesDataFileBucket);
    brMessagesData = new BufferedReader(frMessagesData);
    // Read the file header.
    @SuppressWarnings("unused")
    String bucketHeader = brMessagesData.readLine();
    ConcurrentHashMap<String, ConcurrentLinkedQueue<IMessage>> queueMap = queuesBuckets
            .get(bucketIndex).queueMap;
    if (queueMap == null) {
        queueMap = new ConcurrentHashMap<String, ConcurrentLinkedQueue<IMessage>>();
    }
    String buffer;
    while ((buffer = brMessagesData.readLine()) != null) {
        String[] queueBuffer = buffer.split(Constants.KV_SPLIT_FLAG);
        if (queueBuffer[0] == "") {
            LOG.warn("[MessageQueuesForDisk] readLine = " + buffer);
        }
        String key = queueBuffer[0];
        ConcurrentLinkedQueue<IMessage> queue = queueMap.get(key);
        if (queue == null) {
            queue = stringToQueue(queueBuffer[1]);
            this.sizeOfHashMapsInMem = this.sizeOfHashMapsInMem
                    + (sizeOfRef + sizeOfInteger + sizeOfEmptyMessageQueue);
        } else {
            queue.addAll(stringToQueue(queueBuffer[1]));
        }
        queueMap.put(key, queue);
    }
    queuesBuckets.get(bucketIndex).queueMap = queueMap;
    brMessagesData.close();
    frMessagesData.close();
    // Update the meta data of the bucket.
    BucketMeta meta = queuesBuckets.get(bucketIndex);
    // Update the size of messages data in memory.
    this.sizeOfMessagesDataInMem = this.sizeOfMessagesDataInMem + (meta.length - meta.lengthInMemory);
    this.countOfMessagesDataInMem = this.countOfMessagesDataInMem + (meta.count - meta.countInMemory);
    meta.onDiskFlag = false;
    meta.lengthInMemory = meta.length;
    meta.countInMemory = meta.count;
    queuesBuckets.set(bucketIndex, meta);
    if (!messagesDataFileBucket.delete()) {
        throw new IOException("Bucket file delete failed!");
    }
    this.readDiskTime = this.readDiskTime + (System.currentTimeMillis() - start);
    /** Clock */
}

From source file:com.tct.mail.browse.SendersView.java

private static void handlePriority(int maxChars, String messageInfoString, ConversationInfo conversationInfo,
        ArrayList<SpannableString> styledSenders, ArrayList<String> displayableSenderNames,
        ArrayList<String> displayableSenderEmails, String account, final TextAppearanceSpan unreadStyleSpan,
        final CharacterStyle readStyleSpan, final boolean showToHeader) {
    boolean shouldAddPhotos = displayableSenderEmails != null;
    int maxPriorityToInclude = -1; // inclusive
    int numCharsUsed = messageInfoString.length(); // draft, number drafts,
                                                   // count
    int numSendersUsed = 0;
    int numCharsToRemovePerWord = 0;
    int maxFoundPriority = 0;
    if (numCharsUsed > maxChars) {
        numCharsToRemovePerWord = numCharsUsed - maxChars;
    }/* www . j  a v  a 2  s . c  o m*/

    final Map<Integer, Integer> priorityToLength = PRIORITY_LENGTH_MAP_CACHE.get();
    try {
        priorityToLength.clear();
        int senderLength;
        for (ParticipantInfo info : conversationInfo.participantInfos) {
            final String senderName = info.name;
            senderLength = !TextUtils.isEmpty(senderName) ? senderName.length() : 0;
            priorityToLength.put(info.priority, senderLength);
            maxFoundPriority = Math.max(maxFoundPriority, info.priority);
        }
        while (maxPriorityToInclude < maxFoundPriority) {
            if (priorityToLength.containsKey(maxPriorityToInclude + 1)) {
                int length = numCharsUsed + priorityToLength.get(maxPriorityToInclude + 1);
                if (numCharsUsed > 0)
                    length += 2;
                // We must show at least two senders if they exist. If we don't
                // have space for both
                // then we will truncate names.
                if (length > maxChars && numSendersUsed >= 2) {
                    break;
                }
                numCharsUsed = length;
                numSendersUsed++;
            }
            maxPriorityToInclude++;
        }
    } finally {
        PRIORITY_LENGTH_MAP_CACHE.release(priorityToLength);
    }
    // We want to include this entry if
    // 1) The onlyShowUnread flags is not set
    // 2) The above flag is set, and the message is unread
    ParticipantInfo currentParticipant;
    SpannableString spannableDisplay;
    CharacterStyle style;
    boolean appendedElided = false;
    Map<String, Integer> displayHash = Maps.newHashMap();
    String firstDisplayableSenderEmail = null;
    String firstDisplayableSender = null;
    for (int i = 0; i < conversationInfo.participantInfos.size(); i++) {
        currentParticipant = conversationInfo.participantInfos.get(i);
        final String currentEmail = currentParticipant.email;

        final String currentName = currentParticipant.name;
        String nameString = !TextUtils.isEmpty(currentName) ? currentName : "";
        if (nameString.length() == 0) {
            // if we're showing the To: header, show the object version of me.
            nameString = getMe(showToHeader /* useObjectMe */);
        }
        if (numCharsToRemovePerWord != 0) {
            nameString = nameString.substring(0, Math.max(nameString.length() - numCharsToRemovePerWord, 0));
        }

        final int priority = currentParticipant.priority;
        style = CharacterStyle.wrap(currentParticipant.readConversation ? readStyleSpan : unreadStyleSpan);
        if (priority <= maxPriorityToInclude) {
            spannableDisplay = new SpannableString(sBidiFormatter.unicodeWrap(nameString));
            // Don't duplicate senders; leave the first instance, unless the
            // current instance is also unread.
            int oldPos = displayHash.containsKey(currentName) ? displayHash.get(currentName) : DOES_NOT_EXIST;
            // If this sender doesn't exist OR the current message is
            // unread, add the sender.
            if (oldPos == DOES_NOT_EXIST || !currentParticipant.readConversation) {
                // If the sender entry already existed, and is right next to the
                // current sender, remove the old entry.
                if (oldPos != DOES_NOT_EXIST && i > 0 && oldPos == i - 1 && oldPos < styledSenders.size()) {
                    // Remove the old one!
                    styledSenders.set(oldPos, null);
                    if (shouldAddPhotos && !TextUtils.isEmpty(currentEmail)) {
                        displayableSenderEmails.remove(currentEmail);
                        displayableSenderNames.remove(currentName);
                    }
                }
                displayHash.put(currentName, i);
                spannableDisplay.setSpan(style, 0, spannableDisplay.length(), 0);
                styledSenders.add(spannableDisplay);
            }
        } else {
            if (!appendedElided) {
                spannableDisplay = new SpannableString(sElidedString);
                spannableDisplay.setSpan(style, 0, spannableDisplay.length(), 0);
                appendedElided = true;
                styledSenders.add(spannableDisplay);
            }
        }
        if (shouldAddPhotos) {
            String senderEmail = TextUtils.isEmpty(currentName) ? account
                    : TextUtils.isEmpty(currentEmail) ? currentName : currentEmail;
            if (i == 0) {
                // Always add the first sender!
                firstDisplayableSenderEmail = senderEmail;
                firstDisplayableSender = currentName;
            } else {
                if (!Objects.equal(firstDisplayableSenderEmail, senderEmail)) {
                    int indexOf = displayableSenderEmails.indexOf(senderEmail);
                    if (indexOf > -1) {
                        displayableSenderEmails.remove(indexOf);
                        displayableSenderNames.remove(indexOf);
                    }
                    displayableSenderEmails.add(senderEmail);
                    displayableSenderNames.add(currentName);
                    if (displayableSenderEmails.size() > DividedImageCanvas.MAX_DIVISIONS) {
                        displayableSenderEmails.remove(0);
                        displayableSenderNames.remove(0);
                    }
                }
            }
        }
    }
    if (shouldAddPhotos && !TextUtils.isEmpty(firstDisplayableSenderEmail)) {
        if (displayableSenderEmails.size() < DividedImageCanvas.MAX_DIVISIONS) {
            displayableSenderEmails.add(0, firstDisplayableSenderEmail);
            displayableSenderNames.add(0, firstDisplayableSender);
        } else {
            displayableSenderEmails.set(0, firstDisplayableSenderEmail);
            displayableSenderNames.set(0, firstDisplayableSender);
        }
    }
}