[GitHub] brooklyn-server pull request #555: Add DurationPredicates

2017-02-15 Thread asfgit
Github user asfgit closed the pull request at:

https://github.com/apache/brooklyn-server/pull/555


---
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 infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---


[GitHub] brooklyn-server pull request #555: Add DurationPredicates

2017-02-09 Thread grkvlt
Github user grkvlt commented on a diff in the pull request:

https://github.com/apache/brooklyn-server/pull/555#discussion_r100346521
  
--- Diff: 
utils/common/src/main/java/org/apache/brooklyn/util/time/DurationPredicates.java
 ---
@@ -0,0 +1,119 @@
+/*
+ * 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.brooklyn.util.time;
+
+import com.google.common.base.Predicate;
+import com.google.common.base.Stopwatch;
+
+public class DurationPredicates {
+
+/**
+ * @return A {@link Predicate} that checks if the {@link Duration} 
supplied
+ * to {@link Predicate#apply(Object)} is positive.
+ */
+public static Predicate isPositive() {
+return new Predicate() {
+@Override
+public boolean apply(Duration duration) {
+return duration != null && duration.isPositive();
+}
+};
+}
+
+/**
+ * @return A {@link Predicate} that checks if the {@link Duration} 
supplied
+ * to {@link Predicate#apply(Object)} is negative.
+ */
+public static Predicate isNegative() {
+return new Predicate() {
+@Override
+public boolean apply(Duration duration) {
+return duration != null && duration.isNegative();
+}
+};
+}
+
+/**
+ * @param duration
+ *The {@link Duration} that will be the basis for 
comparison in
+ *the returned {@link Predicate}.
+ * @return A {@link Predicate} that checks if the {@link Duration} 
that was
+ * supplied to this method is longer than any {@link Duration}
+ * supplied to to the returned {@link Predicate#apply(Object)}.
+ */
+public static Predicate isLongerThanDuration(final Duration 
duration) {
+return new Predicate() {
+@Override
+public boolean apply(Duration other) {
+return duration != null && other != null && 
duration.isLongerThan(other);
+}
+};
+}
+
+/**
+ * @param duration
+ *The {@link Duration} that will be the basis for 
comparison in
+ *the returned {@link Predicate}.
+ * @return A {@link Predicate} that checks if the {@link Duration} 
that was
+ * supplied to this method is longer than any {@link Stopwatch}
+ * supplied to the returned {@link Predicate#apply(Object)}.
+ */
+public static Predicate isLongerThanStopwatch(final 
Duration duration) {
+return new Predicate() {
+@Override
+public boolean apply(Stopwatch other) {
+return duration != null && other != null && 
duration.isLongerThan(other);
+}
+};
+}
+
+/**
+ * @param duration
+ *The {@link Duration} that will be the basis for 
comparison in
+ *the returned {@link Predicate}.
+ * @return A {@link Predicate} that checks if the {@link Duration} 
that was
+ * supplied to this method is shorter than any {@link Duration}
+ * supplied to to the returned {@link Predicate#apply(Object)}.
+ */
+public static Predicate isShorterThanDuration(final Duration 
duration) {
+return new Predicate() {
+@Override
+public boolean apply(Duration other) {
+return duration != null && other != null && 
duration.isShorterThan(other);
--- End diff --

Again, the `Duration` the predicate speaks about here is the one called 
`other`, the `duration` is constant over the life of the predicate.


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

[GitHub] brooklyn-server pull request #555: Add DurationPredicates

2017-02-09 Thread mikezaccardo
GitHub user mikezaccardo opened a pull request:

https://github.com/apache/brooklyn-server/pull/555

Add DurationPredicates

Adds `DurationPredicates` which contain `Predicate`s for common `Duration` 
comparison operations.

You can merge this pull request into a Git repository by running:

$ git pull https://github.com/mikezaccardo/brooklyn-server 
add-duration-predicates

Alternatively you can review and apply these changes as the patch at:

https://github.com/apache/brooklyn-server/pull/555.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

This closes #555


commit 2de629e95eb374905154fcaaf2e26b91e618983f
Author: Mike Zaccardo 
Date:   2017-02-09T16:16:29Z

Add DurationPredicates




---
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 infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---