Example usage for org.apache.commons.lang3 StringUtils rightPad

List of usage examples for org.apache.commons.lang3 StringUtils rightPad

Introduction

In this page you can find the example usage for org.apache.commons.lang3 StringUtils rightPad.

Prototype

public static String rightPad(final String str, final int size) 

Source Link

Document

Right pad a String with spaces (' ').

The String is padded to the size of size .

 StringUtils.rightPad(null, *)   = null StringUtils.rightPad("", 3)     = "   " StringUtils.rightPad("bat", 3)  = "bat" StringUtils.rightPad("bat", 5)  = "bat  " StringUtils.rightPad("bat", 1)  = "bat" StringUtils.rightPad("bat", -1) = "bat" 

Usage

From source file:com.netflix.genie.web.data.entities.AgentConnectionEntityTest.java

/**
 * Verify validated fields value.//from   w  ww .  ja v a 2  s  . c o m
 */
@Test
public void cantCreateAgentConnectionEntityDueToSize() {

    final List<Pair<String, String>> invalidParameterPairs = Lists.newArrayList();

    invalidParameterPairs.add(Pair.of(JOB, null));
    invalidParameterPairs.add(Pair.of(null, HOST));
    invalidParameterPairs.add(Pair.of(JOB, " "));
    invalidParameterPairs.add(Pair.of(" ", HOST));
    invalidParameterPairs.add(Pair.of(StringUtils.rightPad(JOB, 256), HOST));
    invalidParameterPairs.add(Pair.of(JOB, StringUtils.rightPad(HOST, 256)));

    for (final Pair<String, String> invalidParameters : invalidParameterPairs) {
        final AgentConnectionEntity entity = new AgentConnectionEntity(invalidParameters.getLeft(),
                invalidParameters.getRight());

        try {
            this.validate(entity);
        } catch (final ConstraintViolationException e) {
            // Expected, move on to the next pair.
            continue;
        }

        Assert.fail("Entity unexpectedly passed validation: " + entity.toString());
    }
}

From source file:com.daraf.projectdarafprotocol.clienteapp.ingresos.IngresoFacturaRQ.java

@Override
public void build(String input) {
    if (validate(input)) {
        //            if (input.length() == 1 && input.equals("2")) {
        //                //no se ha registrado correctamente la factura
        ////from   w  w w. j av a2  s . co  m
        //            } else 
        if (input.length() < 2000) {
            input = StringUtils.rightPad(input, 2000);
        }
        try {
            String facturaValues[] = MyStringUtil.splitByFixedLengths(input,
                    new int[] { 10, 20, 4, 8, 10, 1948 });
            this.idFactura = facturaValues[0];
            this.identificacion = facturaValues[1];
            this.numeroDetalles = facturaValues[2];
            this.fecha = facturaValues[3];
            this.total = facturaValues[4];
            int numFacturas = Integer.parseInt(this.numeroDetalles);
            String detalleValues[] = StringUtils.splitPreserveAllTokens(facturaValues[5], FIELD_SEPARATOR_CHAR);

            if (detalles == null) {
                detalles = new ArrayList<>();
            } else {
                detalles.clear();
            }
            int stringIndex = 0;

            DetalleFacturaAppRQ f = null;
            for (int i = 0; i < numFacturas; i++) {
                f = new DetalleFacturaAppRQ();
                f.setIdProducto(detalleValues[stringIndex].trim());
                stringIndex++;
                f.setCantidad(detalleValues[stringIndex].trim());
                stringIndex++;
                this.detalles.add(f);
            }
        } catch (Exception ex) {
            Logger.getLogger(IngresoFacturaRQ.class.getName()).log(Level.SEVERE, null, ex);
        }

    }
}

From source file:jclparser.NewClass.java

