Example usage for java.util Hashtable remove

List of usage examples for java.util Hashtable remove

Introduction

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

Prototype

public synchronized V remove(Object key) 

Source Link

Document

Removes the key (and its corresponding value) from this hashtable.

Usage

From source file:org.jibble.pircbot.PircBot.java

/**
 * Remove a user from the specified channel in our memory.
 *//*from w  ww.ja v  a  2  s.  c  o  m*/
private final User removeUser(String channel, String nick) {
    channel = channel.toLowerCase();
    User user = new User("", nick);
    synchronized (_channels) {
        Hashtable users = (Hashtable) _channels.get(channel);
        if (users != null) {
            return (User) users.remove(user);
        }
    }
    return null;
}

From source file:io.cloudslang.content.database.services.dbconnection.DBConnectionManager.java

/**
 * clean any empty datasource and pool in the dbmsPool table.
 *//*w ww. j a va2  s  .  c  o m*/
public void cleanDataSources() {

    Hashtable<String, List<String>> removedDsKeyTable = null;

    //gather all the empty ds's key, can't remove item while iterate
    Enumeration<String> allPoolKeys = dbmsPoolTable.keys();
    while (allPoolKeys.hasMoreElements()) {
        String dbPoolKey = allPoolKeys.nextElement();
        Hashtable<String, DataSource> dsTable = dbmsPoolTable.get(dbPoolKey);
        Enumeration<String> allDsKeys = dsTable.keys();
        while (allDsKeys.hasMoreElements()) {
            String dsKey = allDsKeys.nextElement();
            DataSource ds = dsTable.get(dsKey);

            //c3p0 impl
            if (ds != null && ds instanceof PooledDataSource) {
                PooledDataSource pDs = (PooledDataSource) ds;
                int conCount;
                try {
                    conCount = pDs.getNumConnectionsAllUsers();
                } catch (SQLException e) {
                    //                  todo      logger.error
                    //                                ("Failed to get total number of connections for datasource. dbmsPoolKey = "
                    //                                        + dbPoolKey, e);
                    continue;
                }
                //no connections
                if (conCount == 0) {
                    List<String> removedList = null;
                    if (removedDsKeyTable == null) {
                        removedDsKeyTable = new Hashtable<>();
                    } else {
                        removedList = removedDsKeyTable.get(dbPoolKey);
                    }

                    if (removedList == null) {
                        removedList = new ArrayList<>();
                        removedList.add(dsKey);
                        removedDsKeyTable.put(dbPoolKey, removedList);
                    } else {
                        removedList.add(dsKey);
                    }
                }
            }
        }
    }

    //have empty ds
    if (removedDsKeyTable != null && !removedDsKeyTable.isEmpty()) {
        Enumeration<String> removedPoolKeys = removedDsKeyTable.keys();
        while (removedPoolKeys.hasMoreElements()) {
            String removedPoolKey = removedPoolKeys.nextElement();
            PooledDataSourceProvider provider = this.getProvider(removedPoolKey);
            List<String> removedDsList = removedDsKeyTable.get(removedPoolKey);
            Hashtable<String, DataSource> dsTable = dbmsPoolTable.get(removedPoolKey);
            for (String dsKey : removedDsList) {
                DataSource removedDs = dsTable.remove(dsKey);
                try {
                    provider.closePooledDataSource(removedDs);
                } catch (SQLException e) {
                    //can't show the dsKey since it has encrypted password there
                    //                  todo      logger.error("Failed to close datadsource in dmbs poolKey = "
                    //                                + removedPoolKey, e);
                    continue;
                }

                //tracing
                //                todo    if (logger.isDebugEnabled()) {
                //                        logger.debug("Removed one datasource in dbms poolKey = "
                //                                + removedPoolKey);
                //                    }
            }
            //don't have any ds for the pool key
            if (dsTable.isEmpty()) {
                dbmsPoolTable.remove(removedPoolKey);
                //tracing
                //              todo      if (logger.isDebugEnabled()) {
                //                        logger.debug("Removed dbms poolKey = " + removedPoolKey);
                //                    }
            }
        }
    }
}

From source file:com.heliosapm.script.AbstractDeployedScript.java

/**
 * Finds the ObjectName of the configuration MBean to watch
 * @return the ObjectName of the configuration MBean to watch
 *//*from w w  w.j a  v  a  2  s.com*/
