001 package com.croftsoft.core.lang.lifecycle; 002 003 /********************************************************************* 004 * Convenience methods for Lifecycle objects. 005 * 006 * @version 007 * $Date: 2008/04/19 21:27:13 $ 008 * @since 009 * 2002-02-15 010 * @author 011 * <a href="https://www.croftsoft.com/">David Wallace Croft</a> 012 *********************************************************************/ 013 014 public final class LifecycleLib 015 ////////////////////////////////////////////////////////////////////// 016 ////////////////////////////////////////////////////////////////////// 017 { 018 019 /********************************************************************* 020 * Initializes the initializable, catching and printing any Exception. 021 * 022 * @param initializable 023 * 024 * If null, does nothing. 025 *********************************************************************/ 026 public static void init ( Initializable initializable ) 027 ////////////////////////////////////////////////////////////////////// 028 { 029 try 030 { 031 if ( initializable != null ) 032 { 033 initializable.init ( ); 034 } 035 } 036 catch ( Exception ex ) 037 { 038 ex.printStackTrace ( ); 039 } 040 } 041 042 /********************************************************************* 043 * Initializes the initializables, catching and printing any Exception. 044 * 045 * @param initializables 046 * 047 * If null, does nothing. 048 *********************************************************************/ 049 public static void init ( Initializable... initializables ) 050 ////////////////////////////////////////////////////////////////////// 051 { 052 if ( initializables != null ) 053 { 054 for ( int i = 0; i < initializables.length; i++ ) 055 { 056 init ( initializables [ i ] ); 057 } 058 } 059 } 060 061 /********************************************************************* 062 * Starts the startable, catching and printing any Exception. 063 * 064 * @param startable 065 * 066 * If null, does nothing. 067 *********************************************************************/ 068 public static void start ( Startable startable ) 069 ////////////////////////////////////////////////////////////////////// 070 { 071 try 072 { 073 if ( startable != null ) 074 { 075 startable.start ( ); 076 } 077 } 078 catch ( Exception ex ) 079 { 080 ex.printStackTrace ( ); 081 } 082 } 083 084 /********************************************************************* 085 * Starts the startables, catching and printing any Exception. 086 * 087 * @param startables 088 * 089 * If null, does nothing. 090 *********************************************************************/ 091 public static void start ( Startable... startables ) 092 ////////////////////////////////////////////////////////////////////// 093 { 094 if ( startables != null ) 095 { 096 for ( int i = 0; i < startables.length; i++ ) 097 { 098 start ( startables [ i ] ); 099 } 100 } 101 } 102 103 /********************************************************************* 104 * Stops the stoppable, catching and printing any Exception. 105 * 106 * @param stoppable 107 * 108 * If null, does nothing. 109 *********************************************************************/ 110 public static void stop ( Stoppable stoppable ) 111 ////////////////////////////////////////////////////////////////////// 112 { 113 try 114 { 115 if ( stoppable != null ) 116 { 117 stoppable.stop ( ); 118 } 119 } 120 catch ( Exception ex ) 121 { 122 ex.printStackTrace ( ); 123 } 124 } 125 126 /********************************************************************* 127 * Stops the stoppables, catching and printing any Exception. 128 * 129 * @param stoppables 130 * 131 * If null, does nothing. 132 *********************************************************************/ 133 public static void stop ( Stoppable... stoppables ) 134 ////////////////////////////////////////////////////////////////////// 135 { 136 if ( stoppables != null ) 137 { 138 for ( int i = 0; i < stoppables.length; i++ ) 139 { 140 stop ( stoppables [ i ] ); 141 } 142 } 143 } 144 145 /********************************************************************* 146 * Destroys the destroyable, catching and printing any Exception. 147 * 148 * @param destroyable 149 * 150 * If null, does nothing. 151 *********************************************************************/ 152 public static void destroy ( Destroyable destroyable ) 153 ////////////////////////////////////////////////////////////////////// 154 { 155 try 156 { 157 if ( destroyable != null ) 158 { 159 destroyable.destroy ( ); 160 } 161 } 162 catch ( Exception ex ) 163 { 164 ex.printStackTrace ( ); 165 } 166 } 167 168 /********************************************************************* 169 * Destroys the destroyables, catching and printing any Exception. 170 * 171 * @param destroyables 172 * 173 * If null, does nothing. 174 *********************************************************************/ 175 public static void destroy ( Destroyable... destroyables ) 176 ////////////////////////////////////////////////////////////////////// 177 { 178 if ( destroyables != null ) 179 { 180 for ( int i = 0; i < destroyables.length; i++ ) 181 { 182 destroy ( destroyables [ i ] ); 183 } 184 } 185 } 186 187 /********************************************************************* 188 * Updates the updatable, catching and printing any Exception. 189 * 190 * @param updatable 191 * 192 * If null, does nothing. 193 *********************************************************************/ 194 public static void update ( Updatable updatable ) 195 ////////////////////////////////////////////////////////////////////// 196 { 197 try 198 { 199 if ( updatable != null ) 200 { 201 updatable.update ( ); 202 } 203 } 204 catch ( Exception ex ) 205 { 206 ex.printStackTrace ( ); 207 } 208 } 209 210 /********************************************************************* 211 * Updates the updatables, catching and printing any Exception. 212 * 213 * @param updatables 214 * 215 * If null, does nothing. 216 *********************************************************************/ 217 public static void update ( Updatable... updatables ) 218 ////////////////////////////////////////////////////////////////////// 219 { 220 if ( updatables != null ) 221 { 222 for ( int i = 0; i < updatables.length; i++ ) 223 { 224 update ( updatables [ i ] ); 225 } 226 } 227 } 228 229 ////////////////////////////////////////////////////////////////////// 230 ////////////////////////////////////////////////////////////////////// 231 232 private LifecycleLib ( ) { } 233 234 ////////////////////////////////////////////////////////////////////// 235 ////////////////////////////////////////////////////////////////////// 236 }