Example usage for java.util HashSet contains

List of usage examples for java.util HashSet contains

Introduction

In this page you can find the example usage for java.util HashSet contains.

Prototype

public boolean contains(Object o) 

Source Link

Document

Returns true if this set contains the specified element.

Usage

From source file:malware_classification.Malware_Classification.java

private double[][] get_elements(double[][] data, HashSet<Integer> indices) {
    double[][] new_data = new double[indices.size()][data[0].length];
    int new_data_index = 0;
    for (int i = 0; i < data.length; i++) {
        if (indices.contains(i)) {
            System.arraycopy(data[i], 0, new_data[new_data_index], 0, data[i].length);
            new_data_index++;
        }/*from   www.j  a v  a 2s.  c o  m*/
    }

    return new_data;
}

From source file:eu.stratosphere.nephele.jobmanager.web.JobmanagerInfoServlet.java

/**
 * Writes infos about archived job in Json format, including groupvertices and groupverticetimes
 * /*  ww w . j a v  a  2 s  . co m*/
 * @param wrt
 * @param jobEvent
 */
private void writeJsonForArchivedJob(PrintWriter wrt, RecentJobEvent jobEvent) {

    try {

        wrt.write("[");

        ManagementGraph jobManagementGraph = jobmanager.getManagementGraph(jobEvent.getJobID());

        //Serialize job to json
        wrt.write("{");
        wrt.write("\"jobid\": \"" + jobEvent.getJobID() + "\",");
        wrt.write("\"jobname\": \"" + jobEvent.getJobName() + "\",");
        wrt.write("\"status\": \"" + jobEvent.getJobStatus() + "\",");
        wrt.write("\"SCHEDULED\": "
                + jobmanager.getArchive().getJobTime(jobEvent.getJobID(), JobStatus.SCHEDULED) + ",");
        wrt.write("\"RUNNING\": " + jobmanager.getArchive().getJobTime(jobEvent.getJobID(), JobStatus.RUNNING)
                + ",");
        wrt.write("\"FINISHED\": " + jobmanager.getArchive().getJobTime(jobEvent.getJobID(), JobStatus.FINISHED)
                + ",");
        wrt.write("\"FAILED\": " + jobmanager.getArchive().getJobTime(jobEvent.getJobID(), JobStatus.FAILED)
                + ",");
        wrt.write("\"CANCELED\": " + jobmanager.getArchive().getJobTime(jobEvent.getJobID(), JobStatus.CANCELED)
                + ",");
        wrt.write("\"CREATED\": " + jobmanager.getArchive().getJobTime(jobEvent.getJobID(), JobStatus.CREATED)
                + ",");

        if (jobEvent.getJobStatus() == JobStatus.FAILED) {
            ManagementGraphIterator managementGraphIterator = new ManagementGraphIterator(jobManagementGraph,
                    true);
            wrt.write("\"failednodes\": [");
            HashSet<String> map = new HashSet<String>();
            boolean first = true;
            while (managementGraphIterator.hasNext()) {
                ManagementVertex managementVertex = managementGraphIterator.next();
                String instanceName = managementVertex.getInstanceName();
                if (managementVertex.getExecutionState() == ExecutionState.FAILED
                        && !map.contains(instanceName)) {
                    if (first) {
                        first = false;
                    } else {
                        wrt.write(",");
                    }
                    wrt.write("{");
                    wrt.write("\"node\": \"" + instanceName + "\",");
                    wrt.write("\"message\": \"" + StringUtils.escapeHtml(managementVertex.getOptMessage())
                            + "\"");
                    wrt.write("}");
                    map.add(instanceName);
                }
            }
            wrt.write("],");
        }

        // Serialize ManagementGraph to json
        wrt.write("\"groupvertices\": [");
        boolean first = true;
        for (ManagementGroupVertex groupVertex : jobManagementGraph.getGroupVerticesInTopologicalOrder()) {
            //Write seperator between json objects
            if (first) {
                first = false;
            } else {
                wrt.write(",");
            }

            wrt.write(groupVertex.toJson());

        }
        wrt.write("],");

        // write accumulators
        AccumulatorEvent accumulators = jobmanager.getAccumulatorResults(jobEvent.getJobID());
        Map<String, Object> accMap = AccumulatorHelper.toResultMap(accumulators.getAccumulators());

        wrt.write("\n\"accumulators\": [");
        int i = 0;
        for (Entry<String, Object> accumulator : accMap.entrySet()) {
            wrt.write(
                    "{ \"name\": \"" + accumulator.getKey() + " (" + accumulator.getValue().getClass().getName()
                            + ")\"," + " \"value\": \"" + accumulator.getValue().toString() + "\"}\n");
            if (++i < accMap.size()) {
                wrt.write(",");
            }
        }
        wrt.write("],\n");

        wrt.write("\"groupverticetimes\": {");
        first = true;
        for (ManagementGroupVertex groupVertex : jobManagementGraph.getGroupVerticesInTopologicalOrder()) {

            if (first) {
                first = false;
            } else {
                wrt.write(",");
            }

            // Calculate start and end time for groupvertex
            long started = Long.MAX_VALUE;
            long ended = 0;

            // Take earliest running state and latest endstate of groupmembers
            for (int j = 0; j < groupVertex.getNumberOfGroupMembers(); j++) {
                ManagementVertex vertex = groupVertex.getGroupMember(j);

                long running = jobmanager.getArchive().getVertexTime(jobEvent.getJobID(), vertex.getID(),
                        ExecutionState.RUNNING);
                if (running != 0 && running < started) {
                    started = running;
                }

                long finished = jobmanager.getArchive().getVertexTime(jobEvent.getJobID(), vertex.getID(),
                        ExecutionState.FINISHED);
                long canceled = jobmanager.getArchive().getVertexTime(jobEvent.getJobID(), vertex.getID(),
                        ExecutionState.CANCELED);
                long failed = jobmanager.getArchive().getVertexTime(jobEvent.getJobID(), vertex.getID(),
                        ExecutionState.FAILED);

                if (finished != 0 && finished > ended) {
                    ended = finished;
                }

                if (canceled != 0 && canceled > ended) {
                    ended = canceled;
                }

                if (failed != 0 && failed > ended) {
                    ended = failed;
                }

            }

            wrt.write("\"" + groupVertex.getID() + "\": {");
            wrt.write("\"groupvertexid\": \"" + groupVertex.getID() + "\",");
            wrt.write("\"groupvertexname\": \"" + groupVertex + "\",");
            wrt.write("\"STARTED\": " + started + ",");
            wrt.write("\"ENDED\": " + ended);
            wrt.write("}");

        }

        wrt.write("}");

        wrt.write("}");

        wrt.write("]");

    } catch (EofException eof) { // Connection closed by client
        LOG.info("Info server for jobmanager: Connection closed by client, EofException");
    } catch (IOException ioe) { // Connection closed by client   
        LOG.info("Info server for jobmanager: Connection closed by client, IOException");
    }

}

