brooklyn-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From grkvlt <...@git.apache.org>
Subject [GitHub] brooklyn-server pull request #555: Add DurationPredicates
Date Thu, 09 Feb 2017 16:47:11 GMT
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.
---

Mime
View raw message