001 /* 002 * Copyright (c) 2007-2015 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.property; 022 023 import java.util.Set; 024 import java.util.TreeSet; 025 026 import cascading.util.Util; 027 import org.slf4j.Logger; 028 import org.slf4j.LoggerFactory; 029 030 import static cascading.util.Util.join; 031 032 /** Class UnitOfWorkDef is the base class for framework specific fluent definition interfaces. */ 033 public class UnitOfWorkDef<T> 034 { 035 private static final Logger LOG = LoggerFactory.getLogger( UnitOfWorkDef.class ); 036 037 protected String name; 038 protected Set<String> tags = new TreeSet<String>(); 039 040 public String getName() 041 { 042 return name; 043 } 044 045 /** 046 * Method setName sets the UnitOfWork name. 047 * 048 * @param name type String 049 * @return this 050 */ 051 public T setName( String name ) 052 { 053 this.name = name; 054 return (T) this; 055 } 056 057 public String getTags() 058 { 059 return join( tags, "," ); 060 } 061 062 /** 063 * Method addTag will associate a "tag" with this UnitOfWork. A UnitOfWork can have an unlimited number of tags. 064 * <p/> 065 * Tags allow for search and organization by management tools. 066 * <p/> 067 * Tag values are opaque, but adopting a simple convention of 'category:value' allows for complex use cases. 068 * <p/> 069 * Note that tags should not contain whitespace characters, even though this is not an error, a warning will be 070 * issues. 071 * 072 * @param tag type String 073 * @return this 074 */ 075 public T addTag( String tag ) 076 { 077 if( tag == null || tag.isEmpty() ) 078 return (T) this; 079 080 tag = tag.trim(); 081 082 if( Util.containsWhitespace( tag ) ) 083 LOG.warn( "tags should not contain whitespace characters: '{}'", tag ); 084 085 tags.add( tag ); 086 087 return (T) this; 088 } 089 090 /** 091 * Method addTags will associate the given "tags" with this UnitOfWork. A UnitOfWork can have an unlimited number of tags. 092 * <p/> 093 * Tags allow for search and organization by management tools. 094 * <p/> 095 * Tag values are opaque, but adopting a simple convention of 'category:value' allows for complex use cases. 096 * <p/> 097 * Note that tags should not contain whitespace characters, even though this is not an error, a warning will be 098 * issues. 099 * 100 * @param tags type String 101 * @return this 102 */ 103 public T addTags( String... tags ) 104 { 105 for( String tag : tags ) 106 addTag( tag ); 107 108 return (T) this; 109 } 110 }