public static File analyze(File f) {

    String procedure = StringUtils.substringBeforeLast(f.getName(), ".");

    if (f.exists()) {
        f.delete();/*w w  w. j a va2 s .  c o m*/
    }

    System.out.println("gepeto args2 = " + procedure);

    String tmp;

    PROC proc = parse(PROC.class, "SYS1.VIDA.PROCLIB", procedure);

    List<STEP> steps = proc.getListSTEP();

    List<String> nodes = new ArrayList<>();
    List<String> fromsTos = new ArrayList<>();

    String nodeTemplate = "{\"key\": \"%s\", \"category\": \"program\", \"color\": \"lightblue\", \"label\": \"%s\", \"num\": \"%s\", \"card\": \"%s\"},";
    String dsnTemplate = "{\"key\": \"%s\", \"color\": \"magenta\", \"label\": \"%s\"},";
    String fromToTemplate = "{\"from\": \"%s\", \"to\": \"%s\"},";

    Map<String, Integer> programs = new HashMap<>();
    Set<String> files = new HashSet<>();

    for (STEP step : steps) {
        String pgm = step.getProgram().getName();
        String xxx = "";

        CARD card = step.getProgram().getCard();
        if (card != null) {
            if (card instanceof CARD_IKJEFT01) {
                pgm = ((CARD_IKJEFT01) card).getProgram();
            }

            xxx = step.getProgram().getCard().toString();

            System.out.println("VVV " + step.getProgram().getCard().toString());
            //                if (card instanceof CARD_SORT) {
            //                    pgm = ((CARD_SORT) card).getProgram();
            //                }
        }

        Integer num = programs.get(pgm);
        num = num == null ? 1 : num + 1;
        programs.put(pgm, num);

        if (num > 1) {
            pgm = pgm + " (" + num + ")";
        }

        String t = String.format(nodeTemplate, pgm, "XXX", "XXX", xxx);

        nodes.add(t);

        List<DSN> dsns = step.getListDSN();
        for (DSN dsn : dsns) {
            if (dsn.getName().trim().isEmpty()) {
                continue;
            }

            if (files.add(dsn.getName())) {

                String u = String.format(dsnTemplate, dsn.getName(), dsn.getLabel());
                files.add(nodeTemplate);
                nodes.add(u);
            }

            String from = dsn.getMode().equals("INPUT") ? dsn.getName() : pgm;
            String to = !dsn.getMode().equals("INPUT") ? dsn.getName() : pgm;
            tmp = String.format(fromToTemplate, from, to);

            if (!pgm.equalsIgnoreCase("COPIADOR")) {
                fromsTos.add(tmp);
            }

            System.out.println("Label: " + StringUtils.rightPad(dsn.getLabel(), 8) + " Dsn: " + dsn.getName()
                    + " Type: " + dsn.getType() + " Mode: " + dsn.getMode());
        }
    }

    String lastNode = nodes.remove(nodes.size() - 1);
    lastNode = StringUtils.removeEnd(lastNode, ",");
    nodes.add(lastNode);
    String lastFromsTos = fromsTos.remove(fromsTos.size() - 1);
    lastFromsTos = StringUtils.removeEnd(lastFromsTos, ",");
    fromsTos.add(lastFromsTos);

    try {
        FileUtils.writeStringToFile(f, "{\"class\": \"go.GraphLinksModel\",\"nodeDataArray\": [", true);
        FileUtils.writeLines(f, nodes, true);
        FileUtils.writeStringToFile(f, "],", true);
        FileUtils.writeStringToFile(f, "\"linkDataArray\": [", true);
        FileUtils.writeLines(f, fromsTos, true);
        FileUtils.writeStringToFile(f, "]}", true);
    } catch (IOException ex) {
        Logger.getLogger(NewClass.class.getName()).log(Level.SEVERE, null, ex);
    }

    System.out.println("directoru " + f.getAbsolutePath());

    //        for (String node : nodes) {
    //            System.out.println(node + ",");
    //        }
    //
    //        for (String fromTo : fromsTos) {
    //            System.out.println(fromTo + ",");
    //        }
    return f;
}

From source file:de.micromata.genome.logging.spi.ifiles.IndexDirectory.java

private static String fileToStoredName(File logFile) {
    String name = getDirectoryNameFromFile(logFile);
    String lwwrite = StringUtils.substring(name, 0, LOG_FILE_NAME_SIZE);
    lwwrite = StringUtils.rightPad(lwwrite, LOG_FILE_NAME_SIZE);
    return lwwrite;
}

From source file:l1j.server.server.command.executor.L1Equipment.java

