Example usage for java.util SortedMap keySet

List of usage examples for java.util SortedMap keySet

Introduction

In this page you can find the example usage for java.util SortedMap keySet.

Prototype

Set<K> keySet();

Source Link

Document

Returns a Set view of the keys contained in this map.

Usage

From source file:com.streamsets.pipeline.lib.jdbc.JdbcMultiRowRecordWriter.java

private static PreparedStatement generatePreparedStatement(SortedMap<String, String> columns, int numRecords,
        Object tableName, Connection connection) throws SQLException {
    String valuePlaceholder = String.format("(%s)", Joiner.on(", ").join(columns.values()));
    String valuePlaceholders = StringUtils.repeat(valuePlaceholder, ", ", numRecords);
    String query = String.format("INSERT INTO %s (%s) VALUES %s", tableName,
            // keySet and values will both return the same ordering, due to using a SortedMap
            Joiner.on(", ").join(columns.keySet()), valuePlaceholders);

    return connection.prepareStatement(query);
}

From source file:org.opencms.module.CmsModuleXmlHandler.java

/**
 * Generates a detached XML element for a module.<p>
 * /* www  .ja v a  2  s  .  c  o  m*/
 * @param module the module to generate the XML element for
 * 
 * @return the detached XML element for the module
 */
public static Element generateXml(CmsModule module) {

    Document doc = DocumentHelper.createDocument();

    Element moduleElement = doc.addElement(N_MODULE);

    moduleElement.addElement(N_NAME).setText(module.getName());
    if (!module.getName().equals(module.getNiceName())) {
        moduleElement.addElement(N_NICENAME).addCDATA(module.getNiceName());
    } else {
        moduleElement.addElement(N_NICENAME);
    }
    if (CmsStringUtil.isNotEmpty(module.getGroup())) {
        moduleElement.addElement(N_GROUP).setText(module.getGroup());
    }
    if (CmsStringUtil.isNotEmpty(module.getActionClass())) {
        moduleElement.addElement(N_CLASS).setText(module.getActionClass());
    } else {
        moduleElement.addElement(N_CLASS);
    }
    if (CmsStringUtil.isNotEmpty(module.getDescription())) {
        moduleElement.addElement(N_DESCRIPTION).addCDATA(module.getDescription());
    } else {
        moduleElement.addElement(N_DESCRIPTION);
    }
    moduleElement.addElement(N_VERSION).setText(module.getVersion().toString());
    if (CmsStringUtil.isNotEmpty(module.getAuthorName())) {
        moduleElement.addElement(N_AUTHORNAME).addCDATA(module.getAuthorName());
    } else {
        moduleElement.addElement(N_AUTHORNAME);
    }
    if (CmsStringUtil.isNotEmpty(module.getAuthorEmail())) {
        moduleElement.addElement(N_AUTHOREMAIL).addCDATA(module.getAuthorEmail());
    } else {
        moduleElement.addElement(N_AUTHOREMAIL);
    }
    if (module.getDateCreated() != CmsModule.DEFAULT_DATE) {
        moduleElement.addElement(N_DATECREATED).setText(CmsDateUtil.getHeaderDate(module.getDateCreated()));
    } else {
        moduleElement.addElement(N_DATECREATED);
    }

    if (CmsStringUtil.isNotEmpty(module.getUserInstalled())) {
        moduleElement.addElement(N_USERINSTALLED).setText(module.getUserInstalled());
    } else {
        moduleElement.addElement(N_USERINSTALLED);
    }
    if (module.getDateInstalled() != CmsModule.DEFAULT_DATE) {
        moduleElement.addElement(N_DATEINSTALLED).setText(CmsDateUtil.getHeaderDate(module.getDateInstalled()));
    } else {
        moduleElement.addElement(N_DATEINSTALLED);
    }
    Element dependenciesElement = moduleElement.addElement(N_DEPENDENCIES);
    for (int i = 0; i < module.getDependencies().size(); i++) {
        CmsModuleDependency dependency = module.getDependencies().get(i);
        dependenciesElement.addElement(N_DEPENDENCY)
                .addAttribute(I_CmsXmlConfiguration.A_NAME, dependency.getName())
                .addAttribute(A_VERSION, dependency.getVersion().toString());
    }
    Element exportpointsElement = moduleElement.addElement(I_CmsXmlConfiguration.N_EXPORTPOINTS);
    for (int i = 0; i < module.getExportPoints().size(); i++) {
        CmsExportPoint point = module.getExportPoints().get(i);
        exportpointsElement.addElement(I_CmsXmlConfiguration.N_EXPORTPOINT)
                .addAttribute(I_CmsXmlConfiguration.A_URI, point.getUri())
                .addAttribute(I_CmsXmlConfiguration.A_DESTINATION, point.getConfiguredDestination());
    }
    Element resourcesElement = moduleElement.addElement(N_RESOURCES);
    for (int i = 0; i < module.getResources().size(); i++) {
        String resource = module.getResources().get(i);
        resourcesElement.addElement(I_CmsXmlConfiguration.N_RESOURCE).addAttribute(I_CmsXmlConfiguration.A_URI,
                resource);
    }
    Element parametersElement = moduleElement.addElement(N_PARAMETERS);
    SortedMap<String, String> parameters = module.getParameters();
    if (parameters != null) {
        List<String> names = new ArrayList<String>(parameters.keySet());
        Collections.sort(names);
        for (String name : names) {
            String value = parameters.get(name).toString();
            Element paramNode = parametersElement.addElement(I_CmsXmlConfiguration.N_PARAM);
            paramNode.addAttribute(I_CmsXmlConfiguration.A_NAME, name);
            paramNode.addText(value);
        }
    }

    // add resource types       
    List<I_CmsResourceType> resourceTypes = module.getResourceTypes();
    if (resourceTypes.size() > 0) {
        Element resourcetypesElement = moduleElement.addElement(CmsVfsConfiguration.N_RESOURCETYPES);
        CmsVfsConfiguration.generateResourceTypeXml(resourcetypesElement, resourceTypes, true);
    }

    List<CmsExplorerTypeSettings> explorerTypes = module.getExplorerTypes();
    if (explorerTypes.size() > 0) {
        Element explorerTypesElement = moduleElement.addElement(CmsWorkplaceConfiguration.N_EXPLORERTYPES);
        CmsWorkplaceConfiguration.generateExplorerTypesXml(explorerTypesElement, explorerTypes, true);
    }

    // return the modules node
    moduleElement.detach();
    return moduleElement;
}

