use of java.util.StringJoiner in project oc-explorer by devgateway.
the class ExcelSheetDefault method writeRowFlattenObject.
/**
* Function to flat export an array of objects. Example:
* [{
* x: aaa,
* y: bbb,
* },{
* x: ccc,
* y: ddd,
* }]
*
* Will be printed as:
* | x | y |
* | aaa ; bbb | ccc ; ddd |
*
* @param clazz
* @param objects
* @param row
*/
private void writeRowFlattenObject(final Class clazz, final List<Object> objects, final Row row) {
final Iterator<Field> fields = ExcelFieldService.getFields(clazz);
while (fields.hasNext()) {
final Field field = fields.next();
final FieldType fieldType = ExcelFieldService.getFieldType(field);
try {
switch(fieldType) {
case basic:
final int coll = getFreeColl(row);
final StringJoiner flattenValue = new StringJoiner(" | ");
for (final Object obj : objects) {
final Object value = getFieldValue(field, obj);
if (value != null) {
flattenValue.add(value.toString());
}
}
writeHeaderLabel(field, row, coll);
writeCell(flattenValue.toString(), row, coll);
break;
case object:
if (ExcelFieldService.isCollection(field)) {
logger.error("Unsupported operation for field: '" + field.getName() + "'! You can not " + "flatten an array of objects that contains other array of objects");
} else {
headerPrefix.push(ExcelFieldService.getFieldName(field));
final Class fieldClass = ExcelFieldService.getFieldClass(field);
final List<Object> newObjects = new ArrayList();
for (Object obj : objects) {
final Object value = getFieldValue(field, obj);
if (value != null) {
newObjects.add(value);
}
}
writeRowFlattenObject(fieldClass, newObjects, row);
headerPrefix.pop();
}
break;
case objectSeparateSheet:
logger.error("Unsupported operation for field: '" + field.getName() + "'! You can not flatten " + "an array of objects that contains objects that need to be printed in other sheet.");
break;
default:
logger.error("Undefined field type");
break;
}
} catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
logger.error(e);
}
}
}
use of java.util.StringJoiner in project oc-explorer by devgateway.
the class ExcelSheetDefault method getHeaderPrefix.
/**
* Compute the header prefix for the current object.
*/
private String getHeaderPrefix() {
if (headerPrefix.isEmpty()) {
return "";
}
final StringJoiner header = new StringJoiner("/");
final Enumeration<String> elements = headerPrefix.elements();
while (elements.hasMoreElements()) {
header.add(elements.nextElement());
}
return header.toString() + "/";
}
use of java.util.StringJoiner in project elastic-core-maven by OrdinaryDude.
the class FullTextTrigger method indexRow.
/**
* Index a row
*
* @param row Row column data
* @throws SQLException Unable to index row
*/
private void indexRow(Object[] row) throws SQLException {
indexLock.readLock().lock();
try {
String query = tableName + ";" + columnNames.get(dbColumn) + ";" + (Long) row[dbColumn];
Document document = new Document();
document.add(new StringField("_QUERY", query, Field.Store.YES));
long now = System.currentTimeMillis();
document.add(new TextField("_MODIFIED", DateTools.timeToString(now, DateTools.Resolution.SECOND), Field.Store.NO));
document.add(new TextField("_TABLE", tableName, Field.Store.NO));
StringJoiner sj = new StringJoiner(" ");
for (int index : indexColumns) {
String data = (row[index] != null ? (String) row[index] : "NULL");
document.add(new TextField(columnNames.get(index), data, Field.Store.NO));
sj.add(data);
}
document.add(new TextField("_DATA", sj.toString(), Field.Store.NO));
indexWriter.updateDocument(new Term("_QUERY", query), document);
} catch (IOException exc) {
Logger.logErrorMessage("Unable to index row", exc);
throw new SQLException("Unable to index row", exc);
} finally {
indexLock.readLock().unlock();
}
}
use of java.util.StringJoiner in project opennms by OpenNMS.
the class GraphPainter method getStyleName.
/**
* Cannot return null
*/
private String getStyleName(Edge edge) {
final String styleName = edge.getStyleName();
final StringJoiner stringJoiner = new StringJoiner(" ");
if (!Strings.isNullOrEmpty(styleName)) {
stringJoiner.add(styleName);
}
if (isSelected(m_graphContainer.getSelectionManager(), edge)) {
stringJoiner.add("selected");
}
String status = getEdgeStatus(edge);
if (!Strings.isNullOrEmpty(status)) {
stringJoiner.add(status);
}
return stringJoiner.toString();
}
use of java.util.StringJoiner in project bazel by bazelbuild.
the class MavenDownloader method getDownloadDestination.
private Path getDownloadDestination(Artifact artifact) {
String groupIdPath = artifact.getGroupId().replace('.', '/');
String artifactId = artifact.getArtifactId();
String version = artifact.getVersion();
String filename = artifactId + '-' + version + '.' + artifact.getExtension();
StringJoiner joiner = new StringJoiner("/");
joiner.add(groupIdPath).add(artifactId).add(version).add(filename);
return outputDirectory.getRelative(joiner.toString());
}
Aggregations