protected ObjectName findWatchedConfiguration() {
    /*
     * if extension != config
     *       look for {shortName}.config
     *       if not found
     *          look for {pwd}.config   (error if not found)
     *          listen for registration of a future {shortName}.config
     *             when notified:
     *                stop listening on {pwd}.config and listen on {shortName}.config  
     * 
     * else   (we are a config)
     *       if(shortName != {pwd})
     *          look for {pwd}.config
     *       else  (we are the {pwd}.config
     *          look for {pwd.parent}.config (error if not found)
     */

    final Hashtable<String, String> keyAttrs = new Hashtable<String, String>(objectName.getKeyPropertyList());

    final String pwd = sourceFile.getParentFile().getName();

    if (!"config".equals(extension)) {
        // look for {shortName}.config
        keyAttrs.put("extension", "config");
        ObjectName watchedObjectName = JMXHelper.objectName(CONFIG_DOMAIN, keyAttrs);
        if (JMXHelper.isRegistered(watchedObjectName)) {
            return watchedObjectName;
        }
        // nope. register a listener in case he shows up, then look for {pwd}.config
        final NotificationListener lateComerListener = new NotificationListener() {
            @Override
            public void handleNotification(Notification notification, Object handback) {

            }
        };
        JMXHelper.addMBeanRegistrationListener(watchedObjectName, lateComerListener, 1);
        keyAttrs.put("name", pwd);
        watchedObjectName = JMXHelper.objectName(CONFIG_DOMAIN, keyAttrs);
        if (JMXHelper.isRegistered(watchedObjectName)) {
            return watchedObjectName;
        }
        log.warn("Failed to find expected dir watched configuration \n\tfor [" + objectName
                + "] \n\tat ObjectName [" + watchedObjectName + "]");
        throw new RuntimeException("Failed to find expected dir watched configuration for [" + objectName
                + "] at ObjectName [" + watchedObjectName + "]");
    }
    // we're a config
    if (!shortName.equals(pwd)) {
        // we're a script config, so look for {pwd}.config
        keyAttrs.put("name", pwd);
        ObjectName watchedObjectName = JMXHelper.objectName(CONFIG_DOMAIN, keyAttrs);
        if (JMXHelper.isRegistered(watchedObjectName)) {
            return watchedObjectName;
        }
        log.warn("Failed to find expected dir watched configuration \n\tfor [" + objectName
                + "] \n\tat ObjectName [" + watchedObjectName + "]");
        return null;
        //throw new RuntimeException("Failed to find expected dir watched configuration for [" + objectName + "] at ObjectName [" + watchedObjectName + "]");            
    }
    // we're a {pwd}.connfig, so we need to find {pwd.parent}.config
    // yank the highest d# attribute so we go up one dir
    Integer high = JMXHelper.getHighestKey(objectName, "d");
    if (high == null) {
        return null;
    }
    keyAttrs.remove("d" + JMXHelper.getHighestKey(objectName, "d"));
    if (this.rootDir.equals(sourceFile.getParentFile().getParentFile().getAbsolutePath())) {
        return null;
    }
    // update the name to the {pwd.parent}            
    keyAttrs.put("name", sourceFile.getParentFile().getParentFile().getName());
    ObjectName watchedObjectName = JMXHelper.objectName(CONFIG_DOMAIN, keyAttrs);
    if (JMXHelper.isRegistered(watchedObjectName)) {
        return watchedObjectName;
    }
    log.warn("Failed to find expected parent dir watched configuration \n\tfor [" + objectName
            + "] \n\tat ObjectName [" + watchedObjectName + "]");
    throw new RuntimeException("Failed to find expected parent dir watched configuration for [" + objectName
            + "] at ObjectName [" + watchedObjectName + "]");
}

From source file:edu.stanford.epad.common.pixelmed.SegmentationObjectsFileWriter.java

/**
 * Test if the attribute is common to all frames.
 * /*  ww  w  .j  a  v  a2  s . c o m*/
 * @param tags provides the TagName of the attributes to be checked.
 * @param sequence is the attribute sequence of all frames.
 * @return Return (key, value) of common attributes.
 * @throws DicomException
 */
private Hashtable<AttributeTag, SequenceAttribute> get_common_attributes(AttributeTag[] tags,
        SequenceAttribute sequence) throws DicomException {
    Hashtable<AttributeTag, SequenceAttribute> attrs = new Hashtable<AttributeTag, SequenceAttribute>();
    for (AttributeTag tag : tags) {
        attrs.put(tag, new SequenceAttribute(tag));
    }

    @SuppressWarnings("unchecked")
    Iterator<SequenceItem> it = sequence.iterator();
    boolean initial = true;
    while (it.hasNext()) {
        AttributeList l = it.next().getAttributeList();
        if (initial) {
            // Initialize the attributes.
            initial = false;
            Enumeration<AttributeTag> i = attrs.keys();
            while (i.hasMoreElements()) {
                AttributeTag key = i.nextElement();
                SequenceAttribute seq = null;
                // Since some keys are not the top-level attributes, get their parent sequence attributes instead.
                if (key.equals(TagFromName.StackID)) {
                    seq = (SequenceAttribute) l.get(TagFromName.FrameContentSequence);
                } else if (key.equals(TagFromName.SliceThickness) || key.equals(TagFromName.PixelSpacing)) {
                    seq = (SequenceAttribute) l.get(TagFromName.PixelMeasuresSequence);
                } else {
                    seq = (SequenceAttribute) l.get(key);
                }

                if (seq == null)
                    seq = new SequenceAttribute(key);
                attrs.put(key, seq);
            }
        } else {
            // Check if the values are equal.
            Enumeration<AttributeTag> i = attrs.keys();
            while (i.hasMoreElements()) {
                AttributeTag key = i.nextElement();
                SequenceAttribute seq = null;
                // Since some keys are not the top-level attributes, get their parent sequence attributes instead.
                if (key.equals(TagFromName.StackID))
                    seq = (SequenceAttribute) l.get(TagFromName.FrameContentSequence);
                else if (key.equals(TagFromName.SliceThickness) || key.equals(TagFromName.PixelSpacing))
                    seq = (SequenceAttribute) l.get(TagFromName.PixelMeasuresSequence);
                else
                    seq = (SequenceAttribute) l.get(key);
                if (compare_sequence_attribute(key, attrs.get(key), seq) != true)
                    attrs.remove(key);
            }
        }
    }

    return attrs;
}

