001 /* 002 * Copyright (c) 2007-2014 Concurrent, Inc. All Rights Reserved. 003 * 004 * Project and contact information: http://www.cascading.org/ 005 * 006 * This file is part of the Cascading project. 007 * 008 * Licensed under the Apache License, Version 2.0 (the "License"); 009 * you may not use this file except in compliance with the License. 010 * You may obtain a copy of the License at 011 * 012 * http://www.apache.org/licenses/LICENSE-2.0 013 * 014 * Unless required by applicable law or agreed to in writing, software 015 * distributed under the License is distributed on an "AS IS" BASIS, 016 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 017 * See the License for the specific language governing permissions and 018 * limitations under the License. 019 */ 020 021 package cascading.operation.regex; 022 023 import java.beans.ConstructorProperties; 024 import java.util.regex.Pattern; 025 026 import cascading.management.annotation.Property; 027 import cascading.management.annotation.PropertyDescription; 028 import cascading.management.annotation.Visibility; 029 import cascading.operation.BaseOperation; 030 import cascading.tuple.Fields; 031 032 /** Class RegexOperation is the base class for all regex Operations. */ 033 public class RegexOperation<C> extends BaseOperation<C> 034 { 035 /** Field patternString */ 036 protected String patternString = ".*"; 037 038 /** Constructor RegexOperation creates a new RegexOperation instance. */ 039 public RegexOperation() 040 { 041 } 042 043 /** 044 * Constructor RegexOperation creates a new RegexOperation instance. 045 * 046 * @param numArgs of type int 047 */ 048 @ConstructorProperties({"numArgs"}) 049 public RegexOperation( int numArgs ) 050 { 051 super( numArgs ); 052 } 053 054 /** 055 * Constructor RegexOperation creates a new RegexOperation instance. 056 * 057 * @param fieldDeclaration of type Fields 058 */ 059 @ConstructorProperties({"fieldDeclaration"}) 060 public RegexOperation( Fields fieldDeclaration ) 061 { 062 super( fieldDeclaration ); 063 } 064 065 /** 066 * Constructor RegexOperation creates a new RegexOperation instance. 067 * 068 * @param numArgs of type int 069 * @param patternString of type String 070 */ 071 @ConstructorProperties({"numArgs", "patternString"}) 072 public RegexOperation( int numArgs, String patternString ) 073 { 074 super( numArgs ); 075 this.patternString = patternString; 076 } 077 078 /** 079 * Constructor RegexOperation creates a new RegexOperation instance. 080 * 081 * @param patternString of type String 082 */ 083 @ConstructorProperties({"patternString"}) 084 public RegexOperation( String patternString ) 085 { 086 this.patternString = patternString; 087 } 088 089 /** 090 * Constructor RegexOperation creates a new RegexOperation instance. 091 * 092 * @param numArgs of type int 093 * @param fieldDeclaration of type Fields 094 */ 095 @ConstructorProperties({"numArgs", "fieldDeclaration"}) 096 public RegexOperation( int numArgs, Fields fieldDeclaration ) 097 { 098 super( numArgs, fieldDeclaration ); 099 } 100 101 /** 102 * Constructor RegexOperation creates a new RegexOperation instance. 103 * 104 * @param numArgs of type int 105 * @param fieldDeclaration of type Fields 106 * @param patternString of type String 107 */ 108 @ConstructorProperties({"numArgs", "fieldDeclaration", "patternString"}) 109 public RegexOperation( int numArgs, Fields fieldDeclaration, String patternString ) 110 { 111 super( numArgs, fieldDeclaration ); 112 this.patternString = patternString; 113 } 114 115 /** 116 * Method getPatternString returns the patternString of this RegexOperation object. 117 * 118 * @return the patternString (type String) of this RegexOperation object. 119 */ 120 @Property(name = "patternString", visibility = Visibility.PRIVATE) 121 @PropertyDescription("The regular expression pattern string.") 122 public final String getPatternString() 123 { 124 return patternString; 125 } 126 127 /** 128 * Method getPattern returns the pattern of this RegexOperation object. 129 * 130 * @return the pattern (type Pattern) of this RegexOperation object. 131 */ 132 protected Pattern getPattern() 133 { 134 return Pattern.compile( getPatternString() ); 135 } 136 137 @Override 138 public boolean equals( Object object ) 139 { 140 if( this == object ) 141 return true; 142 if( !( object instanceof RegexOperation ) ) 143 return false; 144 if( !super.equals( object ) ) 145 return false; 146 147 RegexOperation that = (RegexOperation) object; 148 149 if( patternString != null ? !patternString.equals( that.patternString ) : that.patternString != null ) 150 return false; 151 152 return true; 153 } 154 155 @Override 156 public int hashCode() 157 { 158 int result = super.hashCode(); 159 result = 31 * result + ( patternString != null ? patternString.hashCode() : 0 ); 160 return result; 161 } 162 }