Example usage for java.util SortedSet isEmpty

List of usage examples for java.util SortedSet isEmpty

Introduction

In this page you can find the example usage for java.util SortedSet isEmpty.

Prototype

boolean isEmpty();

Source Link

Document

Returns true if this set contains no elements.

Usage

From source file:com.aurel.track.exchange.excel.ExcelImportBL.java

/**
 * Gets the rows with missing required fields
 * //from w w w .  ja  v  a  2 s .  co m
 * @param missingFieldErrorsMap
 * @param locale
 * @return
 */
static List<String> getMissingRequiredFieldErrorsForJsonMap(
        Map<Integer, SortedSet<Integer>> missingFieldErrorsMap, Locale locale) {
    List<String> missingFieldErrors = new ArrayList<String>();
    for (Integer fieldID : missingFieldErrorsMap.keySet()) {
        SortedSet<Integer> missingFieldRows = missingFieldErrorsMap.get(fieldID);
        if (missingFieldRows != null && !missingFieldRows.isEmpty()) {
            TFieldConfigBean fieldConfigBean = FieldRuntimeBL.getDefaultFieldConfig(fieldID, locale);
            String fieldLabel = null;
            if (fieldConfigBean != null) {
                fieldLabel = FieldRuntimeBL.getDefaultFieldConfig(fieldID, locale).getLabel();
            }
            String mergedRowsString = MergeUtil.getMergedString(missingFieldRows, ", ");
            missingFieldErrors
                    .add(LocalizeUtil.getParametrizedString("admin.actions.importExcel.err.requiredField",
                            new Object[] { fieldLabel, mergedRowsString }, locale));
        }

    }
    return missingFieldErrors;
}

From source file:org.apache.tajo.storage.hbase.HBaseTablespace.java

/**
 * Returns initial region split keys./*from  ww w. j av a 2 s . c o m*/
 *
 * @param conf
 * @param schema
 * @param meta
 * @return
 * @throws java.io.IOException
 */
private byte[][] getSplitKeys(TajoConf conf, String hbaseTableName, Schema schema, TableMeta meta)
        throws MissingTablePropertyException, InvalidTablePropertyException, IOException {

    String splitRowKeys = meta.getProperty(HBaseStorageConstants.META_SPLIT_ROW_KEYS_KEY, "");
    String splitRowKeysFile = meta.getProperty(HBaseStorageConstants.META_SPLIT_ROW_KEYS_FILE_KEY, "");

    if ((splitRowKeys == null || splitRowKeys.isEmpty())
            && (splitRowKeysFile == null || splitRowKeysFile.isEmpty())) {
        return null;
    }

    ColumnMapping columnMapping = new ColumnMapping(schema, meta.getPropertySet());
    boolean[] isBinaryColumns = columnMapping.getIsBinaryColumns();
    boolean[] isRowKeys = columnMapping.getIsRowKeyMappings();

    boolean rowkeyBinary = false;
    int numRowKeys = 0;
    Column rowKeyColumn = null;
    for (int i = 0; i < isBinaryColumns.length; i++) {
        if (isBinaryColumns[i] && isRowKeys[i]) {
            rowkeyBinary = true;
        }
        if (isRowKeys[i]) {
            numRowKeys++;
            rowKeyColumn = schema.getColumn(i);
        }
    }

    if (rowkeyBinary && numRowKeys > 1) {
        throw new InvalidTablePropertyException("If rowkey is mapped to multi column and a rowkey is binary, "
                + "Multiple region for creation is not support.", hbaseTableName);
    }

    if (splitRowKeys != null && !splitRowKeys.isEmpty()) {
        String[] splitKeyTokens = splitRowKeys.split(",");
        byte[][] splitKeys = new byte[splitKeyTokens.length][];
        for (int i = 0; i < splitKeyTokens.length; i++) {
            if (numRowKeys == 1 && rowkeyBinary) {
                splitKeys[i] = HBaseBinarySerializerDeserializer.serialize(rowKeyColumn,
                        new TextDatum(splitKeyTokens[i]));
            } else {
                splitKeys[i] = HBaseTextSerializerDeserializer.serialize(rowKeyColumn,
                        new TextDatum(splitKeyTokens[i]));
            }
        }
        return splitKeys;
    }

    if (splitRowKeysFile != null && !splitRowKeysFile.isEmpty()) {
        // If there is many split keys, Tajo allows to define in the file.
        Path path = new Path(splitRowKeysFile);
        FileSystem fs = path.getFileSystem(conf);

        if (!fs.exists(path)) {
            throw new MissingTablePropertyException(
                    "hbase.split.rowkeys.file=" + path.toString() + " not exists.", hbaseTableName);
        }

        SortedSet<String> splitKeySet = new TreeSet<>();
        BufferedReader reader = null;

        try {
            reader = new BufferedReader(new InputStreamReader(fs.open(path)));
            String line = null;
            while ((line = reader.readLine()) != null) {
                if (line.isEmpty()) {
                    continue;
                }
                splitKeySet.add(line);
            }
        } finally {
            if (reader != null) {
                reader.close();
            }
        }

        if (splitKeySet.isEmpty()) {
            return null;
        }

        byte[][] splitKeys = new byte[splitKeySet.size()][];
        int index = 0;
        for (String eachKey : splitKeySet) {
            if (numRowKeys == 1 && rowkeyBinary) {
                splitKeys[index++] = HBaseBinarySerializerDeserializer.serialize(rowKeyColumn,
                        new TextDatum(eachKey));
            } else {
                splitKeys[index++] = HBaseTextSerializerDeserializer.serialize(rowKeyColumn,
                        new TextDatum(eachKey));
            }
        }

        return splitKeys;
    }

    return null;
}