From source file:com.evolveum.midpoint.model.common.stringpolicy.ValuePolicyProcessor.java

private void testInvalidCharacters(List<String> valueCharacters, HashSet<String> validChars,
        OperationResult result, List<LocalizableMessage> message) {
    StringBuilder invalidCharacters = new StringBuilder();
    for (String character : valueCharacters) {
        if (!validChars.contains(character)) {
            invalidCharacters.append(character);
        }//from w  w w  .ja  v  a  2 s  .c  om
    }
    if (invalidCharacters.length() > 0) {
        LocalizableMessage msg = new LocalizableMessageBuilder().key("ValuePolicy.charactersNotAllowed")
                .arg(invalidCharacters).build();
        result.addSubresult(new OperationResult("Check if value does not contain invalid characters",
                OperationResultStatus.FATAL_ERROR, msg));
        message.add(msg);
    }
}

From source file:malware_classification.Malware_Classification.java

private double[][] get_elements_not_excluded(double[][] data, HashSet<Integer> indices) {
    double[][] new_data = new double[data.length - indices.size()][data[0].length];
    int new_data_index = 0;
    for (int i = 0; i < data.length; i++) {
        if (!indices.contains(i)) {
            System.arraycopy(data[i], 0, new_data[new_data_index], 0, data[i].length);
            new_data_index++;
        }//ww  w  . j ava  2  s .c o m
    }

    return new_data;

}

