metron-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ottobackwards <...@git.apache.org>
Subject [GitHub] incubator-metron pull request #370: METRON-586 add FILL_LEFT and FILL_RIGHT ...
Date Sun, 04 Dec 2016 04:01:34 GMT
Github user ottobackwards commented on a diff in the pull request:

    https://github.com/apache/incubator-metron/pull/370#discussion_r90770168
  
    --- Diff: metron-platform/metron-common/src/main/java/org/apache/metron/common/dsl/functions/StringFunctions.java
---
    @@ -222,4 +222,71 @@ public Object apply(List<Object> args) {
           return null;
         }
       }
    +
    +  private enum FillDirection{
    +    LEFT,
    +    RIGHT
    +  }
    +
    +  @Stellar(name="FILL_LEFT"
    +          , description="Fills or pads a given string with a given character, to a given
length on the left"
    +          , params = { "input - string", "fill - the fill character", "len - the required
length"}
    +          , returns = "Filled String"
    +  )
    +  public static class FillLeft extends BaseStellarFunction {
    +    @Override
    +    public Object apply(List<Object> args) {
    +      if(args.size() < 3) {
    +        throw new IllegalStateException("FILL_LEFT expects three args: [string,char,length]
where char is the fill character string and length is the required length of the result");
    +      }
    +      return fill(FillDirection.LEFT,args.get(0),args.get(1),args.get(2));
    +    }
    +  }
    +
    +  @Stellar(name="FILL_RIGHT"
    +          , description="Fills or pads a given string with a given character, to a given
length on the right"
    +          , params = { "input - string", "fill - the fill character", "len - the required
length"}
    +          , returns = "Filled String"
    +  )
    +  public static class FillRight extends BaseStellarFunction {
    +    @Override
    +    public Object apply(List<Object> args) {
    +      if(args.size() < 3) {
    +        throw new IllegalStateException("FILL_RIGHT expects three args: [string,char,length]
where char is the fill character string and length is the required length of the result");
    +      }
    +      return fill(FillDirection.RIGHT,args.get(0),args.get(1),args.get(2));
    +    }
    +  }
    +
    +  private static Object fill(FillDirection direction, Object inputObject, Object fillObject,
Object requiredLengthObject){
    +    if(inputObject == null) {
    +      return null;
    +    }
    +    String input = inputObject.toString();
    +
    +    if(requiredLengthObject == null || fillObject == null) {
    +      return input;
    --- End diff --
    
    I agree, that is a malformed expression, I'll modify


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

Mime
View raw message