Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 5B17A200C16 for ; Thu, 9 Feb 2017 17:47:14 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id 59995160B50; Thu, 9 Feb 2017 16:47:14 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id A434A160B4B for ; Thu, 9 Feb 2017 17:47:13 +0100 (CET) Received: (qmail 93365 invoked by uid 500); 9 Feb 2017 16:47:12 -0000 Mailing-List: contact dev-help@brooklyn.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@brooklyn.apache.org Delivered-To: mailing list dev@brooklyn.apache.org Received: (qmail 93349 invoked by uid 99); 9 Feb 2017 16:47:12 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 09 Feb 2017 16:47:12 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 7A54FDFB0E; Thu, 9 Feb 2017 16:47:12 +0000 (UTC) From: grkvlt To: dev@brooklyn.apache.org Reply-To: dev@brooklyn.apache.org References: In-Reply-To: Subject: [GitHub] brooklyn-server pull request #555: Add DurationPredicates Content-Type: text/plain Message-Id: <20170209164712.7A54FDFB0E@git1-us-west.apache.org> Date: Thu, 9 Feb 2017 16:47:12 +0000 (UTC) archived-at: Thu, 09 Feb 2017 16:47:14 -0000 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 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); + } + }; + } + + /** + * @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 isShorterThanStopwatch(final Duration duration) { + return new Predicate() { + @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. ---