From source file:co.cask.cdap.data.tools.ReplicationStatusTool.java

private static void checkHDFSReplicationComplete(SortedMap<String, String> masterChecksumMap)
        throws IOException {
    boolean complete;
    SortedMap<String, String> slaveChecksumMap = getClusterChecksumMap();

    // Verify that all files on Master are present on Slave. Ignore any extra files on Slave. This could
    // happen when old snapshot files are pruned by CDAP on the Master cluster.
    complete = !checkDifferences(masterChecksumMap.keySet(), slaveChecksumMap.keySet(), "File");

    for (Map.Entry<String, String> checksumEntry : masterChecksumMap.entrySet()) {
        String file = checksumEntry.getKey();
        String masterChecksum = checksumEntry.getValue();
        String slaveChecksum = slaveChecksumMap.get(file);

        if (slaveChecksum != null && !masterChecksum.equals(slaveChecksum)) {
            System.out.println("Master Checksum " + masterChecksum + " for File " + file
                    + " does not match with" + " Slave Checksum " + slaveChecksum);
            complete = false;// w  w w. j  ava2  s  .c o m
        }
    }

    if (complete) {
        // If checksums match for all files.
        System.out.println("Master and Slave Checksums match. HDFS Replication is complete.");
    } else {
        System.out.println("HDFS Replication is NOT Complete.");
    }
}

From source file:com.swisscom.safeconnect.backend.BackendConnector.java

