Search in sources :

Example 51 with StringJoiner

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);
        }
    }
}
Also used : ArrayList(java.util.ArrayList) InvocationTargetException(java.lang.reflect.InvocationTargetException) Field(java.lang.reflect.Field) StringJoiner(java.util.StringJoiner)

Example 52 with StringJoiner

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() + "/";
}
Also used : StringJoiner(java.util.StringJoiner)

Example 53 with StringJoiner

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();
    }
}
Also used : SQLException(java.sql.SQLException) StringField(org.apache.lucene.document.StringField) TextField(org.apache.lucene.document.TextField) Term(org.apache.lucene.index.Term) IOException(java.io.IOException) Document(org.apache.lucene.document.Document) StringJoiner(java.util.StringJoiner)

Example 54 with StringJoiner

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();
}
Also used : StringJoiner(java.util.StringJoiner)

Example 55 with StringJoiner

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());
}
Also used : StringJoiner(java.util.StringJoiner)

Aggregations

StringJoiner (java.util.StringJoiner)98 ArrayList (java.util.ArrayList)22 List (java.util.List)11 IOException (java.io.IOException)6 HashSet (java.util.HashSet)6 Map (java.util.Map)6 HashMap (java.util.HashMap)4 Collectors (java.util.stream.Collectors)4 ClassName (com.squareup.javapoet.ClassName)3 FieldSpec (com.squareup.javapoet.FieldSpec)3 ParameterizedTypeName (com.squareup.javapoet.ParameterizedTypeName)3 TypeName (com.squareup.javapoet.TypeName)3 TypeSpec (com.squareup.javapoet.TypeSpec)3 Expression (com.sri.ai.expresso.api.Expression)3 Attribute (io.requery.meta.Attribute)3 Field (java.lang.reflect.Field)3 Scanner (java.util.Scanner)3 RaptorColumnHandle (com.facebook.presto.raptor.RaptorColumnHandle)2 Range (com.facebook.presto.spi.predicate.Range)2 MaterializedResult (com.facebook.presto.testing.MaterializedResult)2