public List<String> getOutput(L1PcInstance pc) {
    List<String> list = new ArrayList<String>();
    List<L1ItemInstance> val = new ArrayList<L1ItemInstance>();
    String[] col = new String[] { "weapon", "shield", "armor", "helm", "boots", "cloak", "amulet", "earring",
            "belt", "glove", "ring(1)", "ring(2)", "ring(3)" };
    val.add(pc.getInventory().getEquippedWeapon());
    val.add(pc.getInventory().getEquippedShield());
    val.add(pc.getInventory().getEquippedArmor());
    val.add(pc.getInventory().getEquippedHelm());
    val.add(pc.getInventory().getEquippedBoots());
    val.add(pc.getInventory().getEquippedCloak());
    val.add(pc.getInventory().getEquippedAmulet());
    val.add(pc.getInventory().getEquippedEarring());
    val.add(pc.getInventory().getEquippedBelt());
    val.add(pc.getInventory().getEquippedGlove());
    L1ItemInstance[] ring = pc.getInventory().getRingEquipped();
    val.add(ring[0]);
    val.add(ring[1]);
    val.add(pc.getInventory().getEquippedRing2());

    for (int i = 0; i < val.size() && i < col.length; ++i) {
        list.add(StringUtils.rightPad(col[i], 8) + ":"
                + (val.get(i) == null ? "none" : val.get(i).getLogName()));
    }/*w  ww  .  j a v a 2  s. c  o  m*/
    return list;
}

From source file:basedefense.client.ClientProxy.java

/**
 * Executes a version check using GitHub's API.
 *///from  w w w.  ja v  a  2  s .com
private void executeVersionCheck() {
    BaseDefenseModification.getInstance().getLogger().info("Version Check");
    long initializationTime = System.currentTimeMillis();

    if (!Boolean.valueOf(System.getProperty("basedefense.disableVersionCheck", "false"))) {
        this.latestVersion = (new ModificationVersionCheck()).check();
        this.latestVersion.ifPresent(v -> {
            if (v.equalsIgnoreCase(BaseDefenseModification.getInstance().getVersion()))
                return;

            BaseDefenseModification.getInstance().getLogger().warn("+--------------------------------+");
            BaseDefenseModification.getInstance().getLogger().warn("+          Base Defense          +");
            BaseDefenseModification.getInstance().getLogger().warn("+          is outdated!          +");
            BaseDefenseModification.getInstance().getLogger().warn("+--------------------------------+");
            BaseDefenseModification.getInstance().getLogger().warn("+  The support for this version  +");
            BaseDefenseModification.getInstance().getLogger().warn("+  has been discontinued.        +");
            BaseDefenseModification.getInstance().getLogger().warn("+  Please update to a newer      +");
            BaseDefenseModification.getInstance().getLogger().warn("+  release!                      +");
            BaseDefenseModification.getInstance().getLogger().warn("+--------------------------------+");
            BaseDefenseModification.getInstance().getLogger().warn("+  Installed: "
                    + StringUtils.rightPad(BaseDefenseModification.getInstance().getVersion(), 17) + "  +");
            BaseDefenseModification.getInstance().getLogger()
                    .warn("+  Latest:    " + StringUtils.rightPad(v, 17) + "  +");
            BaseDefenseModification.getInstance().getLogger().warn("+--------------------------------+");
        });
    } else {
        this.latestVersion = Optional.empty();

        BaseDefenseModification.getInstance().getLogger().warn("+---------------------------------+");
        BaseDefenseModification.getInstance().getLogger().warn("+          VERSION CHECK          +");
        BaseDefenseModification.getInstance().getLogger().warn("+             DISABLED            +");
        BaseDefenseModification.getInstance().getLogger().warn("+---------------------------------+");
        BaseDefenseModification.getInstance().getLogger().warn("+  Installed: "
                + StringUtils.rightPad(BaseDefenseModification.getInstance().getVersion(), 18) + "  +");
        BaseDefenseModification.getInstance().getLogger().warn("+---------------------------------+");
    }

    BaseDefenseModification.getInstance().getLogger()
            .info("Version Check ended (took " + (System.currentTimeMillis() - initializationTime) + " ms)");
}

From source file:com.movies.mapped.Person.java

private String getStringWithPadding(final String string, final int paddingType) {
    if (StringUtils.isNotBlank(string)) {
        switch (paddingType) {
        case MovieConstants.LEFT_PAD:
            return StringUtils.leftPad(string, string.length() + 1);
        case MovieConstants.RIGHT_PAD:
            return StringUtils.rightPad(string, string.length() + 1);
        default:// www.  ja va2 s. c  o  m
            throw new IllegalArgumentException("String should be padded either from left or right!");
        }
    } else {
        return "";
    }
}

From source file:de.micromata.genome.logging.spi.ifiles.IndexHeader.java