private static String buildUrl(String path, String phoneNumber, String... params) {
    if (params.length % 2 != 0)
        return "";

    StringBuilder sb = new StringBuilder("https://");
    sb.append(Config.PLUMBER_ADDR).append("/");
    sb.append(path).append("/");

    Map<String, String> paramsMap = new HashMap<>();
    for (int i = 0; i < params.length / 2; i++) {
        paramsMap.put(params[i * 2], params[i * 2 + 1]);
    }/*  w  w  w  . j a  v  a2s .c  o m*/
    SortedMap<String, String> sortedParams = new TreeMap<>(paramsMap);

    StringBuilder tokenData = new StringBuilder();
    for (String k : sortedParams.keySet()) {
        tokenData.append(sortedParams.get(k));
    }

    String token = Token.generateToken(phoneNumber, tokenData.toString());

    sb.append("?");
    for (String k : paramsMap.keySet()) {
        sb.append(k).append("=").append(paramsMap.get(k)).append("&");
    }

    sb.append("t=").append(token);
    sb.append("&id=").append(BackendConnector.getBase64EncodedString(phoneNumber));

    return sb.toString();
}

From source file:com.bytelightning.opensource.pokerface.ScriptHelperImpl.java

/**
 * Normalization code courtesy of 'Mike Houston' http://stackoverflow.com/questions/2993649/how-to-normalize-a-url-in-java
 *///  w  ww .j a  va2s.  c  o  m
public static String NormalizeURL(final String taintedURL) throws MalformedURLException {
    final URL url;
    try {
        url = new URI(taintedURL).normalize().toURL();
    } catch (URISyntaxException e) {
        throw new MalformedURLException(e.getMessage());
    }

    final String path = url.getPath().replace("/$", "");
    final SortedMap<String, String> params = CreateParameterMap(url.getQuery());
    final int port = url.getPort();
    final String queryString;

    if (params != null) {
        // Some params are only relevant for user tracking, so remove the most commons ones.
        for (Iterator<String> i = params.keySet().iterator(); i.hasNext();) {
            final String key = i.next();
            if (key.startsWith("utm_") || key.contains("session"))
                i.remove();
        }
        queryString = "?" + Canonicalize(params);
    } else
        queryString = "";

    return url.getProtocol() + "://" + url.getHost() + (port != -1 && port != 80 ? ":" + port : "") + path
            + queryString;
}

From source file:com.sun.faces.generate.RenderKitSpecificationGenerator.java

public static void generateAllRenderersFrame() throws Exception {
    StringBuffer sb = null;/*from   w ww  .  ja  v a 2  s .c  om*/

    // generate the allrenderers-frame.html
    sb = new StringBuffer(2048);
    appendResourceToStringBuffer("com/sun/faces/generate/facesdoc/allrenderers-frame.top", sb);
    sb.append("<FONT size=\"+1\" CLASS=\"FrameHeadingFont\">\n");
    sb.append("<B>" + renderKitId + " RenderKit</B></FONT>\n");
    sb.append("<BR>\n\n");
    sb.append("<DL CLASS=\"FrameItemFont\">\n\n");

    SortedMap renderersByComponentFamily = getComponentFamilyRendererMap(renderKitId);
    Iterator rendererIter = null, keyIter = renderersByComponentFamily.keySet().iterator();
    String curType = null, curFamily = null;
    List renderers = null;
    RendererBean renderer = null;

    while (keyIter.hasNext()) {
        curFamily = (String) keyIter.next();
        sb.append("  <DT>" + curFamily + "</DT>\n");
        renderers = (List) renderersByComponentFamily.get(curFamily);
        rendererIter = renderers.iterator();
        while (rendererIter.hasNext()) {
            renderer = (RendererBean) rendererIter.next();
            curType = renderer.getRendererType();
            sb.append("  <DD><A HREF=\"" + renderKitId + "/" + curFamily + curType
                    + ".html\" TARGET=\"rendererFrame\">" + curType + "</A><DD>\n");
        }
    }

    sb.append("</dl>\n");

    appendResourceToStringBuffer("com/sun/faces/generate/facesdoc/allrenderers-frame.bottom", sb);
    writeStringToFile(sb.toString(), new File(directory, "allrenderers-frame.html"));
}

