nifi-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] [nifi] mgaido91 commented on a change in pull request #3615: NIFI-6500 Support Padding functions in Expression Language
Date Wed, 31 Jul 2019 20:13:22 GMT
mgaido91 commented on a change in pull request #3615: NIFI-6500 Support Padding functions in
Expression Language
URL: https://github.com/apache/nifi/pull/3615#discussion_r309410305
 
 

 ##########
 File path: nifi-commons/nifi-expression-language/src/main/java/org/apache/nifi/attribute/expression/language/evaluation/functions/PaddingEvaluator.java
 ##########
 @@ -0,0 +1,72 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.nifi.attribute.expression.language.evaluation.functions;
+
+import org.apache.nifi.attribute.expression.language.evaluation.Evaluator;
+import org.apache.nifi.attribute.expression.language.evaluation.EvaluatorState;
+import org.apache.nifi.attribute.expression.language.evaluation.QueryResult;
+import org.apache.nifi.attribute.expression.language.evaluation.StringQueryResult;
+import org.apache.nifi.attribute.expression.language.evaluation.StringEvaluator;
+
+import java.util.Map;
+
+abstract class PaddingEvaluator extends StringEvaluator {
+
+    public static final char DEFAULT_PADDING_CHARACTER = '_';
+
+    private final Evaluator<String> subject;
+    private final Evaluator<Long> desiredLength;
+    private final Evaluator<String> pad;
+
+    PaddingEvaluator( final Evaluator<String> subject,
+                             final Evaluator<Long> desiredLength,
+                             final Evaluator<String> pad) {
+        this.subject = subject;
+        this.desiredLength = desiredLength;
+        this.pad = pad;
+    }
+
+    @Override
+    public QueryResult<String> evaluate(final Map<String, String> attributes,
final EvaluatorState context) {
+        final String subjectValue = subject.evaluate(attributes, context).getValue();
+        if (subjectValue == null) {
+            return new StringQueryResult(null);
+        }
+        final Long desiredLengthValue = desiredLength.evaluate(attributes, context).getValue();
+        if(desiredLengthValue == null || desiredLengthValue > Integer.MAX_VALUE) {
+            return new StringQueryResult(null);
+        }
+
+        char padValue;
 
 Review comment:
   yes. `StringUtils` you're using has a method for that.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

Mime
View raw message