From source file:jp.ac.tohoku.ecei.sb.metabolome.lims.gui.MainWindowController.java

@SuppressWarnings("unchecked")
private void initializeTable(TableView tableView, Class clazz) {
    ArrayList<TableColumn> columns = new ArrayList<>();
    HashSet<String> methodNames = new HashSet<>();
    method: for (Method one : clazz.getMethods()) {
        for (String black : new String[] { "getClass", "getAttributeKeySet" })
            if (one.getName().equals(black))
                continue method;
        if (!one.getName().startsWith("get") && !one.getName().startsWith("is"))
            continue;
        if (one.getParameterCount() != 0)
            continue;
        if (methodNames.contains(one.getName()))
            continue;
        methodNames.add(one.getName());/*from  w w w  .j av  a  2 s.  c  om*/

        TableColumn oneColumn = new TableColumn();
        String name = one.getName().substring(3);
        if (one.getName().startsWith("is")) {
            name = one.getName().substring(2);
        }
        oneColumn.setText(name);
        oneColumn.setCellValueFactory(new PropertyValueFactory(name));

        if (one.getName().equals("getId"))
            columns.add(0, oneColumn);
        else
            columns.add(oneColumn);
    }

    tableView.getColumns().addAll(columns.toArray());
}

From source file:com.addthis.hydra.job.HostFailWorker.java

/**
 * Retrieve information about the implications of failing a host, to inform/warn a user in the UI
 *
 * @param hostsToFail The hosts that will be failed
 * @return A JSONObject with various data about the implications of the failure
 *//*w w  w.  jav  a2 s  . co m*/
public JSONObject getInfoForHostFailure(String hostsToFail, boolean deadFilesystem) throws JSONException {
    if (hostsToFail == null) {
        return new JSONObject();
    }
    HashSet<String> ids = new HashSet<>(Arrays.asList(hostsToFail.split(",")));
    long totalClusterAvail = 0, totalClusterUsed = 0, hostAvail = 0;
    List<String> hostsDown = new ArrayList<>();
    for (HostState host : spawn.hostManager.listHostStatus(null)) {
        // Sum up disk availability across the entire cluster and across the specified hosts
        if (host.getMax() != null && host.getUsed() != null) {
            if (getFailureState(host.getHostUuid()) == FailState.ALIVE) {
                totalClusterAvail += host.getMax().getDisk();
                totalClusterUsed += host.getUsed().getDisk();
            }
            if (ids.contains(host.getHostUuid())) {
                hostAvail += host.getMax().getDisk();
            }
        }
        if (!ids.contains(host.getHostUuid()) && shouldBlockHostFailure(ids, host)) {
            hostsDown.add(host.getHostUuid() + " on " + host.getHost());
        }
    }
    // Guard against division by zero in the case of unexpected values
    totalClusterAvail = Math.max(1, totalClusterAvail);
    hostAvail = Math.min(totalClusterAvail - 1, hostAvail);
    return constructInfoMessage(hostsToFail, deadFilesystem, (double) (totalClusterUsed) / totalClusterAvail,
            (double) (totalClusterUsed) / (totalClusterAvail - hostAvail), hostsDown);
}

From source file:com.squid.kraken.v4.core.analysis.engine.project.DynamicManager.java

protected String checkUniqueId(String ID, HashSet<String> IDs) {
    if (!IDs.contains(ID)) {
        return ID;
    } else {//from w ww  .ja v a2  s  . co m
        int num = 1;
        String dedup = ID + "_" + num;
        while (IDs.contains(dedup)) {
            dedup = ID + "_" + (++num);
        }
        return dedup;
    }
}

From source file:jp.terasoluna.fw.web.thin.LimitedLock.java