From source file:com.sun.faces.generate.RenderKitSpecificationGenerator.java

public static void generateRenderKitSummary() throws Exception {
    StringBuffer sb = null;//from www .j  a  v  a  2 s  .co m

    // generate the renderkit-summary.html
    sb = new StringBuffer(2048);
    appendResourceToStringBuffer("com/sun/faces/generate/facesdoc/renderkit-summary.top", sb);
    sb.append("<H2>" + renderKitId + " RenderKit</H2>\n");
    sb.append("<BR>\n\n");

    RenderKitBean renderKit = null;
    if (null == (renderKit = fcb.getRenderKit(renderKitId))) {
        RenderKitBean[] kits = null;
        if (null == (kits = fcb.getRenderKits())) {
            throw new IllegalStateException("no RenderKits");
        }
        if (null == (renderKit = kits[0])) {
            throw new IllegalStateException("no RenderKits");
        }
    }

    DescriptionBean descBean = renderKit.getDescription("");
    String description = (null == descBean) ? "" : descBean.getDescription();
    sb.append("<P>" + description + "</P>\n");
    sb.append("<P />");
    sb.append("<TABLE BORDER=\"1\" CELLPADDING=\"3\" CELLSPACING=\"0\" WIDTH=\"100%\">");
    sb.append("<TR BGCOLOR=\"#CCCCFF\" CLASS=\"TableHeadingColor\">\n");
    sb.append("<TD COLSPAN=\"3\"><FONT SIZE=\"+2\">\n");
    sb.append("<B>Renderer Summary</B></FONT></TD>\n");
    sb.append("\n");
    sb.append("<TR>\n");
    sb.append("<TH>component-family</TH>\n");
    sb.append("<TH>renderer-type</TH>\n");
    sb.append("<TH>description</TH>\n");
    sb.append("</TR>\n");

    SortedMap renderersByComponentFamily = getComponentFamilyRendererMap(renderKitId);
    Iterator rendererIter = null, keyIter = renderersByComponentFamily.keySet().iterator();
    String curType = null, curFamily = null;
    List renderers = null;
    RendererBean renderer = null;

    while (keyIter.hasNext()) {
        curFamily = (String) keyIter.next();
        renderers = (List) renderersByComponentFamily.get(curFamily);
        rendererIter = renderers.iterator();
        sb.append("  <TR>\n");
        sb.append("    <TD rowspan=\"" + renderers.size() + "\">" + curFamily + "</TD>\n");
        while (rendererIter.hasNext()) {
            renderer = (RendererBean) rendererIter.next();
            curType = renderer.getRendererType();
            sb.append("    <TD><A HREF=\"" + curFamily + curType + ".html\" TARGET=\"rendererFrame\">" + curType
                    + "</A></TD>\n");
            descBean = renderer.getDescription("");
            description = (null == descBean) ? "" : descBean.getDescription();
            sb.append("    <TD>" + getFirstSentance(description) + "</TD>");
            if (rendererIter.hasNext()) {
                sb.append("  </TR>\n");
                sb.append("  <TR>\n");
            }
        }
        sb.append("  </TR>\n");
    }

    sb.append("</TABLE>\n\n");

    appendResourceToStringBuffer("com/sun/faces/generate/facesdoc/renderkit-summary.bottom", sb);
    writeStringToFile(sb.toString(), new File(renderKitDirectory, "renderkit-summary.html"));
}

From source file:com.aurel.track.report.dashboard.AverageTimeToCloseItem.java

/**
 * Add the time series to the timeSeriesCollection
 * SortedMap at first and second level (year and period)
 * (Sorted because the accumulated should be calculated in the right order)
 * @param timeSeriesCollection/*from   www. j  a v a 2 s.  c o  m*/
 * @param yearToPeriodToOpenedWorkItemCountMap
 * @param selectedTimeInterval