From source file:org.apache.tajo.storage.hbase.HBaseStorageManager.java

/**
 * Returns initial region split keys.//from  www . j  av a2s. c  o m
 *
 * @param conf
 * @param schema
 * @param meta
 * @return
 * @throws java.io.IOException
 */
private byte[][] getSplitKeys(TajoConf conf, Schema schema, TableMeta meta) throws IOException {
    String splitRowKeys = meta.getOption(HBaseStorageConstants.META_SPLIT_ROW_KEYS_KEY, "");
    String splitRowKeysFile = meta.getOption(HBaseStorageConstants.META_SPLIT_ROW_KEYS_FILE_KEY, "");

    if ((splitRowKeys == null || splitRowKeys.isEmpty())
            && (splitRowKeysFile == null || splitRowKeysFile.isEmpty())) {
        return null;
    }

    ColumnMapping columnMapping = new ColumnMapping(schema, meta);
    boolean[] isBinaryColumns = columnMapping.getIsBinaryColumns();
    boolean[] isRowKeys = columnMapping.getIsRowKeyMappings();

    boolean rowkeyBinary = false;
    int numRowKeys = 0;
    Column rowKeyColumn = null;
    for (int i = 0; i < isBinaryColumns.length; i++) {
        if (isBinaryColumns[i] && isRowKeys[i]) {
            rowkeyBinary = true;
        }
        if (isRowKeys[i]) {
            numRowKeys++;
            rowKeyColumn = schema.getColumn(i);
        }
    }

    if (rowkeyBinary && numRowKeys > 1) {
        throw new IOException("If rowkey is mapped to multi column and a rowkey is binary, "
                + "Multiple region for creation is not support.");
    }

    if (splitRowKeys != null && !splitRowKeys.isEmpty()) {
        String[] splitKeyTokens = splitRowKeys.split(",");
        byte[][] splitKeys = new byte[splitKeyTokens.length][];
        for (int i = 0; i < splitKeyTokens.length; i++) {
            if (numRowKeys == 1 && rowkeyBinary) {
                splitKeys[i] = HBaseBinarySerializerDeserializer.serialize(rowKeyColumn,
                        new TextDatum(splitKeyTokens[i]));
            } else {
                splitKeys[i] = HBaseTextSerializerDeserializer.serialize(rowKeyColumn,
                        new TextDatum(splitKeyTokens[i]));
            }
        }
        return splitKeys;
    }

    if (splitRowKeysFile != null && !splitRowKeysFile.isEmpty()) {
        // If there is many split keys, Tajo allows to define in the file.
        Path path = new Path(splitRowKeysFile);
        FileSystem fs = path.getFileSystem(conf);
        if (!fs.exists(path)) {
            throw new IOException("hbase.split.rowkeys.file=" + path.toString() + " not exists.");
        }

        SortedSet<String> splitKeySet = new TreeSet<String>();
        BufferedReader reader = null;
        try {
            reader = new BufferedReader(new InputStreamReader(fs.open(path)));
            String line = null;
            while ((line = reader.readLine()) != null) {
                if (line.isEmpty()) {
                    continue;
                }
                splitKeySet.add(line);
            }
        } finally {
            if (reader != null) {
                reader.close();
            }
        }

        if (splitKeySet.isEmpty()) {
            return null;
        }

        byte[][] splitKeys = new byte[splitKeySet.size()][];
        int index = 0;
        for (String eachKey : splitKeySet) {
            if (numRowKeys == 1 && rowkeyBinary) {
                splitKeys[index++] = HBaseBinarySerializerDeserializer.serialize(rowKeyColumn,
                        new TextDatum(eachKey));
            } else {
                splitKeys[index++] = HBaseTextSerializerDeserializer.serialize(rowKeyColumn,
                        new TextDatum(eachKey));
            }
        }

        return splitKeys;
    }

    return null;
}

