List of usage examples for org.apache.commons.lang3 StringUtils overlay
public static String overlay(final String str, String overlay, int start, int end)
Overlays part of a String with another String.
A null string input returns null .
From source file:org.audit4j.core.DeIndentifyUtil.java
/** * Deidentify from left.//ww w . j a va2 s . c o m * * @param str the str * @param size the size * @return the string * * @since 2.0.0 */ public static String deidentifyFromLeft(String str, int size) { int end = str.length(); int repeat = 0; if (size > str.length()) { repeat = 0; } else { repeat = str.length() - size; } return StringUtils.overlay(str, StringUtils.repeat('*', repeat), size, end); }
From source file:org.audit4j.core.DeIndentifyUtil.java
/** * Deidentify from right.//w w w . jav a 2s .com * * @param str the str * @param size the size * @return the string * * @since 2.0.0 */ public static String deidentifyFromRight(String str, int size) { int end = str.length(); int repeat = 0; if (size > str.length()) { repeat = str.length(); } else { repeat = end - size; } return StringUtils.overlay(str, StringUtils.repeat('*', repeat), 0, end - size); }
From source file:org.audit4j.core.DeIndentifyUtil.java
/** * Deidentify middle./*from w ww . j a v a 2s. c o m*/ * * @param str the str * @param start the start * @param end the end * @return the string * * @since 2.0.0 */ public static String deidentifyMiddle(String str, int start, int end) { int repeat = 0; if (end - start > str.length()) { repeat = str.length(); } else { repeat = (str.length() - end) - start; } return StringUtils.overlay(str, StringUtils.repeat('*', repeat), start, str.length() - end); }
From source file:VCF.Genotype.java
/** * Change a particular piece of data associated with the genotype * @param name The format of the data to be changed (as a string) * @param value The new value//from w w w .j a v a 2 s. co m * @throws VCF.Exceptions.VCFNoDataException If there is a no data for the * requested format */ public void replaceData(String name, String value) throws VCFNoDataException { List<String> format = position.getFormat(); int pos = format.indexOf(name); if (pos == -1) { throw new VCFNoDataException("No data field called " + name); } String info = geno.getInfo(); int start = 0; if (pos > 0) { start = StringUtils.ordinalIndexOf(info, ":", pos) + 1; } int end = info.length(); if (pos < format.size() - 1) { end = StringUtils.ordinalIndexOf(info, ":", pos + 1); } geno.setInfo(StringUtils.overlay(info, value, start, end)); }
From source file:VCF.Genotype.java
/** * Remove data for the given format. It is up to the caller to ensure the * appropriate format is removed from the position. * @param name The name of the format data to remove * @throws VCFNoDataException If there is no data field with that name *//*from w w w. j a v a 2 s. com*/ public void removeData(String name) throws VCFNoDataException { List<String> format = position.getFormat(); int pos = format.indexOf(name); if (pos == -1) { throw new VCFNoDataException("No data field called " + name); } String info = geno.getInfo(); int start = 0; if (pos > 0) { start = StringUtils.ordinalIndexOf(info, ":", pos); } int end = info.length(); if (pos < format.size() - 1) { end = StringUtils.ordinalIndexOf(info, ":", pos + 1); } geno.setInfo(StringUtils.overlay(info, "", start, end)); }