You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@brooklyn.apache.org by GitBox <gi...@apache.org> on 2022/02/07 10:09:16 UTC

[GitHub] [brooklyn-server] algairim opened a new pull request #1297: New functionals to apply to an iterable: generic AllEqualsFunction an…

algairim opened a new pull request #1297:
URL: https://github.com/apache/brooklyn-server/pull/1297


   …d a sub-functin AllTrueFunction to check if all true in particular
   
   Signed-off-by: Mykola Mandra <my...@cloudsoft.io>


-- 
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.

To unsubscribe, e-mail: dev-unsubscribe@brooklyn.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [brooklyn-server] algairim commented on a change in pull request #1297: New functionals to apply to an iterable: generic AllEqualsFunction an…

Posted by GitBox <gi...@apache.org>.
algairim commented on a change in pull request #1297:
URL: https://github.com/apache/brooklyn-server/pull/1297#discussion_r800567823



##########
File path: utils/common/src/main/java/org/apache/brooklyn/util/collections/CollectionFunctionals.java
##########
@@ -119,6 +115,35 @@ public T apply(Iterable<? extends T> input) {
         @Override public String toString() { return "firstElementFunction"; }
     }
 
+    public static class AllEqualsFunction implements Function<Iterable<?>, Comparable<?>> {
+        private final Comparable<?> value;
+
+        public AllEqualsFunction(Comparable<?> value) {
+            if (Objects.isNull(value)) {
+                throw new IllegalArgumentException("The value to compare all to must be defined");
+            }
+            this.value = value;
+        }
+
+        @Override
+        public Boolean apply(@Nullable Iterable<?> input) {
+            if (Objects.isNull(input) || Iterables.isEmpty(input)) return null;

Review comment:
       Documented in 568af812d307c52c6cb7f1abbb6e363526ddd3ec




-- 
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.

To unsubscribe, e-mail: dev-unsubscribe@brooklyn.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [brooklyn-server] algairim commented on a change in pull request #1297: New functionals to apply to an iterable: generic AllEqualsFunction an…

Posted by GitBox <gi...@apache.org>.
algairim commented on a change in pull request #1297:
URL: https://github.com/apache/brooklyn-server/pull/1297#discussion_r800511537



##########
File path: utils/common/src/main/java/org/apache/brooklyn/util/collections/CollectionFunctionals.java
##########
@@ -119,6 +115,35 @@ public T apply(Iterable<? extends T> input) {
         @Override public String toString() { return "firstElementFunction"; }
     }
 
+    public static class AllEqualsFunction implements Function<Iterable<?>, Comparable<?>> {
+        private final Comparable<?> value;
+
+        public AllEqualsFunction(Comparable<?> value) {
+            if (Objects.isNull(value)) {
+                throw new IllegalArgumentException("The value to compare all to must be defined");
+            }
+            this.value = value;
+        }
+
+        @Override
+        public Boolean apply(@Nullable Iterable<?> input) {
+            if (Objects.isNull(input) || Iterables.isEmpty(input)) return null;

Review comment:
       This should address your doubt @jcabrerizo 




-- 
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.

To unsubscribe, e-mail: dev-unsubscribe@brooklyn.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [brooklyn-server] jcabrerizo commented on a change in pull request #1297: New functionals to apply to an iterable: generic AllEqualsFunction an…

Posted by GitBox <gi...@apache.org>.
jcabrerizo commented on a change in pull request #1297:
URL: https://github.com/apache/brooklyn-server/pull/1297#discussion_r800516429



##########
File path: utils/common/src/main/java/org/apache/brooklyn/util/collections/CollectionFunctionals.java
##########
@@ -119,6 +115,35 @@ public T apply(Iterable<? extends T> input) {
         @Override public String toString() { return "firstElementFunction"; }
     }
 
+    public static class AllEqualsFunction implements Function<Iterable<?>, Comparable<?>> {
+        private final Comparable<?> value;
+
+        public AllEqualsFunction(Comparable<?> value) {
+            if (Objects.isNull(value)) {
+                throw new IllegalArgumentException("The value to compare all to must be defined");
+            }
+            this.value = value;
+        }
+
+        @Override
+        public Boolean apply(@Nullable Iterable<?> input) {
+            if (Objects.isNull(input) || Iterables.isEmpty(input)) return null;

Review comment:
       Agree, but for me, it looks like we need to have flag for do not evaluate unless is not empty or not null. 
   Yes, the use of `brooklyn:attributeWhenReady` will help, but if only the function used, the transformer will return null if the source sensor is not returning a false value.
   
   I'm happy to approve but please, add some comments explaining why it will return `null` comparing with an empty collection




-- 
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.

To unsubscribe, e-mail: dev-unsubscribe@brooklyn.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [brooklyn-server] algairim commented on a change in pull request #1297: New functionals to apply to an iterable: generic AllEqualsFunction an…

Posted by GitBox <gi...@apache.org>.
algairim commented on a change in pull request #1297:
URL: https://github.com/apache/brooklyn-server/pull/1297#discussion_r800508180



##########
File path: utils/common/src/main/java/org/apache/brooklyn/util/collections/CollectionFunctionals.java
##########
@@ -119,6 +115,35 @@ public T apply(Iterable<? extends T> input) {
         @Override public String toString() { return "firstElementFunction"; }
     }
 
+    public static class AllEqualsFunction implements Function<Iterable<?>, Comparable<?>> {
+        private final Comparable<?> value;
+
+        public AllEqualsFunction(Comparable<?> value) {
+            if (Objects.isNull(value)) {
+                throw new IllegalArgumentException("The value to compare all to must be defined");
+            }
+            this.value = value;
+        }
+
+        @Override
+        public Boolean apply(@Nullable Iterable<?> input) {
+            if (Objects.isNull(input) || Iterables.isEmpty(input)) return null;

Review comment:
       In the real scenario we cannot say if it is true or false since there is nothing to compare yet, hence, we return null. This will mean that the result sensor will have no value until there is something certain to compare, as in example below:
   ```
   # Calculates process status of the group - all must be 'RUNNING'
   - type: org.apache.brooklyn.enricher.stock.Aggregator
     brooklyn.config:
       enricher.sourceSensor: $brooklyn:sensor("my.custom.app.isRunning")
       enricher.targetSensor: $brooklyn:sensor("service.process.isRunning")
       enricher.aggregating.fromMembers: true
       enricher.transformation:
         $brooklyn:object:
           type: "org.apache.brooklyn.util.collections.CollectionFunctionals$AllTrueFunction"
   ```
   
   Returning `false` prematurely could be misleading @jcabrerizo.




-- 
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.

To unsubscribe, e-mail: dev-unsubscribe@brooklyn.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [brooklyn-server] algairim commented on a change in pull request #1297: New functionals to apply to an iterable: generic AllEqualsFunction an…

Posted by GitBox <gi...@apache.org>.
algairim commented on a change in pull request #1297:
URL: https://github.com/apache/brooklyn-server/pull/1297#discussion_r800511017



##########
File path: utils/common/src/main/java/org/apache/brooklyn/util/collections/CollectionFunctionals.java
##########
@@ -119,6 +115,35 @@ public T apply(Iterable<? extends T> input) {
         @Override public String toString() { return "firstElementFunction"; }
     }
 
+    public static class AllEqualsFunction implements Function<Iterable<?>, Comparable<?>> {
+        private final Comparable<?> value;
+
+        public AllEqualsFunction(Comparable<?> value) {
+            if (Objects.isNull(value)) {
+                throw new IllegalArgumentException("The value to compare all to must be defined");
+            }
+            this.value = value;
+        }
+
+        @Override
+        public Boolean apply(@Nullable Iterable<?> input) {
+            if (Objects.isNull(input) || Iterables.isEmpty(input)) return null;

Review comment:
       Moreover, if there is a DSL watching this `$brooklyn:attributeWhenReady("service.process.isRunning")`, then it will wait until there is a value to read.




-- 
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.

To unsubscribe, e-mail: dev-unsubscribe@brooklyn.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [brooklyn-server] jcabrerizo merged pull request #1297: New functionals to apply to an iterable: generic AllEqualsFunction an…

Posted by GitBox <gi...@apache.org>.
jcabrerizo merged pull request #1297:
URL: https://github.com/apache/brooklyn-server/pull/1297


   


-- 
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.

To unsubscribe, e-mail: dev-unsubscribe@brooklyn.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [brooklyn-server] jcabrerizo commented on a change in pull request #1297: New functionals to apply to an iterable: generic AllEqualsFunction an…

Posted by GitBox <gi...@apache.org>.
jcabrerizo commented on a change in pull request #1297:
URL: https://github.com/apache/brooklyn-server/pull/1297#discussion_r800503666



##########
File path: utils/common/src/main/java/org/apache/brooklyn/util/collections/CollectionFunctionals.java
##########
@@ -119,6 +115,35 @@ public T apply(Iterable<? extends T> input) {
         @Override public String toString() { return "firstElementFunction"; }
     }
 
+    public static class AllEqualsFunction implements Function<Iterable<?>, Comparable<?>> {
+        private final Comparable<?> value;
+
+        public AllEqualsFunction(Comparable<?> value) {
+            if (Objects.isNull(value)) {
+                throw new IllegalArgumentException("The value to compare all to must be defined");
+            }
+            this.value = value;
+        }
+
+        @Override
+        public Boolean apply(@Nullable Iterable<?> input) {
+            if (Objects.isNull(input) || Iterables.isEmpty(input)) return null;

Review comment:
       I think it should return `false` if the input is empty or null unless the comparable is an empty iterable or a null value.
   
   Not sure how functional is my logic about 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.

To unsubscribe, e-mail: dev-unsubscribe@brooklyn.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org