@Stellar(name="IS_DOMAIN" ,description = "Tests if a string refers to a valid domain name. Domain names are evaluated according" + " to the standards RFC1034 section 3, and RFC1123 section 2.1." ,params = { "address - The string to test" } , returns = "True if the string refers to a valid domain name and false if otherwise") public static class IS_DOMAIN extends Predicate2StellarFunction { public IS_DOMAIN() { super(new DomainValidation()); } }
@Test public void ensureDocumentation() { ClassLoader classLoader = getClass().getClassLoader(); int numFound = 0; for (Class<?> clazz : new ClasspathFunctionResolver().resolvables()) { if (clazz.isAnnotationPresent(Stellar.class)) { numFound++; Stellar annotation = clazz.getAnnotation(Stellar.class); Assert.assertFalse("Must specify a name for " + clazz.getName(),StringUtils.isEmpty(annotation.name())); Assert.assertFalse("Must specify a description annotation for " + clazz.getName(),StringUtils.isEmpty(annotation.description())); Assert.assertFalse("Must specify a returns annotation for " + clazz.getName(), StringUtils.isEmpty(annotation.returns())); } } Assert.assertTrue(numFound > 0); }
/** * Resolves a Stellar function from a given class. * @param clazz The class. */ public static StellarFunctionInfo resolveFunction(Class<? extends StellarFunction> clazz) { StellarFunctionInfo info = null; // the class must be annotated if (clazz.isAnnotationPresent(Stellar.class)) { Stellar annotation = clazz.getAnnotation(Stellar.class); String fullyQualifiedName = getNameFromAnnotation(annotation); StellarFunction function = createFunction(clazz); if (fullyQualifiedName != null && function != null) { info = new StellarFunctionInfo( annotation.description(), fullyQualifiedName, annotation.params(), annotation.returns(), function); } } return info; }
/** * Returns the fully-qualified function name from a Stellar annotation. * @param annotation The Stellar annotation. */ public static String getNameFromAnnotation(Stellar annotation) { // find the function name String name = annotation.name(); if(name == null || name.trim().length() == 0) { return null; } else { name = name.trim(); } // find the function namespace String namespace = annotation.namespace(); if(namespace == null || namespace.length() == 0) { namespace = null; } else { namespace = namespace.trim(); } return Joiner.on("_").skipNulls().join(Arrays.asList(namespace, name)); }
@Stellar( name="TO_LOWER" , description = "Transforms the first argument to a lowercase string" , params = { "input - String" } , returns = "Lowercase string" ) public static class ToLower extends BaseStellarFunction { @Override public Object apply(List<Object> strings) { return strings.get(0)==null?null:strings.get(0).toString().toLowerCase(); } }
@Stellar(name="TO_STRING" , description = "Transforms the first argument to a string" , params = { "input - Object" } , returns = "String" ) public static class ToString extends BaseStellarFunction { @Override public Object apply(List<Object> strings) { return strings.get(0)==null?null:strings.get(0).toString(); } }
@Stellar(name="LOG2" ,description="Returns the log (base 2) of a number." ,params = { "number - The number to take the log (base 2) value of" } , returns="The log (base 2) of the number passed in." ) public static class Log2 extends StellarMathFunction { public Log2() { super(MathOperations.LOG2); } }
@Stellar(name="TAN" ,description="Returns the tangent of a number." ,params = { "number - The number to take the tangent of" } , returns="The tangent of the number passed in." ) public static class Tan extends StellarMathFunction { public Tan() { super(MathOperations.TAN); } }
@Stellar(name="ROUND" ,description="Rounds a number to the nearest integer. This is half-up rounding." ,params = { "number - The number to round" } , returns="The nearest integer (based on half-up rounding)." ) public static class Round extends StellarMathFunction { public Round() { super(MathOperations.ROUND); } }
@Stellar(namespace="LOCAL" ,name="LS" ,description="Lists the contents of a directory" ,params = { "path - The path of the file." } ,returns = "The contents of the directory in tabular form sorted by last modification date." ) public static class FileLs extends FileSystemLs { public FileLs() { super(FS_TYPE.LOCAL); } }
@Stellar(namespace="HDFS" ,name="READ" ,description="Retrieves the contents as a string of a file in HDFS." ,params = { "path - The path in HDFS of the file."} ,returns = "The contents of the file in the path from HDFS and null otherwise." ) public static class HDFSGet extends FileSystemGet { public HDFSGet() { super(FS_TYPE.HDFS); } }
@Stellar(name="TO_LONG" , description="Transforms the first argument to a long integer" , params = { "input - Object of string or numeric type"} , returns = "Long version of the first argument" ) public static class TO_LONG extends Cast<Long> { public TO_LONG() { super(Long.class); } }
@Stellar(name="TO_FLOAT" , description="Transforms the first argument to a float" , params = { "input - Object of string or numeric type"} , returns = "Float version of the first argument" ) public static class TO_FLOAT extends Cast<Float> { public TO_FLOAT() { super(Float.class); } } }
@Stellar(name="LOG10" ,description="Returns the log (base 10) of a number." ,params = { "number - The number to take the log (base 10) value of" } , returns="The log (base 10) of the number passed in." ) public static class Log10 extends StellarMathFunction { public Log10() { super(MathOperations.LOG10); } }
@Stellar(name="IS_IP" , description = "Determine if an string is an IP or not." , params = { "ip - An object which we wish to test is an ip" ,"type (optional) - Object of string or collection type (e.g. list) one of IPV4 or IPV6 or both. The default is IPV4." } , returns = "True if the string is an IP and false otherwise.") public static class IS_IP extends Predicate2StellarFunction { public IS_IP() { super(new IPValidation()); } }
@Stellar(name="IS_EMAIL" ,description = "Tests if a string is a valid email address" ,params = { "address - The string to test" } , returns = "True if the string is a valid email address and false if otherwise.") public static class IS_EMAIL extends Predicate2StellarFunction { public IS_EMAIL() { super(new EmailValidation()); } }
@Stellar(name="TO_DOUBLE" , description="Transforms the first argument to a double precision number" , params = { "input - Object of string or numeric type"} , returns = "Double version of the first argument" ) public static class TO_DOUBLE extends Cast<Double> { public TO_DOUBLE() { super(Double.class); } }
@Stellar(name="LN" ,description="Returns the natural log of a number." ,params = { "number - The number to take the natural log value of" } , returns="The natural log of the number passed in." ) public static class Ln extends StellarMathFunction { public Ln() { super(MathOperations.LN); } }
@Stellar(name="SQRT" ,description="Returns the square root of a number." ,params = { "number - The number to take the square root of" } , returns="The square root of the number passed in." ) public static class Sqrt extends StellarMathFunction { public Sqrt() { super(MathOperations.SQRT); } }
@Stellar(name="CEILING" ,description="Returns the ceiling of a number." ,params = { "number - The number to take the ceiling of" } , returns="The ceiling of the number passed in." ) public static class Ceil extends StellarMathFunction { public Ceil() { super(MathOperations.CEIL); } }