@Override protected Object doExecute() throws Exception { TablePrinter printer = new TablePrinter(); printer.column("id"); List<String> containers = clusterService.getEnsembleContainers(); if (containers != null) { for (String container : containers) { printer.row(container); } } printer.print(); return null; }
/** * Returns a list of text lines for easier printing on other output formats */ public List<String> asTextLines() { String text = asText(); List<String> list = new ArrayList<>(); StringTokenizer iter = new StringTokenizer(text, "\n"); while (iter.hasMoreTokens()) { list.add(iter.nextToken()); } return list; }
TablePrinter table = new TablePrinter("MyTest","OtherTest","SillyColumn"); table.addRow("ABC","DEF","GHIJKLMNOPQRSTUVWXYZ"); table.addRow("This is a test","of the","TablePrinter class"); table.print();
protected void printVersions(Container[] containers, List<String> versions, String defaultVersionId, PrintStream out) { TablePrinter table = new TablePrinter(); table.columns("version", "default", "# containers", "description"); // they are sorted in the correct order by default for (String versionId : versions) { boolean isDefault = versionId.equals(defaultVersionId); Version version = profileService.getRequiredVersion(versionId); int active = countContainersByVersion(containers, version); String description = version.getAttributes().get(Version.DESCRIPTION); table.row(version.getId(), (isDefault ? "true" : ""), activeContainerCountText(active), description); } table.print(); }
protected String textResult(ProjectOverviewDTO project) { StringBuilder buffer = new StringBuilder("\n\n"); Set<String> perspectives = project.getPerspectives(); TablePrinter table = new TablePrinter(); table.columns("perspective"); for (String perspective : perspectives) { table.row(perspective); } addTableTextOutput(buffer, null, table); Set<String> builders = project.getBuilders(); table = new TablePrinter(); table.columns("builder"); for (String builder : builders) { table.row(builder); } addTableTextOutput(buffer, null, table); return buffer.toString(); }
public void print() { print(System.out); }
/** * Defines the columns of the table */ public void columns(String... headers) { for (String header : headers) { // force lazy creation column(header); } }
protected void printStatus(PrintStream out, AutoScaleStatus status) { TablePrinter table = new TablePrinter(); table.columns("auto scale profile", "status", "message"); List<AutoScaleProfileStatus> profileStatuses = status.getProfileStatuses(); for (AutoScaleProfileStatus profile : profileStatuses) { table.row(getStringOrBlank(profile.getProfile()), getStringOrBlank(profile.getStatus()), getStringOrBlank(profile.getMessage())); } table.print(); } }
protected String textResult(ProjectDto projectDto) { StringBuilder buffer = new StringBuilder("\n\n"); FunktionConfig config = projectDto.getConfig(); if (config != null) { List<FunktionRule> rules = config.getRules(); if (rules != null && !rules.isEmpty()) { TablePrinter table = new TablePrinter(); table.columns("name", "trigger", "action", "chain"); for (FunktionRule rule : rules) { table.row(rule.getName(), rule.getTrigger(), rule.getAction(), rule.getChain()); } addTableTextOutput(buffer, "Rules", table); } } return buffer.toString(); } }
public void print() { print(System.out); }
/** * Defines the columns of the table */ public void columns(String... headers) { for (String header : headers) { // force lazy creation column(header); } }
@Override protected void printRequirements(PrintStream out, FabricRequirements requirements) { TablePrinter table = new TablePrinter(); table.columns("profile", "# minimum", "# maximum", "depends on"); List<ProfileRequirements> profileRequirements = requirements.getProfileRequirements(); for (ProfileRequirements profile : profileRequirements) { table.row(profile.getProfile(), getStringOrBlank(profile.getMinimumInstances()), getStringOrBlank(profile.getMaximumInstances()), getStringOrBlank(profile.getDependentProfiles())); } table.print(); }
@Override protected Object doExecute() throws Exception { IOpenShiftConnection connection = getOrCreateConnection(); TablePrinter printer = new TablePrinter(); printer.column("id"); for (IDomain domain :connection.getDomains()){ printer.row(domain.getId()); } printer.print(); return null; } }
public void print(final PrintStream out) { print(new TableWriter() { @Override public String toString() { return "PrintStreamTableWriter()"; } @Override public void print(String text) { out.print(text); } @Override public void println() { out.println(); } }); }
/** * Adds a new row of values */ public void row(String... values) { int columnIndex = 0; for (String value : values) { Column column = column(columnIndex++); if (value != null) { int length = value.length(); column.ensureWidth(length); } } rows.add(values); }
public static void addTableTextOutput(StringBuilder buffer, String title, TablePrinter table) { if (Strings.isNotBlank(title)) { buffer.append(title); buffer.append(":\n\n"); } buffer.append(table.asText()); buffer.append("\n"); }
@Override protected Object doExecute() throws Exception { IOpenShiftConnection connection = getOrCreateConnection(); TablePrinter printer = new TablePrinter(); printer.columns("domain", "application id"); for (IDomain domain : connection.getDomains()) { if (domainId == null || domainId.equals(domain.getId())) { String displayDomain = domain.getId(); domain.refresh(); for (IApplication application : domain.getApplications()) { printer.row(displayDomain, application.getName()); displayDomain = ""; } } } printer.print(); return null; } }
/** * Prints the table as a text string */ public String asText() { ByteArrayOutputStream out = new ByteArrayOutputStream(); print(new PrintStream(out)); return new String(out.toByteArray()); }
/** * Adds a new row of values */ public void row(String... values) { int columnIndex = 0; for (String value : values) { Column column = column(columnIndex++); if (value != null) { int length = value.length(); column.ensureWidth(length); } } rows.add(values); }
protected void printProfiles(ProfileService profileService, List<Profile> profiles, PrintStream out) { TablePrinter table = new TablePrinter(); table.columns("id", "# containers", "parents"); for (Profile profile : profiles) { String versionId = profile.getVersion(); String profileId = profile.getId(); // skip profiles that do not exists (they may have been deleted) if (profileService.hasProfile(versionId, profileId) && (hidden || !profile.isHidden())) { int active = fabricService.getAssociatedContainers(versionId, profileId).length; String parents = Strings.join(profile.getParentIds(), " "); table.row(profileId, activeContainerCountText(active), parents); } } table.print(); }