List of usage examples for org.apache.commons.lang3 StringUtils repeat
public static String repeat(final char ch, final int repeat)
From source file:org.jamocha.dn.NetworkToDot.java
public NetworkToDot(final SideEffectFunctionToNetwork network, final String... rules) { super();//w ww .j a v a 2s . c o m Arrays.sort(rules); for (final TerminalNode terminalNode : network.getTerminalNodes()) { final String ruleName = terminalNode.getRule().getParent().getName(); if (rules.length != 0 && Arrays.binarySearch(rules, ruleName) < 0) { continue; } this.terminalNodes.put(terminalNode, ruleName); final Node sourceNode = terminalNode.getEdge().getSourceNode(); final Map<Template, String> template2Name = new HashMap<>(); final Map<Template, Integer> template2Occurences = new HashMap<>(); final List<Template> templates = Arrays.asList(sourceNode.getMemory().getTemplate()); final List<FactAddress> addresses = new ArrayList<>(Collections.nCopies(templates.size(), null)); final List<String> names = new ArrayList<>(Collections.nCopies(templates.size(), null)); for (int i = 0; i < templates.size(); i++) { final Template template = templates.get(i); String name = template2Name.get(template); if (null == name) { int length = 1; while (null == name || template2Name.containsValue(name)) { name = template.getName().substring(0, length++); } template2Name.put(template, name); } final Integer occurencesI = template2Occurences.get(template); int occurences = 0; if (null != occurencesI) { occurences = occurencesI; } occurences++; template2Occurences.put(template, occurences); name = name + StringUtils.repeat("'", occurences - 1); names.set(i, name); } final String sourceNodeName = getNodeName(sourceNode); sourceNode.accept(new GraphConstructingNodeVisitor(names, templates, addresses)); generateEdge(sourceNodeName, ruleName, "(" + String.join(", ", names) + ")"); } }
From source file:org.javabeanstack.util.Strings.java
/** * Replica "character" tantas veces "times" * @param character caracter a repetir /*from w w w. j a va2 s .c o m*/ * @param times cantidad de veces * @return repite un caracter tantas veces segn parmetro. */ public static String replicate(String character, int times) { return StringUtils.repeat(character, times); }
From source file:org.javabeanstack.util.Strings.java
/** * Reemplazara con un caracter "replace" cualquier valor dentro de "var" * que se encuentre comprendido entre caracteres "limit" * //from w ww.j a v a 2 s . co m * @param var * @param limit lista de caracteres limitadores. * @param replace caracter con que se reemplazara las posiciones entre * los caracteres "limit" * @return cadena procesada. */ public static String varReplace(String var, String limit, String replace) { String result = var; // Si esta vacio la variable if (Strings.isNullorEmpty(var) || Strings.isNullorEmpty(limit)) { return var; } String limit1, limit2; if (limit.length() == 2) { limit1 = StringUtils.left(limit, 1); limit2 = StringUtils.right(limit, 1); } else { limit1 = limit.substring(0, 1); limit2 = limit.substring(0, 1); } int c = 0, p1 = 0, p2 = 0, c2 = 0; while (true) { c = c + 1; p1 = findString(limit1, result, c); if (limit1.equals(limit2)) { c = c + 1; } p2 = findString(limit2, result, c); // Verificar que el caracter no sea un limitador interno if (!limit1.equals(limit2)) { c2 = c; while (p1 >= 0) { int innerLimit1 = occurs(limit1, result.substring(p1, p2)); int innerLimit2 = occurs(limit2, result.substring(p1, p2 + 1)); if (innerLimit2 == 0) { break; } if (innerLimit1 - innerLimit2 != 0) { c2 = c2 + innerLimit1 - innerLimit2; p2 = findString(limit2, result, c2); } else { break; } } } if (p1 == -1 || p2 == -1) { break; } result = StringUtils.left(result, p1 + 1) + StringUtils.repeat(replace, p2 - p1 - 1) + result.substring(p2); } return result; }
From source file:org.jpos.qi.system.SQLQueryObject.java
@Override public String toString() { try {/* w ww .j av a 2 s . c o m*/ Object res = DB.exec(db -> { StringBuilder sb = new StringBuilder(""); for (int n = 0; n < queries.length; n++) { String query = queries[n]; String title = titles[n]; int mxrows = maxRows[n]; sb.append(' ').append(title).append("\n\n"); db.session().doWork(new Work() { @Override public void execute(Connection connection) throws SQLException { PreparedStatement stmt = connection.prepareStatement(query); ResultSet rs = stmt.executeQuery(); ResultSetMetaData md = rs.getMetaData(); int cols = md.getColumnCount(); String[] header = new String[cols]; int[] colsize = new int[cols]; for (int i = 1; i <= cols; i++) { header[i - 1] = StringUtils.defaultIfEmpty(md.getColumnLabel(i), md.getColumnName(i)); colsize[i - 1] = header[i - 1].length(); } int rows = 0; String[][] out = new String[mxrows][cols]; while (rs.next() && rows < mxrows) { for (int i = 1; i <= cols; i++) { out[rows][i - 1] = rs.getString(i); if (out[rows][i - 1] == null) out[rows][i - 1] = " "; int l = out[rows][i - 1].length(); if (colsize[i - 1] < l) colsize[i - 1] = l; } rows++; } rs.close(); stmt.close(); StringBuilder sbSep = new StringBuilder(" "); sb.append(' '); for (int i = 1; i <= cols; i++) { if (isNumericDataType(md.getColumnType(i))) sb.append(StringUtils.leftPad(header[i - 1], colsize[i - 1])); else sb.append(StringUtils.rightPad(header[i - 1], colsize[i - 1])); sbSep.append(StringUtils.repeat('-', colsize[i - 1])); sb.append(' '); sbSep.append(' '); } sb.append('\n'); sbSep.append('\n'); sb.append(sbSep); for (int j = 0; j < rows; j++) { sb.append(' '); for (int i = 1; i <= cols; i++) { if (isNumericDataType(md.getColumnType(i))) sb.append(StringUtils.leftPad(out[j][i - 1], colsize[i - 1])); else sb.append(StringUtils.rightPad(out[j][i - 1], colsize[i - 1])); sb.append(' '); } sb.append('\n'); } sb.append(sbSep).append('\n'); } }); } sb.append(" Last refreshed at ").append(new Date()); return sb; }); return res.toString(); } catch (Exception e) { QI.getQI().getLog().error(e); return e.toString(); } }
From source file:org.kalypso.contribs.eclipse.core.runtime.StatusPrinter.java
public boolean print(final IStatus status) { final String severity = StatusUtilities.getLocalizedSeverity(status); if (status instanceof IStatusWithTime) { final Date time = ((IStatusWithTime) status).getTime(); m_pw.print(m_df.format(time));// ww w . ja va2s . com m_pw.print(' '); } m_pw.print(StringUtils.repeat(' ', m_indentation)); m_pw.print(severity); m_pw.print(": "); m_pw.print(status.getMessage()); final Throwable exception = status.getException(); if (exception != null) m_pw.format(" (Exception: %s)", exception.getLocalizedMessage()); final IStatus[] children = status.getChildren(); final StatusPrinter childrenPrinter = getChildPrinter(); for (final IStatus child : children) childrenPrinter.print(child); m_pw.println(); m_pw.flush(); return true; }
From source file:org.kalypso.core.status.CopyStatusClipboardAction.java
private static void printStatus(final PrintWriter pw, final IStatus status, final int level) { final String severity = StatusUtilities.getLocalizedSeverity(status); final String message = status.getMessage(); final String indent = StringUtils.repeat(" ", level * 4); //$NON-NLS-1$ pw.format("%s%s: %s%n", indent, severity, message); //$NON-NLS-1$ final Throwable exception = status.getException(); if (exception != null) { pw.println();//from w ww .jav a 2s . c om exception.printStackTrace(pw); } pw.println(); final IStatus[] children = status.getChildren(); for (final IStatus child : children) { printStatus(pw, child, level + 1); pw.println(); } pw.println(); }
From source file:org.kalypso.gmlschema.ui.GmlTreePrintVisitor.java
@Override public boolean visit(final Object element, final int indent) { final String space = StringUtils.repeat(". ", indent); //$NON-NLS-1$ final String text = m_labelProvider.getText(element); final String[] lines = text.split("\n"); //$NON-NLS-1$ for (final String line : lines) { m_buffer.append(space);//from w w w . j ava2s .c o m m_buffer.append(line); m_buffer.append("\n"); //$NON-NLS-1$ } return true; }
From source file:org.kalypso.kalypsomodel1d2d.conv.Control1D2DConverter.java
/** * writes out the time steps. <BR> * IMPORTANT: we write the dates in the time zone according to the kalypso-preferences! */// www. j a v a2s. co m private void writeTimeStep(final Formatter formatter, final String message, final Calendar calculationStep, final Calendar lastStepCal, final String uRVal, final int niti) throws CoreException, IOException { final String dashes = StringUtils.repeat("-", message.length()); //$NON-NLS-1$ formatter.format("com %s%n", dashes); //$NON-NLS-1$ formatter.format("com %s%n", message); //$NON-NLS-1$ formatter.format("com %s%n", dashes); //$NON-NLS-1$ final long timeStepInterval; final double timeStepMinutes; final int year; final int dayOfYear; final double ihre; final TimeZone displayTimeZone = KalypsoCorePlugin.getDefault().getTimeZone(); Calendar kalypsoCalendarStep = Calendar.getInstance(displayTimeZone); // unsteady if (calculationStep != null) { // REMARK: we write the date in the kalypso-preferences time zone! kalypsoCalendarStep.setTime(calculationStep.getTime()); dayOfYear = kalypsoCalendarStep.get(Calendar.DAY_OF_YEAR); year = kalypsoCalendarStep.get(Calendar.YEAR); // REMARK: we write the date in the kalypso-preferences time zone! final Calendar kalypsoCallendarPreviousStep = Calendar.getInstance(displayTimeZone); kalypsoCallendarPreviousStep.setTime(lastStepCal.getTime()); timeStepInterval = kalypsoCalendarStep.getTimeInMillis() - kalypsoCallendarPreviousStep.getTimeInMillis(); // FIXME: should never happen, kalypso does not allow summertime timezones any more // if timeStepInterval is zero, step will be ignored // (this will happen on summertime to wintertime transition) if (timeStepInterval == 0) { formatter.format(Messages.getString("org.kalypso.kalypsomodel1d2d.conv.Control1D2DConverter.14")); //$NON-NLS-1$ return; } timeStepMinutes = (double) timeStepInterval / (60 * 1000); ihre = getTimeInPercentage(kalypsoCalendarStep); } // steady dont need startdate else { kalypsoCalendarStep = null; dayOfYear = 0; year = 0; timeStepMinutes = 0; ihre = 0; } formatter.format("DT MIN %e%8d%8d%8.2f", timeStepMinutes, year, dayOfYear, ihre); //$NON-NLS-1$ // BC lines if (niti == 0) formatter.format("%nBC%n"); //$NON-NLS-1$ else formatBC(formatter, uRVal, niti); // order is important, first QC than HC, SQC and EFE formatBoundCondLines(formatter, kalypsoCalendarStep, Kalypso1D2DDictConstants.DICT_COMPONENT_TIME, Kalypso1D2DDictConstants.DICT_COMPONENT_DISCHARGE); formatBoundCondLines(formatter, kalypsoCalendarStep, Kalypso1D2DDictConstants.DICT_COMPONENT_TIME, Kalypso1D2DDictConstants.DICT_COMPONENT_WATERLEVEL); formatBoundCondLines(formatter, kalypsoCalendarStep, Kalypso1D2DDictConstants.DICT_COMPONENT_WATERLEVEL, Kalypso1D2DDictConstants.DICT_COMPONENT_DISCHARGE); FormatterUtils.checkIoException(formatter); for (final Map.Entry<Integer, IFlowRelationship> buildingData : m_buildingProvider.getBuildingData() .entrySet()) { final Integer buildingID = buildingData.getKey(); final IFlowRelationship building = buildingData.getValue(); final int buildingKind = 10; int lIntDirection = 0; if (building instanceof IBuildingFlowRelation) { if (((IBuildingFlowRelation) building).getKind() != KIND.TABULAR) { final String msg = Messages.getString( "org.kalypso.kalypsomodel1d2d.conv.Control1D2DConverter.43", //$NON-NLS-1$ ((IBuildingFlowRelation) building).getKind()); throw new CoreException(new Status(IStatus.ERROR, KalypsoModel1D2DPlugin.PLUGIN_ID, msg)); } lIntDirection = ((IBuildingFlowRelation) building).getDirection(); } else if (building instanceof IBuildingFlowRelation2D) { if (((IBuildingFlowRelation2D) building).getKind() != KIND2D.TABULAR) { final String msg = Messages.getString( "org.kalypso.kalypsomodel1d2d.conv.Control1D2DConverter.43", //$NON-NLS-1$ ((IBuildingFlowRelation) building).getKind()); throw new CoreException(new Status(IStatus.ERROR, KalypsoModel1D2DPlugin.PLUGIN_ID, msg)); } lIntDirection = ((IBuildingFlowRelation2D) building).getDirection(); } final double direction = Math.toRadians(lIntDirection); formatter.format("FC%14d%8d%8.3f%8.3f%8.3f%8.3f%8.3f%n", buildingID, buildingKind, 0.0, 0.0, 0.0, 0.0, //$NON-NLS-1$ direction); FormatterUtils.checkIoException(formatter); } formatBoundCondLines(formatter, kalypsoCalendarStep, Kalypso1D2DDictConstants.DICT_COMPONENT_TIME, Kalypso1D2DDictConstants.DICT_COMPONENT_SPECIFIC_DISCHARGE_1D); formatBoundCondLines(formatter, kalypsoCalendarStep, Kalypso1D2DDictConstants.DICT_COMPONENT_TIME, Kalypso1D2DDictConstants.DICT_COMPONENT_SPECIFIC_DISCHARGE_2D); // add other conti lines types as well (buildings)? if (m_controlModel.getHasWindDrag() && !m_boolPrintWindLineDone) { formatter.format("WVA 1.0 1.0 1%n"); //$NON-NLS-1$ m_boolPrintWindLineDone = true; } formatter.format("ENDSTEP %s%n", message); //$NON-NLS-1$ FormatterUtils.checkIoException(formatter); }
From source file:org.kalypso.model.wspm.tuhh.core.profile.export.knauf.base.KnaufProfileWrapper.java
public String getKennziffer(final IProfileRecord point) { final IProfilePointMarker[] markers = getPointMarkers(point); if (ArrayUtils.isEmpty(markers)) return StringUtils.repeat(" ", 2); //$NON-NLS-1$ for (final IProfilePointMarker marker : markers) { final IComponent component = marker.getComponent(); final String identifier = component.getId(); if (StringUtils.equals(IWspmTuhhConstants.MARKER_TYP_DURCHSTROEMTE, identifier)) { if (isLeftMarker(marker, identifier)) { return "PA";//$NON-NLS-1$ }/*from w w w. j ava 2 s . c o m*/ return "PE";//$NON-NLS-1$ } // else if( StringUtils.equals( IWspmTuhhConstants.MARKER_TYP_BORDVOLL, identifier ) ) // { // if( isLeftMarker( marker, identifier ) ) // { // return "LB";//$NON-NLS-1$ // } // // return "RB"; //$NON-NLS-1$ // } else if (StringUtils.equals(IWspmTuhhConstants.MARKER_TYP_TRENNFLAECHE, identifier)) { if (isLeftMarker(marker, identifier)) { return "LU";//$NON-NLS-1$ } return "RU";//$NON-NLS-1$ } } return StringUtils.repeat(" ", 2); //$NON-NLS-1$ }
From source file:org.kalypso.model.wspm.tuhh.core.profile.export.knauf.beans.KnaufSA30Bean.java
/** @return String of length 9 */ public String getDescription() { final int index = m_point.indexOfComponent(IWspmPointProperties.POINT_PROPERTY_COMMENT); if (index < 0) return StringUtils.repeat(" ", 9); //$NON-NLS-1$ final Object value = m_point.getValue(index); if (Objects.isNull(value)) return StringUtils.repeat(" ", 9); //$NON-NLS-1$ String description = value.toString(); if (description.length() == 9) return description; else if (description.length() > 9) return description.substring(0, 8); while (description.length() < 9) description += " "; //$NON-NLS-1$ return description; }