From source file:pt.iflow.flows.FlowData.java

@Deprecated
private InstantiationResult instantiateSubFlow(UserInfoInterface ui, XmlBlock xmlblock, int anFlowId,
        List<FlowSetting> alSettings, Hashtable<Integer, Block> htBlocks, int offset) throws Exception {
    Class<?>[] argsClass = new Class[] { int.class, int.class, int.class, String.class };
    String subflow = null;//w ww  . j  a va 2s. c o m
    Attribute attrActiv = null;
    final int FLOW = 0;
    final int SUBFLOW = 1;
    final int TYPE = 2;

    offset += iOFFSET;

    int size = (xmlblock.getXmlAttributeCount() - 1) / 4; // raio de conta

    String[][] saInVars = new String[size][3];
    String[][] saOutVars = new String[size][3];

    // Attributes do block In & Out
    for (int attrNumber = 0; attrNumber < xmlblock.getXmlAttributeCount(); attrNumber++) {
        XmlAttribute xmlAttribute = xmlblock.getXmlAttribute(attrNumber);
        String name = xmlAttribute.getName();

        int pos = -1;
        try {
            pos = Integer.parseInt(name.substring(8, 9));
        } catch (NumberFormatException nfe) {
        }

        if (name.charAt(0) == 'I') {
            if (name.substring(1, 8).equals("bigflow")) {
                saInVars[pos][FLOW] = xmlAttribute.getValue();
            } else {
                saInVars[pos][SUBFLOW] = xmlAttribute.getValue();
            }
        } else if (name.charAt(0) == 'O') {
            if (name.substring(1, 8).equals("bigflow")) {
                saOutVars[pos][FLOW] = xmlAttribute.getValue();
            } else {
                saOutVars[pos][SUBFLOW] = xmlAttribute.getValue();
            }
        } else if (name.charAt(0) == 'M') {
            subflow = xmlAttribute.getValue();
        } else if (name.charAt(0) == 'A') {
            attrActiv = new Attribute(xmlAttribute.getName(), xmlAttribute.getValue());
        } else if (name.charAt(0) == 'T') {
            saInVars[pos][TYPE] = xmlAttribute.getValue();
            saOutVars[pos][TYPE] = xmlAttribute.getValue();
        }
    }

    if (!this.hasSubFlow(subflow)) {
        this._htSubFlows.put(subflow, subflow);
    } else {
        throw new Exception("Recursividade de Fluxos encontrada!");
    }
    byte[] sXml = BeanFactory.getFlowHolderBean().readSubFlowData(ui, subflow);
    XmlFlow xmlSubFlow = FlowMarshaller.unmarshal(sXml);
    InstantiationResult flowResult = instantiateFlow(ui, xmlSubFlow, anFlowId, alSettings, htBlocks, offset);

    if (flowResult == null) {
        throw new Exception("N&atilde;o foi possivel instanciar o subfluxo " + subflow);
    } else if (flowResult.start == null) {
        throw new Exception("O subfluxo " + subflow + " n&atilde;o tem BlockStart");
    } else if (flowResult.end == null || flowResult.end.size() == 0) {
        throw new Exception("O subfluxo " + subflow + " n&atilde;o tem BlockEnd");
    }

    if (!_htSubFlowEndPorts.containsKey(subflow)) {
        Hashtable<Integer, Object[]> htPorts = new Hashtable<Integer, Object[]>();
        this.buildConnEndPorts(ui, htBlocks, htPorts, flowResult.start);
        _htSubFlowEndPorts.put(subflow, htPorts);
    }

    // remove the start & end blocks
    // replace them by BlockSubFlowIn & BlockSubFlowOut
    htBlocks.remove(new Integer(flowResult.start.getId()));
    this._vFlow.remove(flowResult.start);
    Iterator<Block> it = flowResult.getEndIterator();
    while (it.hasNext()) {
        Block bEnd = it.next();
        htBlocks.remove(new Integer(bEnd.getId()));
        this._vFlow.remove(bEnd);
    }

    // BlockSubFlowIn
    Integer blockIdIn = new Integer(flowResult.start.getId() - 100000);
    Object[] args = new Object[] { new Integer(anFlowId), blockIdIn, new Integer(0), new String(subflow) };
    String className = "pt.iflow.blocks.BlockSubFlowIn";
    Class<? extends Block> blockClassIn = loadBlockClass(ui, className);
    Constructor<? extends Block> argsConstructor = blockClassIn.getConstructor(argsClass);
    Block bBlockIn = argsConstructor.newInstance(args);

    // attributes
    for (int i = 0; i < saInVars.length; i++) {
        if (StringUtils.isEmpty(saInVars[i][FLOW]) || StringUtils.isEmpty(saInVars[i][SUBFLOW]))
            continue;
        Attribute attr = new Attribute();
        attr.setName(saInVars[i][FLOW]);
        attr.setValue(saInVars[i][SUBFLOW]);
        bBlockIn.addAttribute(attr);
        attr = new Attribute("Type_" + saInVars[i][FLOW], saInVars[i][TYPE]);
        bBlockIn.addAttribute(attr);
    }

    // BlockSubFlowOut
    Integer blockIdOut = new Integer(flowResult.end.get(0).getId() - 100000);
    args = new Object[] { new Integer(anFlowId), blockIdOut, new Integer(0), new String(subflow) };
    className = "pt.iflow.blocks.BlockSubFlowOut";
    Class<? extends Block> blockClassOut = loadBlockClass(ui, className);
    argsConstructor = blockClassOut.getConstructor(argsClass);
    Block bBlockOut = argsConstructor.newInstance(args);

    for (int i = 0; i < saOutVars.length; i++) {
        if (saOutVars[i][FLOW] == null || saOutVars[i][FLOW].equals("") || saOutVars[i][SUBFLOW] == null
                || saOutVars[i][SUBFLOW].equals(""))
            continue;
        Attribute attr = new Attribute();
        attr.setName(saOutVars[i][FLOW]);
        attr.setValue(saOutVars[i][SUBFLOW]);
        bBlockOut.addAttribute(attr);
        attr = new Attribute("Type_" + saOutVars[i][FLOW], saOutVars[i][TYPE]);
        bBlockOut.addAttribute(attr);
    }
    if (attrActiv != null)
        bBlockOut.addAttribute(attrActiv);

    // portos do BlockSubFlowIn
    Port port = null;
    try {
        XmlPort xmlPort = xmlblock.getXmlPort(0); // portIn -> portIn
        port = new Port();
        port.setName("portIn");
        port.setConnectedBlockId(xmlPort.getConnectedBlockId() + (offset - iOFFSET));
        port.setConnectedPortName(xmlPort.getConnectedPortName());
        Field fPort = blockClassIn.getField("portIn");
        fPort.set(bBlockIn, port);

        port = new Port(); // portOutThread
        port.setName("portOutThread");
        port.setConnectedBlockId(bBlockOut.getId());
        port.setConnectedPortName("portInThread");
        fPort = blockClassIn.getField("portOutThread");
        fPort.set(bBlockIn, port);

        port = new Port(); // portOut
        port.setName("portOut");
        fPort = blockClassIn.getField("portOut");
        fPort.set(bBlockIn, port);

        Port[] patmp = flowResult.start.getOutPorts(ui);
        for (int p = 0; patmp != null && p < patmp.length; p++) {
            if (patmp[p] == null)
                continue;

            Integer iBId = new Integer(patmp[p].getConnectedBlockId());
            Block bInnerBlock = (Block) htBlocks.get(iBId);
            if (bInnerBlock == null)
                continue;

            bInnerBlock.getInPorts(ui)[0].setConnectedBlockId(bBlockIn.getId());
            bBlockIn.getOutPorts(ui)[0].setConnectedBlockId(patmp[p].getConnectedBlockId());
            bBlockIn.getOutPorts(ui)[0].setConnectedPortName(patmp[p].getConnectedPortName());
        }

        //       xmlPort = xmlblock.getXmlPort(2); // portError -> portError
        //       port = new Port();
        //       port.setName("portError");
        //       port.setConnectedBlockId(xmlPort.getConnectedBlockId()
        //           + (offset - iOFFSET));
        //       port.setConnectedPortName(xmlPort.getConnectedPortName());
        //       fPort = blockClassIn.getField("portError");
        //       fPort.set(bBlockIn, port);
    } catch (Exception e) {
        e.printStackTrace();
        throw new Exception("Erro ao criar porto " + port.getName() + " para o bloco SubFlowIn");
    }

    // portos do BlockSubFlowOut
    try {
        port = new Port(); // portIn
        port.setName("portIn");
        Field fPort = blockClassOut.getField("portIn");
        fPort.set(bBlockOut, port);

        Hashtable<Integer, Object[]> htPorts = _htSubFlowEndPorts.get(subflow);
        Iterator<Integer> portIt = htPorts.keySet().iterator();
        while (portIt.hasNext()) {
            Integer itmp = portIt.next();
            Object[] otmp = (Object[]) htPorts.get(itmp);
            Port outPort = (Port) otmp[0];

            outPort.setConnectedBlockId(bBlockOut.getId());
            outPort.setConnectedPortName(port.getName());

            bBlockOut.getInPorts(ui)[0].setConnectedBlockId(itmp.intValue());
            bBlockOut.getInPorts(ui)[0].setConnectedPortName(outPort.getName());
        }

        port = new Port(); // portInThread
        port.setName("portInThread");
        port.setConnectedBlockId(bBlockIn.getId());
        port.setConnectedPortName("portOutThread");
        fPort = blockClassOut.getField("portInThread");
        fPort.set(bBlockOut, port);

        XmlPort xmlPort = xmlblock.getXmlPort(1); // portSuccess -> portOut
        port = new Port();
        port.setName("portOut");
        port.setConnectedBlockId(xmlPort.getConnectedBlockId() + (offset - iOFFSET));
        port.setConnectedPortName(xmlPort.getConnectedPortName());
        fPort = blockClassOut.getField("portOut");
        fPort.set(bBlockOut, port);

        //       xmlPort = xmlblock.getXmlPort(2); // portError
        //       port = new Port();
        //       port.setName("portError");
        //       port.setConnectedBlockId(xmlPort.getConnectedBlockId()
        //           + (offset - iOFFSET));
        //       port.setConnectedPortName(xmlPort.getConnectedPortName());
        //       fPort = blockClassOut.getField("portError");
        //       fPort.set(bBlockOut, port);
    } catch (Exception e) {
        e.printStackTrace();
        throw new Exception("Erro ao criar porto " + port.getName() + " para o bloco SubFlowOut");
    }

    this._vFlow.add(bBlockIn);
    this._vFlow.add(bBlockOut);

    htBlocks.put(blockIdIn, bBlockIn);
    htBlocks.put(blockIdOut, bBlockOut);

    ArrayList<Block> altmp = new ArrayList<Block>();
    altmp.add(bBlockOut);

    return new InstantiationResult(bBlockIn, altmp);
}