/**
 * ?bN?B/*from   w w  w. j av  a2  s.  c  om*/
 * <p>
 * ?Xbh?bN?AXbh?Xbh??s?A?Xbh@?B<br>
 * ?Xbh?bN???A?\bhA?B<br>
 * Xbh?Xbh??s???AInterruptedExceptionX??[?A?Xbh?Xe?[^XNA?B<br>
 * (?ANXO????A?Xe?[^Xs?B)
 * </p>
 * <p>
 * ?L?AX?[p?[NX?Bg|Cg?B<br>
 * <ul>
 * <li>?bNXbh?l??\bh?s?A?bNO?AlXbh?A?bNXbhf?B<br>
 * ?bNXbh?\bh?s(??bN)?A?bNXbh??AXbhf?s?B</li>
 * </ul>
 * </p>
 * @throws InterruptedException ?Xbh????(NX@\?A?bNf??)
 * @see java.util.concurrent.locks.ReentrantLock#lockInterruptibly()
 */
@Override
public void lockInterruptibly() throws InterruptedException {
    boolean successToLock = false;
    // ?bNXbh????A
    // ?VXbh?bNv??A
    // ?bNXbh??B
    // (?bN?Xbh?AI?bN(??bN)|???A
    // ?bNXbh??B)
    if (getOwner() != Thread.currentThread()) {
        synchronized (lock) {
            // u?bN???Asuper.unlock();?s?A?bNXbh?bN?B
            // Xbh?bN???A
            // ?bNXbh?bN?A
            // Xbh?A?J?A?bN?oR?bN??A
            // ?bN?\bhXbh?A??Xbh?B
            // ?AXbh?bN??A
            // ?Au?bN?Asuper.lockInterruptibly();?sOXbh????A
            // Xbh?Au?bN???A??????
            // (?bNXbh???AXbh?A??)?A
            // Xbh?bN??A?bNv?Xbh?l??A
            // ??@?Ax??B
            int queueLength = getQueueLength();
            if (queueLength > threshold) {
                HashSet<Thread> oldWaitingThreadSet = null;
                synchronized (waitingThreadList) {
                    List<Thread> oldWaitingThreadList = waitingThreadList.subList(0, queueLength - threshold);
                    oldWaitingThreadSet = new HashSet<Thread>(oldWaitingThreadList);
                }
                // waitingThreadListXbh?A
                // ??bNXbh?A
                // ??bNXbhXg?A
                // oldWaitingThreadListoldWaitingThreadSet?AgetQueuedThreads()?B
                for (Thread queuedThread : getQueuedThreads()) {
                    if (oldWaitingThreadSet.contains(queuedThread)) {
                        if (log.isDebugEnabled()) {
                            log.debug("interrupt thread '" + queuedThread + "'.");
                        }
                        synchronized (waitingThreadList) {
                            // ?waitingThreadList.remove?A?XbhfinallyO?A?s?
                            // ?XbhremoveO?AXbh?f?s\??A
                            // f??Xbh??A
                            // remove?B
                            waitingThreadList.remove(queuedThread);
                            queuedThread.interrupt();

                            // ??A
                            // Xbh?bNL?[?o^CO?A
                            // Xbh?A???getQueueLength()?s?A
                            // getQueueLength()?AwaitingThreadList??A
                            // waitingThreadList.subLists(ListsubLists)?A
                            // (synchronized (lock))?AXbh?bNL?[?o?B
                            while (getQueuedThreads().contains(queuedThread)) {
                                Thread.yield();
                            }
                        }
                    }
                }
            }
        }
    }

    try {
        synchronized (waitingThreadList) {
            waitingThreadList.add(Thread.currentThread());
        }
        super.lockInterruptibly();
        successToLock = true;
    } finally {
        // O??A
        // NX?(?s)???s??
        // NX?(/?s)???I
        // ???sKv?A
        // locktB?[h?bN?B
        synchronized (lock) {
            synchronized (waitingThreadList) {
                waitingThreadList.remove(Thread.currentThread()); // O?remove?Aremove
                if (!successToLock) {
                    // O?NX????A
                    // ?Xe?[^Xc?A
                    // ?Xe?[^XNA?B
                    // ?bN??AreturnO????A
                    // ?Xe?[^XNAreturn?B
                    Thread.interrupted();
                }
            }
        }
    }
}

From source file:com.globalsight.connector.mindtouch.MindTouchCreateJobHandler.java

@ActionHandler(action = "connect", formClass = "")
public void prepareConnect(HttpServletRequest p_request, HttpServletResponse p_response, Object form)
        throws Exception {
    String mtcId = p_request.getParameter("mtcId");
    MindTouchConnector mtc = MindTouchManager.getMindTouchConnectorById(Long.parseLong(mtcId));
    p_request.setAttribute("mindtouchConnector", mtc);

    List<GlobalSightLocale> trgServerLocaleList = new ArrayList<GlobalSightLocale>();
    HashSet<String> trgServerLocales = new HashSet<String>();
    List<MindTouchConnectorTargetServer> targetServers = MindTouchManager
            .getAllTargetServers(Long.parseLong(mtcId));
    for (MindTouchConnectorTargetServer trgServer : targetServers) {
        trgServerLocales.add(trgServer.getTargetLocale().toLowerCase());
    }//  w ww . j a va2  s  .  c  om
    Vector allLocales = new Vector();
    try {
        allLocales = ServerProxy.getLocaleManager().getAvailableLocales();
        for (int i = 0; i < allLocales.size(); i++) {
            GlobalSightLocale gsl = (GlobalSightLocale) allLocales.get(i);
            if (trgServerLocales.contains(gsl.toString().toLowerCase())) {
                trgServerLocaleList.add(gsl);
            }
        }
    } catch (Exception e) {
        logger.error(e);
    }
    p_request.setAttribute("allAvailableLocales", allLocales);
    p_request.setAttribute("targetServerLocales", trgServerLocaleList);
}

From source file:com.novartis.opensource.yada.format.Joiner.java

/**
 * The meaty bit. Uses hsqld to create in memory db tables for the combined rows of converted results in each yqr. 
 * Then uses the join spec to build data structures, mapping columns to tables, tables to columns, and table pairs to columns.
 * Then builds a select join query from the structures, executes it, wraps and returns the results.
 * @return a {@link JSONArray} containing structured results, or a {@link StringBuffer} containing delimited results
 * @throws YADAResponseException if there is a problem with the in-memory database
 *//*w ww  .  j a va2s.c  om*/
public Object join() throws YADAResponseException {
    Object result = null;
    try {
        Class.forName("org.hsqldb.jdbcDriver");
    } catch (ClassNotFoundException e1) {
        //TODO exception handling
    }
    try (Connection c = DriverManager.getConnection("jdbc:hsqldb:mem:mymemdb", "SA", "");) {
        StringBuffer sql = null;
        StringBuffer buffer = new StringBuffer();
        JSONArray rows = new JSONArray();
        boolean isFormatStructured = isFormatStructured();
        // create tables and insert data
        for (YADAQueryResult yqr : getYadaQueryResults()) {
            // create tables
            sql = new StringBuffer();
            sql.append("CREATE TABLE");
            sql.append(" T" + yqr.hashCode());
            sql.append(" (");
            for (int col = 0; col < yqr.getConvertedHeader().size(); col++) {
                sql.append(yqr.getConvertedHeader().get(col).replaceAll("\"", ""));
                sql.append(" VARCHAR(4000)");
                if (col < yqr.getConvertedHeader().size() - 1)
                    sql.append(",");
            }
            sql.append(")");
            l.debug(sql.toString());
            try (PreparedStatement create = c.prepareStatement(sql.toString());) {
                create.executeUpdate();
            } catch (SQLException e) {
                String msg = "Unable to create in-memory tables";
                throw new YADAResponseException(msg, e);
            }

            StringBuilder header = new StringBuilder();
            StringBuilder params = new StringBuilder();
            String delim = "";

            //TODO build these in first iteration of converted header during CREATE construction
            for (String hdr : yqr.getConvertedHeader()) {
                header.append(delim).append(hdr);
                params.append(delim).append("?");
                delim = ",";
            }

            // inserts

            sql = new StringBuffer();
            sql.append("INSERT INTO T" + yqr.hashCode());
            sql.append(" (");
            sql.append(header.toString().replaceAll("\"", ""));
            sql.append(") VALUES (");
            sql.append(params);
            sql.append(")");
            l.debug(sql.toString());
            try (PreparedStatement insert = c.prepareStatement(sql.toString());) {

                for (int i = 0; i < yqr.getConvertedResults().size(); i++) {
                    //TODO xml
                    if (isFormatStructured) // json (and someday xml)
                    {
                        @SuppressWarnings("unchecked")
                        List<String> results = (List<String>) yqr.getConvertedResult(i);
                        for (String res : results) {
                            JSONObject row = new JSONObject(res);
                            for (int k = 1; k <= yqr.getConvertedHeader().size(); k++) {
                                String key = yqr.getConvertedHeader().get(k - 1);
                                insert.setString(k, row.getString(key));
                            }
                            insert.addBatch();
                        }
                    } else // delimited
                    {
                        @SuppressWarnings("unchecked")
                        List<List<String>> results = (List<List<String>>) yqr.getConvertedResult(i);
                        for (int j = 0; j < results.size(); j++) {
                            for (int k = 1; k <= yqr.getConvertedHeader().size(); k++) {
                                insert.setString(k, results.get(j).get(k - 1));
                            }
                            insert.addBatch();
                        }
                    }
                }
                insert.executeBatch();
            } catch (SQLException e) {
                String msg = "Unable to populate in-memory tables";
                throw new YADAResponseException(msg, e);
            }
        }

        // derive/apply the join spec
        // get columns from converted headers
        // TODO create this list in previous YQR iteration
        List<List<String>> localHeaders = new ArrayList<>();
        for (int i = 0; i < getYadaQueryResults().length; i++) {
            localHeaders.add(getYadaQueryResults()[i].getConvertedHeader());
        }

        String specStr = "";
        if (isOuter())
            specStr = getYADAQueryParamValue(YADARequest.PS_LEFTJOIN);
        else
            specStr = getYADAQueryParamValue(YADARequest.PS_JOIN);

        HashSet<String> specSet = null;

        if (!specStr.equals("")) {
            if (specStr.equals("true")) {
                specSet = new HashSet<>();
                for (int i = 0; i < localHeaders.size() - 1; i++) {
                    for (int j = 0; j < localHeaders.get(i).size(); j++) {
                        String hdr = localHeaders.get(i).get(j);
                        for (int k = i + 1; k < localHeaders.size(); k++) {
                            if (localHeaders.get(k).contains(hdr))
                                specSet.add(hdr.replaceAll("\"", ""));
                        }
                    }
                }
            } else {
                specSet = new HashSet<>(Arrays.asList(specStr.split(",")));
            }
            l.debug("specStr = " + specStr);
            l.debug("specSet = " + specSet.toString());
        }

        // hash the column indexes by request
        Map<String, Set<String>> S_t2c = new LinkedHashMap<>(); // the cols mapped to tables
        Map<String, Set<String>> S_c2t = new HashMap<>(); // the tables mapped to the columns
        for (int i = 0; i < localHeaders.size() - 1; i++) {
            String table = "T" + getYadaQueryResults()[i].hashCode();
            String nextTable = "T" + getYadaQueryResults()[i + 1].hashCode();
            HashSet<String> dupeCheck = new HashSet<>();
            List<String> iHdr = localHeaders.get(i);
            List<String> jHdr = localHeaders.get(i + 1);
            for (String hdr : iHdr) {
                String _hdr = hdr.replaceAll("\"", "");
                dupeCheck.add(_hdr);
            }
            for (String hdr : jHdr) {
                String _hdr = hdr.replaceAll("\"", "");
                if (dupeCheck.contains(_hdr) && (specSet == null || (specSet.contains(_hdr)
                        || specSet.contains(_hdr.toLowerCase()) || specSet.contains(_hdr.toUpperCase())))) {
                    // table to columns
                    if (!S_t2c.containsKey(table)) {
                        S_t2c.put(table, new HashSet<String>());
                    }
                    S_t2c.get(table).add(_hdr);

                    // column to tables
                    if (!S_c2t.containsKey(_hdr)) {
                        S_c2t.put(_hdr, new HashSet<String>());
                    }
                    S_c2t.get(_hdr).add(table);

                    // nextTable to columns
                    if (!S_t2c.containsKey(nextTable)) {
                        S_t2c.put(nextTable, new HashSet<String>());
                    }
                    S_t2c.get(nextTable).add(_hdr);
                    // column to tables
                    S_c2t.get(_hdr).add(nextTable);
                }
            }
        }

        // hash the table combo to the col
        HashMap<List<String>, List<String>> S_tt2c = new HashMap<>();
        for (String col : S_c2t.keySet()) {
            List<String> tables = new ArrayList<>(S_c2t.get(col));
            if (tables.size() == 2) {
                if (S_tt2c.get(tables) == null)
                    S_tt2c.put(tables, new ArrayList<>(Arrays.asList(col)));
                else
                    S_tt2c.get(tables).add(col);
            } else {
                for (int i = 0; i < tables.size() - 1; i++) {
                    List<String> biTabs = new ArrayList<>();
                    biTabs.add(tables.get(i));
                    biTabs.add(tables.get(++i));
                    if (S_tt2c.get(biTabs) == null)
                        S_tt2c.put(biTabs, new ArrayList<>(Arrays.asList(col)));
                    else
                        S_tt2c.get(biTabs).add(col);
                }
            }
        }

        /*
         *   i=0, table = t1,
         *   i=1, table = t2,
         *   joinTable = (
         */

        // build join
        sql = new StringBuffer();
        sql.append("SELECT");
        String delim = " ";
        StringBuilder gh = new StringBuilder();
        Set<String> globalHeader = getGlobalHeader();
        for (String hdr : globalHeader) {
            //TODO consider using COALESCE in here to return empty strings instead of 'null' on LEFT JOINs, maybe make that a parameter as well
            gh.append(delim + hdr.replaceAll("\"", ""));
            delim = ", ";
        }
        sql.append(gh);
        sql.append(" FROM");
        String[] tables = S_t2c.keySet().toArray(new String[S_t2c.size()]);
        //      Arrays.sort(tables);
        for (int i = 0; i < tables.length; i++) {
            String table = tables[i];
            if (i == 0) {
                sql.append(" " + table);
            } else {
                List<String> joinTables = Arrays.asList(tables[i - 1], tables[i]);
                List<String> columns = S_tt2c.get(joinTables);
                if (columns == null) {
                    joinTables = Arrays.asList(tables[i], tables[i - 1]);
                    columns = S_tt2c.get(joinTables);
                }
                if (isOuter())
                    sql.append(" LEFT");
                sql.append(" JOIN " + table + " ON");
                for (int j = 0; j < columns.size(); j++) {
                    String col = columns.get(j);
                    if (j > 0)
                        sql.append(" AND");
                    sql.append(" " + joinTables.get(0) + "." + col + " = " + joinTables.get(1) + "." + col);
                }
            }
        }
        sql.append(" GROUP BY");
        sql.append(gh);
        l.debug(sql.toString());
        ResultSet rs = null;
        String colsep = getYADAQueryParamValue(YADARequest.PS_DELIMITER);
        String recsep = getYADAQueryParamValue(YADARequest.PS_ROW_DELIMITER);
        try (PreparedStatement select = c.prepareStatement(sql.toString());) {
            rs = select.executeQuery();
            if (isFormatStructured) {
                while (rs.next()) {
                    JSONObject j = new JSONObject();
                    for (String key : globalHeader) {
                        j.put(key, rs.getString(key));
                    }
                    rows.put(j);
                }
                result = rows;
            } else {
                while (rs.next()) {
                    delim = "";
                    for (int j = 0; j < rs.getMetaData().getColumnCount(); j++) {
                        buffer.append(delim + rs.getString(j + 1));
                        delim = colsep;
                    }
                    buffer.append(recsep);
                }
                result = buffer;
            }
        } catch (SQLException e) {
            String msg = "Unable to format result sets.";
            throw new YADAResponseException(msg, e);
        } finally {
            try {
                if (rs != null)
                    rs.close();
            } catch (SQLException e) {
                String msg = "There was a problem releasing resources.";
                throw new YADAResponseException(msg, e);
            }
        }
    } catch (SQLException e) {
        String msg = "Unable to connect to in-memory database.";
        throw new YADAResponseException(msg, e);
    }
    return result;
}