From source file:io.fabric8.maven.plugin.HelmIndexMojo.java

protected void generateHTML(File outputHtmlFile, Map<String, ChartInfo> charts) throws MojoExecutionException {
    Map<String, SortedSet<ChartInfo>> chartMap = new TreeMap<>();
    for (ChartInfo chartInfo : charts.values()) {
        String key = chartInfo.getName();
        SortedSet<ChartInfo> set = chartMap.get(key);
        if (set == null) {
            set = new TreeSet(createChartComparator());
            chartMap.put(key, set);//  w ww  .ja  v a2s.  c  o m
        }
        set.add(chartInfo);
    }
    try (PrintWriter writer = new PrintWriter(new FileWriter(outputHtmlFile))) {
        writer.println("<html>");
        writer.println("<head>");
        writer.println(getHtmlFileContentOrDefault(headHtmlFile, "<link href='style.css' rel=stylesheet>\n"
                + "<link href='custom.css' rel=stylesheet>\n" + "<title>" + helmTitle + "</title>\n"));
        writer.println("</head>");
        writer.println("<body>");

        writer.println(getHtmlFileContentOrDefault(introductionHtmlFile, "<h1>" + helmTitle + "</h1>"));

        writer.println("<table class='table table-striped table-hover'>");
        writer.println("  <hhead>");
        writer.println("    <tr>");
        writer.println("      <th>Chart</th>");
        writer.println("      <th>Versions</th>");
        writer.println("    </tr>");
        writer.println("  </hhead>");
        writer.println("  <tbody>");
        for (Map.Entry<String, SortedSet<ChartInfo>> entry : chartMap.entrySet()) {
            String key = entry.getKey();
            SortedSet<ChartInfo> set = entry.getValue();
            if (!set.isEmpty()) {
                ChartInfo first = set.first();
                HelmMojo.Chart firstChartfile = first.getChartfile();
                if (firstChartfile == null) {
                    continue;
                }
                String chartDescription = getDescription(firstChartfile);
                writer.println("    <tr>");
                writer.println("      <td title='" + chartDescription + "'>");
                String iconHtml = "";
                String iconUrl = findIconURL(first, set);
                if (Strings.isNotBlank(iconUrl)) {
                    iconHtml = "<img class='logo' src='" + iconUrl + "'>";
                }
                writer.println("        " + iconHtml + "<span class='chart-name'>" + key + "</span>");
                writer.println("      </td>");
                writer.println("      <td class='versions'>");
                for (ChartInfo chartInfo : set) {
                    HelmMojo.Chart chartfile = chartInfo.getChartfile();
                    if (chartfile == null) {
                        continue;
                    }
                    String description = getDescription(chartfile);
                    String version = chartfile.getVersion();
                    String href = chartInfo.getUrl();
                    writer.println(
                            "        <a href='" + href + "' title='" + description + "'>" + version + "</a>");
                }
                writer.println("      </td>");
                writer.println("    </tr>");
            }
        }
        writer.println("  </tbody>");
        writer.println("  </table>");
        writer.println(getHtmlFileContentOrDefault(footerHtmlFile, ""));
        writer.println("</body>");
    } catch (IOException e) {
        throw new MojoExecutionException("Failed to write to " + outputHtmlFile + ". " + e, e);
    }
}