From source file:ucar.unidata.idv.ui.ImageGenerator.java

/**
 * Handle the clear tag/*from   w ww  .jav a  2  s. co  m*/
 *
 * @param node node
 *
 * @return ok
 *
 * @throws Throwable On badness
 */
protected boolean processTagClear(Element node) throws Throwable {
    String name = applyMacros(node, ATTR_NAME);
    Hashtable ht = (Hashtable) propertiesStack.get(0);
    ht.remove(name);
    return true;
}

From source file:at.tuwien.ifs.somtoolbox.reportgenerator.output.SOMDescriptionLATEX.java

/**
 * Creates output describing the layout of the created som this includes tables showing the distribution of the
 * input vectors of the som, as well as (if available) the distribution of the classes on the som. In addition, if
 * the user selected input items for getting their position on the trained SOM, this information is also created in
 * this function.//from   w  w  w . ja  v a 2  s .c  om
 * 
 * @param classInfoAvailable true if class information are available (and therefore a piechart should be inserted,
 *            false otherwise)
 */
protected void printMapLayout(boolean classInfoAvailable) {

    // the information about the selected data items - listed
    InputDatum input;
    Unit unit;
    String key;
    Hashtable<String, Vector<InputDatum>> lookup = new Hashtable<String, Vector<InputDatum>>(); // there we store
    // for each unit the
    // input vectors
    // mapped to it
    Vector<InputDatum> mappedInputs;

    // --- the first table with number of input items and class distribution
    String clsinf = "";
    if (classInfoAvailable) {
        clsinf = " and class distribution";
    }
    this.writer.appendLatexOutput("\\paragraph{Distribution of the input vectors" + clsinf + ":}\n");
    this.writer.appendLatexOutput("Table 3 on page \\pageref{tab:pie} is the Visualisation of a Hit Histogram."
            + "It shows the amount of input units mapped to their corresponding units on the SOM.");
    if (classInfoAvailable) {
        this.writer.appendLatexOutput(
                " The Class Pie Chart Image gives an Overview on the amount of classes being mappewd to this unit."
                        + "White gaps signify empty spaces on the Map, therefore can be interpretetd as natural cluster boundaries.\\\\");
    }
    this.printDistributionDetailTable(null, classInfoAvailable);
    this.writer.appendOutput("A more sophisticated way to visualize the distributioun of classes is the SDH. "
            + TextualDescriptionProvider.getScientificDescription("sdh")
            + "Fgure 1,2 \\& 3 on page \\pageref{fig:sdh1} are the Visualisations SDH Images with increasing Values of \\textit{k}\n");

    int runID = this.testrun.getRunId();
    this.testrun.createSDHImages(this.imgDir + System.getProperty("file.separator"), "SDH_Visualization.jpg",
            30, true, -1);
    this.testrun.createSDHImages(this.imgDir + System.getProperty("file.separator"), "SDH_Visualization.jpg",
            30, true, -1);
    this.testrun.createSDHImages(this.imgDir + System.getProperty("file.separator"), "SDH_Visualization.jpg",
            30, true, -1);
    this.writer.appendOutput("\\begin{center}\n" + "\\begin{figure}[htbp]\n");
    int dim = this.testrun.getSOMDimensions();
    for (int i = 1; i < dim; i = i + dim / 3) {
        this.writer.appendOutput("\\begin{minipage}[hbt]{4.5cm}\n" + "\\includegraphics[width=4.5cm]{"
                + SOMDescriptionLATEX.imgSubdir + "/" + "SDH_pics_" + this.testrun.getRunId() + "/" + "s" + i
                + "_" + this.testrun.getRunId() + "_SDH_Visualization.jpg}");

        this.writer.appendOutput("\\caption{SDH with k = " + i + "}" + "\\label{fig:sdh" + i + "}"
                + "\\end{minipage}\n" + "\\hspace{2cm}\n");

    }
    this.writer.appendOutput("\\end{figure}\n" + "\\end{center}");
    // --- then we give some information about the selected input vectors
    if (this.dataset.getNumberOfSelectedInputs() > 0) {
        this.writer
                .appendLatexOutput("\\subsection{Location and quantization errors of selected input items:}\n");
        this.writer.appendOutput(
                "Table 4 on page \\pageref{tab:loc} shows for all input items their corresponding Map Node and the Quantization Error \\textit{e}m$^q$ of that Node. Additionally the Distance  "
                        + "$\\xi_p^s$ from the Input units Vector \\textit{s} to the prototype vector \\textit{p} of the SOM unit."
                        + "is mapped, and how big the quantization error is. After that, this is visualized in another table.\\\\\n");
        // first a list of the selected data items with more information about them:
        this.writer.appendOutput("\\begin{longtable}{|c|c|l|l|l|}\\hline\n" + "Item No. \n&" + "Mapped Node \n&"
                + "\\textit{e}$^q$ &\n" + "$\\xi_p^s$\n" + "\\\\");

        // we have to somehow map the data items to the units, s.t. we than can walk through the
        // units to retrieve the corresponding data items
        // while doing this, we print a list of all selected items with some additional information
        for (int i = 0; i < this.dataset.getNumberOfSelectedInputs(); i++) {
            this.writer.appendLatexOutput("\\hline");

            input = this.dataset.getInputDatum(this.dataset.getSelectedInputId(i));
            unit = this.testrun.getUnitMappedTo(input);
            key = unit.getXPos() + "_" + unit.getYPos();

            // create the latex output for the list
            this.writer.appendLatexOutput(input.getLabel() + "&"
            // where
                    + "[" + unit.getXPos() + ", " + unit.getYPos() + "] " + " & (qe="
                    + String.format("%.5f", this.testrun.getQEForUnit(unit.getXPos(), unit.getYPos())) + ""
                    + " and mqe="
                    + String.format("%.5f", this.testrun.getMQEForUnit(unit.getXPos(), unit.getYPos())) + ")&"
                    // qe
                    + String.format("%.5f", this.testrun.getInputMappedQE(input.getLabel()).getQE()) + "\n");
            this.writer.appendLatexOutput("\\\\");
            // add this input to the lookup table for creating the table
            if (lookup.containsKey(key)) {
                // there's already one input vector mapped to this unit
                mappedInputs = lookup.get(key);
                lookup.remove(key);
            } else {
                // new
                mappedInputs = new Vector<InputDatum>();
            }
            mappedInputs.add(input);
            lookup.put(key, mappedInputs);
        }
        this.writer.appendLatexOutput(
                "\\hline\\caption{Location and Quantization errors of selected input items}\n"
                        + "\\label{tab:loc}\n" + "\\end{longtable}\n");

        // print the table with the datasets inserted
        // NO!! PAPER IS TOO SMALL FOR IT :(
        // this.writer.appendLatexOutput("The following table visualized the information given in the list above. Values enclosed by \"\" denote "
        // +
        // "the label of a selected input item, the number in the top left corner of each cell gives the number of
        // input items totally mapped to
        // this unit. ");
        // this.printDistributionDetailTable(lookup, classInfoAvailable);
    }
}