public void writeFileHeader(OutputStream os, File indexFile, IndexDirectory indexDirectory) throws IOException {
    indexDirectoryIdx = indexDirectory.createNewLogIdxFile(indexFile);
    ByteBuffer lbb = ByteBuffer.wrap(new byte[Long.BYTES]);
    ByteBuffer ibb = ByteBuffer.wrap(new byte[Integer.BYTES]);
    os.write(INDEX_FILE_TYPE);//from   ww w  . ja v a2 s.  c om
    os.write(INDEX_FILE_VERSION);
    lbb.putLong(0, System.currentTimeMillis());
    os.write(lbb.array());
    ibb.putInt(0, indexDirectoryIdx);
    os.write(ibb.array());
    ByteArrayOutputStream bout = new ByteArrayOutputStream();
    for (Pair<String, Integer> headerp : headerOrder) {
        String hn = StringUtils.rightPad(headerp.getFirst(), HEADER_NAME_LENGTH);
        bout.write(hn.getBytes());
        ibb.putInt(0, headerp.getSecond());
        bout.write(ibb.array());
    }
    byte[] headerar = bout.toByteArray();
    int idxOffset = FILE_TYPE_LENGTH + FILE_VERSION_LENGTH + Long.BYTES /* timestamp */
            + Integer.BYTES /** indexDirectory */
            + Integer.BYTES /* indexOfset */
            + headerar.length;
    ibb.putInt(0, idxOffset);
    os.write(ibb.array());
    os.write(headerar);
    os.flush();
}

From source file:io.konik.zugferd.RandomInvoiceTest.java

@Test
//   @Ignore("Until Random Generator is correct.")
public void validateRandomInvoice() {
    //setup/*from   w w w  .  jav  a2s . c  om*/
    //      Class<?>[] validationGroups = InvoiceValidator.resolveIntoValidationGroups(invoice.getContext().getGuideline().getConformanceLevel());

    //execute
    Set<ConstraintViolation<Invoice>> validationResult = validator.validate(randomInvoice);

    //verify
    if (!validationResult.isEmpty()) {
        System.out.println("Validation Errors:");
        for (ConstraintViolation<Invoice> constraintViolation : validationResult) {
            String left = StringUtils.rightPad(constraintViolation.getPropertyPath().toString(), 100);
            System.out.println(left + constraintViolation.getMessage() + " invalid value is: "
                    + constraintViolation.getInvalidValue());
        }
        assertThat(validationResult).as("See System out for details").isEmpty();
    }
}

From source file:net.morimekta.idltool.cmd.RemoteList.java

@Override
public void execute(IdlTool idlTool) throws IOException {
    Meta localMeta = idlTool.getLocalMeta();

    boolean first = true;

    for (String repository : idlTool.getIdl().getRepositories()) {
        try {/* ww  w. j ava  2s  .co m*/
            Meta meta = idlTool.getRepositoryMeta(repository);
            int longestRemote = Math.max(30,
                    meta.getRemotes().keySet().stream().mapToInt(String::length).max().orElse(0));

            if (first) {
                first = false;
            } else {
                System.out.println();
            }

            if (meta.getRemotes().isEmpty()) {
                System.out.println(format("%s%s%s is empty.", new Color(Color.YELLOW, Color.BOLD), repository,
                        Color.CLEAR));
                continue;
            }

            System.out.println(format("%s%s%s", Color.GREEN, repository, Color.CLEAR));
            System.out.println(format("%s%s - %s - %s%s", new Color(Color.YELLOW, Color.BOLD),
                    StringUtils.center("<<-- remote -->>    ", longestRemote),
                    StringUtils.center("remote date", 19), StringUtils.center("local date", 19), Color.CLEAR));

            for (Map.Entry<String, Remote> remoteEntry : meta.getRemotes().entrySet().stream()
                    .sorted(comparator()).collect(Collectors.toList())) {
                Remote local = localMeta.getRemotes().get(remoteEntry.getKey());

                boolean change = false;
                if (local != null && remoteEntry.getValue().getTime() != local.getTime()) {
                    change = true;
                }

                System.out.println(format("%s%s - %s - %s%s", change ? Color.YELLOW : Color.CLEAR,
                        StringUtils.rightPad(remoteEntry.getKey(), longestRemote),
                        StringUtils.rightPad(formatAgo(remoteEntry.getValue().getTime()), 19),
                        local == null ? "" : formatAgo(local.getTime()), Color.CLEAR));
            }
        } catch (Exception e) {
            System.out.println("Bad repository " + repository + ": " + e.getMessage());
        }
    }
}