From source file:visolate.Visolate.java

public void mouseClicked(double x, double y, int modifiers) {

    SortedSet<Net> clickedNets = new TreeSet<Net>();

    model.getNetsAtPoint(x, y, 1.0 / display.getDPI(), clickedNets);

    if (manualTopology.isSelected()) {
        clearSelection();//from w  ww . j  a v a2  s  .  c om
        TopologyProcessor.mergeNets(clickedNets);
        return;
    }

    if ((selectedNet != null) && clickedNets.contains(selectedNet)) {

        Iterator<Net> it = (clickedNets.tailSet(selectedNet)).iterator();

        it.next();

        if (it.hasNext()) {
            selectedNet = it.next();
        } else {
            selectedNet = clickedNets.iterator().next();
        }

    } else {

        selectedNet = null;

        if (!clickedNets.isEmpty()) {
            selectedNet = clickedNets.iterator().next();
        }
    }

    Net selectedNetSave = selectedNet;

    if (!((modifiers & MouseEvent.CTRL_DOWN_MASK) != 0))
        clearSelection();

    selectedNet = selectedNetSave;

    if (selectedNet != null) {
        selectedNets.add(selectedNet);
        selectedNet.setHighlighted(true);
    }
}

From source file:io.fabric8.maven.plugin.mojo.internal.HelmIndexMojo.java

protected void generateHTML(File outputHtmlFile, Map<String, ChartInfo> charts) throws MojoExecutionException {
    Map<String, SortedSet<ChartInfo>> chartMap = new TreeMap<>();
    for (ChartInfo chartInfo : charts.values()) {
        String key = chartInfo.getName();
        SortedSet<ChartInfo> set = chartMap.get(key);
        if (set == null) {
            set = new TreeSet<>(createChartComparator());
            chartMap.put(key, set);/*  w w w .ja  v  a 2s .  c  om*/
        }
        set.add(chartInfo);
    }
    try (PrintWriter writer = new PrintWriter(new FileWriter(outputHtmlFile))) {
        writer.println("<html>");
        writer.println("<head>");
        writer.println(getHtmlFileContentOrDefault(headHtmlFile, "<link href='style.css' rel=stylesheet>\n"
                + "<link href='custom.css' rel=stylesheet>\n" + "<title>" + helmTitle + "</title>\n"));
        writer.println("</head>");
        writer.println("<body>");

        writer.println(getHtmlFileContentOrDefault(introductionHtmlFile, "<h1>" + helmTitle + "</h1>"));

        writer.println("<table class='table table-striped table-hover'>");
        writer.println("  <hhead>");
        writer.println("    <tr>");
        writer.println("      <th>Chart</th>");
        writer.println("      <th>Versions</th>");
        writer.println("    </tr>");
        writer.println("  </hhead>");
        writer.println("  <tbody>");
        for (Map.Entry<String, SortedSet<ChartInfo>> entry : chartMap.entrySet()) {
            String key = entry.getKey();
            SortedSet<ChartInfo> set = entry.getValue();
            if (!set.isEmpty()) {
                ChartInfo first = set.first();
                HelmMojo.Chart firstChartfile = first.getChartfile();
                if (firstChartfile == null) {
                    continue;
                }
                String chartDescription = getDescription(firstChartfile);
                writer.println("    <tr>");
                writer.println("      <td title='" + chartDescription + "'>");
                String iconHtml = "";
                String iconUrl = findIconURL(first, set);
                if (Strings.isNotBlank(iconUrl)) {
                    iconHtml = "<img class='logo' src='" + iconUrl + "'>";
                }
                writer.println("        " + iconHtml + "<span class='chart-name'>" + key + "</span>");
                writer.println("      </td>");
                writer.println("      <td class='versions'>");
                for (ChartInfo chartInfo : set) {
                    HelmMojo.Chart chartfile = chartInfo.getChartfile();
                    if (chartfile == null) {
                        continue;
                    }
                    String description = getDescription(chartfile);
                    String version = chartfile.getVersion();
                    String href = chartInfo.firstUrl();
                    writer.println(
                            "        <a href='" + href + "' title='" + description + "'>" + version + "</a>");
                }
                writer.println("      </td>");
                writer.println("    </tr>");
            }
        }
        writer.println("  </tbody>");
        writer.println("  </table>");
        writer.println(getHtmlFileContentOrDefault(footerHtmlFile, ""));
        writer.println("</body>");
    } catch (IOException e) {
        throw new MojoExecutionException("Failed to write to " + outputHtmlFile + ". " + e, e);
    }
}