From source file:org.adl.sequencer.impl.ADLSequencer.java

/**
 * Applies the Overall Rollup Process to the target activity. <br>
 * <b>Internal Sequencing Process</b><br>
 * <br>//  w  w w  .j a v a  2 s. c  o  m
 * 
 * @param ioTarget
 *            Identifies the activity where rollup is applied.
 * 
 * @param ioRollupSet
 *            Identifies the set of activities remaining.
 */
private void doOverallRollup(SeqActivity ioTarget, Hashtable<String, Integer> ioRollupSet) {

    // This method implements the loop of RB.1.5. The other rollup process
    // are encapsulated in the RollupRuleset object.

    if (_Debug) {
        System.out.println("  :: ADLSequencer --> BEGIN - doOverallRollup");
        System.out.println("  ::-->  Target: " + ioTarget.getID());
    }

    // Attempt to get Rollup Rule information from the activity node
    ISeqRollupRuleset rollupRules = ioTarget.getRollupRules();

    if (rollupRules == null) {
        rollupRules = new SeqRollupRuleset();
    }

    // Apply the rollup processes to the activity
    rollupRules.evaluate(ioTarget);

    if (_Debug) {
        boolean objMeasureStatus = ioTarget.getObjMeasureStatus(false);
        double objMeasure = ioTarget.getObjMeasure(false);

        boolean objStatus = ioTarget.getObjStatus(false);
        boolean objSatisfied = ioTarget.getObjSatisfied(false);

        boolean proStatus = ioTarget.getProgressStatus(false);
        boolean proCompleted = ioTarget.getAttemptCompleted(false);

        System.out.println("  ::--> RESULTS");
        System.out.println("  :: OBJ Measure ::   " + objMeasureStatus + "  //  " + objMeasure);
        System.out.println("  :: OBJ Status  ::   " + objStatus + "  //  " + objSatisfied);
        System.out.println("  :: Progress    ::   " + proStatus + "  //  " + proCompleted);
    }

    // Remove this activity from the rollup set
    ioRollupSet.remove(ioTarget.getID());

    if (_Debug) {
        System.out.println("  :: ADLSequencer --> END   - doOverallRollup");
    }
}

