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

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

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 <mi...@cloudsoftcorp.com>
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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

Posted by asfgit <gi...@git.apache.org>.
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] brooklyn-server issue #555: Add DurationPredicates

Posted by grkvlt <gi...@git.apache.org>.
Github user grkvlt commented on the issue:

    https://github.com/apache/brooklyn-server/pull/555
  
    @mikezaccardo remember we need tests for these too!


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

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

Posted by grkvlt <gi...@git.apache.org>.
Github user grkvlt commented on a diff in the pull request:

    https://github.com/apache/brooklyn-server/pull/555#discussion_r100346173
  
    --- 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<Duration> isPositive() {
    +        return new Predicate<Duration>() {
    +            @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<Duration> isNegative() {
    +        return new Predicate<Duration>() {
    +            @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<Duration> isLongerThanDuration(final Duration duration) {
    +        return new Predicate<Duration>() {
    +            @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<Stopwatch> isLongerThanStopwatch(final Duration duration) {
    +        return new Predicate<Stopwatch>() {
    +            @Override
    +            public boolean apply(Stopwatch other) {
    +                return duration != null && other != null && duration.isLongerThan(other);
    --- End diff --
    
    This is confusing. A `Predicate<Stopwatch>` is making a boolean statement about `Stopwatch`-es, so in this case maybe reverse the check and the name?


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

[GitHub] brooklyn-server issue #555: Add DurationPredicates

Posted by ahgittin <gi...@git.apache.org>.
Github user ahgittin commented on the issue:

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


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

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

Posted by grkvlt <gi...@git.apache.org>.
Github user grkvlt commented on a diff in the pull request:

    https://github.com/apache/brooklyn-server/pull/555#discussion_r100346586
  
    --- 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<Duration> isPositive() {
    +        return new Predicate<Duration>() {
    +            @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<Duration> isNegative() {
    +        return new Predicate<Duration>() {
    +            @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<Duration> isLongerThanDuration(final Duration duration) {
    +        return new Predicate<Duration>() {
    +            @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<Stopwatch> isLongerThanStopwatch(final Duration duration) {
    +        return new Predicate<Stopwatch>() {
    +            @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<Duration> isShorterThanDuration(final Duration duration) {
    +        return new Predicate<Duration>() {
    +            @Override
    +            public boolean apply(Duration other) {
    +                return duration != null && other != null && duration.isShorterThan(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 Stopwatch}
    +     *         supplied to to the returned {@link Predicate#apply(Object)}.
    +     */
    +    public static Predicate<Stopwatch> isShorterThanStopwatch(final Duration duration) {
    +        return new Predicate<Stopwatch>() {
    +            @Override
    +            public boolean apply(Stopwatch other) {
    +                return duration != null && other != null && duration.isShorterThan(other);
    --- End diff --
    
    Same.


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

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

Posted by grkvlt <gi...@git.apache.org>.
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<Duration> isPositive() {
    +        return new Predicate<Duration>() {
    +            @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<Duration> isNegative() {
    +        return new Predicate<Duration>() {
    +            @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<Duration> isLongerThanDuration(final Duration duration) {
    +        return new Predicate<Duration>() {
    +            @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<Stopwatch> isLongerThanStopwatch(final Duration duration) {
    +        return new Predicate<Stopwatch>() {
    +            @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<Duration> isShorterThanDuration(final Duration duration) {
    +        return new Predicate<Duration>() {
    +            @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 feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---