From source file:cerrla.LocalCrossEntropyDistribution.java

/**
 * Modifies the policy values before updating (cutting the values down to
 * size)./* w  w  w.ja  va2s . c  o  m*/
 * 
 * @param elites
 *            The policy values to modify.
 * @param numElite
 *            The minimum number of elite samples.
 * @param staleValue
 *            The number of policies a sample hangs around for.
 * @param minValue
 *            The minimum observed value.
 * @return The policy values that were removed.
 */
private SortedSet<PolicyValue> preUpdateModification(SortedSet<PolicyValue> elites, int numElite,
        int staleValue, double minValue) {
    // Firstly, remove any policy values that have been around for more
    // than N steps

    // Make a backup - just in case the elites are empty afterwards
    SortedSet<PolicyValue> backup = new TreeSet<PolicyValue>(elites);

    // Only remove stuff if the elites are a representative solution
    if (!ProgramArgument.GLOBAL_ELITES.booleanValue()) {
        int iteration = policyGenerator_.getPoliciesEvaluated();
        for (Iterator<PolicyValue> iter = elites.iterator(); iter.hasNext();) {
            PolicyValue pv = iter.next();
            if (iteration - pv.getIteration() >= staleValue) {
                if (ProgramArgument.RETEST_STALE_POLICIES.booleanValue())
                    policyGenerator_.retestPolicy(pv.getPolicy());
                iter.remove();
            }
        }
    }
    if (elites.isEmpty())
        elites.addAll(backup);

    SortedSet<PolicyValue> tailSet = null;
    if (elites.size() > numElite) {
        // Find the N_E value
        Iterator<PolicyValue> pvIter = elites.iterator();
        PolicyValue currentPV = null;
        for (int i = 0; i < numElite; i++)
            currentPV = pvIter.next();

        // Iter at N_E value. Remove any values less than N_E's value
        tailSet = new TreeSet<PolicyValue>(elites.tailSet(new PolicyValue(null, currentPV.getValue(), -1)));
        elites.removeAll(tailSet);
    }

    return tailSet;
}

From source file:org.apache.hadoop.yarn.server.timeline.LeveldbTimelineStore.java

