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.operation.BaseOperation; 027 import cascading.tuple.Fields; 028 029 /** Class RegexOperation is the base class for all regex Operations. */ 030 public class RegexOperation<C> extends BaseOperation<C> 031 { 032 /** Field patternString */ 033 protected String patternString = ".*"; 034 035 /** Constructor RegexOperation creates a new RegexOperation instance. */ 036 public RegexOperation() 037 { 038 } 039 040 /** 041 * Constructor RegexOperation creates a new RegexOperation instance. 042 * 043 * @param numArgs of type int 044 */ 045 @ConstructorProperties({"numArgs"}) 046 public RegexOperation( int numArgs ) 047 { 048 super( numArgs ); 049 } 050 051 /** 052 * Constructor RegexOperation creates a new RegexOperation instance. 053 * 054 * @param fieldDeclaration of type Fields 055 */ 056 @ConstructorProperties({"fieldDeclaration"}) 057 public RegexOperation( Fields fieldDeclaration ) 058 { 059 super( fieldDeclaration ); 060 } 061 062 /** 063 * Constructor RegexOperation creates a new RegexOperation instance. 064 * 065 * @param numArgs of type int 066 * @param patternString of type String 067 */ 068 @ConstructorProperties({"numArgs", "patternString"}) 069 public RegexOperation( int numArgs, String patternString ) 070 { 071 super( numArgs ); 072 this.patternString = patternString; 073 } 074 075 /** 076 * Constructor RegexOperation creates a new RegexOperation instance. 077 * 078 * @param patternString of type String 079 */ 080 @ConstructorProperties({"patternString"}) 081 public RegexOperation( String patternString ) 082 { 083 this.patternString = patternString; 084 } 085 086 /** 087 * Constructor RegexOperation creates a new RegexOperation instance. 088 * 089 * @param numArgs of type int 090 * @param fieldDeclaration of type Fields 091 */ 092 @ConstructorProperties({"numArgs", "fieldDeclaration"}) 093 public RegexOperation( int numArgs, Fields fieldDeclaration ) 094 { 095 super( numArgs, fieldDeclaration ); 096 } 097 098 /** 099 * Constructor RegexOperation creates a new RegexOperation instance. 100 * 101 * @param numArgs of type int 102 * @param fieldDeclaration of type Fields 103 * @param patternString of type String 104 */ 105 @ConstructorProperties({"numArgs", "fieldDeclaration", "patternString"}) 106 public RegexOperation( int numArgs, Fields fieldDeclaration, String patternString ) 107 { 108 super( numArgs, fieldDeclaration ); 109 this.patternString = patternString; 110 } 111 112 /** 113 * Method getPatternString returns the patternString of this RegexOperation object. 114 * 115 * @return the patternString (type String) of this RegexOperation object. 116 */ 117 public final String getPatternString() 118 { 119 return patternString; 120 } 121 122 /** 123 * Method getPattern returns the pattern of this RegexOperation object. 124 * 125 * @return the pattern (type Pattern) of this RegexOperation object. 126 */ 127 protected Pattern getPattern() 128 { 129 return Pattern.compile( getPatternString() ); 130 } 131 132 @Override 133 public boolean equals( Object object ) 134 { 135 if( this == object ) 136 return true; 137 if( !( object instanceof RegexOperation ) ) 138 return false; 139 if( !super.equals( object ) ) 140 return false; 141 142 RegexOperation that = (RegexOperation) object; 143 144 if( patternString != null ? !patternString.equals( that.patternString ) : that.patternString != null ) 145 return false; 146 147 return true; 148 } 149 150 @Override 151 public int hashCode() 152 { 153 int result = super.hashCode(); 154 result = 31 * result + ( patternString != null ? patternString.hashCode() : 0 ); 155 return result; 156 } 157 }