*/
public static SortedMap<Date, Object> transformPeriodsToDates(
        SortedMap/*<Integer, SortedMap<Integer, Object>>*/ yearToPeriodToValuesMap, int selectedTimeInterval) {
    SortedMap<Date, Object> dateToValue = new TreeMap<Date, Object>();
    for (Iterator iterator = yearToPeriodToValuesMap.keySet().iterator(); iterator.hasNext();) {
        Integer year = (Integer) iterator.next();
        SortedMap<Integer, Object> intervalToStatusChangeBeans = (SortedMap<Integer, Object>) yearToPeriodToValuesMap
                .get(year);
        Iterator<Integer> periodIterator = intervalToStatusChangeBeans.keySet().iterator();
        while (periodIterator.hasNext()) {
            Integer period = periodIterator.next();
            Object periodValue = intervalToStatusChangeBeans.get(period);
            if (periodValue != null) {
                dateToValue.put(createDate(period.intValue(), year.intValue(), selectedTimeInterval),
                        periodValue);
            }
        }
    }
    return dateToValue;
}

From source file:org.apache.hadoop.hbase.regionserver.ccindex.IndexedRegion.java

public static Result getOldValueInBaseTable(IndexedRegion r, IndexSpecification indexSpec, byte[] row,
        SortedMap<byte[], byte[]> columnValues, Integer lockId) throws IOException {
    if (r.orgTable == null) {
        HTableDescriptor td = r.getTableDesc();

        r.orgTable = new HTable(r.conf, td.getName());
        r.orgTable.setWriteBufferSize(1000 * 1000 * 100);
    }/*from w  w  w .j a v a2s. c  o  m*/
    HashSet<String> IndexColumns = new HashSet<String>();
    for (byte[] column : indexSpec.getIndexedColumns()) {
        IndexColumns.add(new String(column));
    }
    for (byte[] column : columnValues.keySet())
        if (IndexColumns.contains(new String(column))) {
            Get oldGet = new Get(row);
            oldGet.addColumn(column);
            Result oldResult = null;
            if (r.isClosed()) {
                oldResult = r.orgTable.get(oldGet);
            } else
                oldResult = r.superGet(oldGet, lockId);
            return oldResult;

        }
    return null;
}

From source file:annis.CSVHelper.java

public static SortedMap<Integer, SortedSet<String>> exportCSVHeader(Iterator<AnnotatedMatch> matches,
        PrintWriter w) {//from   www .j a  v  a 2 s.  c  om
    // figure out what annotations are used at each match position
    SortedMap<Integer, SortedSet<String>> columnsByNodePos = new TreeMap<>();
    while (matches.hasNext()) {
        AnnotatedMatch match = matches.next();
        for (int j = 0; j < match.size(); ++j) {
            AnnotatedSpan span = match.get(j);
            if (columnsByNodePos.get(j) == null) {
                columnsByNodePos.put(j, new TreeSet<String>());
            }
            for (Annotation annotation : span.getAnnotations()) {
                columnsByNodePos.get(j).add("anno_" + annotation.getQualifiedName());
            }

            for (Annotation meta : span.getMetadata()) {
                columnsByNodePos.get(j).add("meta_" + meta.getQualifiedName());
            }

        }
    }

    CSVWriter csvWriter = new CSVWriter(w, '\t', CSVWriter.NO_QUOTE_CHARACTER, '\\');
    // print column names and data types
    int count = columnsByNodePos.keySet().size();
    ArrayList<String> headerLine = new ArrayList<>();

    for (int j = 0; j < count; ++j) {
        headerLine.add(fullColumnName(j + 1, "id"));
        headerLine.add(fullColumnName(j + 1, "span"));

        SortedSet<String> annotationNames = columnsByNodePos.get(j);
        for (String name : annotationNames) {
            headerLine.add(fullColumnName(j + 1, name));
        }
    }
    csvWriter.writeNext(headerLine.toArray(new String[headerLine.size()]));

    return columnsByNodePos;
}