@Override
public TimelineEvents getEntityTimelines(String entityType, SortedSet<String> entityIds, Long limit,
        Long windowStart, Long windowEnd, Set<String> eventType) throws IOException {
    TimelineEvents events = new TimelineEvents();
    if (entityIds == null || entityIds.isEmpty()) {
        return events;
    }//from  w  ww  .jav a 2  s.  c  om
    // create a lexicographically-ordered map from start time to entities
    Map<byte[], List<EntityIdentifier>> startTimeMap = new TreeMap<byte[], List<EntityIdentifier>>(
            new Comparator<byte[]>() {
                @Override
                public int compare(byte[] o1, byte[] o2) {
                    return WritableComparator.compareBytes(o1, 0, o1.length, o2, 0, o2.length);
                }
            });
    LeveldbIterator iterator = null;
    try {
        // look up start times for the specified entities
        // skip entities with no start time
        for (String entityId : entityIds) {
            byte[] startTime = getStartTime(entityId, entityType);
            if (startTime != null) {
                List<EntityIdentifier> entities = startTimeMap.get(startTime);
                if (entities == null) {
                    entities = new ArrayList<EntityIdentifier>();
                    startTimeMap.put(startTime, entities);
                }
                entities.add(new EntityIdentifier(entityId, entityType));
            }
        }
        for (Entry<byte[], List<EntityIdentifier>> entry : startTimeMap.entrySet()) {
            // look up the events matching the given parameters (limit,
            // start time, end time, event types) for entities whose start times
            // were found and add the entities to the return list
            byte[] revStartTime = entry.getKey();
            for (EntityIdentifier entityIdentifier : entry.getValue()) {
                EventsOfOneEntity entity = new EventsOfOneEntity();
                entity.setEntityId(entityIdentifier.getId());
                entity.setEntityType(entityType);
                events.addEvent(entity);
                KeyBuilder kb = KeyBuilder.newInstance().add(ENTITY_ENTRY_PREFIX).add(entityType)
                        .add(revStartTime).add(entityIdentifier.getId()).add(EVENTS_COLUMN);
                byte[] prefix = kb.getBytesForLookup();
                if (windowEnd == null) {
                    windowEnd = Long.MAX_VALUE;
                }
                byte[] revts = writeReverseOrderedLong(windowEnd);
                kb.add(revts);
                byte[] first = kb.getBytesForLookup();
                byte[] last = null;
                if (windowStart != null) {
                    last = KeyBuilder.newInstance().add(prefix).add(writeReverseOrderedLong(windowStart))
                            .getBytesForLookup();
                }
                if (limit == null) {
                    limit = DEFAULT_LIMIT;
                }
                iterator = new LeveldbIterator(db);
                for (iterator.seek(first); entity.getEvents().size() < limit && iterator.hasNext(); iterator
                        .next()) {
                    byte[] key = iterator.peekNext().getKey();
                    if (!prefixMatches(prefix, prefix.length, key) || (last != null
                            && WritableComparator.compareBytes(key, 0, key.length, last, 0, last.length) > 0)) {
                        break;
                    }
                    TimelineEvent event = getEntityEvent(eventType, key, prefix.length,
                            iterator.peekNext().getValue());
                    if (event != null) {
                        entity.addEvent(event);
                    }
                }
            }
        }
    } catch (DBException e) {
        throw new IOException(e);
    } finally {
        IOUtils.cleanup(LOG, iterator);
    }
    return events;
}

From source file:io.fabric8.maven.plugin.ManifestIndexMojo.java