From source file:org.adl.sequencer.impl.ADLSequencer.java

/**
 * Initiates deterministic rollup from the target activity and any other
 * activities that may have been affected. <br>
 * <b>Internal Sequencing Process</b><br>
 * <br>//  w w  w .j  a  va  2  s .c o  m
 * 
 * @param ioTarget
 *            Identifies the activity where rollup is applied.
 * 
 * @param iWriteObjIDs
 *            Identifies the set of objective IDs that are affected by this
 *            invokation; or <code>null</code> if none.
 */
private void invokeRollup(SeqActivity ioTarget, List<String> iWriteObjIDs) {

    if (_Debug) {
        System.out.println("  :: ADLSequencer --> BEGIN - invokeRollup");
        System.out.println("  ::-->  Start: " + ioTarget.getID());
    }

    Hashtable<String, Integer> rollupSet = new Hashtable<String, Integer>();

    // Case #1 -- Rollup applies along the active path
    if (ioTarget == mSeqTree.getCurrentActivity()) {

        if (_Debug) {
            System.out.println("  ::--> CASE #1 Rollup");
        }

        SeqActivity walk = ioTarget;

        // Walk from the target to the root, apply rollup rules at each step
        while (walk != null) {

            if (_Debug) {
                System.out.println("  ::--> Adding :: " + walk.getID());
            }

            rollupSet.put(walk.getID(), Integer.valueOf(walk.getDepth()));

            List<String> writeObjIDs = walk.getObjIDs(null, false);

            if (writeObjIDs != null) {
                for (int i = 0; i < writeObjIDs.size(); i++) {
                    String objID = writeObjIDs.get(i);

                    if (_Debug) {
                        System.out.println("  ::--> Rolling up Obj -- " + objID);
                    }

                    // Need to identify all activity's that 'read' this
                    // objective
                    // into their primary objective -- those activities need
                    // to be
                    // included in the rollup set
                    List<String> acts = mSeqTree.getObjMap(objID);

                    if (_Debug) {
                        System.out.println("  ACTS == " + acts);
                    }

                    if (acts != null) {
                        for (int j = 0; j < acts.size(); j++) {
                            SeqActivity act = getActivity(acts.get(j));

                            if (_Debug) {
                                System.out.println("  *+> " + j + " <+*  :: " + act.getID());
                            }

                            // Only rollup at the parent of the affected
                            // activity
                            act = act.getParent();

                            if (act != null) {
                                // Only add if the activity is selected
                                if (act.getIsSelected()) {
                                    if (_Debug) {
                                        System.out.println("  ::--> Adding :: " + act.getID());
                                    }

                                    rollupSet.put(act.getID(), Integer.valueOf(act.getDepth()));
                                }
                            }
                        }
                    }
                }
            }

            walk = walk.getParent();
        }

        // Remove the Current Activity from the rollup set
        rollupSet.remove(ioTarget.getID());

    }

    // Case #2 -- Rollup applies when the state of a global shared objective
    // is written to...
    if (iWriteObjIDs != null) {

        if (_Debug) {
            System.out.println("  ::--> CASE #2 Rollup");
        }

        for (int i = 0; i < iWriteObjIDs.size(); i++) {
            String objID = iWriteObjIDs.get(i);

            if (_Debug) {
                System.out.println("  ::--> Rolling up Obj -- " + objID);
            }

            // Need to identify all activity's that 'read' this objective
            // into their primary objective -- those activities need to be
            // included in the rollup set
            List<String> acts = mSeqTree.getObjMap(objID);

            if (_Debug) {
                System.out.println("  ACTS == " + acts);
            }

            if (acts != null) {
                for (int j = 0; j < acts.size(); j++) {
                    SeqActivity act = getActivity(acts.get(j));

                    if (_Debug) {
                        System.out.println("  *+> " + j + " <+*  :: " + act.getID());
                    }

                    // Only rollup at the parent of the affected activity
                    act = act.getParent();

                    if (act != null) {
                        // Only add if the activity is selected
                        if (act.getIsSelected()) {
                            if (_Debug) {
                                System.out.println("  ::--> Adding :: " + act.getID());
                            }

                            rollupSet.put(act.getID(), Integer.valueOf(act.getDepth()));
                        }
                    }
                }
            }
        }
    }

    // Perform the deterministic rollup extension
    while (rollupSet.size() != 0) {
        if (_Debug) {
            System.out.println("  ::--> Rollup Set Size == " + rollupSet.size());

            for (Entry<String, Integer> entry : rollupSet.entrySet()) {
                System.out.println("  ::-->  " + entry.getKey() + "  //  " + entry.getValue());
            }
        }

        // Find the deepest activity
        SeqActivity deepest = null;
        int depth = -1;

        for (Entry<String, Integer> entry : rollupSet.entrySet()) {
            String key = entry.getKey();
            int thisDepth = entry.getValue();

            if (depth == -1) {
                depth = thisDepth;
                deepest = getActivity(key);
            } else if (thisDepth > depth) {
                depth = thisDepth;
                deepest = getActivity(key);
            }
        }

        if (deepest != null) {
            doOverallRollup(deepest, rollupSet);

            // If rollup was performed on the root, set the course's status
            if (deepest == mSeqTree.getRoot()) {
                @SuppressWarnings("unused")
                String completed = "unknown";
                if (deepest.getObjStatus(false)) {
                    completed = (deepest.getObjSatisfied(false)) ? "satisfied" : "notSatisfied";
                }

                if (deepest.getObjMeasureStatus(false)) {
                    completed = (new Double(deepest.getObjMeasure(false))).toString();
                }

                if (deepest.getProgressStatus(false)) {
                    completed = (deepest.getAttemptCompleted(false)) ? "completed" : "incomplete";
                }

                //ADLSeqUtilities.setCourseStatus(mSeqTree.getCourseID(),
                //      mSeqTree.getLearnerID(), satisfied, measure,
                //      completed);
            }

        } else {
            if (_Debug) {
                System.out.println("  :: ERROR :: No activity found");
            }
        }
    }

    if (_Debug) {
        System.out.println("  :: ADLSequencer --> END   - invokeRollup");
    }
}

