List of usage examples for org.apache.commons.lang3 StringUtils splitPreserveAllTokens
public static String[] splitPreserveAllTokens(final String str, final String separatorChars)
Splits the provided text into an array, separators specified, preserving all tokens, including empty tokens created by adjacent separators.
From source file:com.daraf.projectdarafprotocol.appdb.consultas.ConsultaProductoRS.java
@Override public void build(String input) { if (validate(input)) { if (input.length() < 401) { input = StringUtils.rightPad(input, 73, " "); }/*from w w w. j a va 2 s. com*/ try { String values[] = MyStringUtil.splitByFixedLengths(input, new int[] { 1, 72 }); this.resultado = values[0]; if (this.resultado.equals("1")) { String productoValues[] = StringUtils.splitPreserveAllTokens(values[1], Cuerpo.FIELD_SEPARATOR_CHAR); this.producto = new Producto(); this.producto.setId(productoValues[0]); this.producto.setNombre(productoValues[1]); this.producto.setPrecio(productoValues[2]); this.producto.setCantidad(productoValues[3]); } } catch (Exception ex) { Logger.getLogger(ConsultaProductoRS.class.getName()).log(Level.SEVERE, null, ex); } } }
From source file:com.khartec.waltz.jobs.sample.MeasurablesGenerator.java
private static void generateRegions(DSLContext dsl) throws IOException { List<String> lines = readLines(OrgUnitGenerator.class.getResourceAsStream("/regions.csv")); System.out.println("Deleting existing Regions & Countries ..."); int deletedCount = dsl.deleteFrom(MEASURABLE) .where(MEASURABLE.MEASURABLE_CATEGORY_ID .in(DSL.select(MEASURABLE_CATEGORY.ID).from(MEASURABLE_CATEGORY) .where(MEASURABLE_CATEGORY.EXTERNAL_ID.eq(REGION_CATEGORY_EXTERNAL_ID)))) .and(MEASURABLE.PROVENANCE.eq("demo")).execute(); System.out.println("Deleted: " + deletedCount + " existing Regions & Countries"); Map<String, Map<String, Set<String>>> regionHierarchy = lines.stream().skip(1) .map(line -> StringUtils.splitPreserveAllTokens(line, ",")) .filter(cells -> notEmpty(cells[0]) && notEmpty(cells[6]) && notEmpty(cells[5])) .map(cells -> Tuple.tuple(cells[0], cells[6], cells[5])) .collect(groupingBy(t -> t.v3, groupingBy(t -> t.v2, mapping(t -> t.v1, toSet())))); final long measurableCategoryId = dsl.select(MEASURABLE_CATEGORY.ID).from(MEASURABLE_CATEGORY) .where(MEASURABLE_CATEGORY.EXTERNAL_ID.eq(REGION_CATEGORY_EXTERNAL_ID)).fetchAny().value1(); AtomicInteger insertCount = new AtomicInteger(0); regionHierarchy.forEach((region, subRegionMap) -> { final long regionId = dsl.insertInto(MEASURABLE) .set(createRegion(null, region, measurableCategoryId, false)).returning(MEASURABLE.ID) .fetchOne().getId();/*from ww w. j a v a2 s. com*/ insertCount.incrementAndGet(); subRegionMap.forEach((subRegion, countries) -> { final long subRegionId = dsl.insertInto(MEASURABLE) .set(createRegion(regionId, subRegion, measurableCategoryId, true)).returning(MEASURABLE.ID) .fetchOne().getId(); insertCount.incrementAndGet(); insertCount.addAndGet(dsl.batchInsert(countries.stream() .map(country -> createRegion(subRegionId, country, measurableCategoryId, true)) .collect(toList())).execute().length); }); }); System.out.println("Inserted: " + insertCount + " Regions & Countries"); }
From source file:ml.shifu.core.util.CommonUtils.java
public static String[] loadHeader(InputStream is, String delimiter) { Set<String> nameSet = new HashSet<>(); try (Scanner scanner = new Scanner(is)) { String headerLine = scanner.nextLine().trim(); if (StringUtils.isEmpty(headerLine)) { throw new MalformedDataException("Header is empty"); }// w w w .jav a 2 s.c o m LOG.info("Delimiter: " + delimiter); String[] header = StringUtils.splitPreserveAllTokens(headerLine, delimiter); LOG.info("Number of Fields: " + header.length); LOG.info(Arrays.toString(header)); for (int i = 0; i < header.length; i++) { header[i] = header[i].trim(); if (StringUtils.isEmpty(header[i])) { throw new MalformedDataException("Field is empty: #" + i + ", " + headerLine); } if (nameSet.contains(header[i])) { throw new MalformedDataException("Duplicated field names: " + header[i]); } nameSet.add(header[i]); } return header; } }
From source file:com.daraf.projectdarafprotocol.clienteapp.consultas.ConsultaProductoRS.java
@Override public void build(String input) { if (validate(input)) { if (input.length() < 73) { input = StringUtils.rightPad(input, 73, " "); }//from w w w . j a v a 2 s . c o m try { String values[] = MyStringUtil.splitByFixedLengths(input, new int[] { 1, 72 }); this.resultado = values[0]; if (this.resultado.equals("1")) { String productoValues[] = StringUtils.splitPreserveAllTokens(values[1], Cuerpo.FIELD_SEPARATOR_CHAR); this.producto = new Producto(); this.producto.setId(productoValues[0]); this.producto.setNombre(productoValues[1]); this.producto.setPrecio(productoValues[2]); this.producto.setCantidad(productoValues[3]); } } catch (Exception ex) { Logger.getLogger(ConsultaProductoRS.class.getName()).log(Level.SEVERE, null, ex); } } }
From source file:com.espe.distribuidas.pmaldito.servidorbdd.operaciones.Archivo.java
/** * permite obtener la tabla de la trama/*from www. j a v a 2 s .co m*/ * * @param string * @return */ public static String tabla(String string) { String partes[] = StringUtils.splitPreserveAllTokens(string, "_"); return StringUtils.stripEnd(partes[1], "0"); }
From source file:io.wcm.config.core.management.impl.PersistenceTypeConversion.java
/** * Convert object from persistence to be used in configuration. * @param value Persisted value// w w w . j a v a 2 s . com * @param parameterType Parameter type * @return Configured value */ public static Object fromPersistenceType(Object value, Class<?> parameterType) { if (!isTypeConversionRequired(parameterType)) { return value; } if (Map.class.isAssignableFrom(parameterType) && (value instanceof String[])) { String[] rows = (String[]) value; Map<String, String> map = new LinkedHashMap<>(); for (int i = 0; i < rows.length; i++) { String[] keyValue = StringUtils.splitPreserveAllTokens(rows[i], KEY_VALUE_DELIMITER); if (keyValue.length == 2 && StringUtils.isNotEmpty(keyValue[0])) { map.put(keyValue[0], StringUtils.isEmpty(keyValue[1]) ? null : keyValue[1]); } } return map; } throw new IllegalArgumentException("Type conversion not supported: " + parameterType.getName()); }
From source file:com.daraf.projectdarafprotocol.appdb.consultas.ConsultaFacturaRS.java
@Override public void build(String input) { if (validate(input)) { if (input.length() < 500) { input = StringUtils.rightPad(input, 500); }// w w w. j a v a2s . co m try { String facturaValues[] = MyStringUtil.splitByFixedLengths(input, new int[] { 1, 10, 1, 8, 1, 10, 1, 10, 1, 4, 453 }); this.resultado = facturaValues[0]; this.factura = new Factura(); this.factura.setId(facturaValues[1]); this.factura.setFecha(facturaValues[3]); this.factura.setTotal(facturaValues[5]); this.factura.setIdentificacionCliente(facturaValues[7]); this.factura.setNumeroDetalles(facturaValues[9]); String detalleValues[] = StringUtils.splitPreserveAllTokens(facturaValues[10], FIELD_SEPARATOR_CHAR); List<DetalleFacturaAppRQ> detallesFactura; detallesFactura = new ArrayList<>(); int stringIndex = 0; int valora = Integer.parseInt(this.factura.getNumeroDetalles().trim()); int valor = valora * 2; String detalleValores[] = new String[valor]; int j = 0; for (int i = 0; i < detalleValues.length; i++) { if (i != 0 && i != detalleValues.length - 1) { detalleValores[j] = detalleValues[i]; j++; } } DetalleFacturaAppRQ f = null; for (int i = 0; i < Integer.parseInt(this.factura.getNumeroDetalles().trim()); i++) { f = new DetalleFacturaAppRQ(); f.setIdProducto(detalleValores[stringIndex].trim()); stringIndex++; f.setCantidad(detalleValores[stringIndex].trim()); stringIndex++; detallesFactura.add(f); } this.factura.setDetalles(detallesFactura); } catch (Exception ex) { Logger.getLogger(IngresoFacturaRQ.class.getName()).log(Level.SEVERE, null, ex); } } }
From source file:com.espe.distribuidas.pmaldito.servidorbdd.operaciones.Consultar.java
/** * Metodo que permite recuperar un registro de una tabla en funcion de un * campo regular, recibe la tabla, el numero de columna en donde tiene que * consultar y el valor que hay que comparar en ese columna * * @param tabla/*from w w w.j a v a 2 s .c o m*/ * @param numColumna * @param valorColumna * @return */ @SuppressWarnings({ "ConvertToTryWithResources", "element-type-mismatch" }) public ArrayList campoRegular(String tabla, Integer numColumna, String valorColumna) { @SuppressWarnings("MismatchedQueryAndUpdateOfCollection") ArrayList<String> datosRegistro = new ArrayList<>(); String string; try { FileReader fr = new FileReader(tabla); BufferedReader br = new BufferedReader(fr); while ((string = br.readLine()) != null) { if (string.length() > 0) { String registro[] = StringUtils.splitPreserveAllTokens(string, "|"); if (registro[numColumna].equalsIgnoreCase(valorColumna)) { datosRegistro.addAll(Arrays.asList(registro)); break; } } else { break; } } br.close(); } catch (FileNotFoundException e) { System.err.println(e); } catch (IOException e1) { System.err.println(e1); } return datosRegistro; }
From source file:com.daraf.projectdarafprotocol.appdb.ingresos.IngresoFacturaRQ.java
@Override public void build(String input) { if (validate(input)) { if (input.length() < 2000) { input = StringUtils.rightPad(input, 2000); }/*from w w w . j a va 2 s . c om*/ try { String values[] = MyStringUtil.splitByFixedLengths(input, new int[] { 10, 20, 8, 10, 4, 1948 }); this.idFactura = values[0]; this.identificacionCliente = values[1]; this.fecha = values[2]; this.total = values[3]; this.numeroDetalles = values[4]; int num = Integer.parseInt(numeroDetalles); int stringIndex = 0; Detalle det = null; String detallesValue[] = StringUtils.splitPreserveAllTokens(values[5], FIELD_SEPARATOR_CHAR); if (detalles == null) { detalles = new ArrayList<>(); } else { detalles.clear(); } for (int i = 0; i < num; i++) { det = new Detalle(); det.setIdFactura(detallesValue[stringIndex].trim()); stringIndex++; det.setIdProducto(detallesValue[stringIndex].trim()); stringIndex++; det.setNombreProducto(detallesValue[stringIndex].trim()); stringIndex++; det.setCantidad(detallesValue[stringIndex].trim()); stringIndex++; this.detalles.add(det); } } catch (Exception ex) { System.out.println("" + ex); } } }
From source file:au.com.addstar.SpigotUpdater.java
private static void loadPlugins(List<String> search) { if (datFile.exists()) { long start = System.currentTimeMillis(); try {/*from w w w .j av a 2 s.c om*/ BufferedReader b = new BufferedReader(new FileReader(datFile)); String l; while ((l = b.readLine()) != null) { if (!l.startsWith("#")) { String[] lineArray = StringUtils.splitPreserveAllTokens(l, ","); if (lineArray.length != 0) { String pluginName = lineArray[0]; String type = lineArray[1]; String source = lineArray[2]; String url = lineArray[3]; if (source.equals("SPIGOT")) { String resourceID = lineArray[4]; Plugin plugin = new Plugin(); plugin.setName(pluginName); plugin.setType(type); plugin.setUrl(url); plugin.setResourceID(Integer.parseInt(resourceID)); plugin.setLatestFile(); plugin.setLatestVer(); if (plugin.getVersion() == null) plugin.setVersion(""); if (plugin.getLastUpdated() == null) plugin.setLastUpdated(new Date(0L)); if (search.size() > 0) { for (String needle : search) { if (pluginName.startsWith(needle)) { plugins.add(plugin); } } } else { plugins.add(plugin); } plugins.sort(getComparator()); } } } } } catch (IOException e) { e.printStackTrace(); } long total = System.currentTimeMillis() - start; } }