protected void generateHTML(File outputHtmlFile, Map<String, ManifestInfo> manifests, boolean kubernetes,
        File introductionHtmlFile, File headHtmlFile, File footerHtmlFile) throws MojoExecutionException {
    Map<String, SortedSet<ManifestInfo>> manifestMap = new TreeMap<>();
    for (ManifestInfo manifestInfo : manifests.values()) {
        String key = manifestInfo.getName();
        SortedSet<ManifestInfo> set = manifestMap.get(key);
        if (set == null) {
            set = new TreeSet(createManifestComparator());
            manifestMap.put(key, set);/*from  w  w w .j  a  va  2  s  .  co  m*/
        }
        set.add(manifestInfo);
    }
    try (PrintWriter writer = new PrintWriter(new FileWriter(outputHtmlFile))) {
        writer.println("<html>");
        writer.println("<head>");
        writer.println(getHtmlFileContentOrDefault(headHtmlFile, "<link href='style.css' rel=stylesheet>\n"
                + "<link href='custom.css' rel=stylesheet>\n" + "<title>" + manifestTitle + "</title>\n"));
        writer.println("</head>");
        writer.println("<body>");

        writer.println(getHtmlFileContentOrDefault(introductionHtmlFile, "<h1>" + manifestTitle + "</h1>"));

        writer.println("<table class='table table-striped table-hover'>");
        writer.println("  <hhead>");
        writer.println("    <tr>");
        writer.println("      <th>Manifest</th>");
        writer.println("      <th>Versions</th>");
        writer.println("    </tr>");
        writer.println("  </hhead>");
        writer.println("  <tbody>");
        for (Map.Entry<String, SortedSet<ManifestInfo>> entry : manifestMap.entrySet()) {
            String key = entry.getKey();
            SortedSet<ManifestInfo> set = entry.getValue();
            if (!set.isEmpty()) {
                ManifestInfo first = set.first();
                first.configure(this);
                if (!first.isValid()) {
                    continue;
                }

                String manifestDescription = getDescription(first);
                writer.println("    <tr>");
                writer.println("      <td title='" + manifestDescription + "'>");
                String iconHtml = "";
                String iconUrl = findIconURL(set);
                if (Strings.isNotBlank(iconUrl)) {
                    iconHtml = "<img class='logo' src='" + iconUrl + "'>";
                }
                writer.println("        " + iconHtml + "<span class='manifest-name'>" + key + "</span>");
                writer.println("      </td>");
                writer.println("      <td class='versions'>");
                int count = 0;
                for (ManifestInfo manifestInfo : set) {
                    if (maxVersionsPerApp > 0 && ++count > maxVersionsPerApp) {
                        break;
                    }
                    String description = getDescription(manifestInfo);
                    String version = manifestInfo.getVersion();
                    String href = kubernetes ? manifestInfo.getKubernetesUrl() : manifestInfo.getOpenShiftUrl();
                    String versionId = manifestInfo.getId();
                    String command = kubernetes ? "kubectl" : "oc";
                    writer.println(
                            "        <a class='btn btn-default' role='button' data-toggle='collapse' href='#"
                                    + versionId + "' aria-expanded='false' aria-controls='" + versionId
                                    + "' title='" + description + "'>\n" + version + "\n" + "</a>\n"
                                    + "<div class='collapse' id='" + versionId + "'>\n"
                                    + "  <div class='well'>\n" + "    <p>To install version <b>" + version
                                    + "</b> of <b>" + key + "</b> type the following command:</p>\n"
                                    + "    <code>" + command + " apply -f " + href + "</code>\n"
                                    + "    <div class='version-buttons'><a class='btn btn-primary' title='Download the YAML manifest for "
                                    + key + " version " + version + "' href='" + href
                                    + "'><i class='fa fa-download' aria-hidden='true'></i> Download Manifest</a> "
                                    + "<a class='btn btn-primary' target='gofabric8' title='Run this application via the go.fabric8.io website' href='https://go.fabric8.io/?manifest="
                                    + href
                                    + "'><i class='fa fa-external-link' aria-hidden='true'></i> Run via browser</a></div>\n"
                                    + "  </div>\n" + "</div>");
                }
                writer.println("      </td>");
                writer.println("    </tr>");
            }
        }
        writer.println("  </tbody>");
        writer.println("  </table>");
        writer.println(getHtmlFileContentOrDefault(footerHtmlFile, ""));
        writer.println("</body>");
    } catch (IOException e) {
        throw new MojoExecutionException("Failed to write to " + outputHtmlFile + ". " + e, e);
    }
}

From source file:io.fabric8.maven.plugin.mojo.internal.ManifestIndexMojo.java

