001/* 002 * Copyright (c) 2016-2017 Chris K Wensel <chris@wensel.net>. All Rights Reserved. 003 * Copyright (c) 2007-2017 Xplenty, Inc. All Rights Reserved. 004 * 005 * Project and contact information: http://www.cascading.org/ 006 * 007 * This file is part of the Cascading project. 008 * 009 * Licensed under the Apache License, Version 2.0 (the "License"); 010 * you may not use this file except in compliance with the License. 011 * You may obtain a copy of the License at 012 * 013 * http://www.apache.org/licenses/LICENSE-2.0 014 * 015 * Unless required by applicable law or agreed to in writing, software 016 * distributed under the License is distributed on an "AS IS" BASIS, 017 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 018 * See the License for the specific language governing permissions and 019 * limitations under the License. 020 */ 021 022package cascading.operation.assertion; 023 024import java.beans.ConstructorProperties; 025 026import cascading.management.annotation.Property; 027import cascading.management.annotation.PropertyDescription; 028import cascading.management.annotation.Visibility; 029 030/** 031 * Class AssertGroupSizeEquals is an {@link cascading.operation.GroupAssertion} that asserts the number of items in the current group 032 * is less than the given size. 033 * <p> 034 * If a patternString is given, only grouping keys that match the regular expression will have this assertion applied. 035 * Note multiple key values will be delimited by a tab character. 036 */ 037public class AssertGroupSizeLessThan extends AssertGroupBase 038 { 039 040 /** 041 * Constructor AssertGroupSizeLessThan creates a new AssertGroupSizeLessThan instance. 042 * 043 * @param size of type long 044 */ 045 @ConstructorProperties({"size"}) 046 public AssertGroupSizeLessThan( long size ) 047 { 048 super( "group size: %s, is more than or equal to: %s, in group %s: %s", size ); 049 } 050 051 /** 052 * Constructor AssertGroupSizeLessThan creates a new AssertGroupSizeLessThan instance. 053 * 054 * @param patternString of type String 055 * @param size of type long 056 */ 057 @ConstructorProperties({"patternString", "size"}) 058 public AssertGroupSizeLessThan( String patternString, long size ) 059 { 060 super( "group matching '%s' with size: %s, is more than or equal to: %s, in group %s: %s", patternString, size ); 061 } 062 063 @Property(name = "size", visibility = Visibility.PRIVATE) 064 @PropertyDescription("The maximum group size.") 065 @Override 066 public long getSize() 067 { 068 return super.getSize(); 069 } 070 071 @Override 072 protected boolean assertFails( Long groupSize ) 073 { 074 return groupSize >= size; 075 } 076 }