From source file:edu.ku.brc.specify.conversion.GenericDBConversion.java

/**
 * @param rsmd//from w  w  w  .j a  va 2s.com
 * @param map
 * @param tableNames
 * @throws SQLException
 */
protected void buildIndexMapFromMetaData(final ResultSetMetaData rsmd, final Hashtable<String, Integer> map,
        final String[] tableNames) throws SQLException {
    map.clear();

    // Find the missing table name by figuring our which one isn't used.
    Hashtable<String, Boolean> existsMap = new Hashtable<String, Boolean>();
    for (String tblName : tableNames) {
        existsMap.put(tblName, true);
        log.debug("[" + tblName + "]");
    }
    for (int i = 1; i <= rsmd.getColumnCount(); i++) {
        String tableName = rsmd.getTableName(i);
        // log.info("["+tableName+"]");
        if (isNotEmpty(tableName)) {
            if (existsMap.get(tableName) != null) {
                existsMap.remove(tableName);
                log.info("Removing Table Name[" + tableName + "]");
            }
        }
    }

    String missingTableName = null;
    if (existsMap.size() == 1) {
        missingTableName = existsMap.keys().nextElement();
        log.info("Missing Table Name[" + missingTableName + "]");

    } else if (existsMap.size() > 1) {
        throw new RuntimeException("ExistsMap cannot have more than one name in it!");
    } else {
        log.info("No Missing Table Names.");
    }

    for (int i = 1; i <= rsmd.getColumnCount(); i++) {
        strBuf.setLength(0);
        String tableName = rsmd.getTableName(i);
        strBuf.append(isNotEmpty(tableName) ? tableName : missingTableName);
        strBuf.append(".");
        strBuf.append(rsmd.getColumnName(i));
        map.put(strBuf.toString(), i);
    }
}