protected void generateHTML(File outputHtmlFile, Map<String, ManifestInfo> manifests, boolean kubernetes,
        File introductionHtmlFile, File headHtmlFile, File footerHtmlFile) throws MojoExecutionException {
    Map<String, SortedSet<ManifestInfo>> manifestMap = new TreeMap<>();
    for (ManifestInfo manifestInfo : manifests.values()) {
        String key = manifestInfo.getName();
        SortedSet<ManifestInfo> set = manifestMap.get(key);
        if (set == null) {
            set = new TreeSet<>(createManifestComparator());
            manifestMap.put(key, set);/*from  w  w  w . j a va  2  s  .  c o  m*/
        }
        set.add(manifestInfo);
    }
    try (PrintWriter writer = new PrintWriter(new FileWriter(outputHtmlFile))) {
        writer.println("<html>");
        writer.println("<head>");
        writer.println(getHtmlFileContentOrDefault(headHtmlFile, "<link href='style.css' rel=stylesheet>\n"
                + "<link href='custom.css' rel=stylesheet>\n" + "<title>" + manifestTitle + "</title>\n"));
        writer.println("</head>");
        writer.println("<body>");

        writer.println(getHtmlFileContentOrDefault(introductionHtmlFile, "<h1>" + manifestTitle + "</h1>"));

        writer.println("<table class='table table-striped table-hover'>");
        writer.println("  <hhead>");
        writer.println("    <tr>");
        writer.println("      <th>Manifest</th>");
        writer.println("      <th>Versions</th>");
        writer.println("    </tr>");
        writer.println("  </hhead>");
        writer.println("  <tbody>");
        for (Map.Entry<String, SortedSet<ManifestInfo>> entry : manifestMap.entrySet()) {
            String key = entry.getKey();
            SortedSet<ManifestInfo> set = entry.getValue();
            if (!set.isEmpty()) {
                ManifestInfo first = set.first();
                first.configure(this);
                if (!first.isValid()) {
                    continue;
                }

                String manifestDescription = getDescription(first);
                writer.println("    <tr>");
                writer.println("      <td title='" + manifestDescription + "'>");
                String iconHtml = "";
                String iconUrl = findIconURL(set);
                if (Strings.isNotBlank(iconUrl)) {
                    iconHtml = "<img class='logo' src='" + iconUrl + "'>";
                }
                writer.println("        " + iconHtml + "<span class='manifest-name'>" + key + "</span>");
                writer.println("      </td>");
                writer.println("      <td class='versions'>");
                int count = 0;
                for (ManifestInfo manifestInfo : set) {
                    if (maxVersionsPerApp > 0 && ++count > maxVersionsPerApp) {
                        break;
                    }
                    String description = getDescription(manifestInfo);
                    String version = manifestInfo.getVersion();
                    String href = kubernetes ? manifestInfo.getKubernetesUrl() : manifestInfo.getOpenShiftUrl();
                    String versionId = manifestInfo.getId();
                    String command = kubernetes ? "kubectl" : "oc";
                    writer.println(
                            "        <a class='btn btn-default' role='button' data-toggle='collapse' href='#"
                                    + versionId + "' aria-expanded='false' aria-controls='" + versionId
                                    + "' title='" + description + "'>\n" + version + "\n" + "</a>\n"
                                    + "<div class='collapse' id='" + versionId + "'>\n"
                                    + "  <div class='well'>\n" + "    <p>To install version <b>" + version
                                    + "</b> of <b>" + key + "</b> type the following command:</p>\n"
                                    + "    <code>" + command + " apply -f " + href + "</code>\n"
                                    + "    <div class='version-buttons'><a class='btn btn-primary' title='Download the YAML manifest for "
                                    + key + " version " + version + "' href='" + href
                                    + "'><i class='fa fa-download' aria-hidden='true'></i> Download Manifest</a> "
                                    + "<a class='btn btn-primary' target='gofabric8' title='Run this application via the go.fabric8.io website' href='https://go.fabric8.io/?manifest="
                                    + href
                                    + "'><i class='fa fa-external-link' aria-hidden='true'></i> Run via browser</a></div>\n"
                                    + "  </div>\n" + "</div>");
                }
                writer.println("      </td>");
                writer.println("    </tr>");
            }
        }
        writer.println("  </tbody>");
        writer.println("  </table>");
        writer.println(getHtmlFileContentOrDefault(footerHtmlFile, ""));
        writer.println("</body>");
    } catch (IOException e) {
        throw new MojoExecutionException("Failed to write to " + outputHtmlFile + ". " + e, e);
    }
}