text
stringlengths 30
1.67M
|
|---|
<s> package zy . sheep ; import android . app . Activity ; import android . os . Bundle ; import android . view . Window ; import android . view . WindowManager ; public class SheepCycleActivity extends Activity { @ Override public void onCreate ( Bundle savedInstanceState ) { super . onCreate ( savedInstanceState ) ; this . requestWindowFeature ( Window . FEATURE_NO_TITLE ) ; this . getWindow ( ) . setFlags ( WindowManager . LayoutParams . FLAG_FULLSCREEN , WindowManager . LayoutParams . FLAG_FULLSCREEN ) ; setContentView ( new MySurfaceView ( this ) ) ; } } </s>
|
<s> package zy . sheep ; import java . util . Iterator ; import java . util . Random ; import java . util . Timer ; import java . util . TimerTask ; import edu . uestc . project . cycle . alg . basic . LinePath ; import edu . uestc . project . cycle . spirit . SpiritGroup ; import edu . uestc . project . cycle . spirit . SpiritManager ; import edu . uestc . project . cycle . spirit . SpiritObject ; import edu . uestc . project . cycle . spirit . SpiritState ; import android . content . Context ; import android . graphics . Bitmap ; import android . graphics . BitmapFactory ; import android . graphics . Canvas ; import android . graphics . Color ; import android . graphics . Paint ; import android . graphics . Path ; import android . graphics . Paint . Style ; import android . view . MotionEvent ; import android . view . SurfaceHolder ; import android . view . SurfaceHolder . Callback ; import android . view . SurfaceView ; public class MySurfaceView extends SurfaceView implements Callback { private SurfaceHolder sfh ; private Paint paint ; private Paint cyclePaint ; private boolean flag ; private float startX , startY ; private float currentX , currentY ; private boolean isCanvasCleared = false ; private final int MAXCLOSE = <NUM_LIT> ; private final int BMPNUM = <NUM_LIT:10> ; private Path path ; private LinePath linePath ; private boolean dragFlag = false ; private boolean pocketOn = false ; private static final int POWERFULL = <NUM_LIT> ; private int currentPower = POWERFULL ; private SpiritGroup sg ; SpiritManager spiritManager ; private Paint powerPaint ; private Timer powerFillTimer ; private boolean isTimerRun = false ; private Paint counterPaint ; private int sheepCounter = <NUM_LIT:0> ; private Bitmap sheepCounterBmp ; public MySurfaceView ( Context context ) { super ( context ) ; sfh = this . getHolder ( ) ; sfh . addCallback ( this ) ; paint = new Paint ( ) ; powerPaint = new Paint ( ) ; cyclePaint = new Paint ( ) ; counterPaint = new Paint ( ) ; counterPaint . setStyle ( Style . STROKE ) ; counterPaint . setColor ( Color . RED ) ; cyclePaint . setColor ( Color . BLUE ) ; cyclePaint . setStyle ( Style . STROKE ) ; paint . setColor ( Color . WHITE ) ; paint . setAntiAlias ( false ) ; paint . setStyle ( Style . STROKE ) ; sheepCounterBmp = BitmapFactory . decodeResource ( this . getResources ( ) , R . drawable . ic_launcher ) ; this . powerFillTimer = new Timer ( ) ; spiritManager = new SpiritManager ( ) ; path = new Path ( ) ; linePath = new LinePath ( ) ; } public void surfaceChanged ( SurfaceHolder holder , int format , int width , int height ) { } public void surfaceCreated ( SurfaceHolder holder ) { creator ( ) ; flag = true ; new Thread ( ) { @ Override public void run ( ) { while ( flag ) { long start = System . currentTimeMillis ( ) ; myDraw ( ) ; long end = System . currentTimeMillis ( ) ; try { if ( end - start < <NUM_LIT:30> ) { Thread . sleep ( <NUM_LIT:30> - ( end - start ) ) ; } } catch ( Exception e ) { e . printStackTrace ( ) ; } } } } . start ( ) ; } public void surfaceDestroyed ( SurfaceHolder holder ) { flag = false ; } public void myDraw ( ) { Canvas canvas = sfh . lockCanvas ( ) ; if ( isCanvasCleared ) { path . reset ( ) ; canvas . drawColor ( Color . BLACK ) ; canvas . drawPath ( path , paint ) ; } else { canvas . drawPath ( path , paint ) ; } Iterator < SpiritObject > iterator = this . spiritManager . iterator ( ) ; while ( iterator . hasNext ( ) ) { SpiritObject object = iterator . next ( ) ; canvas . drawBitmap ( object . getBitmap ( ) , object . getStartX ( ) , object . getStartY ( ) , paint ) ; } canvas . drawCircle ( <NUM_LIT:0> + <NUM_LIT:100> , this . getHeight ( ) - <NUM_LIT:100> , <NUM_LIT:100> , cyclePaint ) ; if ( this . pocketOn ) { cyclePaint . setStyle ( Style . FILL ) ; } else { cyclePaint . setStyle ( Style . STROKE ) ; } powerPaint . setStyle ( Style . STROKE ) ; powerPaint . setColor ( Color . RED ) ; canvas . drawRect ( <NUM_LIT> , this . getHeight ( ) - <NUM_LIT:20> , <NUM_LIT> + POWERFULL , this . getHeight ( ) - <NUM_LIT:10> , powerPaint ) ; powerPaint . setStyle ( Style . FILL ) ; powerPaint . setColor ( Color . BLACK ) ; canvas . drawRect ( <NUM_LIT> , this . getHeight ( ) - <NUM_LIT> , <NUM_LIT> + POWERFULL , this . getHeight ( ) - <NUM_LIT:10> , powerPaint ) ; powerPaint . setColor ( Color . YELLOW ) ; canvas . drawRect ( <NUM_LIT> , this . getHeight ( ) - <NUM_LIT> , <NUM_LIT> + this . currentPower , this . getHeight ( ) - <NUM_LIT:10> , powerPaint ) ; powerPaint . setColor ( Color . RED ) ; canvas . drawBitmap ( this . sheepCounterBmp , <NUM_LIT> , this . getHeight ( ) - <NUM_LIT:100> , paint ) ; counterPaint . setColor ( Color . BLACK ) ; counterPaint . setStyle ( Style . FILL ) ; canvas . drawRect ( <NUM_LIT> , this . getHeight ( ) - <NUM_LIT> , <NUM_LIT> + <NUM_LIT:10> , this . getHeight ( ) - <NUM_LIT> , counterPaint ) ; counterPaint . setColor ( Color . RED ) ; canvas . drawText ( "<STR_LIT>" + this . sheepCounter , <NUM_LIT> , this . getHeight ( ) - <NUM_LIT> , counterPaint ) ; sfh . unlockCanvasAndPost ( canvas ) ; } public void clearCanvas ( ) { Canvas canvas = sfh . lockCanvas ( ) ; canvas . drawRect ( <NUM_LIT:0> , <NUM_LIT:0> , this . getWidth ( ) , this . getHeight ( ) , new Paint ( ) ) ; sfh . unlockCanvasAndPost ( canvas ) ; } @ Override public boolean onTouchEvent ( MotionEvent event ) { int x = ( int ) event . getX ( ) ; int y = ( int ) event . getY ( ) ; if ( event . getAction ( ) == MotionEvent . ACTION_DOWN ) { this . startX = x ; this . startY = y ; if ( this . dragFlag ) { if ( ! this . linePath . isContainsPoint ( x , y ) ) { this . currentX = - <NUM_LIT:1> ; this . currentX = - <NUM_LIT:1> ; } else { this . currentX = x ; this . currentY = y ; } } else { if ( isTimerRun ) { } else { path . moveTo ( x , y ) ; this . linePath . moveToStart ( x , y ) ; this . isCanvasCleared = false ; paint . setColor ( Color . WHITE ) ; } } } else if ( event . getAction ( ) == MotionEvent . ACTION_MOVE ) { if ( this . dragFlag ) { if ( this . currentX != - <NUM_LIT:1> && this . currentY != - <NUM_LIT:1> ) { float dx = x - this . currentX ; float dy = y - this . currentY ; Iterator < SpiritObject > iterator = this . sg . iterator ( ) ; while ( iterator . hasNext ( ) ) { SpiritObject object = iterator . next ( ) ; object . setStartX ( ( int ) ( object . getStartX ( ) + dx ) ) ; object . setStartY ( ( int ) ( object . getStartY ( ) + dy ) ) ; } int pocketX = <NUM_LIT:100> ; int pocketY = this . getHeight ( ) - <NUM_LIT:100> ; if ( Math . sqrt ( ( pocketX - x ) * ( pocketX - x ) + ( pocketY - y ) * ( pocketY - y ) ) <= <NUM_LIT> ) { this . pocketOn = true ; } else { this . pocketOn = false ; } this . currentX = x ; this . currentY = y ; } } else { if ( ( this . linePath . getPathLenght ( ) / <NUM_LIT:10> ) >= <NUM_LIT> ) { this . currentPower = <NUM_LIT:0> ; paint . setColor ( Color . RED ) ; } else { if ( this . isTimerRun ) { } else { path . lineTo ( x , y ) ; linePath . lineTo ( x , y ) ; this . currentPower = <NUM_LIT> - this . linePath . getPathLenght ( ) / <NUM_LIT:10> ; } } } } else if ( event . getAction ( ) == MotionEvent . ACTION_UP ) { if ( this . isTimerRun ) { } else { if ( this . currentPower <= POWERFULL ) { if ( this . currentPower == <NUM_LIT:0> ) { this . linePath . reset ( ) ; } powerFillTimer . schedule ( new TimerTask ( ) { @ Override public void run ( ) { if ( currentPower >= <NUM_LIT> ) { currentPower = <NUM_LIT> ; this . cancel ( ) ; isTimerRun = false ; } else { currentPower += <NUM_LIT:10> ; isTimerRun = true ; } } } , <NUM_LIT:0> , <NUM_LIT:10> ) ; } else { } } if ( this . dragFlag ) { if ( this . pocketOn ) { this . sheepCounter += this . sg . size ( ) ; this . spiritManager . removeByGroup ( this . sg ) ; this . pocketOn = false ; if ( this . spiritManager . size ( ) == <NUM_LIT:0> ) { creator ( ) ; } } else { Iterator < SpiritObject > iterator = this . sg . iterator ( ) ; while ( iterator . hasNext ( ) ) { SpiritObject object = iterator . next ( ) ; object . getState ( ) . unmountState ( SpiritState . SELECTED_STATE ) ; object . setBitmap ( BitmapFactory . decodeResource ( this . getResources ( ) , R . drawable . ic_launcher ) ) ; object . setStartX ( object . getOldestX ( ) ) ; object . setStartY ( object . getOldestY ( ) ) ; } } this . linePath . reset ( ) ; this . dragFlag = false ; } else { if ( this . isTimerRun ) { this . isCanvasCleared = true ; this . linePath . reset ( ) ; } else { path . lineTo ( x , y ) ; linePath . lineTo ( x , y ) ; int tmp = ( int ) Math . sqrt ( ( this . startX - x ) * ( this . startX - x ) + ( this . startY - y ) * ( this . startY - y ) ) ; if ( this . MAXCLOSE < tmp ) { linePath . reset ( ) ; } else { path . close ( ) ; linePath . close ( ) ; Iterator < SpiritObject > iterator = this . spiritManager . iterator ( ) ; while ( iterator . hasNext ( ) ) { SpiritObject object = iterator . next ( ) ; if ( linePath . isContainsRect ( object . getRect ( ) , LinePath . ALL_POINTS ) ) { object . setBitmap ( BitmapFactory . decodeResource ( this . getResources ( ) , R . drawable . a ) ) ; object . setSelected ( true ) ; this . dragFlag = true ; } else { continue ; } } } this . isCanvasCleared = true ; if ( this . dragFlag ) { this . sg = this . spiritManager . getGroupByState ( SpiritState . SELECTED_STATE ) ; } } } } return true ; } private void creator ( ) { int viewHeight = this . getHeight ( ) ; int viewtWidth = this . getWidth ( ) ; Random random = new Random ( System . currentTimeMillis ( ) ) ; for ( int i = <NUM_LIT:0> ; i < BMPNUM ; i ++ ) { int x , y ; while ( true ) { x = random . nextInt ( <NUM_LIT:1000> ) ; if ( x >= viewtWidth - <NUM_LIT> || x <= <NUM_LIT> ) { continue ; } else { break ; } } while ( true ) { y = random . nextInt ( <NUM_LIT:1000> ) ; if ( y >= viewHeight - <NUM_LIT:100> || y < <NUM_LIT:100> ) { continue ; } else { break ; } } SpiritObject tmp = new SpiritObject ( x , y ) ; tmp . setBitmap ( BitmapFactory . decodeResource ( this . getResources ( ) , R . drawable . ic_launcher ) ) ; this . spiritManager . registerSpirit ( tmp ) ; } } } </s>
|
<s> package zy . sheep ; public final class BuildConfig { public final static boolean DEBUG = true ; } </s>
|
<s> package zy . sheep ; public final class R { public static final class attr { } public static final class drawable { public static final int a = <NUM_LIT> ; public static final int b = <NUM_LIT> ; public static final int ic_launcher = <NUM_LIT> ; } public static final class layout { public static final int main = <NUM_LIT> ; } public static final class string { public static final int app_name = <NUM_LIT> ; public static final int hello = <NUM_LIT> ; } } </s>
|
<s> package benedictoxvi . pe . businesstest ; import java . util . ArrayList ; import java . util . Collections ; import java . util . Comparator ; import java . util . List ; import org . junit . Assert ; import org . junit . Before ; import org . junit . Test ; import benedictoxvi . pe . business . AdmCompra ; import benedictoxvi . pe . data . Compra ; import benedictoxvi . pe . datatest . DataBD ; import benedictoxvi . pe . util . Loader ; import benedictoxvi . pe . util . Validaciones ; public class AdmCompraTest { ArrayList < Compra > arrCom = new ArrayList < Compra > ( ) ; AdmCompra admCom = new AdmCompra ( ) ; Compra objCom = new Compra ( ) ; @ Test public void cuandoFecEmisionMayorFecPagoTest ( ) { Assert . assertFalse ( admCom . darAltaCompra ( "<STR_LIT>" , <NUM_LIT> , "<STR_LIT>" , "<STR_LIT>" , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) ) ; } @ Test public void darAltaCompraTest ( ) { Assert . assertTrue ( admCom . darAltaCompra ( "<STR_LIT>" , <NUM_LIT> , "<STR_LIT>" , "<STR_LIT>" , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) ) ; } @ Test public void cuandoRegistramosSinLosValoresObligatoriosTest ( ) { Assert . assertFalse ( admCom . darAltaCompra ( null , <NUM_LIT> , "<STR_LIT>" , "<STR_LIT>" , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) ) ; } @ Test public void cuandoRegistroCompraMismoNumeroTest ( ) { Assert . assertTrue ( admCom . darAltaCompra ( "<STR_LIT>" , <NUM_LIT> , "<STR_LIT>" , "<STR_LIT>" , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) ) ; Assert . assertFalse ( admCom . darAltaCompra ( "<STR_LIT>" , <NUM_LIT> , "<STR_LIT>" , "<STR_LIT>" , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) ) ; } @ Test public void buscarEncontrarComprasTest ( ) { Assert . assertTrue ( admCom . encontrarCompras ( "<STR_LIT>" , <NUM_LIT:0> , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) . size ( ) > <NUM_LIT:0> ) ; } @ Test public void buscarSinEncontrarComprasTest ( ) { Assert . assertTrue ( admCom . encontrarCompras ( "<STR_LIT>" , <NUM_LIT:0> , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) . size ( ) == <NUM_LIT:0> ) ; } @ Test public void anularCompraTest ( ) { Compra compra = admCom . getCompraByNum ( <NUM_LIT> ) ; Assert . assertEquals ( "<STR_LIT>" , compra . getEstado ( ) ) ; Assert . assertTrue ( admCom . anularCompra ( <NUM_LIT> ) ) ; Assert . assertEquals ( "<STR_LIT>" , compra . getEstado ( ) ) ; } @ Test public void pagarCompraTest ( ) { Compra compra = admCom . getCompraByNum ( <NUM_LIT> ) ; Assert . assertEquals ( "<STR_LIT>" , compra . getEstado ( ) ) ; Assert . assertTrue ( admCom . pagarCompra ( compra . getNumero ( ) ) ) ; Assert . assertEquals ( "<STR_LIT>" , compra . getEstado ( ) ) ; } @ Test public void anularCompraPagadaTest ( ) { Compra compra = admCom . getCompraByNum ( <NUM_LIT> ) ; Assert . assertEquals ( "<STR_LIT>" , compra . getEstado ( ) ) ; Assert . assertFalse ( admCom . anularCompra ( compra . getNumero ( ) ) ) ; } @ Test public void pagarCompraAnuladaTest ( ) { Compra compra = admCom . getCompraByNum ( <NUM_LIT> ) ; Assert . assertEquals ( "<STR_LIT>" , compra . getEstado ( ) ) ; Assert . assertFalse ( admCom . pagarCompra ( compra . getNumero ( ) ) ) ; } } </s>
|
<s> package benedictoxvi . pe . businesstest ; import static org . junit . Assert . assertTrue ; import java . util . ArrayList ; import java . util . Date ; import java . util . Iterator ; import java . util . List ; import org . junit . Assert ; import org . junit . Before ; import org . junit . BeforeClass ; import org . junit . Test ; import benedictoxvi . pe . business . AdmVenta ; import benedictoxvi . pe . data . Cliente ; import benedictoxvi . pe . data . Compra ; import benedictoxvi . pe . data . Prospecto ; import benedictoxvi . pe . data . Venta ; import benedictoxvi . pe . datatest . DataBD ; public class AdmVentaTest { AdmVenta objAdmVenta = new AdmVenta ( ) ; ArrayList < Venta > arrVenta = new ArrayList < Venta > ( ) ; static ArrayList < Venta > arrMovimiento = new ArrayList < Venta > ( ) ; @ BeforeClass public static void cargarData ( ) { System . out . println ( "<STR_LIT>" ) ; cargarCursos ( ) ; System . out . println ( "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" ) ; cargarCliente ( ) ; System . out . println ( "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" ) ; cargarMovimientos ( ) ; System . out . println ( "<STR_LIT>" ) ; } public void registrarVentaConBoleta ( ) { System . out . println ( "<STR_LIT>" ) ; listarMovimientos ( ) ; int nroMovimiento = <NUM_LIT:5> ; String CodTipoDocumento = "<STR_LIT:1>" ; String CodCurso = "<STR_LIT>" ; String NomCuro ; double PreCurso ; int CanCurso ; String NomEmpleado ; String ApeEmpleado ; String CodEmpleado ; String CodCliente = "<STR_LIT>" ; String CodTipCliente ; String NroRucCliente ; String nomCliente = "<STR_LIT>" ; String ApePatCliente ; String ApeMatCliente ; String FecEmision = "<STR_LIT>" ; String NomEmpresa = "<STR_LIT>" ; Double Subtot = <NUM_LIT> ; Double MonIGV = <NUM_LIT> ; Double MonTot = <NUM_LIT> ; String Moneda = "<STR_LIT>" ; String FecVencim = "<STR_LIT>" ; String Estado = "<STR_LIT>" ; String FecPagoReal = "<STR_LIT>" ; String Observ = "<STR_LIT>" ; String concepto = "<STR_LIT>" ; assertTrue ( objAdmVenta . registrarPagoConBoleta ( arrVenta , nroMovimiento , CodTipoDocumento , CodCurso , CodCliente , nomCliente , concepto , FecEmision , Subtot , MonIGV , MonTot , Moneda , FecVencim , Estado , FecPagoReal , Observ ) ) ; arrMovimiento . add ( arrVenta . get ( <NUM_LIT:0> ) ) ; System . out . println ( "<STR_LIT>" ) ; listarMovimientos ( ) ; System . out . println ( "<STR_LIT>" ) ; } public void registrarVentaConFactura ( ) { System . out . println ( "<STR_LIT>" ) ; listarMovimientos ( ) ; int nroMovimiento = <NUM_LIT:6> ; String CodTipoDocumento = "<STR_LIT:2>" ; String CodCurso = "<STR_LIT>" ; String NomCuro ; double PreCurso ; int CanCurso ; String NomEmpleado ; String ApeEmpleado ; String CodEmpleado ; String CodCliente = "<STR_LIT>" ; String CodTipCliente ; String NroRucCliente = "<STR_LIT>" ; String nomCliente = "<STR_LIT>" ; String ApePatCliente ; String ApeMatCliente ; String FecEmision = "<STR_LIT>" ; String NomEmpresa = "<STR_LIT>" ; Double Subtot = <NUM_LIT> ; Double MonIGV = <NUM_LIT> ; Double MonTot = <NUM_LIT> ; String Moneda = "<STR_LIT>" ; String FecVencim = "<STR_LIT>" ; String Estado = "<STR_LIT>" ; String FecPagoReal = "<STR_LIT>" ; String Observ = "<STR_LIT>" ; String concepto = "<STR_LIT>" ; assertTrue ( objAdmVenta . registrarPagoConFactura ( arrMovimiento , nroMovimiento , CodTipoDocumento , CodCurso , CodCliente , nomCliente , NroRucCliente , concepto , FecEmision , Subtot , MonIGV , MonTot , Moneda , FecVencim , Estado , FecPagoReal , Observ ) ) ; arrMovimiento . add ( arrVenta . get ( <NUM_LIT:0> ) ) ; System . out . println ( "<STR_LIT>" ) ; listarMovimientos ( ) ; System . out . println ( "<STR_LIT>" ) ; } @ Test public void registrarPagoBoleta ( ) { System . out . println ( "<STR_LIT>" ) ; int NroMovimiento = <NUM_LIT:7> ; String TipoComprobante = "<STR_LIT:1>" ; String NroBoleta = "<STR_LIT>" ; String RUC = "<STR_LIT>" ; String Observacion = "<STR_LIT>" ; String UsuarioRegistro = "<STR_LIT>" ; Date FechaRegistro ; String CodCliente = "<STR_LIT>" ; String CodCuenta = "<STR_LIT>" ; List < Venta > arrNroCuota = new ArrayList < Venta > ( ) ; Venta oVenCuota = null ; oVenCuota = new Venta ( ) ; oVenCuota . setNroCuota ( <NUM_LIT:3> ) ; arrNroCuota . add ( oVenCuota ) ; assertTrue ( objAdmVenta . registraPagoBoletaFactura ( arrMovimiento , NroMovimiento , TipoComprobante , NroBoleta , RUC , CodCliente , CodCuenta , arrNroCuota , UsuarioRegistro ) ) ; } @ Test public void registrarPagoFacturaCuota1_2 ( ) { System . out . println ( "<STR_LIT>" ) ; int NroMovimiento = <NUM_LIT:8> ; String TipoComprobante = "<STR_LIT:2>" ; String NroBoleta = "<STR_LIT>" ; String RUC = "<STR_LIT>" ; String Observacion = "<STR_LIT>" ; String UsuarioRegistro = "<STR_LIT>" ; Date FechaRegistro ; String CodCliente = "<STR_LIT>" ; String CodCuenta = "<STR_LIT>" ; List < Venta > arrNroCuota = new ArrayList < Venta > ( ) ; Venta oVenCuota = null ; oVenCuota = new Venta ( ) ; oVenCuota . setNroCuota ( <NUM_LIT:1> ) ; arrNroCuota . add ( oVenCuota ) ; oVenCuota = new Venta ( ) ; oVenCuota . setNroCuota ( <NUM_LIT:2> ) ; arrNroCuota . add ( oVenCuota ) ; assertTrue ( objAdmVenta . registraPagoBoletaFactura ( arrMovimiento , NroMovimiento , TipoComprobante , NroBoleta , RUC , CodCliente , CodCuenta , arrNroCuota , UsuarioRegistro ) ) ; } @ Test public void registrarPagoFacturaCuota3 ( ) { System . out . println ( "<STR_LIT>" ) ; int NroMovimiento = <NUM_LIT:9> ; String TipoComprobante = "<STR_LIT:2>" ; String NroBoleta = "<STR_LIT>" ; String RUC = "<STR_LIT>" ; String Observacion = "<STR_LIT>" ; String UsuarioRegistro = "<STR_LIT>" ; Date FechaRegistro ; String CodCliente = "<STR_LIT>" ; String CodCuenta = "<STR_LIT>" ; List < Venta > arrNroCuota = new ArrayList < Venta > ( ) ; Venta oVenCuota = null ; oVenCuota = new Venta ( ) ; oVenCuota . setNroCuota ( <NUM_LIT:3> ) ; arrNroCuota . add ( oVenCuota ) ; assertTrue ( objAdmVenta . registraPagoBoletaFactura ( arrMovimiento , NroMovimiento , TipoComprobante , NroBoleta , RUC , CodCliente , CodCuenta , arrNroCuota , UsuarioRegistro ) ) ; } @ Test public void registrarPagoBoletaCuota2 ( ) { System . out . println ( "<STR_LIT>" ) ; int NroMovimiento = <NUM_LIT:10> ; String TipoComprobante = "<STR_LIT:1>" ; String NroBoleta = "<STR_LIT>" ; String RUC = "<STR_LIT>" ; String Observacion = "<STR_LIT>" ; String UsuarioRegistro = "<STR_LIT>" ; Date FechaRegistro ; String CodCliente = "<STR_LIT>" ; String CodCuenta = "<STR_LIT>" ; List < Venta > arrNroCuota = new ArrayList < Venta > ( ) ; Venta oVenCuota = null ; oVenCuota = new Venta ( ) ; oVenCuota . setNroCuota ( <NUM_LIT:3> ) ; arrNroCuota . add ( oVenCuota ) ; assertTrue ( objAdmVenta . registraPagoBoletaFactura ( arrMovimiento , NroMovimiento , TipoComprobante , NroBoleta , RUC , CodCliente , CodCuenta , arrNroCuota , UsuarioRegistro ) ) ; } @ Test public void listarMovimientos ( ) { ArrayList < Venta > arrlstMovimiento = objAdmVenta . listarMovimientos ( arrMovimiento ) ; Assert . assertTrue ( arrlstMovimiento . size ( ) >= <NUM_LIT:0> ) ; System . out . println ( "<STR_LIT>" ) ; } @ Test public void listarMovimientosBoleta ( ) { System . out . println ( "<STR_LIT>" ) ; String codTipoDocumento = "<STR_LIT:1>" ; ArrayList < Venta > arrlstMovimiento = objAdmVenta . listarMovimientosTipoDocumento ( arrMovimiento , codTipoDocumento ) ; Assert . assertTrue ( arrlstMovimiento . size ( ) >= <NUM_LIT:0> ) ; System . out . println ( "<STR_LIT>" ) ; } @ Test public void listarMovimientosFactura ( ) { System . out . println ( "<STR_LIT>" ) ; String codTipoDocumento = "<STR_LIT:2>" ; ArrayList < Venta > arrlstMovimiento = objAdmVenta . listarMovimientosTipoDocumento ( arrMovimiento , codTipoDocumento ) ; Assert . assertTrue ( arrlstMovimiento . size ( ) >= <NUM_LIT:0> ) ; System . out . println ( "<STR_LIT>" ) ; } @ Test public void listarDetalleMovimiento ( ) { System . out . println ( "<STR_LIT>" ) ; int nroMovimiento = <NUM_LIT:2> ; ArrayList < Venta > arrlstMovimiento = objAdmVenta . listarDetalleMovimiento ( arrMovimiento , nroMovimiento ) ; Assert . assertTrue ( arrlstMovimiento . size ( ) >= <NUM_LIT:0> ) ; System . out . println ( "<STR_LIT>" ) ; } @ Test public void listarDetalleMovimientoInexistente ( ) { System . out . println ( "<STR_LIT>" ) ; int nroMovimiento = <NUM_LIT:6> ; ArrayList < Venta > arrlstMovimiento = objAdmVenta . listarDetalleMovimiento ( arrMovimiento , nroMovimiento ) ; Assert . assertTrue ( arrlstMovimiento . size ( ) >= <NUM_LIT:0> ) ; System . out . println ( "<STR_LIT>" ) ; } @ Test public void anularFactura ( ) { System . out . println ( "<STR_LIT>" ) ; listarMovimientos ( ) ; int nroMovimiento = <NUM_LIT:4> ; String Estado = "<STR_LIT>" ; assertTrue ( objAdmVenta . anularDocumento ( arrMovimiento , nroMovimiento ) ) ; System . out . println ( "<STR_LIT>" ) ; listarMovimientos ( ) ; System . out . println ( "<STR_LIT>" ) ; } @ Test public void resumenMovimientos ( ) { System . out . println ( "<STR_LIT>" ) ; listarMovimientos ( ) ; Double SumTotal = <NUM_LIT:0.0> ; for ( Venta oMovi : arrMovimiento ) { SumTotal = SumTotal + oMovi . getMonTotal ( ) ; } System . out . println ( "<STR_LIT>" + SumTotal ) ; System . out . println ( "<STR_LIT>" ) ; } public static void cargarCursos ( ) { List < Venta > olstCurso = new ArrayList < Venta > ( ) ; Venta objVenta = new Venta ( ) ; olstCurso = objVenta . getDataCursos ( ) ; for ( Venta oVenta : olstCurso ) { System . out . println ( "<STR_LIT>" + oVenta . getCodCurso ( ) + "<STR_LIT>" + oVenta . getNomCurso ( ) + "<STR_LIT>" + oVenta . getPreCurso ( ) ) ; } } public static void cargarCliente ( ) { DataBD objData = new DataBD ( ) ; List < Cliente > olstCliente = new ArrayList < Cliente > ( ) ; olstCliente = objData . getDataCliente ( ) ; for ( Cliente oCliente : olstCliente ) { System . out . println ( "<STR_LIT>" + oCliente . getCodCliente ( ) + "<STR_LIT>" + oCliente . getNomCliente ( ) + "<STR_LIT>" + oCliente . getDniCliente ( ) ) ; } } static void cargarMovimientos ( ) { Venta objVenta ; int nroMovimiento = <NUM_LIT:1> ; String codTipoDocumento = "<STR_LIT:2>" ; String codCurso = "<STR_LIT>" ; String nomCurso ; double preCurso ; int CanCurso ; String NomEmpleado ; String ApeEmpleado ; String CodEmpleado ; String codCliente = "<STR_LIT>" ; String codTipCliente ; String nroDniCliente = "<STR_LIT>" ; String nroRucCliente = "<STR_LIT>" ; String nomCliente = "<STR_LIT>" ; String ApePatCliente ; String ApeMatCliente ; String nomEmpresa = "<STR_LIT>" ; String concepto = "<STR_LIT>" ; String fecEmision = "<STR_LIT>" ; Double subTotal = <NUM_LIT> ; Double monIGV = <NUM_LIT> ; Double monTotal = <NUM_LIT> ; String moneda = "<STR_LIT>" ; String fecVencim = "<STR_LIT>" ; String estado = "<STR_LIT>" ; String fecPagoReal = "<STR_LIT>" ; String observacion = "<STR_LIT>" ; objVenta = new Venta ( ) ; objVenta . setNumero ( nroMovimiento ) ; objVenta . setCodTipoDocumento ( codTipoDocumento ) ; objVenta . setCodCurso ( codCurso ) ; objVenta . setCodCliente ( codCliente ) ; objVenta . setNomCliente ( nomCliente ) ; objVenta . setNroRucCliente ( nroRucCliente ) ; objVenta . setConcepto ( concepto ) ; objVenta . setFecEmision ( fecEmision ) ; objVenta . setMonSubtot ( subTotal ) ; objVenta . setMonIGV ( monIGV ) ; objVenta . setMonTotal ( monTotal ) ; objVenta . setMoneda ( moneda ) ; objVenta . setFecVencim ( fecVencim ) ; objVenta . setEstado ( estado ) ; objVenta . setFecPago ( fecPagoReal ) ; objVenta . setObservacion ( observacion ) ; arrMovimiento . add ( objVenta ) ; nroMovimiento = <NUM_LIT:2> ; codTipoDocumento = "<STR_LIT:2>" ; codCurso = "<STR_LIT>" ; codCliente = "<STR_LIT>" ; nroDniCliente = "<STR_LIT>" ; nroRucCliente = "<STR_LIT>" ; nomCliente = "<STR_LIT>" ; concepto = "<STR_LIT>" ; fecEmision = "<STR_LIT>" ; subTotal = <NUM_LIT> ; monIGV = <NUM_LIT> ; monTotal = <NUM_LIT> ; moneda = "<STR_LIT>" ; fecVencim = "<STR_LIT>" ; estado = "<STR_LIT>" ; fecPagoReal = "<STR_LIT>" ; observacion = "<STR_LIT>" ; objVenta = new Venta ( ) ; objVenta . setNumero ( nroMovimiento ) ; objVenta . setCodTipoDocumento ( codTipoDocumento ) ; objVenta . setCodCurso ( codCurso ) ; objVenta . setCodCliente ( codCliente ) ; objVenta . setNomCliente ( nomCliente ) ; objVenta . setNroRucCliente ( nroRucCliente ) ; objVenta . setConcepto ( concepto ) ; objVenta . setFecEmision ( fecEmision ) ; objVenta . setMonSubtot ( subTotal ) ; objVenta . setMonIGV ( monIGV ) ; objVenta . setMonTotal ( monTotal ) ; objVenta . setMoneda ( moneda ) ; objVenta . setFecVencim ( fecVencim ) ; objVenta . setEstado ( estado ) ; objVenta . setFecPago ( fecPagoReal ) ; objVenta . setObservacion ( observacion ) ; arrMovimiento . add ( objVenta ) ; nroMovimiento = <NUM_LIT:3> ; codTipoDocumento = "<STR_LIT:1>" ; codCurso = "<STR_LIT>" ; codCliente = "<STR_LIT>" ; nroDniCliente = "<STR_LIT>" ; nomCliente = "<STR_LIT>" ; concepto = "<STR_LIT>" ; fecEmision = "<STR_LIT>" ; subTotal = <NUM_LIT> ; monIGV = <NUM_LIT> ; monTotal = <NUM_LIT> ; moneda = "<STR_LIT>" ; fecVencim = "<STR_LIT>" ; estado = "<STR_LIT>" ; fecPagoReal = "<STR_LIT>" ; observacion = "<STR_LIT>" ; objVenta = new Venta ( ) ; objVenta . setNumero ( nroMovimiento ) ; objVenta . setCodTipoDocumento ( codTipoDocumento ) ; objVenta . setCodCurso ( codCurso ) ; objVenta . setCodCliente ( codCliente ) ; objVenta . setNomCliente ( nomCliente ) ; objVenta . setNroRucCliente ( nroRucCliente ) ; objVenta . setConcepto ( concepto ) ; objVenta . setFecEmision ( fecEmision ) ; objVenta . setMonSubtot ( subTotal ) ; objVenta . setMonIGV ( monIGV ) ; objVenta . setMonTotal ( monTotal ) ; objVenta . setMoneda ( moneda ) ; objVenta . setFecVencim ( fecVencim ) ; objVenta . setEstado ( estado ) ; objVenta . setFecPago ( fecPagoReal ) ; objVenta . setObservacion ( observacion ) ; arrMovimiento . add ( objVenta ) ; nroMovimiento = <NUM_LIT:4> ; codTipoDocumento = "<STR_LIT:1>" ; codCurso = "<STR_LIT>" ; codCliente = "<STR_LIT>" ; nroDniCliente = "<STR_LIT>" ; nomCliente = "<STR_LIT>" ; concepto = "<STR_LIT>" ; fecEmision = "<STR_LIT>" ; subTotal = <NUM_LIT> ; monIGV = <NUM_LIT> ; monTotal = <NUM_LIT> ; moneda = "<STR_LIT>" ; fecVencim = "<STR_LIT>" ; estado = "<STR_LIT>" ; fecPagoReal = "<STR_LIT>" ; observacion = "<STR_LIT>" ; objVenta = new Venta ( ) ; objVenta . setNumero ( nroMovimiento ) ; objVenta . setCodTipoDocumento ( codTipoDocumento ) ; objVenta . setCodCurso ( codCurso ) ; objVenta . setCodCliente ( codCliente ) ; objVenta . setNomCliente ( nomCliente ) ; objVenta . setNroRucCliente ( nroRucCliente ) ; objVenta . setConcepto ( concepto ) ; objVenta . setFecEmision ( fecEmision ) ; objVenta . setMonSubtot ( subTotal ) ; objVenta . setMonIGV ( monIGV ) ; objVenta . setMonTotal ( monTotal ) ; objVenta . setMoneda ( moneda ) ; objVenta . setFecVencim ( fecVencim ) ; objVenta . setEstado ( estado ) ; objVenta . setFecPago ( fecPagoReal ) ; objVenta . setObservacion ( observacion ) ; arrMovimiento . add ( objVenta ) ; } } </s>
|
<s> package benedictoxvi . pe . businesstest ; import java . util . ArrayList ; import org . junit . Assert ; import org . junit . Before ; import org . junit . Test ; import benedictoxvi . pe . business . AdmProspecto ; import benedictoxvi . pe . data . Prospecto ; import benedictoxvi . pe . util . Loader ; public class AdmProspectoTest { ArrayList < Prospecto > arrPro = new ArrayList < Prospecto > ( ) ; AdmProspecto admPro = new AdmProspecto ( ) ; @ Test public void findEncontrarProspectoTest ( ) { String nombs = "<STR_LIT>" , apepat = "<STR_LIT>" , apemat = "<STR_LIT>" , mail = "<STR_LIT>" , dni = "<STR_LIT>" , tel_cel = "<STR_LIT>" , fecha = "<STR_LIT>" ; ArrayList < Prospecto > filtroPro = admPro . findProspecto ( nombs , apepat , apemat , mail , dni , tel_cel , fecha , "<STR_LIT>" ) ; Assert . assertTrue ( filtroPro . size ( ) >= <NUM_LIT:0> ) ; } @ Test public void findSinEncontrarProspectoTest ( ) { String nombs = "<STR_LIT>" , apepat = "<STR_LIT>" , apemat = "<STR_LIT>" , mail = "<STR_LIT>" , dni = "<STR_LIT>" , tel_cel = "<STR_LIT>" , fecha = "<STR_LIT>" ; ArrayList < Prospecto > filtroPro = admPro . findProspecto ( nombs , apepat , apemat , mail , dni , tel_cel , fecha , "<STR_LIT>" ) ; Assert . assertTrue ( filtroPro . size ( ) == <NUM_LIT:0> ) ; } @ Test public void darAltaProspecto ( ) { Assert . assertEquals ( "<STR_LIT:U+0020>" , admPro . getProspectoByNum ( <NUM_LIT> ) . getEstado ( ) ) ; Assert . assertTrue ( admPro . deProspectoToCliente ( <NUM_LIT> ) ) ; Assert . assertEquals ( "<STR_LIT:C>" , admPro . getProspectoByNum ( <NUM_LIT> ) . getEstado ( ) ) ; } @ Test public void darAltaProspectoAClienteExistente ( ) { Assert . assertEquals ( "<STR_LIT:U+0020>" , admPro . getProspectoByNum ( <NUM_LIT> ) . getEstado ( ) ) ; Assert . assertTrue ( admPro . deProspectoToCliente ( <NUM_LIT> ) ) ; Assert . assertEquals ( "<STR_LIT:C>" , admPro . getProspectoByNum ( <NUM_LIT> ) . getEstado ( ) ) ; Assert . assertFalse ( admPro . deProspectoToCliente ( <NUM_LIT> ) ) ; } @ Test public void modificarProspecto ( ) { Assert . assertNotSame ( "<STR_LIT>" , admPro . getProspectoByNum ( <NUM_LIT:1000> ) . getNombes ( ) ) ; Assert . assertTrue ( admPro . modifcarProspecto ( <NUM_LIT:1000> , null , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , null , null , null , null , null ) ) ; Assert . assertEquals ( "<STR_LIT>" , admPro . getProspectoByNum ( <NUM_LIT:1000> ) . getNombes ( ) ) ; } @ Test public void registrarProspectoTest ( ) { Assert . assertNull ( admPro . getProspectoByNum ( <NUM_LIT:1> ) ) ; Assert . assertTrue ( admPro . registrarProspecto ( <NUM_LIT:1> , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) ) ; Assert . assertNotNull ( admPro . getProspectoByNum ( <NUM_LIT:1> ) ) ; } @ Test public void eliminarProspectoTest ( ) { int num_pro = <NUM_LIT> ; Assert . assertNotNull ( admPro . getProspectoByNum ( num_pro ) ) ; Assert . assertTrue ( admPro . eliminarProspecto ( num_pro ) ) ; Assert . assertNull ( admPro . getProspectoByNum ( num_pro ) ) ; } } </s>
|
<s> package benedictoxvi . pe . businesstest ; import java . util . ArrayList ; import junit . framework . Assert ; import org . junit . Before ; import org . junit . Test ; import benedictoxvi . pe . business . AdmGrupoEstudio ; import benedictoxvi . pe . data . Cliente ; import benedictoxvi . pe . data . GrupoEstudio ; import benedictoxvi . pe . util . Loader ; public class AdmGrupoEstudioTest { ArrayList < GrupoEstudio > arrGru = new ArrayList < GrupoEstudio > ( ) ; AdmGrupoEstudio admGru = new AdmGrupoEstudio ( ) ; @ Test public void encontrarGruposEstudioTest ( ) { Assert . assertTrue ( admGru . encontrarGrupoEstudio ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) . size ( ) > <NUM_LIT:0> ) ; } @ Test public void sinEncontrarGruposEstudioTest ( ) { Assert . assertEquals ( <NUM_LIT:0> , admGru . encontrarGrupoEstudio ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) . size ( ) ) ; } @ Test public void registraGrupoEstudioTest ( ) { Assert . assertTrue ( admGru . registraGrupoEstudio ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , new String [ ] { "<STR_LIT>" , "<STR_LIT>" } , "<STR_LIT>" , "<STR_LIT>" , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ) ) ; } @ Test public void registraGrupoEstudioSinNomGrupoTest ( ) { Assert . assertFalse ( admGru . registraGrupoEstudio ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , new String [ ] { "<STR_LIT>" , "<STR_LIT>" } , "<STR_LIT>" , "<STR_LIT>" , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ) ) ; } @ Test public void registraGrupoEstudioSinFechasTest ( ) { Assert . assertFalse ( admGru . registraGrupoEstudio ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , new String [ ] { "<STR_LIT>" , "<STR_LIT>" } , "<STR_LIT>" , "<STR_LIT>" , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ) ) ; } @ Test public void registraGrupoEstudioConFechaErrorTest ( ) { Assert . assertFalse ( admGru . registraGrupoEstudio ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , new String [ ] { "<STR_LIT>" , "<STR_LIT>" } , "<STR_LIT>" , "<STR_LIT>" , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ) ) ; } @ Test public void registraGrupoEstudioConRangoFechaErrorTest ( ) { Assert . assertFalse ( admGru . registraGrupoEstudio ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , new String [ ] { "<STR_LIT>" , "<STR_LIT>" } , "<STR_LIT>" , "<STR_LIT>" , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ) ) ; } @ Test public void agregarAlumnoPorClienteGrupoEstudioTest ( ) { GrupoEstudio grupo = admGru . getGrupoById ( "<STR_LIT>" ) ; int num_alumnos = grupo . getNumAlumnos ( ) ; Assert . assertTrue ( admGru . addAlumnoGrupoEstudio ( grupo . getCodGrupo ( ) , "<STR_LIT>" ) ) ; Assert . assertEquals ( num_alumnos + <NUM_LIT:1> , grupo . getInscritos ( ) . size ( ) ) ; } @ Test public void agregarAlumnoPorClienteExistenteGrupoEstudioTest ( ) { GrupoEstudio grupo = admGru . getGrupoById ( "<STR_LIT>" ) ; Assert . assertTrue ( admGru . addAlumnoGrupoEstudio ( grupo . getCodGrupo ( ) , "<STR_LIT>" ) ) ; } @ Test public void agregarAlumnoPorClienteGrupoEstudioErroneoTest ( ) { Assert . assertFalse ( admGru . addAlumnoGrupoEstudio ( "<STR_LIT>" , "<STR_LIT>" ) ) ; } @ Test public void agregarAlumnoPorClienteErroneoGrupoEstudioTest ( ) { Assert . assertFalse ( admGru . addAlumnoGrupoEstudio ( "<STR_LIT>" , "<STR_LIT>" ) ) ; } @ Test public void agregarAlumnoGrupoEstudiosAforoMaximo ( ) { GrupoEstudio grupo = admGru . getGrupoById ( "<STR_LIT>" ) ; Assert . assertEquals ( grupo . getAforo ( ) , grupo . getNumAlumnos ( ) ) ; Assert . assertFalse ( admGru . addAlumnoGrupoEstudio ( grupo . getCodGrupo ( ) , "<STR_LIT>" ) ) ; } @ Test public void quitarAlumnoGrupoEstudios ( ) { Assert . assertTrue ( admGru . verificarAlumnoEnGrupo ( "<STR_LIT>" , "<STR_LIT>" ) ) ; Assert . assertFalse ( admGru . addAlumnoGrupoEstudio ( "<STR_LIT>" , "<STR_LIT>" ) ) ; } } </s>
|
<s> package benedictoxvi . pe . businesstest ; import java . util . ArrayList ; import org . junit . Assert ; import org . junit . Test ; import benedictoxvi . pe . business . AdmCliente ; import benedictoxvi . pe . data . Cliente ; public class AdmClienteTest { ArrayList < Cliente > arrCli = new ArrayList < Cliente > ( ) ; AdmCliente admCli = new AdmCliente ( ) ; @ Test public void findEncontrarClienteTest ( ) { String nombs = "<STR_LIT>" , apepat = "<STR_LIT>" , apemat = "<STR_LIT>" , mail = "<STR_LIT>" , dni = "<STR_LIT>" , tel_cel = "<STR_LIT>" , fecha = "<STR_LIT>" ; ArrayList < Cliente > filtroCli = admCli . findCliente ( nombs , apepat , apemat , mail , dni , tel_cel , fecha , "<STR_LIT>" ) ; Assert . assertTrue ( filtroCli . size ( ) >= <NUM_LIT:0> ) ; } @ Test public void findSinEncontrarClienteTest ( ) { String nombs = "<STR_LIT>" , apepat = "<STR_LIT>" , apemat = "<STR_LIT>" , mail = "<STR_LIT>" , dni = "<STR_LIT>" , tel_cel = "<STR_LIT>" , fecha = "<STR_LIT>" ; ArrayList < Cliente > filtroCli = admCli . findCliente ( nombs , apepat , apemat , mail , dni , tel_cel , fecha , "<STR_LIT>" ) ; Assert . assertTrue ( filtroCli . size ( ) == <NUM_LIT:0> ) ; } @ Test public void registrarClienteTest ( ) { Assert . assertNull ( admCli . getClienteByNum ( "<STR_LIT>" ) ) ; Assert . assertTrue ( admCli . registrarCliente ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) ) ; Assert . assertNotNull ( admCli . getClienteByNum ( "<STR_LIT>" ) ) ; } @ Test public void eliminarClienteTest ( ) { String cod_cli = "<STR_LIT>" ; Assert . assertNotNull ( admCli . getClienteByNum ( cod_cli ) ) ; Assert . assertTrue ( admCli . eliminarCliente ( cod_cli ) ) ; Assert . assertNull ( admCli . getClienteByNum ( cod_cli ) ) ; } } </s>
|
<s> package benedictoxvi . pe . businesstest ; import junit . framework . Assert ; import org . junit . Test ; import benedictoxvi . pe . business . AdmAccesosUser ; public class AdmAccesosUserTest { AdmAccesosUser objAcc = new AdmAccesosUser ( ) ; @ Test public void verificarAccesoCorrectoTest ( ) { String my_user = "<STR_LIT>" ; Assert . assertTrue ( objAcc . requestAcceso ( my_user , "<STR_LIT>" ) ) ; } @ Test public void verificarAccesoIncorrectoTest ( ) { String my_user = "<STR_LIT>" ; Assert . assertFalse ( objAcc . requestAcceso ( my_user , "<STR_LIT>" ) ) ; } @ Test public void verificarAdicionCorrectoTest ( ) { String my_user = "<STR_LIT>" ; Assert . assertTrue ( objAcc . requestAdicion ( my_user , "<STR_LIT>" ) ) ; } @ Test public void verificarAdicionIncorrectoTest ( ) { String my_user = "<STR_LIT>" ; Assert . assertFalse ( objAcc . requestAdicion ( my_user , "<STR_LIT>" ) ) ; } @ Test public void verificarModificacionCorrectoTest ( ) { String my_user = "<STR_LIT>" ; Assert . assertTrue ( objAcc . requestModificacion ( my_user , "<STR_LIT>" ) ) ; } @ Test public void verificarModificacionIncorrectoTest ( ) { String my_user = "<STR_LIT>" ; Assert . assertFalse ( objAcc . requestModificacion ( my_user , "<STR_LIT>" ) ) ; } @ Test public void verificarEliminacionCorrectoTest ( ) { String my_user = "<STR_LIT>" ; Assert . assertTrue ( objAcc . requestEliminacion ( my_user , "<STR_LIT>" ) ) ; } @ Test public void verificarEliminacionIncorrectoTest ( ) { String my_user = "<STR_LIT>" ; Assert . assertFalse ( objAcc . requestEliminacion ( my_user , "<STR_LIT>" ) ) ; } @ Test public void rolesByUserTest ( ) { Assert . assertEquals ( <NUM_LIT:2> , objAcc . rolesByUser ( "<STR_LIT>" ) . size ( ) ) ; } @ Test public void modulosByRolTest ( ) { Assert . assertEquals ( <NUM_LIT:5> , objAcc . modulosByRol ( "<STR_LIT>" ) . size ( ) ) ; } @ Test public void addRolUserTest ( ) { Assert . assertEquals ( <NUM_LIT:2> , objAcc . rolesByUser ( "<STR_LIT>" ) . size ( ) ) ; Assert . assertTrue ( objAcc . addRolUser ( "<STR_LIT>" , "<STR_LIT>" ) ) ; Assert . assertEquals ( <NUM_LIT:3> , objAcc . rolesByUser ( "<STR_LIT>" ) . size ( ) ) ; } @ Test public void addRolUserRepetidoTest ( ) { Assert . assertEquals ( <NUM_LIT:2> , objAcc . rolesByUser ( "<STR_LIT>" ) . size ( ) ) ; Assert . assertFalse ( objAcc . addRolUser ( "<STR_LIT>" , "<STR_LIT>" ) ) ; Assert . assertEquals ( <NUM_LIT:2> , objAcc . rolesByUser ( "<STR_LIT>" ) . size ( ) ) ; } @ Test public void removeRolUserTest ( ) { Assert . assertEquals ( <NUM_LIT:1> , objAcc . rolesByUser ( "<STR_LIT>" ) . size ( ) ) ; Assert . assertTrue ( objAcc . removeRolUser ( "<STR_LIT>" , "<STR_LIT>" ) ) ; Assert . assertEquals ( <NUM_LIT:0> , objAcc . rolesByUser ( "<STR_LIT>" ) . size ( ) ) ; } @ Test public void removeRolInexistenteUserTest ( ) { Assert . assertEquals ( <NUM_LIT:1> , objAcc . rolesByUser ( "<STR_LIT>" ) . size ( ) ) ; Assert . assertFalse ( objAcc . removeRolUser ( "<STR_LIT>" , "<STR_LIT>" ) ) ; Assert . assertEquals ( <NUM_LIT:1> , objAcc . rolesByUser ( "<STR_LIT>" ) . size ( ) ) ; } @ Test public void removeUsuarioInexistenteRolTest ( ) { Assert . assertFalse ( objAcc . removeRolUser ( "<STR_LIT>" , "<STR_LIT>" ) ) ; } @ Test public void checkAddRolAccessUser ( ) { Assert . assertFalse ( objAcc . requestAcceso ( "<STR_LIT>" , "<STR_LIT>" ) ) ; Assert . assertTrue ( objAcc . addRolUser ( "<STR_LIT>" , "<STR_LIT>" ) ) ; Assert . assertTrue ( objAcc . requestAcceso ( "<STR_LIT>" , "<STR_LIT>" ) ) ; } } </s>
|
<s> package benedictoxvi . pe . businesstest ; import static org . junit . Assert . * ; import java . util . ArrayList ; import junit . framework . Assert ; import org . junit . Test ; import benedictoxvi . pe . business . AdmUsuarios ; import benedictoxvi . pe . data . Rol ; import benedictoxvi . pe . data . Usuario ; import benedictoxvi . pe . util . Security ; public class AdmUsuarioTest { AdmUsuarios admUsuarios = new AdmUsuarios ( ) ; AdmRolTest test = new AdmRolTest ( ) ; Security sec = new Security ( ) ; @ Test public void createUsuarioTest ( ) { Assert . assertTrue ( admUsuarios . createUsuario ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , new String [ ] { "<STR_LIT>" } , "<STR_LIT>" , "<STR_LIT>" ) ) ; } @ Test public void createUsuarioClavesDistintasTest ( ) { Assert . assertFalse ( admUsuarios . createUsuario ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , new String [ ] { "<STR_LIT>" } , "<STR_LIT>" , "<STR_LIT>" ) ) ; } @ Test public void createUsuarioUsuarioVacioTest ( ) { Assert . assertFalse ( admUsuarios . createUsuario ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , new String [ ] { "<STR_LIT>" } , "<STR_LIT>" , "<STR_LIT>" ) ) ; } @ Test public void cambiarClaveUsuarioTest ( ) { Assert . assertTrue ( admUsuarios . cambiarClaveUsuario ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) ) ; } @ Test public void loginUserTest ( ) { Assert . assertTrue ( admUsuarios . loginUser ( "<STR_LIT>" , "<STR_LIT>" ) ) ; } @ Test public void bloquearUsuarioTest ( ) { Assert . assertTrue ( admUsuarios . loginUser ( "<STR_LIT>" , "<STR_LIT>" ) ) ; Assert . assertTrue ( admUsuarios . bloquearUsuario ( "<STR_LIT>" ) ) ; Assert . assertFalse ( admUsuarios . loginUser ( "<STR_LIT>" , "<STR_LIT>" ) ) ; } @ Test public void desbloquearUsuarioTest ( ) { Assert . assertFalse ( admUsuarios . loginUser ( "<STR_LIT>" , "<STR_LIT>" ) ) ; Assert . assertTrue ( admUsuarios . desbloquearUsuario ( "<STR_LIT>" ) ) ; Assert . assertTrue ( admUsuarios . loginUser ( "<STR_LIT>" , "<STR_LIT>" ) ) ; } @ Test public void modificarDatosUsuarioTest ( ) { Usuario usr = admUsuarios . getUserByName ( "<STR_LIT>" ) ; Assert . assertNotSame ( "<STR_LIT>" , usr . getCargo ( ) ) ; Assert . assertNotSame ( "<STR_LIT>" , usr . getDni ( ) ) ; Assert . assertTrue ( admUsuarios . modificarUsuario ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , null , null , "<STR_LIT>" , "<STR_LIT>" ) ) ; Assert . assertEquals ( "<STR_LIT>" , usr . getCargo ( ) ) ; Assert . assertEquals ( "<STR_LIT>" , usr . getDni ( ) ) ; Assert . assertEquals ( "<STR_LIT>" , usr . getNombre ( ) ) ; Assert . assertEquals ( "<STR_LIT>" , usr . getApellidoPaterno ( ) ) ; Assert . assertEquals ( "<STR_LIT>" , usr . getApellidoMaterno ( ) ) ; } @ Test public void modificarDatosErroneosUsuarioTest ( ) { Usuario usr = admUsuarios . getUserByName ( "<STR_LIT>" ) ; Assert . assertFalse ( admUsuarios . modificarUsuario ( "<STR_LIT>" , null , null , null , "<STR_LIT>" , null , "<STR_LIT>" , "<STR_LIT>" ) ) ; Assert . assertNotSame ( "<STR_LIT>" , usr . getCargo ( ) ) ; } @ Test public void suprimirUsuarioTest ( ) { int num_usuarios = admUsuarios . getarrUsr ( ) . size ( ) ; Assert . assertEquals ( num_usuarios , admUsuarios . getarrUsr ( ) . size ( ) ) ; Assert . assertTrue ( admUsuarios . quitarUsuario ( "<STR_LIT>" ) ) ; num_usuarios = num_usuarios - <NUM_LIT:1> ; Assert . assertEquals ( num_usuarios , admUsuarios . getarrUsr ( ) . size ( ) ) ; } @ Test public void suprimirUsuarioInexistenteTest ( ) { int num_usuarios = admUsuarios . getarrUsr ( ) . size ( ) ; Assert . assertEquals ( num_usuarios , admUsuarios . getarrUsr ( ) . size ( ) ) ; Assert . assertFalse ( admUsuarios . quitarUsuario ( "<STR_LIT>" ) ) ; Assert . assertEquals ( num_usuarios , admUsuarios . getarrUsr ( ) . size ( ) ) ; } } </s>
|
<s> package benedictoxvi . pe . businesstest ; import junit . framework . Assert ; import org . junit . Test ; import benedictoxvi . pe . business . AdmLoginUsuario ; public class AdmLoginUsuarioTest { AdmLoginUsuario admUsr = new AdmLoginUsuario ( ) ; @ Test public void loginSatisfactorioTest ( ) { String usuario = "<STR_LIT>" ; String clave = "<STR_LIT>" ; Assert . assertTrue ( admUsr . loginUsuario ( usuario , clave ) ) ; } @ Test public void loginErroneoTest ( ) { String usuario = "<STR_LIT>" ; String clave = "<STR_LIT>" ; Assert . assertFalse ( admUsr . loginUsuario ( usuario , clave ) ) ; } @ Test public void loginUsuarioVacioTest ( ) { String usuario = "<STR_LIT>" ; String clave = "<STR_LIT>" ; Assert . assertFalse ( admUsr . loginUsuario ( usuario , clave ) ) ; } @ Test public void loginUsuarioInexistenteTest ( ) { String usuario = "<STR_LIT>" ; String clave = "<STR_LIT>" ; Assert . assertFalse ( admUsr . loginUsuario ( usuario , clave ) ) ; } @ Test public void loginClaveVaciaTest ( ) { String usuario = "<STR_LIT>" ; String clave = "<STR_LIT>" ; Assert . assertFalse ( admUsr . loginUsuario ( usuario , clave ) ) ; } @ Test public void bloquearUsuarioPorIntentosFallidosTest ( ) { int max_intentos = <NUM_LIT:5> ; String usuario = "<STR_LIT>" ; String clave = "<STR_LIT>" ; for ( int num_intento = <NUM_LIT:1> ; num_intento <= max_intentos ; num_intento ++ ) { Assert . assertFalse ( admUsr . loginUsuario ( usuario , clave ) ) ; } Assert . assertFalse ( admUsr . loginUsuario ( usuario , clave ) ) ; } } </s>
|
<s> package benedictoxvi . pe . businesstest ; import static org . junit . Assert . * ; import java . util . ArrayList ; import junit . framework . Assert ; import org . junit . Before ; import org . junit . Test ; import benedictoxvi . pe . business . AdmRoles ; import benedictoxvi . pe . data . Modulo ; import benedictoxvi . pe . data . Rol ; public class AdmRolTest { AdmRoles admRol = new AdmRoles ( ) ; ArrayList < Modulo > arrMod = new ArrayList < Modulo > ( ) ; Modulo modVentas = new Modulo ( "<STR_LIT>" , true , true , true , true ) ; Modulo modCompras = new Modulo ( "<STR_LIT>" , true , true , true , true ) ; Modulo modClientes = new Modulo ( "<STR_LIT>" , true , true , true , true ) ; Modulo modProspectos = new Modulo ( "<STR_LIT>" , true , true , true , true ) ; private Rol rolActual ; @ Before public void cargarModulos ( ) { arrMod . add ( new Modulo ( "<STR_LIT>" , true , true , true , true ) ) ; arrMod . add ( new Modulo ( "<STR_LIT>" , true , true , true , true ) ) ; arrMod . add ( new Modulo ( "<STR_LIT>" , true , true , true , true ) ) ; } @ Test public void crearRolConModulosTest ( ) { ArrayList < Modulo > mods = new ArrayList < Modulo > ( ) ; mods . add ( modProspectos ) ; mods . add ( modCompras ) ; Assert . assertTrue ( admRol . registrarRol ( "<STR_LIT>" , "<STR_LIT>" , mods ) ) ; } @ Test public void crearRolConModulosErroneosTest ( ) { ArrayList < Modulo > mods = new ArrayList < Modulo > ( ) ; mods . add ( modProspectos ) ; mods . add ( modClientes ) ; mods . add ( modCompras ) ; Assert . assertFalse ( admRol . registrarRol ( "<STR_LIT>" , "<STR_LIT>" , mods ) ) ; } @ Test public void crearRolConDatosVaciosErroneosTest ( ) { ArrayList < Modulo > mods = new ArrayList < Modulo > ( ) ; mods . add ( modProspectos ) ; Assert . assertFalse ( admRol . registrarRol ( "<STR_LIT>" , "<STR_LIT>" , mods ) ) ; } @ Test public void crearRolSinModulosTest ( ) { ArrayList < Modulo > mods = new ArrayList < Modulo > ( ) ; Assert . assertTrue ( admRol . registrarRol ( "<STR_LIT>" , "<STR_LIT>" , mods ) ) ; } @ Test public void modificarRolTest ( ) { ArrayList < Modulo > mods = new ArrayList < Modulo > ( ) ; Assert . assertTrue ( admRol . modificarRol ( "<STR_LIT>" , "<STR_LIT>" , mods ) ) ; } @ Test public void suprimirRolTest ( ) { int num_roles = admRol . getRoles ( ) . size ( ) ; Assert . assertTrue ( admRol . suprimirRol ( "<STR_LIT>" ) ) ; num_roles = num_roles - <NUM_LIT:1> ; Assert . assertEquals ( num_roles , admRol . getRoles ( ) . size ( ) ) ; } @ Test public void suprimirRolConUsuariosTest ( ) { int num_roles = admRol . getRoles ( ) . size ( ) ; Assert . assertFalse ( admRol . suprimirRol ( "<STR_LIT>" ) ) ; Assert . assertEquals ( num_roles , admRol . getRoles ( ) . size ( ) ) ; } @ Test public void verificarExistenciaRolTest ( ) { Assert . assertNotNull ( admRol . findModuloByIdent ( "<STR_LIT>" ) ) ; } @ Test public void verificarInexistenciaRolTest ( ) { Assert . assertNull ( admRol . findModuloByIdent ( "<STR_LIT>" ) ) ; } } </s>
|
<s> package benedictoxvi . pe . datatest ; import junit . framework . Assert ; import org . junit . Test ; import com . sun . xml . internal . ws . developer . UsesJAXBContext ; import benedictoxvi . pe . data . Modulo ; public class ModuloTest { @ Test public void dataModulo1Test ( ) { Modulo objMod = new Modulo ( ) ; objMod . setNombre ( "<STR_LIT>" ) ; objMod . setDescripcion ( "<STR_LIT>" ) ; objMod . setAcceso ( true ) ; objMod . setAdicionar ( false ) ; objMod . setEditar ( true ) ; objMod . setEliminar ( false ) ; Assert . assertEquals ( "<STR_LIT>" , objMod . getNombre ( ) ) ; Assert . assertEquals ( "<STR_LIT>" , objMod . getDescripcion ( ) ) ; Assert . assertTrue ( objMod . getAcceso ( ) ) ; Assert . assertFalse ( objMod . getAdicionar ( ) ) ; Assert . assertTrue ( objMod . getEditar ( ) ) ; Assert . assertFalse ( objMod . getEliminar ( ) ) ; } @ Test public void dataModulo2Test ( ) { Modulo objMod = new Modulo ( ) ; objMod . setNombre ( "<STR_LIT>" ) ; objMod . setDescripcion ( "<STR_LIT>" ) ; objMod . setAcceso ( true ) ; objMod . setAdicionar ( true ) ; objMod . setEditar ( false ) ; objMod . setEliminar ( false ) ; Assert . assertEquals ( "<STR_LIT>" , objMod . getNombre ( ) ) ; Assert . assertEquals ( "<STR_LIT>" , objMod . getDescripcion ( ) ) ; Assert . assertTrue ( objMod . getAcceso ( ) ) ; Assert . assertTrue ( objMod . getAdicionar ( ) ) ; Assert . assertFalse ( objMod . getEditar ( ) ) ; Assert . assertFalse ( objMod . getEliminar ( ) ) ; } } </s>
|
<s> package benedictoxvi . pe . datatest ; public class UsuarioTest { } </s>
|
<s> package benedictoxvi . pe . datatest ; import org . junit . Test ; public class VentasTest { @ Test public void registrarVenta ( ) { } } </s>
|
<s> package benedictoxvi . pe . datatest ; import static org . junit . Assert . * ; import java . util . ArrayList ; import java . util . List ; import org . junit . Before ; import org . junit . Test ; import benedictoxvi . pe . data . Cliente ; import benedictoxvi . pe . util . * ; public class ClienteTest { Cliente objCli = new Cliente ( ) ; List < String > gruEstudio = new ArrayList < String > ( ) ; List < String > aluGrupo = new ArrayList < String > ( ) ; @ Before public void contruct__ ( ) { objCli . setNomCliente ( "<STR_LIT>" ) ; objCli . setApePatCliente ( "<STR_LIT>" ) ; objCli . setApeMatCliente ( "<STR_LIT>" ) ; objCli . setDniCliente ( "<STR_LIT>" ) ; objCli . setFonCliente ( "<STR_LIT>" ) ; objCli . setFecConCliente ( "<STR_LIT>" ) ; objCli . setEmaCliente ( "<STR_LIT>" ) ; objCli . setEstCliente ( "<STR_LIT>" ) ; gruEstudio . add ( "<STR_LIT>" ) ; gruEstudio . add ( "<STR_LIT>" ) ; gruEstudio . add ( "<STR_LIT>" ) ; gruEstudio . add ( "<STR_LIT>" ) ; } @ Test public void testDataCliente ( ) { assertEquals ( "<STR_LIT>" , objCli . getNomCliente ( ) ) ; assertEquals ( "<STR_LIT>" , objCli . getApePatCliente ( ) ) ; assertEquals ( "<STR_LIT>" , objCli . getApeMatCliente ( ) ) ; assertEquals ( "<STR_LIT>" , objCli . getDniCliente ( ) ) ; assertEquals ( "<STR_LIT>" , objCli . getFonCliente ( ) ) ; assertEquals ( "<STR_LIT>" , objCli . getFecConCliente ( ) ) ; assertEquals ( "<STR_LIT>" , objCli . getEmaCliente ( ) ) ; assertEquals ( "<STR_LIT>" , objCli . getEstCliente ( ) ) ; } @ Test public void testValidaDni ( ) { Validaciones objVal = new Validaciones ( ) ; assertEquals ( true , objVal . isDNI ( objCli . getDniCliente ( ) ) ) ; } @ Test public void testValidaCorreoCliente ( ) { Validaciones objVal = new Validaciones ( ) ; assertEquals ( true , objVal . isEmail ( objCli . getEmaCliente ( ) ) ) ; } @ Test public void testLitarClienteGrupoEstudio ( ) { aluGrupo . add ( objCli . getNomCliente ( ) ) ; assertEquals ( objCli . getNomCliente ( ) , aluGrupo . get ( <NUM_LIT:0> ) ) ; System . out . print ( aluGrupo . get ( <NUM_LIT:0> ) + "<STR_LIT:U+0020-U+0020>" + gruEstudio . get ( <NUM_LIT:0> ) ) ; } } </s>
|
<s> package benedictoxvi . pe . datatest ; import java . util . * ; import benedictoxvi . pe . data . * ; import benedictoxvi . pe . util . Loader ; import benedictoxvi . pe . util . ProcessException ; public final class DataBD { Loader objLoa = new Loader ( ) ; ArrayList < Usuario > dataUsuarios = new ArrayList < Usuario > ( ) ; ArrayList < Compra > dataCompras = new ArrayList < Compra > ( ) ; ArrayList < GrupoEstudio > dataGrupoEstudio = new ArrayList < GrupoEstudio > ( ) ; ArrayList < Prospecto > dataProspecto = new ArrayList < Prospecto > ( ) ; ArrayList < Rol > dataRoles = new ArrayList < Rol > ( ) ; ArrayList < Modulo > dataModulos = new ArrayList < Modulo > ( ) ; ArrayList < Cliente > dataClientes = new ArrayList < Cliente > ( ) ; public ArrayList < Cliente > getDataClientes ( ) { return dataClientes ; } public void setDataClientes ( ArrayList < Cliente > dataClientes ) { this . dataClientes = dataClientes ; } public void setDataModulos ( ArrayList < Modulo > dataModulos ) { this . dataModulos = dataModulos ; } public DataBD ( ) { dataClientes = getDataCliente ( ) ; dataModulos = getDataModulos ( ) ; dataRoles = loadRoles ( ) ; dataCompras = loadCompras ( ) ; dataGrupoEstudio = loadGrupoEstudio ( ) ; dataUsuarios = loadUsuarios ( ) ; dataProspecto = loadProspectos ( ) ; } public ArrayList < Modulo > getDataModulos ( ) { ArrayList < Modulo > mods = new ArrayList < Modulo > ( ) ; Modulo objPro = null ; String url = objLoa . getClass ( ) . getResource ( "<STR_LIT>" ) . getFile ( ) ; ArrayList < String [ ] > lisPro = objLoa . getDataTxt ( url ) ; for ( String [ ] row : lisPro ) { objPro = new Modulo ( ) ; objPro . setNombre ( row [ <NUM_LIT:0> ] ) ; objPro . setDescripcion ( row [ <NUM_LIT:1> ] ) ; mods . add ( objPro ) ; } return mods ; } public ArrayList < Usuario > getDataUsuarios ( ) { return dataUsuarios ; } public void setDataUsuarios ( ArrayList < Usuario > dataUsuarios ) { this . dataUsuarios = dataUsuarios ; } public ArrayList < Compra > getDataCompras ( ) { return dataCompras ; } public void setDataCompras ( ArrayList < Compra > dataCompras ) { this . dataCompras = dataCompras ; } public ArrayList < GrupoEstudio > getDataGrupoEstudio ( ) { return dataGrupoEstudio ; } public void setDataGrupoEstudio ( ArrayList < GrupoEstudio > dataGrupoEstudio ) { this . dataGrupoEstudio = dataGrupoEstudio ; } public ArrayList < Prospecto > getDataProspecto ( ) { return dataProspecto ; } public void setDataProspecto ( ArrayList < Prospecto > dataProspecto ) { this . dataProspecto = dataProspecto ; } public ArrayList < Rol > getDataRoles ( ) { return dataRoles ; } public void setDataRoles ( ArrayList < Rol > dataRoles ) { this . dataRoles = dataRoles ; } public ArrayList < Rol > loadRoles ( ) { ArrayList < Rol > roles = new ArrayList < Rol > ( ) ; Rol objPro = null ; String url = objLoa . getClass ( ) . getResource ( "<STR_LIT>" ) . getFile ( ) ; ArrayList < String [ ] > lisPro = objLoa . getDataTxt ( url ) ; for ( String [ ] row : lisPro ) { objPro = new Rol ( ) ; objPro . setNombre ( row [ <NUM_LIT:0> ] ) ; objPro . setDescrip ( row [ <NUM_LIT:1> ] ) ; for ( String mod : row [ <NUM_LIT:2> ] . split ( "<STR_LIT:/>" ) ) { String [ ] parts = mod . split ( "<STR_LIT::>" ) ; if ( Collections . binarySearch ( dataModulos , new Modulo ( parts [ <NUM_LIT:0> ] ) , new Comparator < Modulo > ( ) { @ Override public int compare ( Modulo o1 , Modulo o2 ) { return o1 . getNombre ( ) . compareTo ( o2 . getNombre ( ) ) ; } } ) < <NUM_LIT:0> ) { new ProcessException ( "<STR_LIT>" + parts [ <NUM_LIT:0> ] + "<STR_LIT>" ) . printStackTrace ( ) ; return null ; } Modulo mod_user = new Modulo ( parts [ <NUM_LIT:0> ] ) ; mod_user . setAcceso ( ( Integer . parseInt ( parts [ <NUM_LIT:1> ] ) == <NUM_LIT:0> ) ? false : true ) ; mod_user . setAdicionar ( ( Integer . parseInt ( parts [ <NUM_LIT:2> ] ) == <NUM_LIT:0> ) ? false : true ) ; mod_user . setEditar ( ( Integer . parseInt ( parts [ <NUM_LIT:3> ] ) == <NUM_LIT:0> ) ? false : true ) ; mod_user . setEliminar ( ( Integer . parseInt ( parts [ <NUM_LIT:4> ] ) == <NUM_LIT:0> ) ? false : true ) ; objPro . getModulo ( ) . add ( mod_user ) ; } roles . add ( objPro ) ; } return roles ; } public ArrayList < Prospecto > loadProspectos ( ) { ArrayList < Prospecto > prospectos = new ArrayList < Prospecto > ( ) ; Prospecto objPro = null ; String url = objLoa . getClass ( ) . getResource ( "<STR_LIT>" ) . getFile ( ) ; ArrayList < String [ ] > lisPro = objLoa . getDataTxt ( url ) ; for ( String [ ] row : lisPro ) { objPro = new Prospecto ( ) ; objPro . setNumProspecto ( Integer . parseInt ( row [ <NUM_LIT:0> ] ) ) ; objPro . setFecProspecto ( row [ <NUM_LIT:1> ] ) ; objPro . setApePaterno ( row [ <NUM_LIT:2> ] ) ; objPro . setApeMaterno ( row [ <NUM_LIT:3> ] ) ; objPro . setNombes ( row [ <NUM_LIT:4> ] ) ; objPro . setCorreo ( row [ <NUM_LIT:5> ] ) ; objPro . setNroDNI ( row [ <NUM_LIT:6> ] ) ; objPro . setTelefono ( row [ <NUM_LIT:7> ] ) ; objPro . setCelular ( row [ <NUM_LIT:8> ] ) ; objPro . setEstado ( row [ <NUM_LIT:9> ] ) ; prospectos . add ( objPro ) ; } return prospectos ; } public ArrayList < Prospecto > loadCuentas ( ) { return null ; } public void loadClientes ( ) { } public ArrayList < GrupoEstudio > loadGrupoEstudio ( ) { ArrayList < GrupoEstudio > grupos = new ArrayList < GrupoEstudio > ( ) ; GrupoEstudio objGru = null ; String url = objLoa . getClass ( ) . getResource ( "<STR_LIT>" ) . getFile ( ) ; ArrayList < String [ ] > lisPro = objLoa . getDataTxt ( url . substring ( <NUM_LIT:1> ) ) ; for ( String [ ] row : lisPro ) { if ( row . length == <NUM_LIT:0> ) continue ; objGru = new GrupoEstudio ( ) ; objGru . setCodGrupo ( row [ <NUM_LIT:0> ] ) ; objGru . setNomGrupo ( row [ <NUM_LIT:1> ] ) ; objGru . setDescripcion ( row [ <NUM_LIT:2> ] ) ; objGru . setNomAcademia ( row [ <NUM_LIT:3> ] ) ; objGru . setNomCurso ( row [ <NUM_LIT:4> ] ) ; objGru . setFecInicio ( row [ <NUM_LIT:5> ] ) ; objGru . setFecFin ( row [ <NUM_LIT:6> ] ) ; objGru . setInstructor ( row [ <NUM_LIT:7> ] . split ( "<STR_LIT:;>" ) ) ; objGru . setLinkSylabus ( row [ <NUM_LIT:8> ] ) ; objGru . setLocal ( row [ <NUM_LIT:9> ] ) ; objGru . setEstado ( "<STR_LIT>" ) ; objGru . setAula ( Integer . parseInt ( row [ <NUM_LIT:10> ] ) ) ; objGru . setCAltitud ( Double . parseDouble ( row [ <NUM_LIT:11> ] ) ) ; objGru . setCLatitud ( Double . parseDouble ( row [ <NUM_LIT:12> ] ) ) ; objGru . setAforo ( Integer . parseInt ( row [ <NUM_LIT> ] ) ) ; grupos . add ( objGru ) ; } int i = <NUM_LIT:0> ; for ( Cliente cli : dataClientes ) { if ( cli . getCodCliente ( ) . equals ( "<STR_LIT>" ) ) { continue ; } i += <NUM_LIT:1> ; grupos . get ( <NUM_LIT:1> ) . getInscritos ( ) . add ( cli ) ; } grupos . get ( <NUM_LIT:1> ) . setAforo ( i ) ; return grupos ; } public ArrayList < Compra > loadCompras ( ) { ArrayList < Compra > compras = new ArrayList < Compra > ( ) ; Compra objPro = null ; String url = objLoa . getClass ( ) . getResource ( "<STR_LIT>" ) . getFile ( ) ; ArrayList < String [ ] > lisPro = objLoa . getDataTxt ( url ) ; for ( String [ ] row : lisPro ) { objPro = new Compra ( ) ; objPro . setConcepto ( row [ <NUM_LIT:0> ] ) ; objPro . setNumero ( Integer . parseInt ( row [ <NUM_LIT:1> ] ) ) ; objPro . setFecEmision ( row [ <NUM_LIT:2> ] ) ; objPro . setNomEmpresa ( row [ <NUM_LIT:3> ] ) ; objPro . setMonSubtot ( Double . parseDouble ( row [ <NUM_LIT:4> ] ) ) ; objPro . setMonIGV ( Double . parseDouble ( row [ <NUM_LIT:5> ] ) ) ; objPro . setMonTotal ( Double . parseDouble ( row [ <NUM_LIT:6> ] ) ) ; objPro . setMoneda ( row [ <NUM_LIT:7> ] ) ; objPro . setFecVencim ( row [ <NUM_LIT:8> ] ) ; objPro . setEstado ( row [ <NUM_LIT:9> ] ) ; objPro . setFecPago ( row [ <NUM_LIT:10> ] ) ; objPro . setObservacion ( row [ <NUM_LIT:11> ] ) ; compras . add ( objPro ) ; } return compras ; } public ArrayList < Usuario > loadUsuarios ( ) { ArrayList < Usuario > usuarios = new ArrayList < Usuario > ( ) ; Usuario objPro = null ; String url = objLoa . getClass ( ) . getResource ( "<STR_LIT>" ) . getFile ( ) ; ArrayList < String [ ] > lisPro = objLoa . getDataTxt ( url ) ; for ( String [ ] row : lisPro ) { objPro = new Usuario ( ) ; objPro . setUsuario ( row [ <NUM_LIT:0> ] ) ; objPro . setPassword ( row [ <NUM_LIT:1> ] ) ; objPro . setNombre ( row [ <NUM_LIT:2> ] ) ; objPro . setApellidoPaterno ( row [ <NUM_LIT:3> ] ) ; objPro . setApellidoMaterno ( row [ <NUM_LIT:4> ] ) ; objPro . setF_ingreso ( row [ <NUM_LIT:5> ] ) ; String roles = row [ <NUM_LIT:6> ] ; for ( String rol : roles . split ( "<STR_LIT:/>" ) ) { for ( Rol usr_rol : dataRoles ) { if ( usr_rol . getNombre ( ) . equalsIgnoreCase ( rol ) ) { objPro . getRoles ( ) . add ( usr_rol ) ; } } } objPro . setCargo ( row [ <NUM_LIT:7> ] ) ; objPro . setDni ( row [ <NUM_LIT:8> ] ) ; objPro . setStatus ( row [ <NUM_LIT:9> ] ) ; usuarios . add ( objPro ) ; } return usuarios ; } public ArrayList < Cliente > getDataCliente ( ) { ArrayList < Cliente > clientes = new ArrayList < Cliente > ( ) ; Cliente objPro = null ; String url = objLoa . getClass ( ) . getResource ( "<STR_LIT>" ) . getFile ( ) ; ArrayList < String [ ] > lisPro = objLoa . getDataTxt ( url ) ; for ( String [ ] row : lisPro ) { objPro = new Cliente ( ) ; objPro . setCodCliente ( row [ <NUM_LIT:0> ] ) ; objPro . setFecConCliente ( row [ <NUM_LIT:1> ] ) ; objPro . setApePatCliente ( row [ <NUM_LIT:2> ] ) ; objPro . setApeMatCliente ( row [ <NUM_LIT:3> ] ) ; objPro . setNomCliente ( row [ <NUM_LIT:4> ] ) ; objPro . setEmaCliente ( row [ <NUM_LIT:5> ] ) ; objPro . setDniCliente ( row [ <NUM_LIT:6> ] ) ; objPro . setFonCliente ( row [ <NUM_LIT:7> ] ) ; objPro . setEstCliente ( row [ <NUM_LIT:8> ] ) ; clientes . add ( objPro ) ; } return clientes ; } public static void main ( String [ ] args ) { DataBD bd = new DataBD ( ) ; } } </s>
|
<s> package benedictoxvi . pe . datatest ; import org . junit . Test ; import junit . framework . Assert ; import benedictoxvi . pe . data . GrupoEstudio ; public class GrupoEstudioTest { @ Test public void testDataGrupoEstudio ( ) { GrupoEstudio objGrp = new GrupoEstudio ( ) ; objGrp . setNomGrupo ( "<STR_LIT>" ) ; objGrp . setNomAcademia ( "<STR_LIT>" ) ; objGrp . setNomCurso ( "<STR_LIT>" ) ; objGrp . setFecInicio ( "<STR_LIT>" ) ; objGrp . setFecFin ( "<STR_LIT>" ) ; objGrp . setEstado ( "<STR_LIT>" ) ; Assert . assertEquals ( "<STR_LIT>" , objGrp . getNomGrupo ( ) ) ; Assert . assertEquals ( "<STR_LIT>" , objGrp . getNomAcademia ( ) ) ; Assert . assertEquals ( "<STR_LIT>" , objGrp . getNomCurso ( ) ) ; Assert . assertEquals ( "<STR_LIT>" , objGrp . getFecInicio ( ) ) ; Assert . assertEquals ( "<STR_LIT>" , objGrp . getFecFin ( ) ) ; Assert . assertEquals ( "<STR_LIT>" , objGrp . getEstado ( ) ) ; } } </s>
|
<s> package benedictoxvi . pe . datatest ; import org . junit . Assert ; import org . junit . Test ; import benedictoxvi . pe . data . Compra ; public class CompraTest { @ Test public void testDataCompra ( ) { Compra objCom = new Compra ( ) ; objCom . setConcepto ( "<STR_LIT>" ) ; objCom . setNumero ( <NUM_LIT> ) ; objCom . setFecEmision ( "<STR_LIT>" ) ; objCom . setNomEmpresa ( "<STR_LIT>" ) ; objCom . setEstado ( "<STR_LIT>" ) ; objCom . setFecPago ( "<STR_LIT>" ) ; objCom . setFecVencim ( "<STR_LIT>" ) ; objCom . setMonSubtot ( <NUM_LIT> ) ; objCom . setMonIGV ( <NUM_LIT> ) ; objCom . setMonTotal ( <NUM_LIT> ) ; objCom . setObservacion ( "<STR_LIT>" ) ; Assert . assertArrayEquals ( new Object [ ] { "<STR_LIT>" , <NUM_LIT> , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , "<STR_LIT>" } , new Object [ ] { objCom . getConcepto ( ) , objCom . getNumero ( ) , objCom . getFecEmision ( ) , objCom . getNomEmpresa ( ) , objCom . getEstado ( ) , objCom . getFecPago ( ) , objCom . getFecVencim ( ) , objCom . getMonSubtot ( ) , objCom . getMonIGV ( ) , objCom . getMonTotal ( ) , objCom . getObservacion ( ) } ) ; objCom = new Compra ( ) ; objCom . setConcepto ( "<STR_LIT>" ) ; objCom . setNumero ( <NUM_LIT> ) ; objCom . setFecEmision ( "<STR_LIT>" ) ; objCom . setNomEmpresa ( "<STR_LIT>" ) ; objCom . setEstado ( "<STR_LIT>" ) ; objCom . setFecPago ( "<STR_LIT>" ) ; objCom . setFecVencim ( "<STR_LIT>" ) ; objCom . setMonSubtot ( <NUM_LIT> ) ; objCom . setMonIGV ( <NUM_LIT> ) ; objCom . setMonTotal ( <NUM_LIT> ) ; objCom . setObservacion ( "<STR_LIT>" ) ; Assert . assertEquals ( "<STR_LIT>" , objCom . getConcepto ( ) ) ; Assert . assertEquals ( <NUM_LIT> , objCom . getNumero ( ) ) ; Assert . assertEquals ( "<STR_LIT>" , objCom . getFecEmision ( ) ) ; Assert . assertEquals ( "<STR_LIT>" , objCom . getNomEmpresa ( ) ) ; Assert . assertEquals ( "<STR_LIT>" , objCom . getEstado ( ) ) ; Assert . assertEquals ( "<STR_LIT>" , objCom . getFecPago ( ) ) ; Assert . assertEquals ( "<STR_LIT>" , objCom . getFecVencim ( ) ) ; Assert . assertEquals ( <NUM_LIT> , objCom . getMonSubtot ( ) , <NUM_LIT:0> ) ; Assert . assertEquals ( <NUM_LIT> , objCom . getMonIGV ( ) , <NUM_LIT:0> ) ; Assert . assertEquals ( <NUM_LIT> , objCom . getMonTotal ( ) , <NUM_LIT:0> ) ; Assert . assertEquals ( "<STR_LIT>" , objCom . getObservacion ( ) ) ; } } </s>
|
<s> package benedictoxvi . pe . datatest ; import org . junit . Assert ; import org . junit . Test ; import benedictoxvi . pe . data . Prospecto ; public class ProspectoTest { @ Test public void testDataProspecto ( ) { Prospecto objPro = new Prospecto ( ) ; objPro . setNumProspecto ( <NUM_LIT:1> ) ; objPro . setFecProspecto ( "<STR_LIT>" ) ; objPro . setNombes ( "<STR_LIT>" ) ; objPro . setApePaterno ( "<STR_LIT>" ) ; objPro . setApeMaterno ( "<STR_LIT>" ) ; objPro . setCorreo ( "<STR_LIT>" ) ; objPro . setNroDNI ( "<STR_LIT>" ) ; objPro . setTelefono ( "<STR_LIT>" ) ; objPro . setCelular ( "<STR_LIT>" ) ; objPro . setEstado ( "<STR_LIT>" ) ; Assert . assertEquals ( <NUM_LIT:1> , objPro . getNumProspecto ( ) , <NUM_LIT:0> ) ; Assert . assertEquals ( "<STR_LIT>" , objPro . getFecProspecto ( ) ) ; Assert . assertEquals ( "<STR_LIT>" , objPro . getNombes ( ) ) ; Assert . assertEquals ( "<STR_LIT>" , objPro . getApePaterno ( ) ) ; Assert . assertEquals ( "<STR_LIT>" , objPro . getApeMaterno ( ) ) ; Assert . assertEquals ( "<STR_LIT>" , objPro . getCorreo ( ) ) ; Assert . assertEquals ( "<STR_LIT>" , objPro . getNroDNI ( ) ) ; Assert . assertEquals ( "<STR_LIT>" , objPro . getTelefono ( ) ) ; Assert . assertEquals ( "<STR_LIT>" , objPro . getCelular ( ) ) ; Assert . assertEquals ( "<STR_LIT>" , objPro . getEstado ( ) ) ; objPro = new Prospecto ( ) ; objPro . setNumProspecto ( <NUM_LIT:2> ) ; objPro . setFecProspecto ( "<STR_LIT>" ) ; objPro . setNombes ( "<STR_LIT>" ) ; objPro . setApePaterno ( "<STR_LIT>" ) ; objPro . setApeMaterno ( "<STR_LIT>" ) ; objPro . setCorreo ( "<STR_LIT>" ) ; objPro . setNroDNI ( "<STR_LIT>" ) ; objPro . setTelefono ( "<STR_LIT>" ) ; objPro . setCelular ( "<STR_LIT>" ) ; objPro . setEstado ( "<STR_LIT:X>" ) ; Assert . assertEquals ( <NUM_LIT:2> , objPro . getNumProspecto ( ) , <NUM_LIT:0> ) ; Assert . assertEquals ( "<STR_LIT>" , objPro . getFecProspecto ( ) ) ; Assert . assertEquals ( "<STR_LIT>" , objPro . getNombes ( ) ) ; Assert . assertEquals ( "<STR_LIT>" , objPro . getApePaterno ( ) ) ; Assert . assertEquals ( "<STR_LIT>" , objPro . getApeMaterno ( ) ) ; Assert . assertEquals ( "<STR_LIT>" , objPro . getCorreo ( ) ) ; Assert . assertEquals ( "<STR_LIT>" , objPro . getNroDNI ( ) ) ; Assert . assertEquals ( "<STR_LIT>" , objPro . getTelefono ( ) ) ; Assert . assertEquals ( "<STR_LIT>" , objPro . getCelular ( ) ) ; Assert . assertEquals ( "<STR_LIT:X>" , objPro . getEstado ( ) ) ; } } </s>
|
<s> package benedictoxvi . pe . data ; public abstract class Movimiento { String Concepto ; int Numero ; String FecEmision ; String NomEmpresa ; String FecVencim ; String FecPago ; String Estado ; String Observacion ; Double MonSubtot ; Double MonIGV ; Double MonTotal ; String Moneda ; String Tipo ; public String getConcepto ( ) { return Concepto ; } public void setConcepto ( String concepto ) { Concepto = concepto ; } public int getNumero ( ) { return Numero ; } public void setNumero ( int numero ) { Numero = numero ; } public String getFecEmision ( ) { return FecEmision ; } public void setFecEmision ( String fecEmision ) { FecEmision = fecEmision ; } public String getNomEmpresa ( ) { return NomEmpresa ; } public void setNomEmpresa ( String nomEmpresa ) { NomEmpresa = nomEmpresa ; } public String getFecVencim ( ) { return FecVencim ; } public void setFecVencim ( String fecVencim ) { FecVencim = fecVencim ; } public String getFecPago ( ) { return FecPago ; } public void setFecPago ( String fecPago ) { FecPago = fecPago ; } public String getEstado ( ) { return Estado ; } public void setEstado ( String estado ) { Estado = estado ; } public String getObservacion ( ) { return Observacion ; } public void setObservacion ( String observacion ) { Observacion = observacion ; } public Double getMonSubtot ( ) { return MonSubtot ; } public void setMonSubtot ( Double monSubtot ) { MonSubtot = monSubtot ; } public Double getMonIGV ( ) { return MonIGV ; } public void setMonIGV ( Double monIGV ) { MonIGV = monIGV ; } public Double getMonTotal ( ) { return MonTotal ; } public void setMonTotal ( Double monTotal ) { MonTotal = monTotal ; } public String getMoneda ( ) { return Moneda ; } public void setMoneda ( String moneda ) { Moneda = moneda ; } public String getTipo ( ) { return Tipo ; } public void setTipo ( String tipo ) { Tipo = tipo ; } } </s>
|
<s> package benedictoxvi . pe . data ; public class Prospecto { int NumProspecto ; String FecProspecto ; String NomProspecto ; String ApePaterno ; String ApeMaterno ; String Nombes ; String Correo ; String NroDNI ; String Telefono ; String Celular ; String Estado ; public Prospecto ( ) { } public int getNumProspecto ( ) { return NumProspecto ; } public void setNumProspecto ( int numProspecto ) { NumProspecto = numProspecto ; } public String getFecProspecto ( ) { return FecProspecto ; } public void setFecProspecto ( String fecProspecto ) { FecProspecto = fecProspecto ; } public String getNomProspecto ( ) { return NomProspecto ; } public void setNomProspecto ( String nomProspecto ) { NomProspecto = nomProspecto ; } public String getApePaterno ( ) { return ApePaterno ; } public void setApePaterno ( String apePaterno ) { ApePaterno = apePaterno ; } public String getApeMaterno ( ) { return ApeMaterno ; } public void setApeMaterno ( String apeMaterno ) { ApeMaterno = apeMaterno ; } public String getNombes ( ) { return Nombes ; } public void setNombes ( String nombes ) { Nombes = nombes ; } public String getCorreo ( ) { return Correo ; } public void setCorreo ( String correo ) { Correo = correo ; } public String getNroDNI ( ) { return NroDNI ; } public void setNroDNI ( String nroDNI ) { NroDNI = nroDNI ; } public String getTelefono ( ) { return Telefono ; } public void setTelefono ( String telefono ) { Telefono = telefono ; } public String getCelular ( ) { return Celular ; } public void setCelular ( String celular ) { Celular = celular ; } public String getEstado ( ) { return Estado ; } public void setEstado ( String estado ) { Estado = estado ; } } </s>
|
<s> package benedictoxvi . pe . data ; public class Cliente { public String getCodCliente ( ) { return codCliente ; } public void setCodCliente ( String codCliente ) { this . codCliente = codCliente ; } public String codCliente ; public String nomCliente ; public String apePatCliente ; public String apeMatCliente ; public String emaCliente ; public String dniCliente ; public String fonCliente ; public String fecConCliente ; public String estCliente ; public String getEstCliente ( ) { return estCliente ; } public void setEstCliente ( String estCliente ) { this . estCliente = estCliente ; } public void setDniCliente ( String dniCliente ) { this . dniCliente = dniCliente ; } public String getDniCliente ( ) { return dniCliente ; } public String getNomCliente ( ) { return nomCliente ; } public void setNomCliente ( String nomCliente ) { this . nomCliente = nomCliente ; } public String getApePatCliente ( ) { return apePatCliente ; } public void setApePatCliente ( String apePatCliente ) { this . apePatCliente = apePatCliente ; } public String getApeMatCliente ( ) { return apeMatCliente ; } public void setApeMatCliente ( String apeMatCliente ) { this . apeMatCliente = apeMatCliente ; } public String getEmaCliente ( ) { return emaCliente ; } public void setEmaCliente ( String emaCliente ) { this . emaCliente = emaCliente ; } public String getFonCliente ( ) { return fonCliente ; } public void setFonCliente ( String fonCliente ) { this . fonCliente = fonCliente ; } public String getFecConCliente ( ) { return fecConCliente ; } public void setFecConCliente ( String fecConCliente ) { this . fecConCliente = fecConCliente ; } } </s>
|
<s> package benedictoxvi . pe . data ; import java . util . ArrayList ; import java . util . Comparator ; import java . util . Date ; import java . util . List ; import benedictoxvi . pe . util . Loader ; import benedictoxvi . pe . util . ProcessException ; import benedictoxvi . pe . util . Validaciones ; public class Venta extends Movimiento implements Comparator < Venta > { private String CodAlumno ; private String NomAlumno ; private String ApePatAlumno ; private String ApeMatAlumno ; private String CodTipoDocumento ; private String CodCurso ; private String NomCurso ; private double PreCurso ; private int CanCurso ; private String NomEmpleado ; private String ApeEmpleado ; private String CodEmpleado ; private String CodCliente ; private String CodTipCliente ; private String NroRucCliente ; private String NroDniCliente ; private String NomCliente ; private String ApePatCliente ; private String ApeMatCliente ; private int NroMovimiento ; private String TipoComprobante ; private String NroBoleta ; private String RUC ; private Date FechaPago ; private Double SubTotal ; private Double Igv ; private Double Total ; private String Moneda ; private String Observacion ; private int UsuarioRegistro ; private Date FechaRegistro ; private String CodCuenta ; private String DesCuenta ; private Double MontoTotalCuenta ; private String MonCuenta ; private Double SalCuenta ; private String EstadoCuenta ; private int NroCuota ; private Double MontoCronograma ; private String MonedaCronograma ; private Date FechaVencimientoCronograma ; private Double MontoMora ; private String EstadoCuota ; public Venta ( ) { } @ Override public String toString ( ) { String tipoDocumento = "<STR_LIT>" ; if ( CodTipoDocumento == "<STR_LIT:1>" ) { tipoDocumento = "<STR_LIT>" ; } else if ( CodTipoDocumento == "<STR_LIT:2>" ) { tipoDocumento = "<STR_LIT>" ; } if ( CodCurso == "<STR_LIT>" ) { NomCurso = "<STR_LIT>" ; } return "<STR_LIT>" + Numero + "<STR_LIT>" + tipoDocumento + "<STR_LIT>" + NomCurso + "<STR_LIT>" + NomCliente + "<STR_LIT>" + NroRucCliente + "<STR_LIT>" + Concepto + "<STR_LIT>" + FecEmision + "<STR_LIT>" + FecVencim + "<STR_LIT>" + FecPago + "<STR_LIT>" + Estado + "<STR_LIT>" + Observacion + "<STR_LIT>" + MonSubtot + "<STR_LIT>" + MonIGV + "<STR_LIT>" + MonTotal + "<STR_LIT>" + Moneda + "<STR_LIT:]>" ; } Validaciones objValidaciones = new Validaciones ( ) ; @ Override public int compare ( Venta oVenta1 , Venta oVenta2 ) { if ( objValidaciones . dateToInt ( oVenta1 . getFecVencim ( ) ) == objValidaciones . dateToInt ( oVenta2 . getFecVencim ( ) ) ) { return <NUM_LIT:0> ; } else if ( objValidaciones . dateToInt ( oVenta1 . getFecVencim ( ) ) >= objValidaciones . dateToInt ( oVenta2 . getFecVencim ( ) ) ) { return <NUM_LIT:1> ; } else { return - <NUM_LIT:1> ; } } public ArrayList < Venta > getDataCursos ( ) { Loader objLoa = new Loader ( ) ; ArrayList < Venta > arrVentas = new ArrayList < Venta > ( ) ; Venta objVenta = null ; String url = objLoa . getClass ( ) . getResource ( "<STR_LIT>" ) . getFile ( ) ; ArrayList < String [ ] > lisPro = objLoa . getDataTxt ( url ) ; for ( String [ ] row : lisPro ) { objVenta = new Venta ( ) ; objVenta . setCodCurso ( row [ <NUM_LIT:0> ] ) ; objVenta . setNomCurso ( row [ <NUM_LIT:1> ] ) ; objVenta . setPreCurso ( Double . parseDouble ( row [ <NUM_LIT:2> ] ) ) ; arrVentas . add ( objVenta ) ; } return arrVentas ; } public ArrayList < Venta > getDataCuentas ( ) { Loader objLoa = new Loader ( ) ; ArrayList < Venta > arrVentas = new ArrayList < Venta > ( ) ; Venta objVenta = null ; String url = objLoa . getClass ( ) . getResource ( "<STR_LIT>" ) . getFile ( ) ; ArrayList < String [ ] > lisPro = objLoa . getDataTxt ( url ) ; for ( String [ ] row : lisPro ) { if ( ! row [ <NUM_LIT:0> ] . equalsIgnoreCase ( "<STR_LIT>" ) ) { objVenta = new Venta ( ) ; objVenta . setCodCuenta ( row [ <NUM_LIT:0> ] ) ; objVenta . setCodCliente ( row [ <NUM_LIT:1> ] ) ; objVenta . setCodCurso ( row [ <NUM_LIT:2> ] ) ; objVenta . setMontoTotalCuenta ( Double . parseDouble ( row [ <NUM_LIT:3> ] ) ) ; objVenta . setMoneda ( row [ <NUM_LIT:4> ] ) ; objVenta . setSalCuenta ( Double . parseDouble ( row [ <NUM_LIT:5> ] ) ) ; objVenta . setEstadoCuenta ( row [ <NUM_LIT:6> ] ) ; arrVentas . add ( objVenta ) ; } } return arrVentas ; } public ArrayList < Venta > getDataCronogramaCuentas ( ) { Validaciones oUtil = new Validaciones ( ) ; Loader objLoa = new Loader ( ) ; ArrayList < Venta > arrVentas = new ArrayList < Venta > ( ) ; Venta objVenta = null ; String url = objLoa . getClass ( ) . getResource ( "<STR_LIT>" ) . getFile ( ) ; ArrayList < String [ ] > lisPro = objLoa . getDataTxt ( url ) ; for ( String [ ] row : lisPro ) { if ( ! row [ <NUM_LIT:0> ] . equalsIgnoreCase ( "<STR_LIT>" ) ) { objVenta = new Venta ( ) ; objVenta . setCodCuenta ( row [ <NUM_LIT:0> ] ) ; objVenta . setNroCuota ( Integer . parseInt ( row [ <NUM_LIT:1> ] ) ) ; objVenta . setMontoCronograma ( Double . parseDouble ( row [ <NUM_LIT:2> ] ) ) ; objVenta . setMonedaCronograma ( row [ <NUM_LIT:3> ] ) ; objVenta . setFechaVencimientoCronograma ( oUtil . stringToDate ( row [ <NUM_LIT:4> ] ) ) ; objVenta . setEstadoCuota ( row [ <NUM_LIT:6> ] ) ; arrVentas . add ( objVenta ) ; } } return arrVentas ; } public Venta getCursoByCodigo ( String CodCurso ) { List < Venta > arrCursos = new ArrayList < Venta > ( ) ; arrCursos = getDataCursos ( ) ; for ( Venta oVenCurso : arrCursos ) { if ( oVenCurso . getCodCurso ( ) . equals ( CodCurso ) ) { return oVenCurso ; } } new ProcessException ( "<STR_LIT>" + CodCuenta + "<STR_LIT>" ) . printStackTrace ( ) ; return null ; } public Venta getCuentaByCodigo ( String CodCuenta ) { List < Venta > arrCuenta = new ArrayList < Venta > ( ) ; arrCuenta = getDataCuentas ( ) ; for ( Venta oVenCuenta : arrCuenta ) { if ( oVenCuenta . getCodCuenta ( ) . equals ( CodCuenta ) ) { return oVenCuenta ; } } new ProcessException ( "<STR_LIT>" + CodCuenta + "<STR_LIT>" ) . printStackTrace ( ) ; return null ; } public List < Venta > getCronogramaByCodigoCuenta ( String CodCuenta ) { List < Venta > arrCrono = new ArrayList < Venta > ( ) ; List < Venta > arrCronograma = new ArrayList < Venta > ( ) ; arrCronograma = getDataCronogramaCuentas ( ) ; for ( Venta oVenCrono : arrCronograma ) { if ( oVenCrono . getCodCuenta ( ) . equals ( CodCuenta ) ) { arrCrono . add ( oVenCrono ) ; } } return arrCrono ; } public int getNroCuota ( ) { return NroCuota ; } public void setNroCuota ( int nroCuota ) { NroCuota = nroCuota ; } public Double getMontoCronograma ( ) { return MontoCronograma ; } public void setMontoCronograma ( Double montoCronograma ) { MontoCronograma = montoCronograma ; } public String getMonedaCronograma ( ) { return MonedaCronograma ; } public void setMonedaCronograma ( String monedaCronograma ) { MonedaCronograma = monedaCronograma ; } public Date getFechaVencimientoCronograma ( ) { return FechaVencimientoCronograma ; } public void setFechaVencimientoCronograma ( Date fechaVencimientoCronograma ) { FechaVencimientoCronograma = fechaVencimientoCronograma ; } public String getEstadoCuota ( ) { return EstadoCuota ; } public void setEstadoCuota ( String estadoCuota ) { EstadoCuota = estadoCuota ; } public int getNroMovimiento ( ) { return NroMovimiento ; } public void setNroMovimiento ( int nroMovimiento ) { NroMovimiento = nroMovimiento ; } public String getTipoComprobante ( ) { return TipoComprobante ; } public void setTipoComprobante ( String tipoComprobante ) { TipoComprobante = tipoComprobante ; } public String getNroBoleta ( ) { return NroBoleta ; } public void setNroBoleta ( String nroBoleta ) { NroBoleta = nroBoleta ; } public String getRUC ( ) { return RUC ; } public void setRUC ( String rUC ) { RUC = rUC ; } public Date getFechaPago ( ) { return FechaPago ; } public void setFechaPago ( Date fechaPago ) { FechaPago = fechaPago ; } public Double getSubTotal ( ) { return SubTotal ; } public void setSubTotal ( Double subTotal ) { SubTotal = subTotal ; } public Double getIgv ( ) { return Igv ; } public void setIgv ( Double igv ) { Igv = igv ; } public Double getTotal ( ) { return Total ; } public void setTotal ( Double total ) { Total = total ; } public String getMoneda ( ) { return Moneda ; } public void setMoneda ( String moneda ) { Moneda = moneda ; } public String getObservacion ( ) { return Observacion ; } public void setObservacion ( String observacion ) { Observacion = observacion ; } public int getUsuarioRegistro ( ) { return UsuarioRegistro ; } public void setUsuarioRegistro ( int usuarioRegistro ) { UsuarioRegistro = usuarioRegistro ; } public Date getFechaRegistro ( ) { return FechaRegistro ; } public void setFechaRegistro ( Date fechaRegistro ) { FechaRegistro = fechaRegistro ; } public String getCodCuenta ( ) { return CodCuenta ; } public void setCodCuenta ( String codCuenta ) { CodCuenta = codCuenta ; } public String getDesCuenta ( ) { return DesCuenta ; } public void setDesCuenta ( String desCuenta ) { DesCuenta = desCuenta ; } public Double getMontoTotalCuenta ( ) { return MontoTotalCuenta ; } public void setMontoTotalCuenta ( Double montoTotalCuenta ) { MontoTotalCuenta = montoTotalCuenta ; } public String getMonCuenta ( ) { return MonCuenta ; } public void setMonCuenta ( String monCuenta ) { MonCuenta = monCuenta ; } public Double getSalCuenta ( ) { return SalCuenta ; } public void setSalCuenta ( Double salCuenta ) { SalCuenta = salCuenta ; } public String getEstadoCuenta ( ) { return EstadoCuenta ; } public void setEstadoCuenta ( String estadoCuenta ) { EstadoCuenta = estadoCuenta ; } public String getNomAlumno ( ) { return NomAlumno ; } public void setNomAlumno ( String nomAlumno ) { NomAlumno = nomAlumno ; } public String getApePatAlumno ( ) { return ApePatAlumno ; } public void setApePatAlumno ( String apePatAlumno ) { ApePatAlumno = apePatAlumno ; } public String getApeMatAlumno ( ) { return ApeMatAlumno ; } public void setApeMatAlumno ( String apeMatAlumno ) { ApeMatAlumno = apeMatAlumno ; } public String getCodTipoDocumento ( ) { return CodTipoDocumento ; } public void setCodTipoDocumento ( String codTipoDocumento ) { CodTipoDocumento = codTipoDocumento ; } public String getCodCurso ( ) { return CodCurso ; } public void setCodCurso ( String codCurso ) { CodCurso = codCurso ; } public String getNomCurso ( ) { return NomCurso ; } public void setNomCurso ( String nomCurso ) { NomCurso = nomCurso ; } public double getPreCurso ( ) { return PreCurso ; } public void setPreCurso ( double preCurso ) { PreCurso = preCurso ; } public int getCanCurso ( ) { return CanCurso ; } public void setCanCurso ( int canCurso ) { CanCurso = canCurso ; } public String getNomEmpleado ( ) { return NomEmpleado ; } public void setNomEmpleado ( String nomEmpleado ) { NomEmpleado = nomEmpleado ; } public String getApeEmpleado ( ) { return ApeEmpleado ; } public void setApeEmpleado ( String apeEmpleado ) { ApeEmpleado = apeEmpleado ; } public String getCodEmpleado ( ) { return CodEmpleado ; } public void setCodEmpleado ( String codEmpleado ) { CodEmpleado = codEmpleado ; } public String getCodAlumno ( ) { return CodAlumno ; } public void setCodAlumno ( String codAlumno ) { CodAlumno = codAlumno ; } public String getCodCliente ( ) { return CodCliente ; } public void setCodCliente ( String codCliente ) { CodCliente = codCliente ; } public String getCodTipCliente ( ) { return CodTipCliente ; } public void setCodTipCliente ( String codTipCliente ) { CodTipCliente = codTipCliente ; } public String getNomCliente ( ) { return NomCliente ; } public void setNomCliente ( String nomCliente ) { NomCliente = nomCliente ; } public String getApePatCliente ( ) { return ApePatCliente ; } public void setApePatCliente ( String apePatCliente ) { ApePatCliente = apePatCliente ; } public String getApeMatCliente ( ) { return ApeMatCliente ; } public void setApeMatCliente ( String apeMatCliente ) { ApeMatCliente = apeMatCliente ; } public String getNroRucCliente ( ) { return NroRucCliente ; } public void setNroRucCliente ( String nroRucCliente ) { NroRucCliente = nroRucCliente ; } private String getNroDniCliente ( ) { return NroDniCliente ; } private void setNroDniCliente ( String nroDniCliente ) { NroDniCliente = nroDniCliente ; } private Double getMontoMora ( ) { return MontoMora ; } private void setMontoMora ( Double montoMora ) { MontoMora = montoMora ; } } </s>
|
<s> package benedictoxvi . pe . data ; public class Permisos { private boolean Acceso ; private boolean Adicionar ; private boolean Editar ; private boolean Eliminar ; private Modulo modulo ; public Permisos ( boolean acceso , boolean adicionar , boolean editar , boolean eliminar , Modulo modulo ) { this . Acceso = acceso ; this . Adicionar = adicionar ; this . Editar = editar ; this . Eliminar = eliminar ; this . modulo = modulo ; } public boolean isAcceso ( ) { return Acceso ; } public void setAcceso ( boolean acceso ) { Acceso = acceso ; } public boolean isAdicionar ( ) { return Adicionar ; } public void setAdicionar ( boolean adicionar ) { Adicionar = adicionar ; } public boolean isEditar ( ) { return Editar ; } public void setEditar ( boolean editar ) { Editar = editar ; } public boolean isEliminar ( ) { return Eliminar ; } public void setEliminar ( boolean eliminar ) { Eliminar = eliminar ; } public Modulo getModulo ( ) { return modulo ; } public void setModulo ( Modulo modulo ) { this . modulo = modulo ; } } </s>
|
<s> package benedictoxvi . pe . data ; import java . lang . annotation . Documented ; import java . util . ArrayList ; public class Usuario { private String dni ; private String nombre ; private String apellidoPaterno ; private String apellidoMaterno ; private String usuario ; private String password ; private String correo ; private String f_ingreso ; private String cargo ; private String status ; private int num_intentos ; public int getNum_intentos ( ) { return num_intentos ; } public void intentoFallido ( ) { setNum_intentos ( getNum_intentos ( ) + <NUM_LIT:1> ) ; } public void setNum_intentos ( int num_intentos ) { this . num_intentos = num_intentos ; } public String getStatus ( ) { return status ; } public boolean isActive ( ) { if ( this . getStatus ( ) . equalsIgnoreCase ( "<STR_LIT:A>" ) ) { return true ; } return false ; } public void setStatus ( String status ) { this . status = status ; } private ArrayList < Rol > roles = new ArrayList < Rol > ( ) ; public ArrayList < Rol > getRoles ( ) { return roles ; } public void setRoles ( ArrayList < Rol > roles ) { this . roles = roles ; } public Usuario ( String dni , String nombre , String apellidoPaterno , String apellidoMaterno , String usuario , String password , String correo , String f_ingreso , String cargo , Rol rol_actual ) { this . dni = dni ; this . nombre = nombre ; this . apellidoPaterno = apellidoPaterno ; this . apellidoMaterno = apellidoMaterno ; this . usuario = usuario ; this . password = password ; this . correo = correo ; this . f_ingreso = f_ingreso ; this . cargo = cargo ; } public Usuario ( ) { } public String getDni ( ) { return dni ; } public void setDni ( String dni ) { this . dni = dni ; } public String getNombre ( ) { return nombre ; } public void setNombre ( String nombre ) { this . nombre = nombre ; } public String getApellidoPaterno ( ) { return apellidoPaterno ; } public void setApellidoPaterno ( String apellidoPaterno ) { this . apellidoPaterno = apellidoPaterno ; } public String getApellidoMaterno ( ) { return apellidoMaterno ; } public void setApellidoMaterno ( String apellidoMaterno ) { this . apellidoMaterno = apellidoMaterno ; } public String getUsuario ( ) { return usuario ; } public void setUsuario ( String usuario ) { this . usuario = usuario ; } public String getPassword ( ) { return password ; } public void setPassword ( String password ) { this . password = password ; } public String getCorreo ( ) { return correo ; } public void setCorreo ( String correo ) { this . correo = correo ; } public String getF_ingreso ( ) { return f_ingreso ; } public void setF_ingreso ( String f_ingreso ) { this . f_ingreso = f_ingreso ; } public String getCargo ( ) { return cargo ; } public void setCargo ( String cargo ) { this . cargo = cargo ; } } </s>
|
<s> package benedictoxvi . pe . data ; public class Modulo { private String nombre ; private String Descripcion ; private Boolean acceso ; public String getDescripcion ( ) { return Descripcion ; } public void setDescripcion ( String descripcion ) { Descripcion = descripcion ; } public Modulo ( ) { } private Boolean adicionar ; private Boolean editar ; private Boolean eliminar ; public Modulo ( String nom_mod ) { this . nombre = nom_mod ; } public Modulo ( String nombre , Boolean acceso , Boolean adicionar , Boolean editar , Boolean eliminar ) { this . nombre = nombre ; this . acceso = acceso ; this . adicionar = adicionar ; this . editar = editar ; this . eliminar = eliminar ; } public String getNombre ( ) { return nombre ; } public void setNombre ( String nombre ) { this . nombre = nombre ; } public Boolean getAcceso ( ) { return acceso ; } public void setAcceso ( Boolean acceso ) { this . acceso = acceso ; } public Boolean getAdicionar ( ) { return adicionar ; } public void setAdicionar ( Boolean adicionar ) { this . adicionar = adicionar ; } public Boolean getEditar ( ) { return editar ; } public void setEditar ( Boolean editar ) { this . editar = editar ; } public Boolean getEliminar ( ) { return eliminar ; } public void setEliminar ( Boolean eliminar ) { this . eliminar = eliminar ; } } </s>
|
<s> package benedictoxvi . pe . data ; import java . util . ArrayList ; public class Rol { private String nombre ; private String descrip ; private ArrayList < Modulo > Modulo = new ArrayList < Modulo > ( ) ; public Rol ( String nombre , String descrip , ArrayList < benedictoxvi . pe . data . Modulo > modulo ) { this . nombre = nombre ; this . descrip = descrip ; for ( int i = <NUM_LIT:0> ; i < modulo . size ( ) ; i ++ ) { this . Modulo . add ( modulo . get ( i ) ) ; } } public Rol ( ) { } public String getNombre ( ) { return nombre ; } public void setNombre ( String nombre ) { this . nombre = nombre ; } public String getDescrip ( ) { return descrip ; } public void setDescrip ( String descrip ) { this . descrip = descrip ; } public ArrayList < Modulo > getModulo ( ) { return Modulo ; } public void setModulo ( ArrayList < Modulo > modulo ) { this . Modulo = modulo ; } } </s>
|
<s> package benedictoxvi . pe . data ; public class Compra extends Movimiento { public boolean isAnulada ( ) { if ( getEstado ( ) . equals ( "<STR_LIT>" ) ) return true ; return false ; } public boolean isNueva ( ) { if ( getEstado ( ) . equals ( "<STR_LIT>" ) ) return true ; return false ; } public boolean isCancelada ( ) { if ( getEstado ( ) . equals ( "<STR_LIT>" ) ) return true ; return false ; } public void pagar ( ) { setEstado ( "<STR_LIT>" ) ; } public void anular ( ) { setEstado ( "<STR_LIT>" ) ; } } </s>
|
<s> package benedictoxvi . pe . data ; import java . util . ArrayList ; public class GrupoEstudio { String CodGrupo ; String NomGrupo ; String Descripcion ; String NomAcademia ; String NomCurso ; String FecInicio ; String FecFin ; public String getCodGrupo ( ) { return CodGrupo ; } public int getNumAlumnos ( ) { return getInscritos ( ) . size ( ) ; } public void setCodGrupo ( String codGrupo ) { CodGrupo = codGrupo ; } String Estado ; String [ ] Instructor ; String LinkSylabus ; String Local ; int Aula ; Double CLatitud ; Double CAltitud ; int Vacantes ; int Aforo ; ArrayList < Cliente > Inscritos = new ArrayList < Cliente > ( ) ; public boolean existsCliente ( String cod_cliente ) { for ( Cliente cli : getInscritos ( ) ) { if ( cli . getCodCliente ( ) . equals ( cod_cliente ) ) { return true ; } } return false ; } public int getVacantes ( ) { return Vacantes ; } public void setVacantes ( int vacantes ) { Vacantes = vacantes ; } public int getAforo ( ) { return Aforo ; } public void setAforo ( int aforo ) { Aforo = aforo ; } public String getInstructorStr ( ) { String list = "<STR_LIT>" ; for ( String ins : getInstructor ( ) ) { list = ins + "<STR_LIT:/>" ; } return list ; } public String [ ] getInstructor ( ) { return Instructor ; } public void setInstructor ( String [ ] instructor ) { Instructor = instructor ; } public String getLinkSylabus ( ) { return LinkSylabus ; } public void setLinkSylabus ( String linkSylabus ) { LinkSylabus = linkSylabus ; } public String getLocal ( ) { return Local ; } public void setLocal ( String local ) { Local = local ; } public int getAula ( ) { return Aula ; } public void setAula ( int aula ) { Aula = aula ; } public Double getCLatitud ( ) { return CLatitud ; } public void setCLatitud ( Double cLatitud ) { CLatitud = cLatitud ; } public Double getCAltitud ( ) { return CAltitud ; } public void setCAltitud ( Double cAltitud ) { CAltitud = cAltitud ; } public String getNomGrupo ( ) { return NomGrupo ; } public void setNomGrupo ( String nomGrupo ) { NomGrupo = nomGrupo ; } public String getNomAcademia ( ) { return NomAcademia ; } public void setNomAcademia ( String nomAcademia ) { NomAcademia = nomAcademia ; } public String getNomCurso ( ) { return NomCurso ; } public void setNomCurso ( String nomCurso ) { NomCurso = nomCurso ; } public String getFecInicio ( ) { return FecInicio ; } public void setFecInicio ( String fecInicio ) { FecInicio = fecInicio ; } public String getFecFin ( ) { return FecFin ; } public void setFecFin ( String fecFin ) { FecFin = fecFin ; } public String getEstado ( ) { return Estado ; } public void setEstado ( String estado ) { Estado = estado ; } public String getDescripcion ( ) { return Descripcion ; } public void setDescripcion ( String descripcion ) { Descripcion = descripcion ; } public ArrayList < Cliente > getInscritos ( ) { return Inscritos ; } public void setInscritos ( ArrayList < Cliente > inscritos ) { Inscritos = inscritos ; } } </s>
|
<s> package benedictoxvi . pe . business ; import java . util . ArrayList ; import benedictoxvi . pe . data . Usuario ; import benedictoxvi . pe . datatest . DataBD ; import benedictoxvi . pe . util . ProcessException ; import benedictoxvi . pe . util . Validaciones ; public class AdmLoginUsuario { ArrayList < Usuario > arrUsr = new ArrayList < Usuario > ( ) ; DataBD bd = new DataBD ( ) ; Validaciones objVal = new Validaciones ( ) ; public AdmLoginUsuario ( ) { arrUsr = bd . getDataUsuarios ( ) ; } public Usuario getUserByName ( String nom_usr ) { Usuario usr_end = null ; for ( Usuario usr : arrUsr ) { if ( usr . getUsuario ( ) . equals ( nom_usr ) ) { usr_end = usr ; break ; } } if ( usr_end == null ) { new ProcessException ( "<STR_LIT>" + nom_usr + "<STR_LIT>" ) . printStackTrace ( ) ; } return usr_end ; } public boolean loginUsuario ( String usuario , String clave ) { String msg_err = null ; if ( ! objVal . isSet ( usuario ) ) { msg_err = "<STR_LIT>" ; } else if ( ! objVal . isSet ( clave ) ) { msg_err = "<STR_LIT>" ; } if ( objVal . isSet ( msg_err ) ) { new ProcessException ( msg_err ) . printStackTrace ( ) ; return false ; } Usuario usr = getUserByName ( usuario ) ; if ( usr != null ) { if ( ! usr . isActive ( ) ) { new ProcessException ( "<STR_LIT>" + usuario + "<STR_LIT>" ) . printStackTrace ( ) ; return false ; } if ( usr . getPassword ( ) . equals ( clave ) ) { usr . setNum_intentos ( <NUM_LIT:0> ) ; objVal . messageOk ( "<STR_LIT>" + usuario + "<STR_LIT>" ) ; return true ; } else { usr . intentoFallido ( ) ; if ( usr . getNum_intentos ( ) == <NUM_LIT:5> ) { usr . setStatus ( "<STR_LIT:B>" ) ; new ProcessException ( "<STR_LIT>" + usuario + "<STR_LIT>" ) . printStackTrace ( ) ; return false ; } new ProcessException ( "<STR_LIT>" + usuario + "<STR_LIT>" ) . printStackTrace ( ) ; } } return false ; } } </s>
|
<s> package benedictoxvi . pe . business ; import java . util . ArrayList ; import java . util . Collections ; import java . util . Comparator ; import benedictoxvi . pe . data . Modulo ; import benedictoxvi . pe . data . Rol ; import benedictoxvi . pe . data . Usuario ; import benedictoxvi . pe . datatest . DataBD ; import benedictoxvi . pe . util . ProcessException ; import benedictoxvi . pe . util . Validaciones ; public class AdmAccesosUser { ArrayList < Usuario > arrUsr = new ArrayList < Usuario > ( ) ; Validaciones objVal = new Validaciones ( ) ; DataBD myBD = new DataBD ( ) ; public AdmAccesosUser ( ) { arrUsr = myBD . getDataUsuarios ( ) ; } public Modulo getModuloInUser ( String nom_user , String nom_modulo ) { Modulo mod_usr = new Modulo ( "<STR_LIT>" , false , false , false , false ) ; boolean find = false ; boolean find_usr = false ; int index = <NUM_LIT:0> ; for ( Usuario usr : myBD . getDataUsuarios ( ) ) { if ( usr . getUsuario ( ) . equalsIgnoreCase ( nom_user ) ) { find_usr = true ; for ( Rol user_rol : usr . getRoles ( ) ) { for ( Modulo mod : user_rol . getModulo ( ) ) { if ( mod . getNombre ( ) . equalsIgnoreCase ( nom_modulo ) ) { objVal . messageOk ( "<STR_LIT>" + nom_modulo + "<STR_LIT>" + nom_user + "<STR_LIT:'>" ) ; return mod ; } } } return null ; } } if ( find_usr == false ) { new ProcessException ( "<STR_LIT>" + nom_user + "<STR_LIT>" ) . printStackTrace ( ) ; return null ; } else if ( find == false ) { new ProcessException ( "<STR_LIT>" + nom_modulo + "<STR_LIT>" + nom_user + "<STR_LIT>" ) . printStackTrace ( ) ; return null ; } return null ; } public Usuario getUserByName ( String nom_usr ) { Usuario usr_end = null ; for ( Usuario usr : arrUsr ) { if ( usr . getUsuario ( ) . equals ( nom_usr ) ) { usr_end = usr ; break ; } } if ( usr_end == null ) { new ProcessException ( "<STR_LIT>" + nom_usr + "<STR_LIT>" ) . printStackTrace ( ) ; } return usr_end ; } public ArrayList < Rol > rolesByUser ( String nom_user ) { Usuario usr = getUserByName ( nom_user ) ; if ( usr == null ) { return null ; } return usr . getRoles ( ) ; } public ArrayList < Modulo > modulosByRol ( String nom_rol ) { return new AdmRoles ( ) . findRol ( nom_rol ) . getModulo ( ) ; } public boolean addRolUser ( String nom_user , String nom_rol ) { Usuario usr_rol = getUserByName ( nom_user ) ; if ( usr_rol != null ) { for ( Rol xrol : usr_rol . getRoles ( ) ) { if ( xrol . getNombre ( ) . equals ( nom_rol ) ) { new ProcessException ( "<STR_LIT>" + nom_user + "<STR_LIT>" + nom_rol + "<STR_LIT:'>" ) . printStackTrace ( ) ; return false ; } } Rol new_rol = new AdmRoles ( ) . findRol ( nom_rol ) ; if ( new_rol != null ) { usr_rol . getRoles ( ) . add ( new_rol ) ; objVal . messageOk ( "<STR_LIT>" + nom_rol + "<STR_LIT>" + nom_user + "<STR_LIT>" ) ; return true ; } } return false ; } public boolean removeRolUser ( String nom_usr , String nom_rol ) { Usuario usr = getUserByName ( nom_usr ) ; if ( usr != null ) { for ( Rol xrol : usr . getRoles ( ) ) { if ( xrol . getNombre ( ) . equals ( nom_rol ) ) { usr . getRoles ( ) . remove ( xrol ) ; objVal . messageOk ( "<STR_LIT>" + nom_usr + "<STR_LIT>" + nom_rol + "<STR_LIT>" ) ; return true ; } } new ProcessException ( "<STR_LIT>" + nom_usr + "<STR_LIT>" + nom_rol + "<STR_LIT:'>" ) . printStackTrace ( ) ; return false ; } return false ; } public boolean requestAcceso ( String nom_user , String nom_modulo ) { Modulo mod_usr = getModuloInUser ( nom_user , nom_modulo ) ; if ( mod_usr != null ) { return mod_usr . getAcceso ( ) ; } return false ; } public boolean requestAdicion ( String nom_user , String nom_modulo ) { Modulo mod_usr = getModuloInUser ( nom_user , nom_modulo ) ; if ( mod_usr != null ) { return mod_usr . getAdicionar ( ) ; } return false ; } public boolean requestModificacion ( String nom_user , String nom_modulo ) { Modulo mod_usr = getModuloInUser ( nom_user , nom_modulo ) ; if ( mod_usr != null ) { return mod_usr . getEditar ( ) ; } return false ; } public boolean requestEliminacion ( String nom_user , String nom_modulo ) { Modulo mod_usr = getModuloInUser ( nom_user , nom_modulo ) ; if ( mod_usr != null ) { return mod_usr . getEliminar ( ) ; } return false ; } } </s>
|
<s> package benedictoxvi . pe . business ; import java . util . ArrayList ; import java . util . Collections ; import java . util . Comparator ; import benedictoxvi . pe . data . Modulo ; import benedictoxvi . pe . data . Rol ; import benedictoxvi . pe . data . Usuario ; import benedictoxvi . pe . datatest . DataBD ; import benedictoxvi . pe . util . ProcessException ; import benedictoxvi . pe . util . Validaciones ; public class AdmRoles { ArrayList < Rol > arrRols = new ArrayList < Rol > ( ) ; ArrayList < Usuario > arrUsr = new ArrayList < Usuario > ( ) ; Validaciones objVal = new Validaciones ( ) ; ArrayList < Modulo > arrMods = new ArrayList < Modulo > ( ) ; DataBD bd = new DataBD ( ) ; public Modulo getNewModulo ( String cod_mod , boolean acceso , boolean adicion , boolean actualiza , boolean suprimir ) { if ( findModuloByIdent ( cod_mod ) != null ) { return new Modulo ( cod_mod , acceso , adicion , actualiza , suprimir ) ; } new ProcessException ( "<STR_LIT>" + cod_mod + "<STR_LIT>" ) . printStackTrace ( ) ; return null ; } public Modulo findModuloByIdent ( String cod_mod ) { Modulo new_mod = null ; try { new_mod = arrMods . get ( Collections . binarySearch ( arrMods , new Modulo ( cod_mod ) , new Comparator < Modulo > ( ) { @ Override public int compare ( Modulo o1 , Modulo o2 ) { return o1 . getNombre ( ) . compareTo ( o2 . getNombre ( ) ) ; } } ) ) ; } catch ( Exception e ) { new_mod = null ; } return new_mod ; } public AdmRoles ( ) { arrMods = bd . getDataModulos ( ) ; arrRols = bd . getDataRoles ( ) ; arrUsr = bd . getDataUsuarios ( ) ; } public ArrayList < Rol > getRoles ( ) { return arrRols ; } public boolean validaNombreRol ( Rol unRol ) { boolean Ok = true ; for ( int i = <NUM_LIT:0> ; i < unRol . getModulo ( ) . size ( ) ; i ++ ) { if ( unRol . getModulo ( ) . get ( i ) . getNombre ( ) == null || unRol . getModulo ( ) . get ( i ) . getNombre ( ) . equals ( "<STR_LIT>" ) ) { Ok = false ; } } return Ok ; } public boolean validaEstadoRol ( Rol unRol ) { boolean Ok = true ; for ( int i = <NUM_LIT:0> ; i < unRol . getModulo ( ) . size ( ) ; i ++ ) { if ( unRol . getModulo ( ) . get ( i ) . getAcceso ( ) == null ) { Ok = false ; } else if ( unRol . getModulo ( ) . get ( i ) . getAdicionar ( ) == null ) { Ok = false ; } else if ( unRol . getModulo ( ) . get ( i ) . getEditar ( ) == null ) { Ok = false ; } else if ( unRol . getModulo ( ) . get ( i ) . getEliminar ( ) == null ) { Ok = false ; } } return Ok ; } public boolean validaDescripcionRol ( Rol unRol ) { boolean Ok = true ; if ( unRol . getDescrip ( ) == null || unRol . getDescrip ( ) . equals ( "<STR_LIT>" ) ) { Ok = false ; } return Ok ; } public boolean buscaRol ( String rol ) { boolean encuentra = false ; for ( int x = <NUM_LIT:0> ; x < arrRols . size ( ) ; x ++ ) { if ( arrRols . get ( x ) . getNombre ( ) . equals ( rol ) ) { System . out . println ( "<STR_LIT>" + arrRols . get ( x ) . getNombre ( ) + "<STR_LIT:U+0020>" + arrRols . get ( x ) . getDescrip ( ) ) ; encuentra = true ; break ; } } return encuentra ; } public Rol findRol ( String nom_rol ) { for ( Rol xrol : arrRols ) { if ( xrol . getNombre ( ) . equals ( nom_rol ) ) { return xrol ; } } new ProcessException ( "<STR_LIT>" + nom_rol + "<STR_LIT>" ) . printStackTrace ( ) ; return null ; } public void eliminaRol ( String rol ) { boolean encontrado = false ; for ( int x = <NUM_LIT:0> ; x < arrRols . size ( ) ; x ++ ) { if ( arrRols . get ( x ) . getNombre ( ) . equals ( rol ) ) { encontrado = true ; System . out . println ( "<STR_LIT>" + arrRols . get ( x ) . getNombre ( ) + "<STR_LIT:U+0020>" + arrRols . get ( x ) . getDescrip ( ) ) ; arrRols . remove ( x ) ; break ; } } if ( encontrado == false ) { System . out . println ( "<STR_LIT>" + rol + "<STR_LIT>" ) ; } } public boolean registrarRol ( String cod_rol , String nom_rol , ArrayList < Modulo > mods ) { Rol new_rol = new Rol ( ) ; String msg_err = null ; if ( ! objVal . isSet ( cod_rol ) ) { msg_err = "<STR_LIT>" ; } else if ( cod_rol . trim ( ) . length ( ) < <NUM_LIT:6> ) { msg_err = "<STR_LIT>" + cod_rol + "<STR_LIT:]>" ; } else if ( ! objVal . isSet ( nom_rol ) ) { msg_err = "<STR_LIT>" + cod_rol + "<STR_LIT:'>" ; } else if ( mods != null ) { for ( Modulo mod : mods ) { if ( findModuloByIdent ( mod . getNombre ( ) ) == null ) { msg_err = ( "<STR_LIT>" + mod . getNombre ( ) + "<STR_LIT>" ) ; break ; } } } if ( mods == null ) { mods = new ArrayList < Modulo > ( ) ; } if ( objVal . isSet ( msg_err ) ) { new ProcessException ( msg_err ) . printStackTrace ( ) ; return false ; } new_rol . setNombre ( cod_rol ) ; new_rol . setDescrip ( nom_rol ) ; new_rol . setModulo ( mods ) ; arrRols . add ( new_rol ) ; objVal . messageOk ( "<STR_LIT>" + cod_rol + "<STR_LIT>" + nom_rol + "<STR_LIT>" ) ; if ( new_rol . getModulo ( ) . size ( ) == <NUM_LIT:0> ) { objVal . messageWar ( "<STR_LIT>" ) ; } return true ; } public boolean suprimirRol ( String cod_rol ) { Rol del_rol = findRol ( cod_rol ) ; if ( del_rol != null ) { for ( Usuario usr : arrUsr ) { for ( Rol rol_usr : usr . getRoles ( ) ) { if ( rol_usr . getNombre ( ) . equals ( cod_rol ) ) { new ProcessException ( "<STR_LIT>" + usr . getUsuario ( ) + "<STR_LIT>" ) . printStackTrace ( ) ; return false ; } } } arrRols . remove ( del_rol ) ; objVal . messageOk ( "<STR_LIT>" + cod_rol + "<STR_LIT>" ) ; return true ; } return false ; } public boolean modificarRol ( String cod_rol , String nom_rol , ArrayList < Modulo > mods ) { Rol mod_rol = findRol ( cod_rol ) ; String msg_err = "<STR_LIT>" ; if ( nom_rol != null && ! objVal . isSet ( nom_rol ) ) { msg_err = "<STR_LIT>" + cod_rol + "<STR_LIT:'>" ; } if ( objVal . isSet ( msg_err ) ) { new ProcessException ( msg_err ) . printStackTrace ( ) ; return false ; } if ( mods == null ) { mods = new ArrayList < Modulo > ( ) ; } mod_rol . setDescrip ( nom_rol ) ; mod_rol . setModulo ( mods ) ; objVal . messageOk ( "<STR_LIT>" + cod_rol + "<STR_LIT>" ) ; return true ; } } </s>
|
<s> package benedictoxvi . pe . business ; import java . text . DateFormat ; import java . text . ParseException ; import java . util . ArrayList ; import java . util . Date ; import benedictoxvi . pe . data . Rol ; import benedictoxvi . pe . data . Usuario ; import benedictoxvi . pe . datatest . DataBD ; import benedictoxvi . pe . util . ProcessException ; import benedictoxvi . pe . util . Validaciones ; public class AdmUsuarios { Validaciones objVal = new Validaciones ( ) ; AdmRoles admRol = new AdmRoles ( ) ; ArrayList < Usuario > arrUsr = new ArrayList < Usuario > ( ) ; DataBD bd = new DataBD ( ) ; public AdmUsuarios ( ) { arrUsr = bd . getDataUsuarios ( ) ; } public ArrayList < Usuario > getarrUsr ( ) { return arrUsr ; } Usuario objUsuarioEncontrado ; public Usuario getObjUsuarioEncontrado ( ) { return objUsuarioEncontrado ; } public void agregarUsuario ( Usuario user ) { arrUsr . add ( user ) ; } public Usuario getUser_name ( String nombre ) { Usuario temp = null ; for ( int i = <NUM_LIT:0> ; i < arrUsr . size ( ) ; i ++ ) { if ( nombre . equals ( arrUsr . get ( i ) . getNombre ( ) ) ) temp = arrUsr . get ( i ) ; break ; } return temp ; } public Date convertirFecha ( String fecha ) throws ParseException { DateFormat df = DateFormat . getDateInstance ( DateFormat . MEDIUM ) ; Date d1 = df . parse ( fecha ) ; return d1 ; } public Usuario getUserByName ( String usuario ) { for ( Usuario usr : arrUsr ) { if ( usr . getUsuario ( ) . equals ( usuario ) ) { return usr ; } } new ProcessException ( "<STR_LIT>" + usuario + "<STR_LIT>" ) . printStackTrace ( ) ; return null ; } public static void DatosUsuarioBuscado ( String usuario , ArrayList < Usuario > dbArray ) { for ( int x = <NUM_LIT:0> ; x < dbArray . size ( ) ; x ++ ) { if ( dbArray . get ( x ) . getUsuario ( ) . equals ( usuario ) ) { System . out . println ( "<STR_LIT>" + dbArray . get ( x ) . getNombre ( ) ) ; System . out . println ( "<STR_LIT>" + dbArray . get ( x ) . getApellidoPaterno ( ) ) ; System . out . println ( "<STR_LIT>" + dbArray . get ( x ) . getApellidoMaterno ( ) ) ; System . out . println ( "<STR_LIT>" + dbArray . get ( x ) . getUsuario ( ) ) ; System . out . println ( "<STR_LIT>" + dbArray . get ( x ) . getPassword ( ) ) ; System . out . println ( "<STR_LIT>" + dbArray . get ( x ) . getCorreo ( ) ) ; System . out . println ( "<STR_LIT>" + dbArray . get ( x ) . getF_ingreso ( ) ) ; System . out . println ( "<STR_LIT>" + dbArray . get ( x ) . getCargo ( ) ) ; } } } public static boolean eliminarUsuario ( String usuario , ArrayList < Usuario > dbArray ) { return false ; } public boolean createUsuario ( String nom_usr , String pwd1 , String pwd2 , String nombs , String apat , String amat , String fing , String [ ] rols , String cargo , String dni ) { String msg_err = null ; if ( ! objVal . isSet ( nom_usr ) ) { msg_err = "<STR_LIT>" ; } else if ( ! objVal . isSet ( new String [ ] { pwd1 , pwd2 } ) ) { msg_err = "<STR_LIT>" ; } else if ( ! pwd1 . equals ( pwd2 ) ) { msg_err = "<STR_LIT>" ; } else if ( ! objVal . isSet ( nombs ) ) { msg_err = "<STR_LIT>" ; } else if ( ! objVal . isSet ( apat ) ) { msg_err = "<STR_LIT>" ; } else if ( ! objVal . isSet ( fing ) ) { msg_err = "<STR_LIT>" ; } else if ( ! objVal . isDate ( fing ) ) { msg_err = "<STR_LIT>" ; } else if ( ! objVal . isSet ( dni ) ) { msg_err = "<STR_LIT>" ; } else if ( ! objVal . isDNI ( dni ) ) { msg_err = "<STR_LIT>" ; } if ( objVal . isSet ( msg_err ) ) { new ProcessException ( msg_err ) . printStackTrace ( ) ; return false ; } Rol add_rol = null ; ArrayList < Rol > roles = new ArrayList < Rol > ( ) ; for ( String nom_rol : rols ) { add_rol = admRol . findRol ( nom_rol ) ; if ( add_rol == null ) { new ProcessException ( "<STR_LIT>" + nom_rol + "<STR_LIT>" ) ; return false ; } roles . add ( add_rol ) ; } Usuario new_usr = new Usuario ( ) ; new_usr . setRoles ( roles ) ; new_usr . setPassword ( pwd1 ) ; new_usr . setUsuario ( nom_usr ) ; new_usr . setApellidoPaterno ( apat ) ; new_usr . setApellidoMaterno ( amat ) ; new_usr . setNombre ( nombs ) ; new_usr . setF_ingreso ( fing ) ; new_usr . setCargo ( cargo ) ; new_usr . setDni ( dni ) ; arrUsr . add ( new_usr ) ; objVal . messageOk ( "<STR_LIT>" + nom_usr + "<STR_LIT>" ) ; return true ; } public boolean loginUser ( String nom_usr , String clave ) { Usuario usr = getUserByName ( nom_usr ) ; if ( usr != null ) { if ( usr . getPassword ( ) . equals ( clave ) ) { if ( ! usr . isActive ( ) ) { new ProcessException ( "<STR_LIT>" + nom_usr + "<STR_LIT>" ) . printStackTrace ( ) ; return false ; } objVal . messageOk ( "<STR_LIT>" + nom_usr + "<STR_LIT:]>" ) ; return true ; } else { new ProcessException ( "<STR_LIT>" + nom_usr + "<STR_LIT:'>" ) . printStackTrace ( ) ; return false ; } } return false ; } public boolean cambiarClaveUsuario ( String nom_usr , String clave_actual , String newpwd1 , String newpwd2 ) { if ( loginUser ( nom_usr , clave_actual ) ) { if ( ! objVal . isValidKey ( newpwd1 ) ) { new ProcessException ( "<STR_LIT>" ) . printStackTrace ( ) ; return false ; } if ( ! newpwd2 . equals ( newpwd2 ) ) { new ProcessException ( "<STR_LIT>" ) . printStackTrace ( ) ; return false ; } objVal . messageOk ( "<STR_LIT>" + nom_usr + "<STR_LIT>" ) ; return true ; } return false ; } public boolean quitarUsuario ( String nom_usr ) { Usuario usr = getUserByName ( nom_usr ) ; if ( usr != null ) { arrUsr . remove ( usr ) ; objVal . messageOk ( "<STR_LIT>" + nom_usr + "<STR_LIT:]>" ) ; return true ; } return false ; } public boolean modificarUsuario ( String nom_usr , String nombs , String apat , String amat , String fing , String [ ] rols , String cargo , String dni ) { String msg_err = "<STR_LIT>" ; if ( ! objVal . isSet ( nom_usr ) ) { new ProcessException ( "<STR_LIT>" ) . printStackTrace ( ) ; return false ; } Usuario upd_usr = getUserByName ( nom_usr ) ; if ( upd_usr == null ) { return false ; } if ( nombs != null && ! objVal . isSet ( nombs ) ) { msg_err = "<STR_LIT>" ; } else if ( apat != null && ! objVal . isSet ( apat ) ) { msg_err = "<STR_LIT>" ; } else if ( fing != null && ! objVal . isSet ( fing ) ) { msg_err = "<STR_LIT>" ; } else if ( fing != null && ! objVal . isDate ( fing ) ) { msg_err = "<STR_LIT>" ; } else if ( dni != null && ! objVal . isSet ( dni ) ) { msg_err = "<STR_LIT>" ; } else if ( dni != null && ! objVal . isDNI ( dni ) ) { msg_err = "<STR_LIT>" ; } if ( objVal . isSet ( msg_err ) ) { new ProcessException ( msg_err ) . printStackTrace ( ) ; return false ; } if ( rols != null ) { ArrayList < Rol > roles = new ArrayList < Rol > ( ) ; for ( String nom_rol : rols ) { Rol add_rol = admRol . findRol ( nom_rol ) ; if ( add_rol == null ) { new ProcessException ( "<STR_LIT>" + nom_rol + "<STR_LIT>" ) ; return false ; } roles . add ( add_rol ) ; } upd_usr . setRoles ( roles ) ; } upd_usr . setNombre ( nombs ) ; upd_usr . setApellidoMaterno ( amat ) ; upd_usr . setApellidoPaterno ( apat ) ; upd_usr . setDni ( dni ) ; if ( cargo != null ) { upd_usr . setCargo ( cargo ) ; } upd_usr . setF_ingreso ( fing ) ; objVal . messageOk ( "<STR_LIT>" + nom_usr + "<STR_LIT:]>" ) ; return true ; } public boolean bloquearUsuario ( String nom_usr ) { Usuario usr = getUserByName ( nom_usr ) ; if ( ! ( usr == null ) ) { if ( usr . getStatus ( ) == "<STR_LIT:X>" ) { objVal . messageOk ( "<STR_LIT>" ) ; } usr . setStatus ( "<STR_LIT:X>" ) ; objVal . messageOk ( "<STR_LIT>" + nom_usr + "<STR_LIT:]>" ) ; return true ; } return false ; } public boolean desbloquearUsuario ( String nom_usr ) { Usuario usr = getUserByName ( nom_usr ) ; if ( ! ( usr == null ) ) { if ( usr . getStatus ( ) == "<STR_LIT:X>" ) { System . out . println ( "<STR_LIT>" ) ; } usr . setStatus ( "<STR_LIT:A>" ) ; objVal . messageOk ( "<STR_LIT>" + nom_usr + "<STR_LIT:]>" ) ; return true ; } return false ; } } </s>
|
<s> package benedictoxvi . pe . business ; import java . text . SimpleDateFormat ; import java . util . ArrayList ; import java . util . Collection ; import java . util . Collections ; import java . util . Date ; import java . util . Iterator ; import java . util . List ; import benedictoxvi . pe . data . Cliente ; import benedictoxvi . pe . data . Venta ; import benedictoxvi . pe . datatest . DataBD ; import benedictoxvi . pe . util . FormatException ; import benedictoxvi . pe . util . ProcessException ; import benedictoxvi . pe . util . Validaciones ; public class AdmVenta { Venta objVenta = new Venta ( ) ; Validaciones objVal = new Validaciones ( ) ; public Boolean registrarPagoConBoleta ( List < Venta > arrVenta , int nroMovimiento , String codTipoDocumento , String codCurso , String codCliente , String nomCliente , String concepto , String fecEmision , Double subtot , Double monIGV , Double monTot , String moneda , String fecVencim , String estado , String fecPagoReal , String observ ) { String msg_err = "<STR_LIT>" ; if ( ! objVal . isSet ( codTipoDocumento ) ) { msg_err = "<STR_LIT>" ; } else if ( ! objVal . isSet ( codCurso ) ) { msg_err = "<STR_LIT>" ; } else if ( ! objVal . isSet ( codCliente ) ) { msg_err = "<STR_LIT>" ; } else if ( ! objVal . isSet ( concepto ) ) { msg_err = "<STR_LIT>" ; } else if ( ! objVal . isDate ( fecEmision ) ) { msg_err = "<STR_LIT>" ; } else if ( subtot <= <NUM_LIT:0> ) { msg_err = "<STR_LIT>" ; } else if ( monIGV <= <NUM_LIT:0> ) { msg_err = "<STR_LIT>" ; } else if ( monIGV >= subtot || monIGV < <NUM_LIT:0> ) { msg_err = "<STR_LIT>" + subtot ; } else if ( monTot <= <NUM_LIT:0> ) { msg_err = "<STR_LIT>" ; } else if ( ! objVal . isSet ( moneda ) ) { msg_err = "<STR_LIT>" ; } else if ( ! objVal . isSet ( fecVencim ) ) { msg_err = "<STR_LIT>" ; } else if ( ! objVal . isDate ( fecVencim ) ) { msg_err = "<STR_LIT>" ; } else if ( objVal . isSet ( fecPagoReal ) && ! objVal . isDate ( fecPagoReal ) ) { msg_err = "<STR_LIT>" ; } if ( objVal . isSet ( msg_err ) ) { new FormatException ( msg_err ) . printStackTrace ( ) ; return false ; } objVenta . setNumero ( nroMovimiento ) ; objVenta . setCodTipoDocumento ( codTipoDocumento ) ; objVenta . setCodCurso ( codCurso ) ; objVenta . setCodCliente ( codCliente ) ; objVenta . setNomCliente ( nomCliente ) ; objVenta . setConcepto ( concepto ) ; objVenta . setFecEmision ( fecEmision ) ; objVenta . setMonSubtot ( subtot ) ; objVenta . setMonIGV ( monIGV ) ; objVenta . setMonTotal ( monTot ) ; objVenta . setMoneda ( moneda ) ; objVenta . setFecVencim ( fecVencim ) ; objVenta . setEstado ( estado ) ; objVenta . setFecPago ( fecPagoReal ) ; objVenta . setObservacion ( observ ) ; arrVenta . add ( objVenta ) ; return true ; } public Boolean registrarPagoConFactura ( ArrayList < Venta > arrVenta , int nroMovimiento , String codTipoDocumento , String codCurso , String codCliente , String nomCliente , String nroRucCliente , String concepto , String fecEmision , Double subtot , Double monIGV , Double monTot , String moneda , String fecVencim , String estado , String fecPagoReal , String observ ) { String msg_err = "<STR_LIT>" ; if ( ! objVal . isSet ( codTipoDocumento ) ) { msg_err = "<STR_LIT>" ; } else if ( ! objVal . isSet ( codCurso ) ) { msg_err = "<STR_LIT>" ; } else if ( ! objVal . isSet ( codCliente ) ) { msg_err = "<STR_LIT>" ; } else if ( ! objVal . isRUC ( nroRucCliente ) ) { msg_err = "<STR_LIT>" ; } else if ( ! objVal . isSet ( concepto ) ) { msg_err = "<STR_LIT>" ; } else if ( ! objVal . isDate ( fecEmision ) ) { msg_err = "<STR_LIT>" ; } else if ( ! objVal . isSet ( fecVencim ) ) { msg_err = "<STR_LIT>" ; } else if ( ! objVal . isDate ( fecVencim ) ) { msg_err = "<STR_LIT>" ; } else if ( subtot <= <NUM_LIT:0> ) { msg_err = "<STR_LIT>" ; } else if ( monIGV <= <NUM_LIT:0> ) { msg_err = "<STR_LIT>" ; } else if ( monIGV >= subtot || monIGV < <NUM_LIT:0> ) { msg_err = "<STR_LIT>" + subtot ; } else if ( monTot <= <NUM_LIT:0> ) { msg_err = "<STR_LIT>" ; } else if ( objVal . isSet ( fecPagoReal ) && ! objVal . isDate ( fecPagoReal ) ) { msg_err = "<STR_LIT>" ; } if ( objVal . isSet ( msg_err ) ) { new FormatException ( msg_err ) . printStackTrace ( ) ; return false ; } objVenta . setNumero ( nroMovimiento ) ; objVenta . setCodTipoDocumento ( codTipoDocumento ) ; objVenta . setCodCurso ( codCurso ) ; objVenta . setCodCliente ( codCliente ) ; objVenta . setNomCliente ( nomCliente ) ; objVenta . setNroRucCliente ( nroRucCliente ) ; objVenta . setConcepto ( concepto ) ; objVenta . setFecEmision ( fecEmision ) ; objVenta . setMonSubtot ( subtot ) ; objVenta . setMonIGV ( monIGV ) ; objVenta . setMonTotal ( monTot ) ; objVenta . setMoneda ( moneda ) ; objVenta . setFecVencim ( fecVencim ) ; objVenta . setEstado ( estado ) ; objVenta . setFecPago ( fecPagoReal ) ; objVenta . setObservacion ( observ ) ; arrVenta . add ( objVenta ) ; return true ; } public ArrayList < Venta > listarMovimientos ( ArrayList < Venta > arrMovimiento ) { Collections . sort ( arrMovimiento , new Venta ( ) ) ; Iterator < Venta > iMovimientos = arrMovimiento . iterator ( ) ; while ( iMovimientos . hasNext ( ) ) { System . out . println ( iMovimientos . next ( ) . toString ( ) ) ; } return arrMovimiento ; } public ArrayList < Venta > listarMovimientosTipoDocumento ( ArrayList < Venta > arrMovimiento , String codTipoDocumento ) { ArrayList < Venta > olstMovimiento = new ArrayList < Venta > ( ) ; Iterator < Venta > iMovimientos = arrMovimiento . iterator ( ) ; Venta oVenta ; while ( iMovimientos . hasNext ( ) ) { oVenta = iMovimientos . next ( ) ; if ( oVenta . getCodTipoDocumento ( ) == codTipoDocumento ) { olstMovimiento . add ( oVenta ) ; System . out . println ( oVenta . toString ( ) ) ; } } if ( olstMovimiento . size ( ) == <NUM_LIT:0> ) { System . err . println ( "<STR_LIT>" ) ; } else { System . out . println ( "<STR_LIT>" + olstMovimiento . size ( ) + "<STR_LIT>" ) ; } return olstMovimiento ; } public ArrayList < Venta > listarDetalleMovimiento ( ArrayList < Venta > arrMovimiento , int nroMovimiento ) { ArrayList < Venta > olstMovimiento = new ArrayList < Venta > ( ) ; Iterator < Venta > iMovimientos = arrMovimiento . iterator ( ) ; Venta oVenta ; while ( iMovimientos . hasNext ( ) ) { oVenta = iMovimientos . next ( ) ; if ( oVenta . getNumero ( ) == nroMovimiento ) { olstMovimiento . add ( oVenta ) ; System . out . println ( oVenta . toString ( ) ) ; } } if ( olstMovimiento . size ( ) == <NUM_LIT:0> ) { System . err . println ( "<STR_LIT>" ) ; } else { System . out . println ( "<STR_LIT>" + olstMovimiento . size ( ) + "<STR_LIT>" ) ; } return olstMovimiento ; } public boolean anularDocumento ( ArrayList < Venta > arrMovimiento , int nroMovimiento ) { for ( Venta oVenta : arrMovimiento ) { if ( oVenta . getNumero ( ) == nroMovimiento ) { return arrMovimiento . remove ( oVenta ) ; } } return false ; } public boolean registraPagoBoletaFactura ( ArrayList < Venta > arrVenta , int nroMovimiento , String tipoComprobante , String nroBoleta , String RUC , String CodCliente , String CodCuenta , List < Venta > arrNroCuota , String usuarioRegistro ) { String Comprobante = "<STR_LIT>" ; String msg_err = "<STR_LIT>" ; if ( ! objVal . isSet ( tipoComprobante ) ) { msg_err = "<STR_LIT>" ; } else if ( ! objVal . isSet ( CodCuenta ) ) { msg_err = "<STR_LIT>" ; } else if ( ! objVal . isSet ( CodCliente ) ) { msg_err = "<STR_LIT>" ; } else if ( ! objVal . isSet ( usuarioRegistro ) ) { msg_err = "<STR_LIT>" ; } if ( validaciones ( CodCliente , CodCuenta ) != true ) { msg_err = "<STR_LIT>" ; } if ( tipoComprobante . equalsIgnoreCase ( "<STR_LIT:1>" ) ) { Comprobante = "<STR_LIT>" ; } else { Comprobante = "<STR_LIT>" ; } if ( objVal . isSet ( msg_err ) ) { new FormatException ( msg_err ) . printStackTrace ( ) ; return false ; } Venta objVenCronograma = new Venta ( ) ; List < Venta > arrCrono = new ArrayList < Venta > ( ) ; arrCrono = objVenCronograma . getCronogramaByCodigoCuenta ( CodCuenta ) ; Venta oCuenta = new Venta ( ) ; oCuenta = objVenCronograma . getCuentaByCodigo ( CodCuenta ) ; Venta oCurso = new Venta ( ) ; oCurso = objVenCronograma . getCursoByCodigo ( oCuenta . getCodCurso ( ) ) ; Cliente objCliente = new Cliente ( ) ; objCliente = getClienteByCodigo ( CodCliente ) ; Date FechaActual = new Date ( ) ; System . out . println ( "<STR_LIT>" + nroMovimiento ) ; System . out . println ( "<STR_LIT>" + Comprobante ) ; System . out . println ( "<STR_LIT>" + nroBoleta ) ; System . out . println ( "<STR_LIT>" + fechaToString ( FechaActual ) ) ; System . out . println ( "<STR_LIT>" + objCliente . getNomCliente ( ) + "<STR_LIT:U+0020>" + objCliente . getApePatCliente ( ) + "<STR_LIT:U+0020>" + objCliente . getApeMatCliente ( ) ) ; System . out . println ( "<STR_LIT>" ) ; String fecha = "<STR_LIT>" ; int n = <NUM_LIT:0> ; Double MontoTotal = <NUM_LIT:0.0> ; Double Mora = <NUM_LIT:0.0> ; Double TotalMora = <NUM_LIT:0.0> ; for ( Venta oCuota : arrNroCuota ) { for ( Venta oCuota2 : arrCrono ) { if ( oCuota2 . getNroCuota ( ) == oCuota . getNroCuota ( ) && oCuota2 . getEstadoCuota ( ) . equals ( "<STR_LIT>" ) ) { Mora = <NUM_LIT:0.0> ; n = n + <NUM_LIT:1> ; long difDias = difDiasEntre2fechas ( oCuota2 . getFechaVencimientoCronograma ( ) , FechaActual ) ; if ( difDias > <NUM_LIT:0> ) { Mora = difDias * <NUM_LIT> * oCuota2 . getMontoCronograma ( ) ; } System . out . println ( "<STR_LIT:-->" + n + "<STR_LIT>" + oCuota2 . getNroCuota ( ) + "<STR_LIT:U+0020>" + oCurso . getNomCurso ( ) + "<STR_LIT>" + oCuota2 . getMontoCronograma ( ) + "<STR_LIT>" + fechaToString ( oCuota2 . getFechaVencimientoCronograma ( ) ) + "<STR_LIT>" + Mora ) ; fecha = fechaToString ( oCuota2 . getFechaVencimientoCronograma ( ) ) ; TotalMora = TotalMora + Mora ; MontoTotal = MontoTotal + oCuota2 . getMontoCronograma ( ) ; } } } System . out . println ( "<STR_LIT:-->" ) ; Double Igv = <NUM_LIT:0.0> ; if ( tipoComprobante . equalsIgnoreCase ( "<STR_LIT:2>" ) ) { Igv = ( <NUM_LIT> ) * MontoTotal ; System . out . println ( "<STR_LIT>" + MontoTotal ) ; System . out . println ( "<STR_LIT>" + Igv ) ; } Double ImporteTotal = ( Igv + MontoTotal + TotalMora ) ; System . out . println ( "<STR_LIT>" + ImporteTotal ) ; System . out . println ( "<STR_LIT>" ) ; objVenta . setNumero ( nroMovimiento ) ; objVenta . setCodTipoDocumento ( tipoComprobante ) ; objVenta . setCodCurso ( oCurso . getCodCurso ( ) ) ; objVenta . setNomCurso ( oCurso . getNomCurso ( ) ) ; objVenta . setCodCliente ( CodCliente ) ; objVenta . setNomCliente ( objCliente . getNomCliente ( ) ) ; objVenta . setNroRucCliente ( RUC ) ; objVenta . setConcepto ( oCurso . getNomCurso ( ) ) ; objVenta . setFecEmision ( fechaToString ( FechaActual ) ) ; objVenta . setMonSubtot ( MontoTotal ) ; objVenta . setMonIGV ( Igv ) ; objVenta . setMonTotal ( ImporteTotal ) ; objVenta . setMoneda ( oCuenta . getMoneda ( ) ) ; objVenta . setFecVencim ( fecha ) ; objVenta . setEstado ( "<STR_LIT:A>" ) ; objVenta . setFecPago ( fechaToString ( FechaActual ) ) ; objVenta . setObservacion ( "<STR_LIT>" ) ; arrVenta . add ( objVenta ) ; return true ; } public Cliente getClienteByCodigo ( String CodCliente ) { DataBD bd = new DataBD ( ) ; List < Cliente > arrCli = new ArrayList < Cliente > ( ) ; arrCli = bd . getDataCliente ( ) ; for ( Cliente cli : arrCli ) { if ( cli . getCodCliente ( ) . equals ( CodCliente ) ) { return cli ; } } new ProcessException ( "<STR_LIT>" + CodCliente + "<STR_LIT>" ) . printStackTrace ( ) ; return null ; } public Boolean validaciones ( String CodCliente , String CodCuenta ) { Boolean res = true ; Cliente objCliente = new Cliente ( ) ; objCliente = getClienteByCodigo ( CodCliente ) ; if ( objCliente == null ) { res = false ; } Venta oVenCuenta = new Venta ( ) ; oVenCuenta = oVenCuenta . getCuentaByCodigo ( CodCuenta ) ; if ( oVenCuenta == null ) { res = false ; } Venta oVenCronograma = new Venta ( ) ; List < Venta > arrCrono = new ArrayList < Venta > ( ) ; arrCrono = oVenCronograma . getCronogramaByCodigoCuenta ( CodCuenta ) ; if ( arrCrono == null ) { res = false ; } return res ; } String fechaToString ( Date pFecha ) { String Fecha = "<STR_LIT>" ; SimpleDateFormat Forma = new SimpleDateFormat ( "<STR_LIT>" ) ; Fecha = Forma . format ( pFecha ) ; return Fecha ; } public long difDiasEntre2fechas ( Date pFecha1 , Date pFecha2 ) { String Fecha1 = fechaToString ( pFecha1 ) ; String Fecha2 = fechaToString ( pFecha2 ) ; String [ ] parts ; int val = <NUM_LIT:0> ; parts = Fecha1 . split ( "<STR_LIT:/>" ) ; if ( parts . length == <NUM_LIT:3> ) { val = Integer . parseInt ( parts [ <NUM_LIT:2> ] + parts [ <NUM_LIT:1> ] + parts [ <NUM_LIT:0> ] ) ; } String [ ] parts2 ; int val2 = <NUM_LIT:0> ; parts2 = Fecha2 . split ( "<STR_LIT:/>" ) ; if ( parts . length == <NUM_LIT:3> ) { val = Integer . parseInt ( parts2 [ <NUM_LIT:2> ] + parts2 [ <NUM_LIT:1> ] + parts2 [ <NUM_LIT:0> ] ) ; } int D1 = Integer . parseInt ( parts [ <NUM_LIT:0> ] ) ; int M1 = Integer . parseInt ( parts [ <NUM_LIT:1> ] ) ; int Y1 = Integer . parseInt ( parts [ <NUM_LIT:2> ] ) ; int D2 = Integer . parseInt ( parts2 [ <NUM_LIT:0> ] ) ; int M2 = Integer . parseInt ( parts2 [ <NUM_LIT:1> ] ) ; int Y2 = Integer . parseInt ( parts2 [ <NUM_LIT:2> ] ) ; java . util . GregorianCalendar date = new java . util . GregorianCalendar ( Y1 , M1 , D1 ) ; java . util . GregorianCalendar date2 = new java . util . GregorianCalendar ( Y2 , M2 , D2 ) ; long difms = date2 . getTimeInMillis ( ) - date . getTimeInMillis ( ) ; long difd = difms / ( <NUM_LIT:1000> * <NUM_LIT> * <NUM_LIT> * <NUM_LIT:24> ) ; return difd ; } } </s>
|
<s> package benedictoxvi . pe . business ; import java . util . ArrayList ; import java . util . Collections ; import java . util . Comparator ; import benedictoxvi . pe . data . Compra ; import benedictoxvi . pe . datatest . DataBD ; import benedictoxvi . pe . util . CompraComparator ; import benedictoxvi . pe . util . FormatException ; import benedictoxvi . pe . util . ProcessException ; import benedictoxvi . pe . util . Validaciones ; public class AdmCompra { Validaciones objVal = new Validaciones ( ) ; ArrayList < Compra > arrCom ; DataBD bd = new DataBD ( ) ; public AdmCompra ( ) { arrCom = bd . getDataCompras ( ) ; } public int listaCompras ( ) { int i = <NUM_LIT:0> ; i = arrCom . size ( ) ; if ( i == <NUM_LIT:0> ) return i ; i = <NUM_LIT:0> ; objVal . printMsg ( "<STR_LIT>" ) ; for ( Compra objCom : arrCom ) { i += <NUM_LIT:1> ; System . out . println ( i + "<STR_LIT>" + objCom . getConcepto ( ) + "<STR_LIT:t>" + objCom . getNumero ( ) + "<STR_LIT:t>" + objCom . getFecEmision ( ) + "<STR_LIT:t>" + objCom . getNomEmpresa ( ) + "<STR_LIT:t>" + objCom . getMonSubtot ( ) + "<STR_LIT:t>" + objCom . getMonIGV ( ) + "<STR_LIT:t>" + objCom . getMonTotal ( ) + "<STR_LIT:t>" + objCom . getMoneda ( ) + "<STR_LIT:t>" + objCom . getFecVencim ( ) + "<STR_LIT:t>" + objCom . getEstado ( ) + "<STR_LIT:t>" + objCom . getFecPago ( ) + "<STR_LIT:t>" + objCom . getObservacion ( ) ) ; } System . out . println ( ) ; return i ; } public Compra getCompraByNum ( int num ) { for ( Compra objCom : arrCom ) { if ( objCom . getNumero ( ) == num ) { return objCom ; } } new ProcessException ( "<STR_LIT>" + num + "<STR_LIT>" ) . printStackTrace ( ) ; return null ; } public boolean findCompraByNum ( int num ) { return ( ( getCompraByNum ( num ) == null ) ? false : true ) ; } public boolean darAltaCompra ( String concepto , int numero , String fecEmision , String nomEmpresa , Double subtot , Double monIGV , Double monTot , String moneda , String fecVencim , String estado , String fecPagoReal , String observ ) { if ( findCompraByNum ( numero ) ) { new ProcessException ( "<STR_LIT>" ) . printStackTrace ( ) ; return false ; } String msg_err = "<STR_LIT>" ; if ( ! objVal . isSet ( concepto ) ) { msg_err = "<STR_LIT>" ; } else if ( ! objVal . isSet ( fecEmision ) ) { msg_err = "<STR_LIT>" ; } else if ( ! objVal . isDate ( fecEmision ) ) { msg_err = "<STR_LIT>" ; } else if ( ! objVal . isSet ( fecVencim ) ) { msg_err = "<STR_LIT>" ; } else if ( ! objVal . isDate ( fecVencim ) ) { msg_err = "<STR_LIT>" ; } else if ( objVal . isSet ( fecPagoReal ) && ! objVal . isDate ( fecPagoReal ) ) { msg_err = "<STR_LIT>" ; } else if ( subtot <= <NUM_LIT:0> ) { msg_err = "<STR_LIT>" ; } else if ( monIGV <= <NUM_LIT:0> ) { msg_err = "<STR_LIT>" ; } else if ( monIGV >= subtot ) { msg_err = "<STR_LIT>" + subtot ; } else if ( monTot <= <NUM_LIT:0> ) { msg_err = "<STR_LIT>" ; } else if ( objVal . isSet ( new String [ ] { fecEmision , fecPagoReal } ) ) { if ( objVal . dateToInt ( fecEmision ) > objVal . dateToInt ( fecPagoReal ) ) { msg_err = "<STR_LIT>" ; } } else if ( objVal . isSet ( new String [ ] { fecEmision , fecVencim } ) ) { if ( objVal . dateToInt ( fecEmision ) > objVal . dateToInt ( fecVencim ) ) { msg_err = "<STR_LIT>" ; } } if ( objVal . isSet ( msg_err ) ) { new FormatException ( msg_err ) . printStackTrace ( ) ; return false ; } Compra objCom = new Compra ( ) ; objCom . setConcepto ( concepto ) ; objCom . setNumero ( numero ) ; objCom . setFecEmision ( fecEmision ) ; objCom . setNomEmpresa ( nomEmpresa ) ; objCom . setEstado ( estado ) ; objCom . setFecPago ( fecPagoReal ) ; objCom . setFecVencim ( fecVencim ) ; objCom . setMonSubtot ( subtot ) ; objCom . setMonIGV ( monIGV ) ; objCom . setMonTotal ( monTot ) ; objCom . setObservacion ( observ ) ; objVal . messageOk ( "<STR_LIT>" + numero ) ; arrCom . add ( objCom ) ; return true ; } public ArrayList < Compra > encontrarCompras ( String concepto , int numero , String fec_emision , String nom_empresa , String fec_venc , String fec_pago , String estado ) { ArrayList < Compra > filCom = new ArrayList < Compra > ( ) ; boolean comparar = false ; for ( Compra objCom : arrCom ) { comparar = objCom . getConcepto ( ) . contains ( concepto ) && objCom . getFecEmision ( ) . contains ( fec_emision ) && objCom . getNomEmpresa ( ) . contains ( nom_empresa ) && objCom . getFecVencim ( ) . contains ( fec_venc ) && objCom . getFecPago ( ) . contains ( fec_pago ) && objCom . getEstado ( ) . contains ( estado ) ; if ( numero != <NUM_LIT:0> ) { if ( objCom . getNumero ( ) == numero && comparar ) { filCom . add ( objCom ) ; } } else if ( comparar ) { filCom . add ( objCom ) ; } } if ( filCom . size ( ) == <NUM_LIT:0> ) { new ProcessException ( "<STR_LIT>" ) . printStackTrace ( ) ; } else { Collections . sort ( filCom , new CompraComparator ( ) ) ; objVal . messageOk ( "<STR_LIT>" + filCom . size ( ) + "<STR_LIT>" ) ; } return filCom ; } public boolean pagarCompra ( int num_com ) { Compra objcom = getCompraByNum ( num_com ) ; if ( objcom != null ) { if ( objcom . isCancelada ( ) ) { new ProcessException ( "<STR_LIT>" + num_com + "<STR_LIT>" ) . printStackTrace ( ) ; return false ; } else if ( objcom . isAnulada ( ) ) { new ProcessException ( "<STR_LIT>" + num_com + "<STR_LIT>" ) . printStackTrace ( ) ; return false ; } objcom . pagar ( ) ; } else { return false ; } objVal . messageOk ( "<STR_LIT>" + num_com ) ; return true ; } public boolean anularCompra ( int num_com ) { Compra objcom = getCompraByNum ( num_com ) ; if ( objcom != null ) { if ( objcom . isCancelada ( ) ) { new ProcessException ( "<STR_LIT>" + num_com + "<STR_LIT>" ) . printStackTrace ( ) ; return false ; } else if ( objcom . isAnulada ( ) ) { new ProcessException ( "<STR_LIT>" + num_com + "<STR_LIT>" ) . printStackTrace ( ) ; return false ; } objcom . anular ( ) ; } else { return false ; } objVal . messageOk ( "<STR_LIT>" + num_com ) ; return true ; } } </s>
|
<s> package benedictoxvi . pe . business ; import java . util . ArrayList ; import benedictoxvi . pe . data . Prospecto ; import benedictoxvi . pe . datatest . DataBD ; import benedictoxvi . pe . util . FormatException ; import benedictoxvi . pe . util . ProcessException ; import benedictoxvi . pe . util . Validaciones ; public class AdmProspecto { Validaciones objVal = new Validaciones ( ) ; ArrayList < Prospecto > arrPro = new ArrayList < Prospecto > ( ) ; DataBD bd = new DataBD ( ) ; public ArrayList < Prospecto > getArrPro ( ) { return arrPro ; } public void setArrPro ( ArrayList < Prospecto > arrPro ) { this . arrPro = arrPro ; } public AdmProspecto ( ) { arrPro = bd . getDataProspecto ( ) ; } public int listaProspectos ( ) { int i = arrPro . size ( ) ; if ( i == <NUM_LIT:0> ) return <NUM_LIT:0> ; i = <NUM_LIT:0> ; for ( Prospecto objPro : arrPro ) { i += <NUM_LIT:1> ; System . out . println ( i + "<STR_LIT>" + objPro . getNumProspecto ( ) + "<STR_LIT:t>" + objPro . getFecProspecto ( ) + "<STR_LIT:t>" + objPro . getNombes ( ) + "<STR_LIT:t>" + objPro . getApePaterno ( ) + "<STR_LIT:t>" + objPro . getApeMaterno ( ) + "<STR_LIT:t>" + objPro . getCorreo ( ) + "<STR_LIT:t>" + objPro . getTelefono ( ) + "<STR_LIT:t>" + objPro . getCelular ( ) + "<STR_LIT:t>" + objPro . getNroDNI ( ) + "<STR_LIT:t>" + objPro . getEstado ( ) ) ; } return i ; } public ArrayList < Prospecto > findProspecto ( String nombs , String apepat , String apemat , String mail , String dni , String tel_cel , String fecha , String estado ) { ArrayList < Prospecto > filtro = new ArrayList < Prospecto > ( ) ; for ( Prospecto objPro : arrPro ) { if ( objPro . getNombes ( ) . contains ( nombs ) && objPro . getApePaterno ( ) . contains ( apepat ) && objPro . getApeMaterno ( ) . contains ( apemat ) && objPro . getCorreo ( ) . contains ( mail ) && objPro . getNroDNI ( ) . contains ( dni ) && ( objPro . getTelefono ( ) . contains ( tel_cel ) || objPro . getCelular ( ) . contains ( tel_cel ) ) && objPro . getFecProspecto ( ) . contains ( fecha ) && objPro . getEstado ( ) . contains ( estado ) ) { filtro . add ( objPro ) ; } } if ( filtro . size ( ) == <NUM_LIT:0> ) { new ProcessException ( "<STR_LIT>" ) . printStackTrace ( ) ; } else { objVal . messageOk ( "<STR_LIT>" + filtro . size ( ) + "<STR_LIT>" ) ; } return filtro ; } public boolean registrarProspecto ( int num_pro , String fecha , String nombs , String apepat , String apemat , String mail , String dni , String telefono , String celular , String estado ) { Prospecto objPro = new Prospecto ( ) ; String msg_err = "<STR_LIT>" ; if ( ! objVal . isSet ( nombs ) ) msg_err = "<STR_LIT>" ; else if ( ! objVal . isSet ( apepat ) ) msg_err = "<STR_LIT>" ; else if ( ! objVal . isSet ( mail ) ) { msg_err = "<STR_LIT>" ; } else if ( ! objVal . isEmail ( mail ) ) { msg_err = "<STR_LIT>" ; } else if ( ! objVal . isDate ( fecha ) ) { msg_err = "<STR_LIT>" ; } else if ( objVal . isSet ( dni ) && ! objVal . isDNI ( dni ) ) { msg_err = "<STR_LIT>" ; } else if ( objVal . isSet ( telefono ) && ! objVal . isDigits ( telefono ) ) { msg_err = "<STR_LIT>" ; } else if ( objVal . isSet ( celular ) && ! objVal . isDigits ( celular ) ) { msg_err = "<STR_LIT>" ; } if ( objVal . isSet ( msg_err ) ) { new FormatException ( msg_err ) . printStackTrace ( ) ; return false ; } objPro . setNumProspecto ( num_pro ) ; objPro . setFecProspecto ( fecha ) ; objPro . setNombes ( nombs ) ; objPro . setApePaterno ( apepat ) ; objPro . setApeMaterno ( apemat ) ; objPro . setCorreo ( mail ) ; objPro . setNroDNI ( dni ) ; objPro . setTelefono ( telefono ) ; objPro . setCelular ( celular ) ; objPro . setEstado ( estado ) ; arrPro . add ( objPro ) ; objVal . messageOk ( "<STR_LIT>" + num_pro ) ; return true ; } public Prospecto getProspectoByNum ( int num_pro ) { for ( Prospecto xpro : arrPro ) { if ( xpro . getNumProspecto ( ) == num_pro ) { return xpro ; } } new ProcessException ( "<STR_LIT>" + num_pro + "<STR_LIT>" ) . printStackTrace ( ) ; return null ; } public boolean deProspectoToCliente ( int num_pro ) { boolean res = modifcarProspecto ( num_pro , null , null , null , null , null , null , null , null , "<STR_LIT:C>" ) ; if ( res ) { objVal . messageOk ( "<STR_LIT>" + num_pro ) ; } return res ; } public boolean deClientetoProspecto ( int num_pro ) { boolean res = modifcarProspecto ( num_pro , null , null , null , null , null , null , null , null , "<STR_LIT:U+0020>" ) ; if ( res ) { objVal . messageOk ( "<STR_LIT>" + num_pro ) ; } return res ; } public boolean eliminarProspecto ( int i ) { for ( Prospecto objPro : arrPro ) { if ( objPro . getNumProspecto ( ) == ( i ) ) { objVal . messageOk ( "<STR_LIT>" + i ) ; return arrPro . remove ( objPro ) ; } } return false ; } public boolean modifcarProspecto ( int num_pro , String fecha , String nombs , String apepat , String apemat , String mail , String dni , String telefono , String celular , String estado ) { boolean ret = false ; boolean cambio = false ; for ( int x = <NUM_LIT:0> ; x < arrPro . size ( ) ; x ++ ) { Prospecto objPro = arrPro . get ( x ) ; if ( objPro . getNumProspecto ( ) == num_pro ) { if ( fecha != null ) { objPro . setFecProspecto ( fecha ) ; cambio = true ; } if ( nombs != null ) { objPro . setNombes ( nombs ) ; cambio = true ; } if ( apepat != null ) { objPro . setApePaterno ( apepat ) ; cambio = true ; } if ( apemat != null ) { objPro . setApeMaterno ( apemat ) ; cambio = true ; } if ( mail != null ) { objPro . setCorreo ( mail ) ; cambio = true ; } if ( dni != null ) { objPro . setNroDNI ( dni ) ; cambio = true ; } if ( telefono != null ) { objPro . setTelefono ( telefono ) ; cambio = true ; } if ( celular != null ) { objPro . setCelular ( celular ) ; cambio = true ; } if ( estado != null ) { if ( estado . equalsIgnoreCase ( "<STR_LIT:C>" ) && objPro . getEstado ( ) . trim ( ) . isEmpty ( ) ) { if ( findProspecto ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , objPro . getNroDNI ( ) , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:C>" ) . size ( ) > <NUM_LIT:0> ) { new ProcessException ( "<STR_LIT>" + objPro . getNroDNI ( ) + "<STR_LIT>" ) . printStackTrace ( ) ; return false ; } } else if ( estado . equalsIgnoreCase ( "<STR_LIT:C>" ) && objPro . getEstado ( ) . equalsIgnoreCase ( "<STR_LIT:C>" ) ) { new ProcessException ( "<STR_LIT>" + num_pro + "<STR_LIT>" ) . printStackTrace ( ) ; return false ; } objPro . setEstado ( estado ) ; cambio = true ; } if ( cambio ) { arrPro . set ( x , objPro ) ; if ( estado == null ) { objVal . messageOk ( "<STR_LIT>" + num_pro ) ; } } ret = true ; return ret ; } } new ProcessException ( "<STR_LIT>" + num_pro + "<STR_LIT:'>" ) ; return ret ; } } </s>
|
<s> package benedictoxvi . pe . business ; import java . util . ArrayList ; import benedictoxvi . pe . businesstest . AdmClienteTest ; import benedictoxvi . pe . data . Cliente ; import benedictoxvi . pe . data . GrupoEstudio ; import benedictoxvi . pe . datatest . DataBD ; import benedictoxvi . pe . util . ProcessException ; import benedictoxvi . pe . util . Validaciones ; public class AdmGrupoEstudio { ArrayList < GrupoEstudio > arrGrupos = new ArrayList < GrupoEstudio > ( ) ; AdmCliente admCli = new AdmCliente ( ) ; Validaciones objVal = new Validaciones ( ) ; DataBD bd = new DataBD ( ) ; public AdmGrupoEstudio ( ) { arrGrupos = bd . getDataGrupoEstudio ( ) ; } public ArrayList < GrupoEstudio > getArrGrupos ( ) { return arrGrupos ; } public int listarGruposEstudio ( ) { if ( this . getArrGrupos ( ) . size ( ) == <NUM_LIT:0> ) return <NUM_LIT:0> ; int i = <NUM_LIT:0> ; for ( GrupoEstudio objGru : getArrGrupos ( ) ) { i += <NUM_LIT:1> ; System . out . println ( i + "<STR_LIT>" + objGru . getNomGrupo ( ) + "<STR_LIT:t>" + objGru . getDescripcion ( ) + "<STR_LIT:t>" + objGru . getNomAcademia ( ) + "<STR_LIT:t>" + objGru . getFecInicio ( ) + "<STR_LIT:t>" + objGru . getFecFin ( ) + "<STR_LIT:t>" + objGru . getInstructorStr ( ) + "<STR_LIT:t>" + "<STR_LIT:t>" + objGru . getLocal ( ) + "<STR_LIT:t>" + objGru . getAula ( ) + "<STR_LIT:t>" + objGru . getCAltitud ( ) + "<STR_LIT:t>" + objGru . getCLatitud ( ) ) ; } return i ; } public void setArrGrupos ( ArrayList < GrupoEstudio > arrGrupos ) { this . arrGrupos = arrGrupos ; } public boolean registraGrupoEstudio ( String cod_grupo , String nom_grupo , String descripcion , String nom_academia , String nom_curso , String fec_inicio , String fec_final , String [ ] instructores , String link , String local , int aula , double latitud , double altitud ) { String msg_err = null ; if ( ! objVal . isSet ( cod_grupo ) ) { msg_err = "<STR_LIT>" ; } else if ( ! objVal . isSet ( nom_grupo ) ) { msg_err = "<STR_LIT>" ; } else if ( ! objVal . isSet ( fec_inicio ) ) { msg_err = "<STR_LIT>" ; } else if ( ! objVal . isDate ( fec_inicio ) ) { msg_err = "<STR_LIT>" ; } else if ( ! objVal . isSet ( fec_final ) ) { msg_err = "<STR_LIT>" ; } else if ( ! objVal . isDate ( fec_final ) ) { msg_err = "<STR_LIT>" ; } else if ( objVal . dateToInt ( fec_final ) < objVal . dateToInt ( fec_inicio ) ) { msg_err = "<STR_LIT>" ; } if ( objVal . isSet ( msg_err ) ) { new ProcessException ( msg_err ) . printStackTrace ( ) ; return false ; } GrupoEstudio objGru = new GrupoEstudio ( ) ; objGru . setCodGrupo ( cod_grupo ) ; objGru . setNomGrupo ( nom_grupo ) ; objGru . setDescripcion ( descripcion ) ; objGru . setNomAcademia ( nom_academia ) ; objGru . setFecInicio ( fec_inicio ) ; objGru . setFecFin ( fec_final ) ; objGru . setInstructor ( instructores ) ; objGru . setLinkSylabus ( link ) ; objGru . setLocal ( local ) ; objGru . setAula ( aula ) ; objGru . setEstado ( "<STR_LIT>" ) ; objGru . setCLatitud ( latitud ) ; objGru . setCAltitud ( altitud ) ; arrGrupos . add ( objGru ) ; objVal . messageOk ( "<STR_LIT>" + cod_grupo ) ; return true ; } public ArrayList < GrupoEstudio > encontrarGrupoEstudio ( String nom_grupo , String nom_acade , String curso , String fec_ini , String fec_fin , String estado ) { ArrayList < GrupoEstudio > filGru = new ArrayList < GrupoEstudio > ( ) ; for ( GrupoEstudio objGru : getArrGrupos ( ) ) { if ( objGru . getNomGrupo ( ) . contains ( nom_grupo ) && objGru . getNomAcademia ( ) . contains ( nom_acade ) && objGru . getNomCurso ( ) . contains ( curso ) && objGru . getFecInicio ( ) . contains ( fec_ini ) && objGru . getFecFin ( ) . contains ( fec_fin ) && objGru . getEstado ( ) . contains ( estado ) ) { filGru . add ( objGru ) ; } } return filGru ; } public GrupoEstudio getGrupoById ( String cod_grupo ) { for ( GrupoEstudio objGru : getArrGrupos ( ) ) { if ( objGru . getCodGrupo ( ) . equals ( cod_grupo ) ) { return objGru ; } } new ProcessException ( "<STR_LIT>" + cod_grupo + "<STR_LIT>" ) . printStackTrace ( ) ; return null ; } public boolean addAlumnoGrupoEstudio ( String codGrupo , String codCliente ) { GrupoEstudio add_grupo = getGrupoById ( codGrupo ) ; if ( add_grupo == null ) { return false ; } if ( add_grupo . getAforo ( ) == add_grupo . getNumAlumnos ( ) ) { new ProcessException ( "<STR_LIT>" + codGrupo + "<STR_LIT>" + add_grupo . getNomGrupo ( ) + "<STR_LIT>" ) . printStackTrace ( ) ; return false ; } if ( add_grupo . existsCliente ( codCliente ) ) { new ProcessException ( "<STR_LIT>" + codCliente + "<STR_LIT>" + codGrupo + "<STR_LIT>" + add_grupo . getNomGrupo ( ) ) . printStackTrace ( ) ; return false ; } Cliente add_cli = admCli . getClienteByCod ( codCliente ) ; if ( add_cli != null ) { add_grupo . getInscritos ( ) . add ( add_cli ) ; objVal . messageOk ( "<STR_LIT>" + codCliente + "<STR_LIT>" + codGrupo ) ; return true ; } return false ; } public boolean verificarAlumnoEnGrupo ( String cod_grupo , String cod_cli ) { GrupoEstudio grupo = getGrupoById ( cod_grupo ) ; if ( grupo != null ) { if ( ! grupo . existsCliente ( cod_cli ) ) { new ProcessException ( "<STR_LIT>" + cod_cli + "<STR_LIT>" + cod_grupo + "<STR_LIT>" ) . printStackTrace ( ) ; return false ; } for ( Cliente objCli : grupo . getInscritos ( ) ) { if ( objCli . getCodCliente ( ) . equals ( cod_cli ) ) { objVal . messageOk ( "<STR_LIT>" + cod_cli + "<STR_LIT>" + cod_grupo + "<STR_LIT>" ) ; return true ; } } } return false ; } } </s>
|
<s> package benedictoxvi . pe . business ; import java . util . ArrayList ; import benedictoxvi . pe . data . Cliente ; import benedictoxvi . pe . datatest . DataBD ; import benedictoxvi . pe . util . FormatException ; import benedictoxvi . pe . util . ProcessException ; import benedictoxvi . pe . util . Validaciones ; public class AdmCliente { ArrayList < Cliente > arrCli = new ArrayList < Cliente > ( ) ; Validaciones objVal = new Validaciones ( ) ; DataBD bd = new DataBD ( ) ; public AdmCliente ( ) { arrCli = bd . getDataCliente ( ) ; } public Cliente getClienteByCod ( String numCli ) { for ( Cliente cli : arrCli ) { if ( cli . getCodCliente ( ) . equals ( numCli ) ) { return cli ; } } new ProcessException ( "<STR_LIT>" + numCli + "<STR_LIT>" ) . printStackTrace ( ) ; return null ; } public Cliente getClienteByNum ( String numCli ) { for ( Cliente cli : arrCli ) { if ( cli . getCodCliente ( ) . equals ( numCli ) ) { return cli ; } } new ProcessException ( "<STR_LIT>" + numCli + "<STR_LIT>" ) . printStackTrace ( ) ; return null ; } public ArrayList < Cliente > findCliente ( String nombs , String apepat , String apemat , String mail , String dni , String tel_cel , String fecha , String estado ) { ArrayList < Cliente > filtro = new ArrayList < Cliente > ( ) ; try { for ( Cliente objCli : arrCli ) { if ( objCli . getNomCliente ( ) . contains ( nombs ) && objCli . getApePatCliente ( ) . contains ( apepat ) && objCli . getApeMatCliente ( ) . contains ( apemat ) && objCli . getEmaCliente ( ) . contains ( mail ) && objCli . getDniCliente ( ) . contains ( dni ) && objCli . getFonCliente ( ) . contains ( tel_cel ) && objCli . getFecConCliente ( ) . contains ( fecha ) && objCli . getEstCliente ( ) . contains ( estado ) ) { filtro . add ( objCli ) ; } } if ( filtro . size ( ) == <NUM_LIT:0> ) { new ProcessException ( "<STR_LIT>" ) . printStackTrace ( ) ; } else { objVal . messageOk ( "<STR_LIT>" + filtro . size ( ) + "<STR_LIT>" ) ; } } catch ( Exception ex ) { ex . printStackTrace ( ) ; } return filtro ; } public boolean modifcarCliente ( String cod_cli , String fecha , String nombs , String apepat , String apemat , String mail , String dni , String telefono , String celular , String estado ) { boolean ret = false ; boolean cambio = false ; for ( int x = <NUM_LIT:0> ; x < arrCli . size ( ) ; x ++ ) { Cliente objCli = arrCli . get ( x ) ; if ( objCli . getCodCliente ( ) . equals ( cod_cli ) ) { if ( fecha != null ) { objCli . setFecConCliente ( fecha ) ; cambio = true ; } if ( nombs != null ) { objCli . setNomCliente ( nombs ) ; cambio = true ; } if ( apepat != null ) { objCli . setApePatCliente ( apepat ) ; cambio = true ; } if ( apemat != null ) { objCli . setApeMatCliente ( apemat ) ; cambio = true ; } if ( mail != null ) { objCli . setEmaCliente ( mail ) ; cambio = true ; } if ( dni != null ) { objCli . setDniCliente ( dni ) ; cambio = true ; } if ( telefono != null ) { objCli . setFonCliente ( telefono ) ; cambio = true ; } if ( estado != null ) { if ( estado . equalsIgnoreCase ( "<STR_LIT:C>" ) && objCli . getEstCliente ( ) . trim ( ) . isEmpty ( ) ) { if ( findCliente ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , objCli . getDniCliente ( ) , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:C>" ) . size ( ) > <NUM_LIT:0> ) { new ProcessException ( "<STR_LIT>" + objCli . getDniCliente ( ) + "<STR_LIT>" ) . printStackTrace ( ) ; return false ; } } else if ( estado . equalsIgnoreCase ( "<STR_LIT:C>" ) && objCli . getEstCliente ( ) . equalsIgnoreCase ( "<STR_LIT:C>" ) ) { new ProcessException ( "<STR_LIT>" + cod_cli + "<STR_LIT>" ) . printStackTrace ( ) ; return false ; } objCli . setEstCliente ( estado ) ; cambio = true ; } if ( cambio ) { arrCli . set ( x , objCli ) ; if ( estado == null ) { objVal . messageOk ( "<STR_LIT>" + cod_cli ) ; } } ret = true ; return ret ; } } new ProcessException ( "<STR_LIT>" + cod_cli + "<STR_LIT:'>" ) ; return ret ; } public boolean deClienteToProspecto ( String cod_cli ) { boolean res = modifcarCliente ( cod_cli , null , null , null , null , null , null , null , null , "<STR_LIT:C>" ) ; if ( res ) { objVal . messageOk ( "<STR_LIT>" + cod_cli ) ; } return res ; } public boolean registrarCliente ( String cod_cli , String fecha , String nombs , String apepat , String apemat , String mail , String dni , String telefono , String celular , String estado ) { Cliente objCli = new Cliente ( ) ; String msg_err = "<STR_LIT>" ; if ( ! objVal . isSet ( nombs ) ) msg_err = "<STR_LIT>" ; else if ( ! objVal . isSet ( apepat ) ) msg_err = "<STR_LIT>" ; else if ( ! objVal . isSet ( mail ) ) { msg_err = "<STR_LIT>" ; } else if ( ! objVal . isEmail ( mail ) ) { msg_err = "<STR_LIT>" ; } else if ( ! objVal . isDate ( fecha ) ) { msg_err = "<STR_LIT>" ; } else if ( objVal . isSet ( dni ) && ! objVal . isDNI ( dni ) ) { msg_err = "<STR_LIT>" ; } else if ( objVal . isSet ( telefono ) && ! objVal . isDigits ( telefono ) ) { msg_err = "<STR_LIT>" ; } else if ( objVal . isSet ( celular ) && ! objVal . isDigits ( celular ) ) { msg_err = "<STR_LIT>" ; } if ( objVal . isSet ( msg_err ) ) { new FormatException ( msg_err ) . printStackTrace ( ) ; return false ; } objCli . setCodCliente ( cod_cli ) ; objCli . setFecConCliente ( fecha ) ; objCli . setNomCliente ( nombs ) ; objCli . setApePatCliente ( apepat ) ; objCli . setApeMatCliente ( apemat ) ; objCli . setEmaCliente ( mail ) ; objCli . setDniCliente ( dni ) ; objCli . setFonCliente ( telefono ) ; objCli . setEstCliente ( estado ) ; arrCli . add ( objCli ) ; objVal . messageOk ( "<STR_LIT>" + cod_cli ) ; return true ; } public boolean eliminarCliente ( String cod_cli ) { for ( Cliente objCli : arrCli ) { if ( objCli . getCodCliente ( ) . equals ( cod_cli ) ) { objVal . messageOk ( "<STR_LIT>" + cod_cli ) ; return arrCli . remove ( objCli ) ; } } return false ; } } </s>
|
<s> package benedictoxvi . pe . util ; import java . text . SimpleDateFormat ; import java . util . Date ; import java . util . regex . Matcher ; import java . util . regex . Pattern ; public class Validaciones { public void printMsg ( String msg , String prev ) { StackTraceElement [ ] trace = ( StackTraceElement [ ] ) Thread . currentThread ( ) . getStackTrace ( ) ; String method1 = trace [ <NUM_LIT:4> ] . getMethodName ( ) ; String method2 = trace [ <NUM_LIT:3> ] . getMethodName ( ) ; System . out . println ( "<STR_LIT>" + prev + method2 + "<STR_LIT:[>" + method1 + "<STR_LIT:]>" + "<STR_LIT:U+0020:U+0020>" + msg ) ; } public void messageOk ( String msg ) { StackTraceElement [ ] trace = ( StackTraceElement [ ] ) Thread . currentThread ( ) . getStackTrace ( ) ; String method1 = trace [ <NUM_LIT:2> ] . getMethodName ( ) ; String method2 = trace [ <NUM_LIT:3> ] . getMethodName ( ) ; System . out . println ( "<STR_LIT>" + method2 + "<STR_LIT:[>" + method1 + "<STR_LIT:]>" + "<STR_LIT:U+0020:U+0020>" + msg ) ; } public void messageWar ( String msg ) { StackTraceElement [ ] trace = ( StackTraceElement [ ] ) Thread . currentThread ( ) . getStackTrace ( ) ; String method1 = trace [ <NUM_LIT:2> ] . getMethodName ( ) ; String method2 = trace [ <NUM_LIT:3> ] . getMethodName ( ) ; System . out . println ( "<STR_LIT>" + method2 + "<STR_LIT:[>" + method1 + "<STR_LIT:]>" + "<STR_LIT:U+0020:U+0020>" + msg ) ; } public void printMsg ( String msg ) { printMsg ( "<STR_LIT:U+0020U+0020>" + msg , "<STR_LIT>" ) ; } public boolean isSet ( String cad ) { boolean ret = true ; if ( cad == null ) { return false ; } if ( cad . trim ( ) . isEmpty ( ) ) ret = false ; else ret = true ; return ret ; } public boolean isValidKey ( String key ) { if ( ! isSet ( key ) ) return false ; if ( key . trim ( ) . length ( ) < <NUM_LIT:8> ) { return false ; } return true ; } public boolean isSet ( String [ ] a_objs ) { boolean ret = true ; for ( String obj : a_objs ) { if ( ! isSet ( obj ) ) { ret = false ; break ; } } return ret ; } public boolean isDigits ( String digs ) { digs = digs . trim ( ) ; for ( char a : digs . toCharArray ( ) ) { if ( ! Character . isDigit ( a ) ) return false ; } return true ; } public boolean isDNI ( String dni ) { if ( ! isDigits ( dni ) ) return false ; if ( dni . trim ( ) . length ( ) == <NUM_LIT:8> ) { return true ; } else { return false ; } } public boolean isEmail ( String correo ) { Pattern pat = null ; Matcher mat = null ; pat = Pattern . compile ( "<STR_LIT>" ) ; mat = pat . matcher ( correo ) ; if ( mat . find ( ) ) { return true ; } else { return false ; } } public boolean isDate ( String date ) { try { String [ ] parts ; parts = date . split ( "<STR_LIT:/>" ) ; int year = Integer . parseInt ( parts [ <NUM_LIT:2> ] ) ; int mes = Integer . parseInt ( parts [ <NUM_LIT:1> ] ) ; int dia = Integer . parseInt ( parts [ <NUM_LIT:0> ] ) ; if ( ! ( dia >= <NUM_LIT:1> && dia <= <NUM_LIT:31> ) ) return false ; if ( ! ( mes >= <NUM_LIT:1> && mes <= <NUM_LIT:12> ) ) return false ; if ( ! ( year >= <NUM_LIT:1000> && year <= <NUM_LIT> ) ) return false ; SimpleDateFormat formatoFecha = new SimpleDateFormat ( "<STR_LIT>" ) ; Date fecha = formatoFecha . parse ( date ) ; } catch ( Exception e ) { return false ; } return true ; } public Date stringToDate ( String s_fecha ) { Date fecha = null ; try { SimpleDateFormat formatoFecha = new SimpleDateFormat ( "<STR_LIT>" ) ; fecha = formatoFecha . parse ( s_fecha ) ; } catch ( Exception e ) { fecha = null ; } return fecha ; } public static void main ( String [ ] args ) { System . out . println ( "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" ) ; } public int dateToInt ( String fecha ) { String [ ] parts ; int val = <NUM_LIT:0> ; if ( isDate ( fecha ) ) { parts = fecha . split ( "<STR_LIT:/>" ) ; if ( parts . length == <NUM_LIT:3> ) { val = Integer . parseInt ( parts [ <NUM_LIT:2> ] + parts [ <NUM_LIT:1> ] + parts [ <NUM_LIT:0> ] ) ; } else { new FormatException ( "<STR_LIT>" + fecha + "<STR_LIT>" ) . printStackTrace ( ) ; } } else { new FormatException ( "<STR_LIT>" + fecha + "<STR_LIT>" ) . printStackTrace ( ) ; } return val ; } public boolean isRUC ( String pRuc ) { if ( ! isDigits ( pRuc ) ) return false ; if ( pRuc . trim ( ) . length ( ) == <NUM_LIT:11> ) { return true ; } else { return false ; } } } </s>
|
<s> package benedictoxvi . pe . util ; import sun . misc . BASE64Decoder ; import sun . misc . BASE64Encoder ; public class Security { BASE64Encoder enc = new BASE64Encoder ( ) ; BASE64Decoder dec = new BASE64Decoder ( ) ; public final String DEFAULT_ENCODING = "<STR_LIT:UTF-8>" ; public String base64encode ( String text ) { try { String rez = enc . encode ( text . getBytes ( DEFAULT_ENCODING ) ) ; return rez ; } catch ( Exception e ) { return null ; } } public String base64decode ( String text ) { try { return new String ( dec . decodeBuffer ( text ) , DEFAULT_ENCODING ) ; } catch ( Exception e ) { return null ; } } } </s>
|
<s> package benedictoxvi . pe . util ; public class ProcessException extends Exception { private static final long serialVersionUID = <NUM_LIT> ; public ProcessException ( ) { super ( ) ; } public ProcessException ( String message , Throwable cause , boolean enableSuppression , boolean writableStackTrace ) { } public ProcessException ( String message , Throwable cause ) { super ( message , cause ) ; } public ProcessException ( String message ) { super ( message ) ; } public ProcessException ( Throwable cause ) { super ( cause ) ; } @ Override public void printStackTrace ( ) { String method1 = ( ( StackTraceElement ) this . getStackTrace ( ) [ <NUM_LIT:0> ] ) . getMethodName ( ) ; String method2 = ( ( StackTraceElement ) this . getStackTrace ( ) [ <NUM_LIT:1> ] ) . getMethodName ( ) ; System . err . println ( "<STR_LIT>" + method2 + "<STR_LIT:[>" + method1 + "<STR_LIT:]>" + "<STR_LIT:U+0020:U+0020>" + this . getMessage ( ) ) ; } public static void main ( String [ ] args ) { System . out . println ( ) ; } } </s>
|
<s> package benedictoxvi . pe . util ; public class UserComparator { } </s>
|
<s> package benedictoxvi . pe . util ; import java . util . Comparator ; import benedictoxvi . pe . data . Compra ; public class CompraComparator implements Comparator < Compra > { Validaciones objValidaciones = new Validaciones ( ) ; @ Override public int compare ( Compra o1 , Compra o2 ) { return ( - <NUM_LIT:1> * ( objValidaciones . dateToInt ( o1 . getFecVencim ( ) ) - objValidaciones . dateToInt ( o2 . getFecVencim ( ) ) ) ) ; } } </s>
|
<s> package benedictoxvi . pe . util ; public interface Checker < T > { public boolean check ( T obj ) ; } </s>
|
<s> package benedictoxvi . pe . util ; public class FormatException extends Exception { private static final long serialVersionUID = <NUM_LIT> ; public FormatException ( ) { super ( ) ; } public FormatException ( String message , Throwable cause , boolean enableSuppression , boolean writableStackTrace ) { } public FormatException ( String message , Throwable cause ) { super ( message , cause ) ; System . out . println ( "<STR_LIT>" ) ; } public FormatException ( String message ) { super ( message ) ; } public FormatException ( Throwable cause ) { super ( cause ) ; } @ Override public void printStackTrace ( ) { String method1 = ( ( StackTraceElement ) this . getStackTrace ( ) [ <NUM_LIT:0> ] ) . getMethodName ( ) ; String method2 = ( ( StackTraceElement ) this . getStackTrace ( ) [ <NUM_LIT:1> ] ) . getMethodName ( ) ; System . err . println ( "<STR_LIT:n>" + method2 + "<STR_LIT:[>" + method1 + "<STR_LIT:]>" + "<STR_LIT:U+0020:U+0020>" + this . getMessage ( ) ) ; } } </s>
|
<s> package benedictoxvi . pe . util ; import java . io . BufferedReader ; import java . io . DataInputStream ; import java . io . FileInputStream ; import java . io . InputStreamReader ; import java . util . ArrayList ; public class Loader { public ArrayList < String [ ] > getDataTxt ( String path ) { ArrayList < String [ ] > c_file = new ArrayList < String [ ] > ( ) ; try { FileInputStream fstream = new FileInputStream ( path . replaceAll ( "<STR_LIT>" , "<STR_LIT:U+0020>" ) ) ; DataInputStream in = new DataInputStream ( fstream ) ; BufferedReader br = new BufferedReader ( new InputStreamReader ( in ) ) ; String strLine ; while ( ( strLine = br . readLine ( ) ) != null ) { c_file . add ( strLine . split ( "<STR_LIT:t>" ) ) ; } in . close ( ) ; } catch ( Exception e ) { e . printStackTrace ( ) ; } return c_file ; } } </s>
|
<s> package org . gildedrose . qualitycontrol ; import static org . gildedrose . builder . ItemBuilder . anItem ; import static org . gildedrose . qualitycontrol . QualityControlFactory . BACKSTAGE_PASS_ITEM_NAME ; import static org . hamcrest . core . Is . is ; import static org . junit . Assert . assertThat ; import org . gildedrose . Item ; import org . gildedrose . qualitycontrol . BackstagePassQualityControl ; import org . junit . Before ; import org . junit . Test ; public class BackstagePassQualityControlTest { private static final int TWENTY_DAYS = <NUM_LIT:20> ; private static final int TEN_DAYS = <NUM_LIT:10> ; private static final int FIVE_DAYS = <NUM_LIT:5> ; private static final int ZERO_DAYS = <NUM_LIT:0> ; private BackstagePassQualityControl qualityControl ; private Item backstagePass ; @ Before public void initialise ( ) { qualityControl = new BackstagePassQualityControl ( ) ; backstagePass = anItem ( ) . withName ( BACKSTAGE_PASS_ITEM_NAME ) . build ( ) ; } @ Test public void shouldIncreaseQualityAsDaysGoBy ( ) { backstagePass . setSellIn ( TWENTY_DAYS ) ; backstagePass . setQuality ( <NUM_LIT:10> ) ; qualityControl . updateQualityFor ( backstagePass ) ; assertThat ( backstagePass . getQuality ( ) , is ( <NUM_LIT:11> ) ) ; } @ Test public void shouldIncreaseQualityByTwoWhenNeedsToBeSoldInTenDaysOrLess ( ) { backstagePass . setSellIn ( TEN_DAYS ) ; backstagePass . setQuality ( <NUM_LIT:10> ) ; qualityControl . updateQualityFor ( backstagePass ) ; assertThat ( backstagePass . getQuality ( ) , is ( <NUM_LIT:12> ) ) ; } @ Test public void shouldIncreaseQualityByThreeWhenNeedsToBeSoldInFiveDaysOrLess ( ) { backstagePass . setSellIn ( FIVE_DAYS ) ; backstagePass . setQuality ( <NUM_LIT:10> ) ; qualityControl . updateQualityFor ( backstagePass ) ; assertThat ( backstagePass . getQuality ( ) , is ( <NUM_LIT> ) ) ; } @ Test public void shouldSetQualityToZeroAfterConcert ( ) { backstagePass . setSellIn ( ZERO_DAYS ) ; backstagePass . setQuality ( <NUM_LIT:10> ) ; qualityControl . updateQualityFor ( backstagePass ) ; assertThat ( backstagePass . getQuality ( ) , is ( <NUM_LIT:0> ) ) ; } @ Test public void shouldNeverIncreaseQualityToMoreThanFifty ( ) { backstagePass . setSellIn ( FIVE_DAYS ) ; backstagePass . setQuality ( <NUM_LIT> ) ; qualityControl . updateQualityFor ( backstagePass ) ; assertThat ( backstagePass . getQuality ( ) , is ( <NUM_LIT> ) ) ; } } </s>
|
<s> package org . gildedrose . qualitycontrol ; import static org . gildedrose . builder . ItemBuilder . anItem ; import static org . hamcrest . core . Is . is ; import static org . junit . Assert . assertThat ; import org . gildedrose . Item ; import org . gildedrose . qualitycontrol . SulfurasQualityControl ; import org . junit . Test ; public class SulfurasQualityControlTest { private SulfurasQualityControl sulfurasQualityControl = new SulfurasQualityControl ( ) ; @ Test public void shouldNeverChangeQuality ( ) { Item sulfuras = anItem ( ) . withName ( "<STR_LIT>" ) . withQuality ( <NUM_LIT:20> ) . withSellIn ( <NUM_LIT:10> ) . build ( ) ; sulfurasQualityControl . updateQualityFor ( sulfuras ) ; assertThat ( sulfuras . getQuality ( ) , is ( <NUM_LIT:20> ) ) ; } } </s>
|
<s> package org . gildedrose . qualitycontrol ; import static org . gildedrose . builder . ItemBuilder . anItem ; import static org . gildedrose . qualitycontrol . QualityControlFactory . AGED_BRIE_ITEM_NAME ; import static org . hamcrest . core . Is . is ; import static org . junit . Assert . assertThat ; import org . gildedrose . Item ; import org . gildedrose . qualitycontrol . AgedBrieQualityControl ; import org . junit . Test ; public class AgedBrieQualityControlTest { private static final String AGED_BRIE = AGED_BRIE_ITEM_NAME ; private AgedBrieQualityControl agedBrieQualityControl = new AgedBrieQualityControl ( ) ; @ Test public void shouldIncreaseAgedBrieWheverItGetsOlder ( ) { Item agedBrie = anItem ( ) . withName ( AGED_BRIE ) . withQuality ( <NUM_LIT:10> ) . build ( ) ; agedBrieQualityControl . updateQualityFor ( agedBrie ) ; assertThat ( agedBrie . getQuality ( ) , is ( <NUM_LIT:11> ) ) ; } @ Test public void shouldNeverIncreaseTheQualityToMoreThanFifty ( ) { Item agedBrie = anItem ( ) . withName ( "<STR_LIT>" ) . withQuality ( <NUM_LIT> ) . build ( ) ; agedBrieQualityControl . updateQualityFor ( agedBrie ) ; assertThat ( agedBrie . getQuality ( ) , is ( <NUM_LIT> ) ) ; } } </s>
|
<s> package org . gildedrose . qualitycontrol ; import static org . gildedrose . builder . ItemBuilder . anItem ; import static org . gildedrose . qualitycontrol . QualityControlFactory . CONJURED_ITEM_NAME ; import static org . hamcrest . core . Is . is ; import static org . junit . Assert . assertThat ; import org . gildedrose . Item ; import org . gildedrose . qualitycontrol . ConjuredQualityControl ; import org . junit . Test ; public class ConjuredQualityControlTest { private ConjuredQualityControl conjuredQualityControl = new ConjuredQualityControl ( ) ; @ Test public void shouldDecreaseQualityByTwoForAllConjuredItems ( ) { Item conjured = anItem ( ) . withName ( CONJURED_ITEM_NAME ) . withQuality ( <NUM_LIT:20> ) . withSellIn ( <NUM_LIT:10> ) . build ( ) ; conjuredQualityControl . updateQualityFor ( conjured ) ; assertThat ( conjured . getQuality ( ) , is ( <NUM_LIT> ) ) ; } @ Test public void shouldNeverSetQualityForLessThanZero ( ) { Item conjured = anItem ( ) . withName ( CONJURED_ITEM_NAME ) . withQuality ( <NUM_LIT:0> ) . withSellIn ( <NUM_LIT:10> ) . build ( ) ; conjuredQualityControl . updateQualityFor ( conjured ) ; assertThat ( conjured . getQuality ( ) , is ( <NUM_LIT:0> ) ) ; } } </s>
|
<s> package org . gildedrose . qualitycontrol ; import static org . gildedrose . builder . ItemBuilder . anItem ; import static org . gildedrose . qualitycontrol . QualityControlFactory . AGED_BRIE_ITEM_NAME ; import static org . gildedrose . qualitycontrol . QualityControlFactory . BACKSTAGE_PASS_ITEM_NAME ; import static org . gildedrose . qualitycontrol . QualityControlFactory . CONJURED_ITEM_NAME ; import static org . gildedrose . qualitycontrol . QualityControlFactory . SULFURAS_ITEM_NAME ; import static org . hamcrest . Matchers . instanceOf ; import static org . hamcrest . core . Is . is ; import static org . junit . Assert . assertThat ; import org . gildedrose . qualitycontrol . AgedBrieQualityControl ; import org . gildedrose . qualitycontrol . BackstagePassQualityControl ; import org . gildedrose . qualitycontrol . ConjuredQualityControl ; import org . gildedrose . qualitycontrol . DefaultQualityControl ; import org . gildedrose . qualitycontrol . QualityControl ; import org . gildedrose . qualitycontrol . QualityControlFactory ; import org . gildedrose . qualitycontrol . SulfurasQualityControl ; import org . junit . Before ; import org . junit . Test ; public class QualityControlFactoryTest { private QualityControlFactory factory ; @ Before public void initialise ( ) { factory = new QualityControlFactory ( ) ; } @ Test public void shouldReturnDefaultQualityControlStrategy ( ) { QualityControl qualityControl = factory . qualityControlFor ( anItem ( ) . build ( ) ) ; assertThat ( qualityControl , is ( instanceOf ( DefaultQualityControl . class ) ) ) ; } @ Test public void shouldReturnBackstageQualityControlWhenItemIsABackstatePass ( ) { QualityControl qualityControl = factory . qualityControlFor ( anItem ( ) . withName ( BACKSTAGE_PASS_ITEM_NAME ) . build ( ) ) ; assertThat ( qualityControl , is ( instanceOf ( BackstagePassQualityControl . class ) ) ) ; } @ Test public void shouldReturnSulfurasQualityControlWhenItemIsASulfuras ( ) { QualityControl qualityControl = factory . qualityControlFor ( anItem ( ) . withName ( SULFURAS_ITEM_NAME ) . build ( ) ) ; assertThat ( qualityControl , is ( instanceOf ( SulfurasQualityControl . class ) ) ) ; } @ Test public void shouldReturnAgedBrieQualityControlWhenItemIsAgedBrie ( ) { QualityControl qualityControl = factory . qualityControlFor ( anItem ( ) . withName ( AGED_BRIE_ITEM_NAME ) . build ( ) ) ; assertThat ( qualityControl , is ( instanceOf ( AgedBrieQualityControl . class ) ) ) ; } @ Test public void shouldReturnConjuredQualityControlWhenItemIsConjured ( ) { QualityControl qualityControl = factory . qualityControlFor ( anItem ( ) . withName ( CONJURED_ITEM_NAME ) . build ( ) ) ; assertThat ( qualityControl , is ( instanceOf ( ConjuredQualityControl . class ) ) ) ; } } </s>
|
<s> package org . gildedrose ; import static org . gildedrose . builder . ItemBuilder . anItem ; import static org . mockito . Mockito . verify ; import static org . mockito . Mockito . when ; import java . util . Arrays ; import java . util . List ; import org . gildedrose . qualitycontrol . DefaultQualityControl ; import org . gildedrose . qualitycontrol . QualityControlFactory ; import org . gildedrose . sellincontrol . SellInControl ; import org . junit . Before ; import org . junit . Test ; import org . junit . runner . RunWith ; import org . mockito . Mock ; import org . mockito . Mockito ; import org . mockito . runners . MockitoJUnitRunner ; @ RunWith ( MockitoJUnitRunner . class ) public class GildedRoseTest { @ Mock private QualityControlFactory qualityControlFactory ; @ Mock private DefaultQualityControl qualityControl ; @ Mock private SellInControl sellInControl ; private GildedRose gildedRose ; private Item item2 ; private Item item1 ; @ Before public void initialise ( ) { when ( qualityControlFactory . qualityControlFor ( Mockito . any ( Item . class ) ) ) . thenReturn ( qualityControl ) ; gildedRose = new GildedRose ( qualityControlFactory , sellInControl ) ; item1 = anItem ( ) . build ( ) ; item2 = anItem ( ) . build ( ) ; } @ Test public void shouldUpdateItemsQuality ( ) { gildedRose . updateQualityFor ( listContaining ( item1 , item2 ) ) ; verifyIfQualityWasUpdatedFor ( item1 , item2 ) ; } @ Test public void shouldUpdateItemsSellIn ( ) { gildedRose . updateQualityFor ( listContaining ( item1 , item2 ) ) ; verifyIfSellInWasUpdatedFor ( item1 , item2 ) ; } private void verifyIfSellInWasUpdatedFor ( Item ... items ) { for ( Item item : items ) { verify ( sellInControl ) . updateSellInFor ( item ) ; } } private void verifyIfQualityWasUpdatedFor ( Item ... items ) { for ( Item item : items ) { verify ( qualityControl ) . updateQualityFor ( item ) ; } } private List < Item > listContaining ( Item ... items ) { return Arrays . asList ( items ) ; } } </s>
|
<s> package org . gildedrose . sellincontrol ; import static org . gildedrose . builder . ItemBuilder . anItem ; import static org . gildedrose . qualitycontrol . QualityControlFactory . SULFURAS_ITEM_NAME ; import static org . hamcrest . core . Is . is ; import static org . junit . Assert . assertThat ; import org . gildedrose . Item ; import org . gildedrose . sellincontrol . SellInControl ; import org . junit . Before ; import org . junit . Test ; public class SellInControlTest { private SellInControl sellInControl ; @ Before public void initialise ( ) { sellInControl = new SellInControl ( ) ; } @ Test public void shouldDecreaseSellInInOne ( ) { Item item = anItem ( ) . withName ( "<STR_LIT>" ) . withSellIn ( <NUM_LIT:10> ) . build ( ) ; sellInControl . updateSellInFor ( item ) ; assertThat ( item . getSellIn ( ) , is ( <NUM_LIT:9> ) ) ; } @ Test public void shouldNotDecreaseSellInForSulfuras ( ) { Item item = anItem ( ) . withName ( SULFURAS_ITEM_NAME ) . withSellIn ( <NUM_LIT:10> ) . build ( ) ; sellInControl . updateSellInFor ( item ) ; assertThat ( item . getSellIn ( ) , is ( <NUM_LIT:10> ) ) ; } } </s>
|
<s> package org . gildedrose . qualitycontrol ; import org . gildedrose . Item ; public class QualityControlFactory { public static final String BACKSTAGE_PASS_ITEM_NAME = "<STR_LIT>" ; public static final String SULFURAS_ITEM_NAME = "<STR_LIT>" ; public static final String AGED_BRIE_ITEM_NAME = "<STR_LIT>" ; public static final String CONJURED_ITEM_NAME = "<STR_LIT>" ; private static enum ItemQualityControl { AGED_BRIE ( AGED_BRIE_ITEM_NAME , new AgedBrieQualityControl ( ) ) , CONJURED ( CONJURED_ITEM_NAME , new ConjuredQualityControl ( ) ) , BACKSTAGE_PASS ( BACKSTAGE_PASS_ITEM_NAME , new BackstagePassQualityControl ( ) ) , SULFURAS ( SULFURAS_ITEM_NAME , new SulfurasQualityControl ( ) ) ; private String itemName ; private QualityControl qualityControl ; private ItemQualityControl ( String itemName , QualityControl qualityControl ) { this . itemName = itemName ; this . qualityControl = qualityControl ; } public static QualityControl qualityControlFor ( Item item ) { for ( ItemQualityControl itemQualityControl : ItemQualityControl . values ( ) ) { if ( itemQualityControl . itemName . equals ( item . getName ( ) ) ) { return itemQualityControl . qualityControl ; } } return new DefaultQualityControl ( ) ; } } public QualityControl qualityControlFor ( Item item ) { return ItemQualityControl . qualityControlFor ( item ) ; } } </s>
|
<s> package org . gildedrose . qualitycontrol ; import org . gildedrose . Item ; public class DefaultQualityControl implements QualityControl { public void updateQualityFor ( Item item ) { item . setQuality ( item . getQuality ( ) - qualityDropFor ( item ) ) ; } private int qualityDropFor ( Item item ) { int defaultQualityDrop = defaultQualityDropFor ( item ) ; return item . getQuality ( ) - defaultQualityDrop >= <NUM_LIT:0> ? defaultQualityDrop : item . getQuality ( ) ; } private int defaultQualityDropFor ( Item item ) { return item . getSellIn ( ) < <NUM_LIT:0> ? DEFAULT_QUALITY_DROP * <NUM_LIT:2> : DEFAULT_QUALITY_DROP ; } } </s>
|
<s> package org . gildedrose . qualitycontrol ; import static java . lang . Math . min ; import org . gildedrose . Item ; public class BackstagePassQualityControl implements QualityControl { private static final int ELEVE_DAYS = <NUM_LIT:11> ; private static final int FIVE_DAYS = <NUM_LIT:5> ; private static final int NO_EXTRA_QUALITY_HIKE = <NUM_LIT:0> ; private static final int DOUBLE_EXTRA_QUALITY_HIKE = <NUM_LIT:2> ; private static final int EXTRA_QUALITY_HIKE = <NUM_LIT:1> ; public void updateQualityFor ( Item backstagePass ) { backstagePass . setQuality ( newQualityFor ( backstagePass ) ) ; } private int newQualityFor ( Item backstagePass ) { return backstagePass . getSellIn ( ) > <NUM_LIT:0> ? min ( backstagePass . getQuality ( ) + qualityHikeFor ( backstagePass ) , MAX_QUALITY_ALLOWED ) : <NUM_LIT:0> ; } private int qualityHikeFor ( Item backstagePass ) { return DEFAULT_QUALITY_HIKE + extraQualityFor ( backstagePass ) ; } private int extraQualityFor ( Item backstagePass ) { if ( concertIsWithinSixAndTenDays ( backstagePass ) ) { return EXTRA_QUALITY_HIKE ; } else if ( concertIsInFiveOrLessDays ( backstagePass ) ) { return DOUBLE_EXTRA_QUALITY_HIKE ; } return NO_EXTRA_QUALITY_HIKE ; } private boolean concertIsInFiveOrLessDays ( Item backstagePass ) { return backstagePass . getSellIn ( ) <= FIVE_DAYS ; } private boolean concertIsWithinSixAndTenDays ( Item backstagePass ) { return backstagePass . getSellIn ( ) > FIVE_DAYS && backstagePass . getSellIn ( ) < ELEVE_DAYS ; } } </s>
|
<s> package org . gildedrose . qualitycontrol ; import org . gildedrose . Item ; public class SulfurasQualityControl implements QualityControl { public void updateQualityFor ( Item item ) { } } </s>
|
<s> package org . gildedrose . qualitycontrol ; import org . gildedrose . Item ; public class ConjuredQualityControl implements QualityControl { private static final int CONJURED_QUALITY_DROP = DEFAULT_QUALITY_DROP * <NUM_LIT:2> ; public void updateQualityFor ( Item item ) { item . setQuality ( item . getQuality ( ) - qualityDropFor ( item ) ) ; } private int qualityDropFor ( Item item ) { return item . getQuality ( ) - CONJURED_QUALITY_DROP > <NUM_LIT:0> ? CONJURED_QUALITY_DROP : item . getQuality ( ) ; } } </s>
|
<s> package org . gildedrose . qualitycontrol ; import org . gildedrose . Item ; public interface QualityControl { int MAX_QUALITY_ALLOWED = <NUM_LIT> ; int DEFAULT_QUALITY_HIKE = <NUM_LIT:1> ; int DEFAULT_QUALITY_DROP = <NUM_LIT:1> ; void updateQualityFor ( Item item ) ; } </s>
|
<s> package org . gildedrose . qualitycontrol ; import static java . lang . Math . min ; import org . gildedrose . Item ; public class AgedBrieQualityControl implements QualityControl { public void updateQualityFor ( Item item ) { item . setQuality ( newQualityFor ( item ) ) ; } private int newQualityFor ( Item item ) { return min ( item . getQuality ( ) + DEFAULT_QUALITY_HIKE , MAX_QUALITY_ALLOWED ) ; } } </s>
|
<s> package org . gildedrose ; import java . util . List ; import org . gildedrose . qualitycontrol . QualityControl ; import org . gildedrose . qualitycontrol . QualityControlFactory ; import org . gildedrose . sellincontrol . SellInControl ; public class GildedRose { private QualityControlFactory qualityControlFactory ; private SellInControl sellInControl ; public GildedRose ( QualityControlFactory qualityControl , SellInControl sellInControl ) { this . qualityControlFactory = qualityControl ; this . sellInControl = sellInControl ; } public void updateQualityFor ( List < Item > items ) { for ( Item item : items ) { udpateSellInFor ( item ) ; updateQualityFor ( item ) ; } } private void updateQualityFor ( Item item ) { QualityControl qualityControl = qualityControlFactory . qualityControlFor ( item ) ; qualityControl . updateQualityFor ( item ) ; } private void udpateSellInFor ( Item item ) { sellInControl . updateSellInFor ( item ) ; } } </s>
|
<s> package org . gildedrose . sellincontrol ; import static org . gildedrose . qualitycontrol . QualityControlFactory . SULFURAS_ITEM_NAME ; import org . gildedrose . Item ; public class SellInControl { private static final int DEFAULT_DECREASE = <NUM_LIT:1> ; private static final int NO_DECREASE = <NUM_LIT:0> ; public void updateSellInFor ( Item item ) { item . setSellIn ( item . getSellIn ( ) - sellInDecreaseFor ( item ) ) ; } private int sellInDecreaseFor ( Item item ) { return SULFURAS_ITEM_NAME . equals ( item . getName ( ) ) ? NO_DECREASE : DEFAULT_DECREASE ; } } </s>
|
<s> package org . gildedrose . builder ; import org . gildedrose . Item ; public class ItemBuilder { private String name ; private int sellIn = <NUM_LIT:1> ; private int quality = <NUM_LIT:1> ; public static ItemBuilder anItem ( ) { return new ItemBuilder ( ) ; } public ItemBuilder withQuality ( int quality ) { this . quality = quality ; return this ; } public ItemBuilder withSellIn ( int sellIn ) { this . sellIn = sellIn ; return this ; } public ItemBuilder withName ( String name ) { this . name = name ; return this ; } public Item build ( ) { return new Item ( name , sellIn , quality ) ; } } </s>
|
<s> package org . gildedrose . jbehave ; import static java . util . Arrays . asList ; import static org . jbehave . core . io . CodeLocations . codeLocationFromClass ; import static org . jbehave . core . reporters . Format . CONSOLE ; import static org . jbehave . core . reporters . Format . TXT ; import java . util . List ; import org . gildedrose . jbehave . steps . UpdateItemsQualitySteps ; import org . jbehave . core . configuration . Configuration ; import org . jbehave . core . configuration . MostUsefulConfiguration ; import org . jbehave . core . io . LoadFromClasspath ; import org . jbehave . core . io . StoryFinder ; import org . jbehave . core . junit . JUnitStories ; import org . jbehave . core . reporters . StoryReporterBuilder ; import org . jbehave . core . steps . CandidateSteps ; import org . jbehave . core . steps . InstanceStepsFactory ; public class GildedRoseStories extends JUnitStories { public GildedRoseStories ( ) { } @ Override public Configuration configuration ( ) { return new MostUsefulConfiguration ( ) . useStoryLoader ( new LoadFromClasspath ( this . getClass ( ) ) ) . useStoryReporterBuilder ( new StoryReporterBuilder ( ) . withDefaultFormats ( ) . withFormats ( CONSOLE , TXT ) ) ; } @ Override protected List < String > storyPaths ( ) { return new StoryFinder ( ) . findPaths ( codeLocationFromClass ( this . getClass ( ) ) . getFile ( ) , asList ( "<STR_LIT>" + System . getProperty ( "<STR_LIT>" , "<STR_LIT:*>" ) + "<STR_LIT>" ) , null ) ; } @ Override public List < CandidateSteps > candidateSteps ( ) { return new InstanceStepsFactory ( configuration ( ) , new UpdateItemsQualitySteps ( ) ) . createCandidateSteps ( ) ; } } </s>
|
<s> package org . gildedrose . jbehave . steps ; import static java . util . Arrays . asList ; import static org . gildedrose . builder . ItemBuilder . anItem ; import static org . hamcrest . core . Is . is ; import static org . junit . Assert . assertThat ; import org . gildedrose . GildedRose ; import org . gildedrose . Item ; import org . gildedrose . qualitycontrol . QualityControlFactory ; import org . gildedrose . sellincontrol . SellInControl ; import org . jbehave . core . annotations . BeforeStory ; import org . jbehave . core . annotations . Given ; import org . jbehave . core . annotations . Named ; import org . jbehave . core . annotations . Then ; import org . jbehave . core . annotations . When ; public class UpdateItemsQualitySteps { private Item item ; private GildedRose gildedRose ; @ BeforeStory public void beforeStoryDo ( ) { gildedRose = new GildedRose ( new QualityControlFactory ( ) , new SellInControl ( ) ) ; } @ Given ( "<STR_LIT>" ) public void givenAnItemWithNameSellInAndQualitySetTo ( @ Named ( "<STR_LIT:name>" ) String name , @ Named ( "<STR_LIT>" ) int sellIn , @ Named ( "<STR_LIT>" ) int quality ) { this . item = anItem ( ) . withName ( name ) . withSellIn ( sellIn ) . withQuality ( quality ) . build ( ) ; } @ When ( "<STR_LIT>" ) public void whenTheQualityOfTheItemIsUpdatedAfterOneDay ( ) { gildedRose . updateQualityFor ( asList ( item ) ) ; } @ Then ( "<STR_LIT>" ) public void thenSellInShouldBe ( @ Named ( "<STR_LIT>" ) int newSellIn ) { assertThat ( item . getSellIn ( ) , is ( newSellIn ) ) ; } @ Then ( "<STR_LIT>" ) public void thenQualityShouldBe ( @ Named ( "<STR_LIT>" ) int newQuality ) { assertThat ( item . getQuality ( ) , is ( newQuality ) ) ; } } </s>
|
<s> package org . gildedrose ; public class Item { public String name ; public int sellIn ; public int quality ; public Item ( String name , int sellIn , int quality ) { this . setName ( name ) ; this . setSellIn ( sellIn ) ; this . setQuality ( quality ) ; } public String getName ( ) { return name ; } public void setName ( String name ) { this . name = name ; } public int getSellIn ( ) { return sellIn ; } public void setSellIn ( int sellIn ) { this . sellIn = sellIn ; } public int getQuality ( ) { return quality ; } public void setQuality ( int quality ) { this . quality = quality ; } } </s>
|
<s> package org . apache . thrift . maven ; import com . google . common . collect . ImmutableList ; import org . apache . maven . artifact . Artifact ; import java . io . File ; import java . util . List ; public final class ThriftTestCompileMojo extends AbstractThriftMojo { private File thriftTestSourceRoot ; private File outputDirectory ; @ Override protected void attachFiles ( ) { project . addTestCompileSourceRoot ( outputDirectory . getAbsolutePath ( ) ) ; projectHelper . addTestResource ( project , thriftTestSourceRoot . getAbsolutePath ( ) , ImmutableList . of ( "<STR_LIT>" ) , ImmutableList . of ( ) ) ; } @ Override protected List < Artifact > getDependencyArtifacts ( ) { @ SuppressWarnings ( "<STR_LIT:unchecked>" ) List < Artifact > testArtifacts = project . getTestArtifacts ( ) ; return testArtifacts ; } @ Override protected File getOutputDirectory ( ) { return outputDirectory ; } @ Override protected File getThriftSourceRoot ( ) { return thriftTestSourceRoot ; } } </s>
|
<s> package org . apache . thrift . maven ; import com . google . common . collect . ImmutableList ; import org . apache . maven . artifact . Artifact ; import java . io . File ; import java . util . List ; public final class ThriftCompileMojo extends AbstractThriftMojo { private File thriftSourceRoot ; private File outputDirectory ; @ Override protected List < Artifact > getDependencyArtifacts ( ) { @ SuppressWarnings ( "<STR_LIT:unchecked>" ) List < Artifact > compileArtifacts = project . getCompileArtifacts ( ) ; return compileArtifacts ; } @ Override protected File getOutputDirectory ( ) { return outputDirectory ; } @ Override protected File getThriftSourceRoot ( ) { return thriftSourceRoot ; } @ Override protected void attachFiles ( ) { project . addCompileSourceRoot ( outputDirectory . getAbsolutePath ( ) ) ; projectHelper . addResource ( project , thriftSourceRoot . getAbsolutePath ( ) , ImmutableList . of ( "<STR_LIT>" ) , ImmutableList . of ( ) ) ; } } </s>
|
<s> package org . apache . thrift . maven ; import com . google . common . collect . ImmutableSet ; import org . apache . maven . artifact . Artifact ; import org . apache . maven . artifact . repository . ArtifactRepository ; import org . apache . maven . plugin . AbstractMojo ; import org . apache . maven . plugin . MojoExecutionException ; import org . apache . maven . plugin . MojoFailureException ; import org . apache . maven . project . MavenProject ; import org . apache . maven . project . MavenProjectHelper ; import org . codehaus . plexus . util . cli . CommandLineException ; import org . codehaus . plexus . util . io . RawInputStreamFacade ; import java . io . File ; import java . io . FilenameFilter ; import java . io . IOException ; import java . security . MessageDigest ; import java . security . NoSuchAlgorithmException ; import java . util . List ; import java . util . Set ; import java . util . jar . JarEntry ; import java . util . jar . JarFile ; import static com . google . common . base . Join . join ; import static com . google . common . base . Preconditions . checkArgument ; import static com . google . common . base . Preconditions . checkNotNull ; import static com . google . common . base . Preconditions . checkState ; import static com . google . common . collect . Sets . newHashSet ; import static java . lang . String . format ; import static java . util . Arrays . asList ; import static java . util . Collections . list ; import static org . codehaus . plexus . util . FileUtils . cleanDirectory ; import static org . codehaus . plexus . util . FileUtils . copyStreamToFile ; import static org . codehaus . plexus . util . FileUtils . getFiles ; abstract class AbstractThriftMojo extends AbstractMojo { private static final String THRIFT_FILE_SUFFIX = "<STR_LIT>" ; private static final String DEFAULT_INCLUDES = "<STR_LIT>" + THRIFT_FILE_SUFFIX ; protected MavenProject project ; protected MavenProjectHelper projectHelper ; private String thriftExecutable ; private String generator ; private File [ ] additionalThriftPathElements = new File [ ] { } ; private File temporaryThriftFileDirectory ; private ArtifactRepository localRepository ; private boolean hashDependentPaths ; private Set < String > includes = ImmutableSet . of ( DEFAULT_INCLUDES ) ; private Set < String > excludes = ImmutableSet . of ( ) ; private long staleMillis = <NUM_LIT:0> ; private boolean checkStaleness = false ; public void execute ( ) throws MojoExecutionException , MojoFailureException { checkParameters ( ) ; final File thriftSourceRoot = getThriftSourceRoot ( ) ; if ( thriftSourceRoot . exists ( ) ) { try { ImmutableSet < File > thriftFiles = findThriftFilesInDirectory ( thriftSourceRoot ) ; final File outputDirectory = getOutputDirectory ( ) ; ImmutableSet < File > outputFiles = findGeneratedFilesInDirectory ( getOutputDirectory ( ) ) ; if ( thriftFiles . isEmpty ( ) ) { getLog ( ) . info ( "<STR_LIT>" ) ; } else if ( checkStaleness && ( ( lastModified ( thriftFiles ) + staleMillis ) < lastModified ( outputFiles ) ) ) { getLog ( ) . info ( "<STR_LIT>" ) ; attachFiles ( ) ; } else { ImmutableSet < File > derivedThriftPathElements = makeThriftPathFromJars ( temporaryThriftFileDirectory , getDependencyArtifactFiles ( ) ) ; outputDirectory . mkdirs ( ) ; cleanDirectory ( outputDirectory ) ; Thrift thrift = new Thrift . Builder ( thriftExecutable , outputDirectory ) . setGenerator ( generator ) . addThriftPathElement ( thriftSourceRoot ) . addThriftPathElements ( derivedThriftPathElements ) . addThriftPathElements ( asList ( additionalThriftPathElements ) ) . addThriftFiles ( thriftFiles ) . build ( ) ; final int exitStatus = thrift . compile ( ) ; if ( exitStatus != <NUM_LIT:0> ) { getLog ( ) . error ( "<STR_LIT>" + thrift . getOutput ( ) ) ; getLog ( ) . error ( "<STR_LIT>" + thrift . getError ( ) ) ; throw new MojoFailureException ( "<STR_LIT>" ) ; } attachFiles ( ) ; } } catch ( IOException e ) { throw new MojoExecutionException ( "<STR_LIT>" , e ) ; } catch ( IllegalArgumentException e ) { throw new MojoFailureException ( "<STR_LIT>" + e . getMessage ( ) , e ) ; } catch ( CommandLineException e ) { throw new MojoExecutionException ( "<STR_LIT>" , e ) ; } } else { getLog ( ) . info ( format ( "<STR_LIT>" , thriftSourceRoot ) ) ; } } ImmutableSet < File > findGeneratedFilesInDirectory ( File directory ) throws IOException { if ( directory == null || ! directory . isDirectory ( ) ) return ImmutableSet . of ( ) ; @ SuppressWarnings ( "<STR_LIT:unchecked>" ) List < File > javaFilesInDirectory = getFiles ( directory , "<STR_LIT>" , null ) ; return ImmutableSet . copyOf ( javaFilesInDirectory ) ; } private long lastModified ( ImmutableSet < File > files ) { long result = <NUM_LIT:0> ; for ( File file : files ) { if ( file . lastModified ( ) > result ) result = file . lastModified ( ) ; } return result ; } private void checkParameters ( ) { checkNotNull ( project , "<STR_LIT>" ) ; checkNotNull ( projectHelper , "<STR_LIT>" ) ; checkNotNull ( thriftExecutable , "<STR_LIT>" ) ; checkNotNull ( generator , "<STR_LIT>" ) ; final File thriftSourceRoot = getThriftSourceRoot ( ) ; checkNotNull ( thriftSourceRoot ) ; checkArgument ( ! thriftSourceRoot . isFile ( ) , "<STR_LIT>" ) ; checkNotNull ( temporaryThriftFileDirectory , "<STR_LIT>" ) ; checkState ( ! temporaryThriftFileDirectory . isFile ( ) , "<STR_LIT>" ) ; final File outputDirectory = getOutputDirectory ( ) ; checkNotNull ( outputDirectory ) ; checkState ( ! outputDirectory . isFile ( ) , "<STR_LIT>" ) ; } protected abstract File getThriftSourceRoot ( ) ; protected abstract List < Artifact > getDependencyArtifacts ( ) ; protected abstract File getOutputDirectory ( ) ; protected abstract void attachFiles ( ) ; private ImmutableSet < File > getDependencyArtifactFiles ( ) { Set < File > dependencyArtifactFiles = newHashSet ( ) ; for ( Artifact artifact : getDependencyArtifacts ( ) ) { dependencyArtifactFiles . add ( artifact . getFile ( ) ) ; } return ImmutableSet . copyOf ( dependencyArtifactFiles ) ; } ImmutableSet < File > makeThriftPathFromJars ( File temporaryThriftFileDirectory , Iterable < File > classpathElementFiles ) throws IOException , MojoExecutionException { checkNotNull ( classpathElementFiles , "<STR_LIT>" ) ; if ( temporaryThriftFileDirectory . exists ( ) ) { cleanDirectory ( temporaryThriftFileDirectory ) ; } Set < File > thriftDirectories = newHashSet ( ) ; for ( File classpathElementFile : classpathElementFiles ) { if ( classpathElementFile . isFile ( ) && classpathElementFile . canRead ( ) && ! classpathElementFile . getName ( ) . endsWith ( "<STR_LIT>" ) ) { JarFile classpathJar ; try { classpathJar = new JarFile ( classpathElementFile ) ; } catch ( IOException e ) { throw new IllegalArgumentException ( format ( "<STR_LIT>" , classpathElementFile ) ) ; } for ( JarEntry jarEntry : list ( classpathJar . entries ( ) ) ) { final String jarEntryName = jarEntry . getName ( ) ; if ( jarEntry . getName ( ) . endsWith ( THRIFT_FILE_SUFFIX ) ) { final File uncompressedCopy = new File ( new File ( temporaryThriftFileDirectory , truncatePath ( classpathJar . getName ( ) ) ) , jarEntryName ) ; uncompressedCopy . getParentFile ( ) . mkdirs ( ) ; copyStreamToFile ( new RawInputStreamFacade ( classpathJar . getInputStream ( jarEntry ) ) , uncompressedCopy ) ; thriftDirectories . add ( uncompressedCopy . getParentFile ( ) ) ; } } } else if ( classpathElementFile . isDirectory ( ) ) { File [ ] thriftFiles = classpathElementFile . listFiles ( new FilenameFilter ( ) { public boolean accept ( File dir , String name ) { return name . endsWith ( THRIFT_FILE_SUFFIX ) ; } } ) ; if ( thriftFiles . length > <NUM_LIT:0> ) { thriftDirectories . add ( classpathElementFile ) ; } } } return ImmutableSet . copyOf ( thriftDirectories ) ; } ImmutableSet < File > findThriftFilesInDirectory ( File directory ) throws IOException { checkNotNull ( directory ) ; checkArgument ( directory . isDirectory ( ) , "<STR_LIT>" , directory ) ; @ SuppressWarnings ( "<STR_LIT:unchecked>" ) List < File > thriftFilesInDirectory = getFiles ( directory , join ( "<STR_LIT:U+002C>" , includes ) , join ( "<STR_LIT:U+002C>" , excludes ) ) ; return ImmutableSet . copyOf ( thriftFilesInDirectory ) ; } ImmutableSet < File > findThriftFilesInDirectories ( Iterable < File > directories ) throws IOException { checkNotNull ( directories ) ; Set < File > thriftFiles = newHashSet ( ) ; for ( File directory : directories ) { thriftFiles . addAll ( findThriftFilesInDirectory ( directory ) ) ; } return ImmutableSet . copyOf ( thriftFiles ) ; } String truncatePath ( final String jarPath ) throws MojoExecutionException { if ( hashDependentPaths ) { try { return toHexString ( MessageDigest . getInstance ( "<STR_LIT>" ) . digest ( jarPath . getBytes ( ) ) ) ; } catch ( NoSuchAlgorithmException e ) { throw new MojoExecutionException ( "<STR_LIT>" , e ) ; } } String repository = localRepository . getBasedir ( ) . replace ( '<STR_LIT:\\>' , '<CHAR_LIT:/>' ) ; if ( ! repository . endsWith ( "<STR_LIT:/>" ) ) { repository += "<STR_LIT:/>" ; } String path = jarPath . replace ( '<STR_LIT:\\>' , '<CHAR_LIT:/>' ) ; int repositoryIndex = path . indexOf ( repository ) ; if ( repositoryIndex != - <NUM_LIT:1> ) { path = path . substring ( repositoryIndex + repository . length ( ) ) ; } int colonIndex = path . indexOf ( '<CHAR_LIT::>' ) ; if ( colonIndex != - <NUM_LIT:1> ) { path = path . substring ( colonIndex + <NUM_LIT:2> ) ; } return path ; } private static final char [ ] HEX_CHARS = "<STR_LIT>" . toCharArray ( ) ; public static String toHexString ( byte [ ] byteArray ) { final StringBuilder hexString = new StringBuilder ( <NUM_LIT:2> * byteArray . length ) ; for ( final byte b : byteArray ) { hexString . append ( HEX_CHARS [ ( b & <NUM_LIT> ) > > <NUM_LIT:4> ] ) . append ( HEX_CHARS [ b & <NUM_LIT> ] ) ; } return hexString . toString ( ) ; } } </s>
|
<s> package org . apache . thrift . maven ; import com . google . common . collect . ImmutableList ; import com . google . common . collect . ImmutableSet ; import org . codehaus . plexus . util . cli . CommandLineException ; import org . codehaus . plexus . util . cli . CommandLineUtils ; import org . codehaus . plexus . util . cli . Commandline ; import java . io . File ; import java . util . List ; import java . util . Set ; import static com . google . common . base . Preconditions . checkArgument ; import static com . google . common . base . Preconditions . checkNotNull ; import static com . google . common . base . Preconditions . checkState ; import static com . google . common . collect . Lists . newLinkedList ; import static com . google . common . collect . Sets . newHashSet ; final class Thrift { final static String GENERATED_JAVA = "<STR_LIT>" ; private final String executable ; private final String generator ; private final ImmutableSet < File > thriftPathElements ; private final ImmutableSet < File > thriftFiles ; private final File javaOutputDirectory ; private final CommandLineUtils . StringStreamConsumer output ; private final CommandLineUtils . StringStreamConsumer error ; private Thrift ( String executable , String generator , ImmutableSet < File > thriftPath , ImmutableSet < File > thriftFiles , File javaOutputDirectory ) { this . executable = checkNotNull ( executable , "<STR_LIT>" ) ; this . generator = checkNotNull ( generator , "<STR_LIT>" ) ; this . thriftPathElements = checkNotNull ( thriftPath , "<STR_LIT>" ) ; this . thriftFiles = checkNotNull ( thriftFiles , "<STR_LIT>" ) ; this . javaOutputDirectory = checkNotNull ( javaOutputDirectory , "<STR_LIT>" ) ; this . error = new CommandLineUtils . StringStreamConsumer ( ) ; this . output = new CommandLineUtils . StringStreamConsumer ( ) ; } public int compile ( ) throws CommandLineException { for ( File thriftFile : thriftFiles ) { Commandline cl = new Commandline ( ) ; cl . setExecutable ( executable ) ; cl . addArguments ( buildThriftCommand ( thriftFile ) . toArray ( new String [ ] { } ) ) ; final int result = CommandLineUtils . executeCommandLine ( cl , null , output , error ) ; if ( result != <NUM_LIT:0> ) { return result ; } } return <NUM_LIT:0> ; } ImmutableList < String > buildThriftCommand ( final File thriftFile ) { final List < String > command = newLinkedList ( ) ; for ( File thriftPathElement : thriftPathElements ) { command . add ( "<STR_LIT>" ) ; command . add ( thriftPathElement . toString ( ) ) ; } command . add ( "<STR_LIT>" ) ; command . add ( javaOutputDirectory . toString ( ) ) ; command . add ( "<STR_LIT>" ) ; command . add ( generator ) ; command . add ( thriftFile . toString ( ) ) ; return ImmutableList . copyOf ( command ) ; } public String getOutput ( ) { return output . getOutput ( ) ; } public String getError ( ) { return error . getOutput ( ) ; } static final class Builder { private final String executable ; private final File javaOutputDirectory ; private Set < File > thriftPathElements ; private Set < File > thriftFiles ; private String generator ; public Builder ( String executable , File javaOutputDirectory ) { this . executable = checkNotNull ( executable , "<STR_LIT>" ) ; this . javaOutputDirectory = checkNotNull ( javaOutputDirectory ) ; checkArgument ( javaOutputDirectory . isDirectory ( ) ) ; this . thriftFiles = newHashSet ( ) ; this . thriftPathElements = newHashSet ( ) ; } public Builder addThriftFile ( File thriftFile ) { checkNotNull ( thriftFile ) ; checkArgument ( thriftFile . isFile ( ) ) ; checkArgument ( thriftFile . getName ( ) . endsWith ( "<STR_LIT>" ) ) ; checkThriftFileIsInThriftPath ( thriftFile ) ; thriftFiles . add ( thriftFile ) ; return this ; } public Builder setGenerator ( String generator ) { checkNotNull ( generator ) ; this . generator = generator ; return this ; } private void checkThriftFileIsInThriftPath ( File thriftFile ) { assert thriftFile . isFile ( ) ; checkState ( checkThriftFileIsInThriftPathHelper ( thriftFile . getParentFile ( ) ) ) ; } private boolean checkThriftFileIsInThriftPathHelper ( File directory ) { assert directory . isDirectory ( ) ; if ( thriftPathElements . contains ( directory ) ) { return true ; } else { final File parentDirectory = directory . getParentFile ( ) ; return ( parentDirectory == null ) ? false : checkThriftFileIsInThriftPathHelper ( parentDirectory ) ; } } public Builder addThriftFiles ( Iterable < File > thriftFiles ) { for ( File thriftFile : thriftFiles ) { addThriftFile ( thriftFile ) ; } return this ; } public Builder addThriftPathElement ( File thriftPathElement ) { checkNotNull ( thriftPathElement ) ; checkArgument ( thriftPathElement . isDirectory ( ) ) ; thriftPathElements . add ( thriftPathElement ) ; return this ; } public Builder addThriftPathElements ( Iterable < File > thriftPathElements ) { for ( File thriftPathElement : thriftPathElements ) { addThriftPathElement ( thriftPathElement ) ; } return this ; } public Thrift build ( ) { checkState ( ! thriftFiles . isEmpty ( ) ) ; return new Thrift ( executable , generator , ImmutableSet . copyOf ( thriftPathElements ) , ImmutableSet . copyOf ( thriftFiles ) , javaOutputDirectory ) ; } } } </s>
|
<s> package org . apache . thrift . maven ; import org . codehaus . plexus . util . FileUtils ; import org . codehaus . plexus . util . cli . CommandLineException ; import org . junit . After ; import org . junit . Before ; import org . junit . Test ; import java . io . File ; import static org . junit . Assert . assertEquals ; import static org . junit . Assert . assertFalse ; import static org . junit . Assert . assertTrue ; import static org . junit . Assert . fail ; public class TestThrift { private File testRootDir ; private File idlDir ; private File genJavaDir ; private Thrift . Builder builder ; @ Before public void setup ( ) throws Exception { final File tmpDir = new File ( System . getProperty ( "<STR_LIT>" ) ) ; testRootDir = new File ( tmpDir , "<STR_LIT>" ) ; if ( testRootDir . exists ( ) ) { FileUtils . cleanDirectory ( testRootDir ) ; } else { assertTrue ( "<STR_LIT>" + testRootDir . getPath ( ) , testRootDir . mkdir ( ) ) ; } File testResourceDir = new File ( "<STR_LIT>" ) ; assertTrue ( "<STR_LIT>" , testRootDir . exists ( ) ) ; idlDir = new File ( testResourceDir , "<STR_LIT>" ) ; genJavaDir = new File ( testRootDir , Thrift . GENERATED_JAVA ) ; builder = new Thrift . Builder ( "<STR_LIT>" , testRootDir ) ; builder . setGenerator ( "<STR_LIT>" ) . addThriftPathElement ( idlDir ) ; } @ Test public void testThriftCompile ( ) throws Exception { executeThriftCompile ( ) ; } @ Test public void testThriftCompileWithGeneratorOption ( ) throws Exception { builder . setGenerator ( "<STR_LIT>" ) ; executeThriftCompile ( ) ; } private void executeThriftCompile ( ) throws CommandLineException { final File thriftFile = new File ( idlDir , "<STR_LIT>" ) ; builder . addThriftFile ( thriftFile ) ; final Thrift thrift = builder . build ( ) ; assertTrue ( "<STR_LIT>" , thriftFile . exists ( ) ) ; assertFalse ( "<STR_LIT>" , genJavaDir . exists ( ) ) ; final int result = thrift . compile ( ) ; assertEquals ( <NUM_LIT:0> , result ) ; assertFalse ( "<STR_LIT>" , genJavaDir . exists ( ) ) ; assertTrue ( "<STR_LIT>" , new File ( testRootDir , "<STR_LIT>" ) . exists ( ) ) ; } @ Test public void testThriftMultipleFileCompile ( ) throws Exception { final File sharedThrift = new File ( idlDir , "<STR_LIT>" ) ; final File tutorialThrift = new File ( idlDir , "<STR_LIT>" ) ; builder . addThriftFile ( sharedThrift ) ; builder . addThriftFile ( tutorialThrift ) ; final Thrift thrift = builder . build ( ) ; assertTrue ( "<STR_LIT>" , sharedThrift . exists ( ) ) ; assertFalse ( "<STR_LIT>" , genJavaDir . exists ( ) ) ; final int result = thrift . compile ( ) ; assertEquals ( <NUM_LIT:0> , result ) ; assertFalse ( "<STR_LIT>" , genJavaDir . exists ( ) ) ; assertTrue ( "<STR_LIT>" , new File ( testRootDir , "<STR_LIT>" ) . exists ( ) ) ; assertTrue ( "<STR_LIT>" , new File ( testRootDir , "<STR_LIT>" ) . exists ( ) ) ; } @ Test public void testBadCompile ( ) throws Exception { final File thriftFile = new File ( testRootDir , "<STR_LIT>" ) ; builder . addThriftPathElement ( testRootDir ) ; assertTrue ( thriftFile . createNewFile ( ) ) ; builder . addThriftFile ( thriftFile ) ; assertTrue ( thriftFile . delete ( ) ) ; final Thrift thrift = builder . build ( ) ; assertTrue ( ! thriftFile . exists ( ) ) ; assertFalse ( "<STR_LIT>" , genJavaDir . exists ( ) ) ; final int result = thrift . compile ( ) ; assertEquals ( <NUM_LIT:1> , result ) ; } @ Test public void testFileInPathPreCondition ( ) throws Exception { final File thriftFile = new File ( testRootDir , "<STR_LIT>" ) ; assertTrue ( thriftFile . createNewFile ( ) ) ; try { builder . addThriftFile ( thriftFile ) ; fail ( "<STR_LIT>" ) ; } catch ( IllegalStateException e ) { } } @ After public void cleanup ( ) throws Exception { if ( testRootDir . exists ( ) ) { FileUtils . cleanDirectory ( testRootDir ) ; assertTrue ( "<STR_LIT>" + testRootDir . getPath ( ) , testRootDir . delete ( ) ) ; } } } </s>
|
<s> package com . iminurnetz . bukkit . plugin . creativestick ; import java . util . Collections ; import java . util . HashSet ; import java . util . List ; import org . bukkit . Material ; import org . bukkit . configuration . file . FileConfiguration ; import com . iminurnetz . bukkit . plugin . BukkitPlugin ; import com . iminurnetz . bukkit . plugin . util . ConfigurationService ; import com . iminurnetz . bukkit . util . MaterialUtils ; public class CSConfigurationService extends ConfigurationService { private FileConfiguration config ; private BukkitPlugin plugin ; public static final double LAST_CHANGED_IN_VERSION = <NUM_LIT> ; public static final String SETTINGS_TAG = "<STR_LIT>" ; public static final boolean ALLOW_OPS = true ; public static final boolean IS_ENABLED = false ; public static final boolean DOES_DROP = true ; public static final String USER_SETTINGS_TAG = SETTINGS_TAG + "<STR_LIT>" ; public static final int UNDO_AMOUNT = <NUM_LIT:5> ; public static final int MAX_UNDOS = <NUM_LIT> ; public static final int DISTANCE = <NUM_LIT:100> ; public static final Material TOOL = Material . STICK ; public static final boolean PROTECT_BOTTOM = true ; public static final boolean RIGHT_CLICK_SWITCH = false ; public static final boolean RIGHT_CLICK_MODES = false ; public static final boolean DEBUG = false ; public static final boolean NATURAL_DROPS = false ; public static final boolean ANNOUNCE = false ; public static final boolean THROW_BUILD = false ; public static final String PERMISSIONS_TAG = "<STR_LIT>" ; public CSConfigurationService ( BukkitPlugin plugin ) { super ( plugin , LAST_CHANGED_IN_VERSION ) ; this . config = getConfiguration ( ) ; this . plugin = plugin ; } public CSPermissionHandler getPermissionHandler ( ) { return new CSPermissionHandler ( plugin , config . getBoolean ( SETTINGS_TAG + "<STR_LIT>" , ALLOW_OPS ) ) ; } public boolean isEnabled ( ) { return config . getBoolean ( SETTINGS_TAG + "<STR_LIT>" , IS_ENABLED ) ; } public boolean doesDrop ( ) { return config . getBoolean ( SETTINGS_TAG + "<STR_LIT>" , DOES_DROP ) ; } public int getUndoAmount ( ) { return config . getInt ( USER_SETTINGS_TAG + "<STR_LIT>" , UNDO_AMOUNT ) ; } public int getDistance ( ) { return config . getInt ( USER_SETTINGS_TAG + "<STR_LIT>" , DISTANCE ) ; } public Material getTool ( ) { return MaterialUtils . getMaterial ( config . getString ( USER_SETTINGS_TAG + "<STR_LIT>" , TOOL . name ( ) ) ) ; } public boolean doProtectBottom ( ) { return config . getBoolean ( USER_SETTINGS_TAG + "<STR_LIT>" , PROTECT_BOTTOM ) ; } public boolean doRightClickSwitch ( ) { return config . getBoolean ( USER_SETTINGS_TAG + "<STR_LIT>" , RIGHT_CLICK_SWITCH ) ; } public boolean doRightClickModes ( ) { return config . getBoolean ( USER_SETTINGS_TAG + "<STR_LIT>" , RIGHT_CLICK_MODES ) ; } public boolean isDebug ( ) { return config . getBoolean ( USER_SETTINGS_TAG + "<STR_LIT>" , DEBUG ) ; } public boolean doesNaturalDrops ( ) { return config . getBoolean ( USER_SETTINGS_TAG + "<STR_LIT>" , NATURAL_DROPS ) ; } public boolean doAnnounce ( ) { return config . getBoolean ( USER_SETTINGS_TAG + "<STR_LIT>" , ANNOUNCE ) ; } public HashSet < Byte > getIgnored ( ) { List < String > names = config . getStringList ( SETTINGS_TAG + "<STR_LIT>" ) ; HashSet < Material > materials = new HashSet < Material > ( ) ; for ( String name : names ) { Material m = MaterialUtils . getMaterial ( name ) ; if ( m != null ) materials . add ( m ) ; } HashSet < Byte > returnSet = new HashSet < Byte > ( ) ; for ( Material m : materials ) { returnSet . add ( ( byte ) m . getId ( ) ) ; } returnSet . add ( ( byte ) Material . AIR . getId ( ) ) ; return returnSet ; } public int getMaxUndos ( ) { return config . getInt ( USER_SETTINGS_TAG + "<STR_LIT>" , MAX_UNDOS ) ; } public boolean useBlockSpawnPermission ( ) { return config . getBoolean ( SETTINGS_TAG + "<STR_LIT>" , false ) ; } public boolean isThrowBuild ( ) { return config . getBoolean ( USER_SETTINGS_TAG + "<STR_LIT>" , THROW_BUILD ) ; } } </s>
|
<s> package com . iminurnetz . bukkit . plugin . creativestick ; import java . util . Date ; import java . util . List ; import java . util . concurrent . Executors ; import java . util . concurrent . ScheduledExecutorService ; import java . util . concurrent . ScheduledFuture ; import java . util . concurrent . TimeUnit ; import java . util . logging . Level ; import org . bukkit . ChatColor ; import org . bukkit . GameMode ; import org . bukkit . Material ; import org . bukkit . block . Block ; import org . bukkit . block . BlockFace ; import org . bukkit . block . BlockState ; import org . bukkit . entity . Player ; import org . bukkit . event . Cancellable ; import org . bukkit . event . EventHandler ; import org . bukkit . event . EventPriority ; import org . bukkit . event . block . Action ; import org . bukkit . event . block . BlockBreakEvent ; import org . bukkit . event . block . BlockEvent ; import org . bukkit . event . block . BlockIgniteEvent ; import org . bukkit . event . block . BlockIgniteEvent . IgniteCause ; import org . bukkit . event . block . BlockPlaceEvent ; import org . bukkit . event . player . PlayerAnimationEvent ; import org . bukkit . event . player . PlayerInteractEvent ; import org . bukkit . event . player . PlayerItemHeldEvent ; import org . bukkit . event . player . PlayerJoinEvent ; import org . bukkit . event . Listener ; import org . bukkit . inventory . ItemStack ; import org . bukkit . material . Ladder ; import org . bukkit . material . MaterialData ; import com . iminurnetz . bukkit . plugin . util . MessageUtils ; import com . iminurnetz . bukkit . util . Item ; import com . iminurnetz . bukkit . util . LocationUtil ; import com . iminurnetz . bukkit . util . MaterialUtils ; public class CSPlayerListener implements Listener { public static CSPlugin plugin ; public CSPlayerListener ( CSPlugin instance ) { plugin = instance ; } @ EventHandler ( priority = EventPriority . MONITOR ) public void onPlayerJoin ( PlayerJoinEvent event ) { checkStatus ( event . getPlayer ( ) ) ; } private final ScheduledExecutorService scheduler = Executors . newScheduledThreadPool ( <NUM_LIT:1> ) ; private static ScheduledFuture < ? > checkerHandle = null ; @ EventHandler ( priority = EventPriority . MONITOR ) public void onItemHeldChange ( PlayerItemHeldEvent event ) { final Player p = event . getPlayer ( ) ; final Runnable checker = new Runnable ( ) { public void run ( ) { checkStatus ( p ) ; } } ; if ( checkerHandle != null ) { checkerHandle . cancel ( true ) ; } checkerHandle = scheduler . schedule ( checker , <NUM_LIT> , TimeUnit . MILLISECONDS ) ; } private void checkStatus ( Player player ) { Stick stick = plugin . getStick ( player ) ; if ( plugin . canUse ( player , stick ) && ( stick . doAnnounce ( ) || stick . isDebug ( ) ) ) { MessageUtils . send ( player , ChatColor . GREEN , "<STR_LIT>" + plugin . getName ( ) ) ; } } @ EventHandler ( priority = EventPriority . HIGHEST ) public void onPlayerInteract ( PlayerInteractEvent event ) { if ( event . getAction ( ) == Action . PHYSICAL ) { return ; } int mode = <NUM_LIT:0> ; Player player = event . getPlayer ( ) ; Stick stick = null ; stick = plugin . getStick ( player ) ; mode = stick . getMode ( ) ; if ( event . getAction ( ) == Action . LEFT_CLICK_BLOCK ) { if ( player . getGameMode ( ) == GameMode . CREATIVE && stick . isEnabled ( ) ) { event . setCancelled ( true ) ; } return ; } if ( event . getAction ( ) == Action . RIGHT_CLICK_BLOCK && stick . isThrowBuild ( ) && player . getItemInHand ( ) . getType ( ) != stick . getTool ( ) ) { return ; } if ( ! stick . doRightClickModes ( ) && ( event . getAction ( ) == Action . RIGHT_CLICK_AIR || event . getAction ( ) == Action . RIGHT_CLICK_BLOCK ) ) { mode = Stick . REMOVE_MODE ; } if ( plugin . canUse ( player , stick , mode ) ) { event . setCancelled ( true ) ; List < Block > targetBlocks = player . getLastTwoTargetBlocks ( stick . getIgnore ( ) , stick . getDistance ( ) ) ; if ( targetBlocks . size ( ) != <NUM_LIT:2> ) { plugin . log ( Level . WARNING , "<STR_LIT>" ) ; return ; } Block targetedBlock = null ; Block placedAgainstBlock = null ; Item item = stick . getItem ( ) ; if ( ! item . isBlock ( ) ) { item = MaterialUtils . getPlaceableMaterial ( item ) ; if ( ! item . isBlock ( ) ) { if ( ! stick . isThrowBuild ( ) ) { MessageUtils . send ( player , ChatColor . RED , "<STR_LIT>" ) ; } else { event . setCancelled ( false ) ; } return ; } } BlockEvent actionEvent = null ; if ( mode == Stick . REPLACE_MODE || mode == Stick . REMOVE_MODE ) { targetedBlock = targetBlocks . get ( <NUM_LIT:1> ) ; placedAgainstBlock = targetBlocks . get ( <NUM_LIT:0> ) ; } else if ( mode == Stick . BUILD_MODE ) { targetedBlock = targetBlocks . get ( <NUM_LIT:0> ) ; placedAgainstBlock = targetBlocks . get ( <NUM_LIT:1> ) ; } if ( targetedBlock . getLocation ( ) . getBlockY ( ) == <NUM_LIT:0> && stick . doProtectBottom ( ) ) { plugin . log ( Level . WARNING , "<STR_LIT>" + player . getDisplayName ( ) + "<STR_LIT>" ) ; return ; } if ( LocationUtil . isSameLocation ( player , targetedBlock ) ) { if ( stick . isDebug ( ) ) { MessageUtils . send ( player , "<STR_LIT>" ) ; } return ; } BlockState after = targetedBlock . getState ( ) ; after . setType ( mode == Stick . REMOVE_MODE ? Material . AIR : item . getMaterial ( ) ) ; MaterialData data = null ; if ( mode == Stick . REMOVE_MODE ) { data = Material . AIR . getNewData ( ( byte ) <NUM_LIT:0> ) ; } else if ( MaterialUtils . isSameMaterial ( item . getMaterial ( ) , Material . LADDER ) ) { BlockFace face = LocationUtil . getFace ( player , targetedBlock ) ; if ( stick . isDebug ( ) ) { MessageUtils . send ( player , "<STR_LIT>" + face + "<STR_LIT>" + player . getEyeLocation ( ) + "<STR_LIT:)>" ) ; } Ladder ladder = new Ladder ( ) ; ladder . setFacingDirection ( face ) ; data = ladder ; } else { data = item . getData ( ) ; } if ( data != null ) after . setData ( data ) ; BlockState before = targetedBlock . getState ( ) ; if ( mode == Stick . REMOVE_MODE ) { stick . setDoItemSwitch ( true ) ; actionEvent = new BlockBreakEvent ( targetedBlock , player ) ; } else if ( MaterialUtils . isSameMaterial ( item . getMaterial ( ) , Material . FIRE ) ) { actionEvent = new BlockIgniteEvent ( targetedBlock , IgniteCause . FLINT_AND_STEEL , player ) ; } else { actionEvent = new BlockPlaceEvent ( after . getBlock ( ) , before , placedAgainstBlock , new ItemStack ( stick . getTool ( ) ) , player , true ) ; } plugin . getServer ( ) . getPluginManager ( ) . callEvent ( actionEvent ) ; if ( ! ( ( Cancellable ) actionEvent ) . isCancelled ( ) ) { plugin . takeAction ( before , after , player ) ; } } } @ EventHandler ( priority = EventPriority . HIGHEST ) public void onPlayerAnimation ( PlayerAnimationEvent event ) { final Player player = event . getPlayer ( ) ; final Stick stick = plugin . getStick ( player ) ; if ( plugin . canUse ( player , stick ) ) { Thread t = new Thread ( new Runnable ( ) { public void run ( ) { try { Thread . sleep ( <NUM_LIT:10> ) ; } catch ( InterruptedException e ) { return ; } long now = new Date ( ) . getTime ( ) ; if ( now - stick . getLastActionTakenAt ( ) > <NUM_LIT> ) { Block target = player . getTargetBlock ( null , <NUM_LIT> ) ; PlayerInteractEvent pie = new PlayerInteractEvent ( player , target . getType ( ) == Material . AIR ? Action . LEFT_CLICK_AIR : Action . LEFT_CLICK_BLOCK , player . getItemInHand ( ) , target , target . getFace ( player . getEyeLocation ( ) . getBlock ( ) ) ) ; onPlayerInteract ( pie ) ; } } } ) ; t . setDaemon ( true ) ; t . start ( ) ; } } } </s>
|
<s> package com . iminurnetz . bukkit . plugin . creativestick ; import java . io . File ; import java . io . IOException ; public class Misc { public static Boolean arguments ( String [ ] array , int amount ) { return Boolean . valueOf ( array . length < amount + <NUM_LIT:2> ) ; } public static Boolean is ( String text , String against ) { return Boolean . valueOf ( text . equalsIgnoreCase ( against ) ) ; } public static Boolean isEither ( String text , String against , String or ) { return Boolean . valueOf ( ( text . equalsIgnoreCase ( against ) ) || ( text . equalsIgnoreCase ( or ) ) ) ; } public static String formatCurrency ( int Balance , String currency ) { return insertCommas ( String . valueOf ( Balance ) ) + "<STR_LIT:U+0020>" + currency ; } public static String insertCommas ( String str ) { if ( str . length ( ) < <NUM_LIT:4> ) { return str ; } return insertCommas ( str . substring ( <NUM_LIT:0> , str . length ( ) - <NUM_LIT:3> ) ) + "<STR_LIT:U+002C>" + str . substring ( str . length ( ) - <NUM_LIT:3> , str . length ( ) ) ; } public static String string ( int i ) { return String . valueOf ( i ) ; } public static boolean validate ( String name ) { return name . matches ( "<STR_LIT>" ) ; } public static String repeat ( char c , int i ) { String tst = "<STR_LIT>" ; for ( int j = <NUM_LIT:0> ; j < i ; j ++ ) { tst = tst + c ; } return tst ; } public static void touch ( File directory , String name ) { try { new File ( directory , name ) . createNewFile ( ) ; } catch ( IOException ex ) { } } public static void touch ( String name ) { try { new File ( name ) . createNewFile ( ) ; } catch ( IOException ex ) { } } public static class string { public static String combine ( int startIndex , String [ ] string , String seperator ) { StringBuilder builder = new StringBuilder ( ) ; for ( int i = startIndex ; i < string . length ; i ++ ) { builder . append ( string [ i ] ) ; builder . append ( seperator ) ; } builder . deleteCharAt ( builder . length ( ) - seperator . length ( ) ) ; return builder . toString ( ) ; } public static String capitalize ( String s ) { return s . toUpperCase ( ) . charAt ( <NUM_LIT:0> ) + s . toLowerCase ( ) . substring ( <NUM_LIT:1> ) ; } public static String camelToPhrase ( String str ) { String newStr = "<STR_LIT>" ; for ( int i = <NUM_LIT:0> ; i < str . length ( ) ; i ++ ) { if ( ( i > <NUM_LIT:0> ) && ( Character . isUpperCase ( str . charAt ( i ) ) ) && ( ! Character . isUpperCase ( str . charAt ( i - <NUM_LIT:1> ) ) ) ) { newStr = newStr + '<CHAR_LIT:U+0020>' ; } newStr = newStr + str . charAt ( i ) ; } return newStr ; } } } </s>
|
<s> package com . iminurnetz . bukkit . plugin . creativestick ; import java . util . ArrayList ; import java . util . HashMap ; import java . util . List ; import java . util . Vector ; import org . bukkit . ChatColor ; import org . bukkit . GameMode ; import org . bukkit . Material ; import org . bukkit . Server ; import org . bukkit . block . Block ; import org . bukkit . block . BlockState ; import org . bukkit . command . Command ; import org . bukkit . command . CommandSender ; import org . bukkit . entity . Player ; import org . bukkit . event . Event ; import org . bukkit . event . Listener ; import org . bukkit . inventory . ItemStack ; import org . bukkit . material . MaterialData ; import org . bukkit . plugin . PluginManager ; import com . iminurnetz . bukkit . plugin . BukkitPlugin ; import com . iminurnetz . bukkit . plugin . util . MessageUtils ; import com . iminurnetz . bukkit . util . InventoryUtil ; import com . iminurnetz . bukkit . util . Item ; import com . iminurnetz . bukkit . util . MaterialUtils ; import com . iminurnetz . util . PersistentProperty ; import com . iminurnetz . util . StringUtils ; public class CSPlugin extends BukkitPlugin { public static ArrayList < Player > drop = new ArrayList < Player > ( ) ; public static CSPermissionHandler permissionHandler ; protected static Server server ; public static PersistentProperty settings ; private static HashMap < Player , Stick > sticks = new HashMap < Player , Stick > ( ) ; protected CSConfigurationService configLoader ; private final Listener playerListener = new CSPlayerListener ( this ) ; public int MIN_SERVER_VERSION = <NUM_LIT> ; public int getMinimumServerVersion ( ) { return this . MIN_SERVER_VERSION ; } public int getMaximumServerVersion ( ) { return this . MAX_SERVER_VERSION ; } public boolean canUse ( Player player , Stick stick ) { return canUse ( player , stick , stick . getMode ( ) ) ; } public boolean canUse ( Player player , Stick stick , int mode ) { if ( configLoader . useBlockSpawnPermission ( ) && ! permissionHandler . canSpawnBlocks ( player ) && mode != Stick . REMOVE_MODE && ! InventoryUtil . hasItem ( player , stick . getItem ( ) ) ) { return false ; } return ( ( player . getItemInHand ( ) . getType ( ) == stick . getTool ( ) || stick . isThrowBuild ( ) ) && stick . isEnabled ( ) && permissionHandler . canUse ( player ) ) ; } private void checkForTool ( Player player , Stick stick ) { if ( stick . isEnabled ( ) && permissionHandler . canUse ( player ) && ! stick . isThrowBuild ( ) ) { if ( ! player . getInventory ( ) . contains ( stick . getTool ( ) ) ) { InventoryUtil . giveItems ( player , stick . getTool ( ) , player . getInventory ( ) . getHeldItemSlot ( ) ) ; if ( stick . isDebug ( ) ) { MessageUtils . send ( player , "<STR_LIT>" + MaterialUtils . getFormattedName ( stick . getTool ( ) ) + "<STR_LIT>" + getName ( ) ) ; } } InventoryUtil . switchToItems ( player , stick . getTool ( ) ) ; } } private boolean checkOptionalItemSwitch ( Player player , String item , Stick stick ) { if ( StringUtils . isEmpty ( item ) ) { return true ; } Item i = null ; try { i = new Item ( item ) ; stick . setItem ( i ) ; return true ; } catch ( InstantiationException e ) { } MessageUtils . send ( player , ChatColor . RED , "<STR_LIT>" ) ; String match ; List < Material > items = MaterialUtils . getMatchingMaterials ( item ) ; if ( items . size ( ) > <NUM_LIT:1> ) match = MaterialUtils . getFormattedNameList ( items ) . toString ( ) ; else match = "<STR_LIT>" ; MessageUtils . send ( player , "<STR_LIT:'>" + item + "<STR_LIT>" + match ) ; return false ; } public boolean doConfig ( Player player , Stick stick , String [ ] originalArgs ) { if ( originalArgs . length < <NUM_LIT:2> ) { MessageUtils . send ( player , stick . showSettings ( ) ) ; return true ; } String param = originalArgs [ <NUM_LIT:1> ] ; if ( ! permissionHandler . canConfigure ( player , param ) ) { MessageUtils . send ( player , CreativeStickCommand . CONFIG . showAccessDenied ( ) ) ; return true ; } String value = StringUtils . join ( "<STR_LIT:U+0020>" , originalArgs , <NUM_LIT:2> ) ; if ( stick . isDebug ( ) ) { MessageUtils . send ( player , "<STR_LIT>" + value ) ; } if ( commandEquals ( param , "<STR_LIT>" ) ) { int distance = stick . getDistance ( ) ; try { distance = Integer . valueOf ( value ) . intValue ( ) ; } catch ( Exception e ) { MessageUtils . send ( player , ChatColor . RED , "<STR_LIT>" ) ; return false ; } if ( distance != stick . getDistance ( ) ) { stick . setDistance ( distance ) ; MessageUtils . send ( player , "<STR_LIT>" + distance + "<STR_LIT:.>" ) ; } return true ; } if ( commandEquals ( param , "<STR_LIT>" ) ) { if ( ! stick . setTool ( value ) ) { MessageUtils . send ( player , ChatColor . RED , "<STR_LIT>" ) ; return false ; } MessageUtils . send ( player , "<STR_LIT>" + stick . getToolName ( ) + "<STR_LIT:.>" ) ; return true ; } if ( commandEquals ( param , "<STR_LIT>" ) ) { boolean protectBottom = StringUtils . isTrue ( value ) ; stick . doProtectBottom ( protectBottom ) ; if ( protectBottom ) MessageUtils . send ( player , "<STR_LIT>" ) ; else MessageUtils . send ( player , "<STR_LIT>" ) ; return true ; } if ( commandEquals ( param , "<STR_LIT>" ) ) { boolean naturalDrops = StringUtils . isTrue ( value ) ; stick . setNaturalDrops ( naturalDrops ) ; if ( naturalDrops ) MessageUtils . send ( player , "<STR_LIT>" ) ; else MessageUtils . send ( player , "<STR_LIT>" ) ; return true ; } if ( commandEquals ( param , "<STR_LIT>" ) ) { boolean doRightClickModes = StringUtils . isTrue ( value ) ; stick . setRightClickModes ( doRightClickModes ) ; if ( doRightClickModes ) MessageUtils . send ( player , "<STR_LIT>" ) ; else MessageUtils . send ( player , "<STR_LIT>" ) ; return true ; } if ( commandEquals ( param , "<STR_LIT>" ) ) { boolean doRightClickSwitch = StringUtils . isTrue ( value ) ; stick . setRightClickSwitch ( doRightClickSwitch ) ; if ( doRightClickSwitch ) MessageUtils . send ( player , "<STR_LIT>" ) ; else MessageUtils . send ( player , "<STR_LIT>" ) ; return true ; } if ( commandEquals ( param , "<STR_LIT>" ) ) { int undo ; try { undo = Integer . valueOf ( value ) . intValue ( ) ; } catch ( NumberFormatException e ) { MessageUtils . send ( player , ChatColor . RED , "<STR_LIT>" ) ; return false ; } stick . setUndoAmount ( undo ) ; MessageUtils . send ( player , "<STR_LIT>" + undo ) ; return true ; } if ( commandEquals ( param , "<STR_LIT>" ) ) { boolean doDebug = StringUtils . isTrue ( value ) ; stick . setDebug ( doDebug ) ; if ( doDebug ) MessageUtils . send ( player , "<STR_LIT>" ) ; else MessageUtils . send ( player , "<STR_LIT>" ) ; return true ; } if ( commandEquals ( param , "<STR_LIT>" ) ) { boolean announce = StringUtils . isTrue ( value ) ; stick . setAnnounce ( announce ) ; if ( announce ) MessageUtils . send ( player , "<STR_LIT>" ) ; else MessageUtils . send ( player , "<STR_LIT>" ) ; return true ; } if ( commandEquals ( param , "<STR_LIT>" ) ) { boolean throwBuild = StringUtils . isTrue ( value ) ; stick . setThrowBuild ( throwBuild ) ; if ( throwBuild ) { MessageUtils . send ( player , "<STR_LIT>" ) ; } else { MessageUtils . send ( player , "<STR_LIT>" ) ; } return true ; } return false ; } private boolean commandEquals ( String param , String string ) { if ( ( param == null && string != null ) || ( param != null && string == null ) ) { return false ; } else if ( param == null ) { return true ; } String cmd = string . toLowerCase ( ) ; String abbr = cmd . substring ( <NUM_LIT:0> , <NUM_LIT:1> ) ; int n = cmd . indexOf ( '<CHAR_LIT:->' ) ; while ( n != - <NUM_LIT:1> ) { abbr += cmd . substring ( n + <NUM_LIT:1> , n + <NUM_LIT:2> ) ; n = cmd . indexOf ( '<CHAR_LIT:->' , n + <NUM_LIT:1> ) ; } return ( param . equalsIgnoreCase ( cmd ) || param . equalsIgnoreCase ( abbr ) ) ; } public void doIgnore ( Player player , Stick stick , String [ ] originalArgs ) { if ( originalArgs . length == <NUM_LIT:1> ) { MessageUtils . send ( player , ChatColor . RED , "<STR_LIT>" + CreativeStickCommand . IGNORE . toString ( ) ) ; return ; } String value = StringUtils . join ( "<STR_LIT:U+0020>" , originalArgs , <NUM_LIT:1> ) ; String [ ] args = value . split ( "<STR_LIT:U+002C>" ) ; for ( String arg : args ) { if ( arg . startsWith ( "<STR_LIT:+>" ) ) { stick . ignore ( MaterialUtils . getMaterial ( arg . substring ( <NUM_LIT:1> ) ) ) ; } else if ( arg . startsWith ( "<STR_LIT:->" ) ) { stick . unignore ( MaterialUtils . getMaterial ( arg . substring ( <NUM_LIT:1> ) ) ) ; } else { stick . onlyIgnore ( MaterialUtils . getMaterial ( arg ) ) ; } } MessageUtils . send ( player , "<STR_LIT>" + MaterialUtils . getFormattedNameList ( stick . getIgnore ( ) ) ) ; } public int doUndo ( Player player , Stick stick , int amount ) { if ( ! permissionHandler . hasPermission ( player , CreativeStickCommand . UNDO . getPermission ( ) ) ) return - <NUM_LIT:1> ; Vector < BlockState > blocks = stick . getBlocks ( ) ; int blocksRemoved = <NUM_LIT:0> ; int lastIndex = blocks . size ( ) ; int currentIndex = lastIndex - <NUM_LIT:1> ; for ( blocksRemoved = <NUM_LIT:0> ; blocksRemoved < ( lastIndex > amount ? amount : lastIndex ) ; blocksRemoved ++ ) { BlockState blockState = blocks . remove ( currentIndex -- ) ; Block block = player . getWorld ( ) . getBlockAt ( blockState . getX ( ) , blockState . getY ( ) , blockState . getZ ( ) ) ; if ( configLoader . useBlockSpawnPermission ( ) && ! permissionHandler . canSpawnBlocks ( player ) ) { InventoryUtil . giveItems ( player , new ItemStack ( block . getType ( ) , <NUM_LIT:1> , ( short ) <NUM_LIT:0> , block . getData ( ) ) ) ; } block . setTypeId ( blockState . getTypeId ( ) ) ; block . setData ( blockState . getRawData ( ) ) ; } player . updateInventory ( ) ; blocks . trimToSize ( ) ; return blocksRemoved ; } public void doUndo ( Player player , Stick stick , String what ) { int amount = stick . getUndoAmount ( ) ; boolean all = false ; if ( what != "<STR_LIT>" ) { if ( what . equalsIgnoreCase ( "<STR_LIT:all>" ) ) all = true ; else { try { amount = Integer . valueOf ( what ) . intValue ( ) ; } catch ( NumberFormatException e ) { MessageUtils . send ( player , ChatColor . RED , "<STR_LIT>" + amount + "<STR_LIT:!>" ) ; } if ( amount <= <NUM_LIT:0> ) return ; } } if ( all ) amount = stick . getBlocks ( ) . size ( ) ; if ( amount == <NUM_LIT:0> ) { MessageUtils . send ( player , "<STR_LIT>" ) ; } else { int blocksRemoved = doUndo ( player , stick , amount ) ; if ( blocksRemoved > <NUM_LIT:0> ) { if ( all ) MessageUtils . send ( player , "<STR_LIT>" ) ; else MessageUtils . send ( player , "<STR_LIT>" + blocksRemoved + "<STR_LIT>" ) ; } else if ( blocksRemoved < <NUM_LIT:0> ) { MessageUtils . send ( player , ChatColor . RED , "<STR_LIT>" ) ; } } } private String getItemFromArgs ( String [ ] args ) { if ( args . length <= <NUM_LIT:1> ) { return "<STR_LIT>" ; } StringBuilder name = new StringBuilder ( ) ; for ( int n = <NUM_LIT:1> ; n < args . length ; n ++ ) { int i = args [ n ] . indexOf ( '<CHAR_LIT:U+002C>' ) ; if ( i != - <NUM_LIT:1> ) { } else { name . append ( args [ n ] ) ; name . append ( "<STR_LIT:U+0020>" ) ; } } return name . toString ( ) . trim ( ) ; } public Stick getStick ( Player player ) { Stick stick ; if ( ! sticks . containsKey ( player ) ) { stick = new Stick ( configLoader ) ; sticks . put ( player , stick ) ; checkForTool ( player , stick ) ; } stick = sticks . get ( player ) ; if ( stick . isThrowBuild ( ) ) { stick . setItem ( new Item ( player . getItemInHand ( ) ) ) ; } return stick ; } private void giveItems ( Player player , BlockState state ) { Stick stick = getStick ( player ) ; List < ItemStack > items ; if ( stick . isDrops ( ) ) { if ( stick . doesNaturalDrops ( ) ) { items = MaterialUtils . getDroppedMaterial ( state ) ; } else { items = new ArrayList < ItemStack > ( ) ; items . add ( new ItemStack ( state . getTypeId ( ) , <NUM_LIT:1> , ( short ) <NUM_LIT:0> , state . getRawData ( ) ) ) ; } InventoryUtil . giveItems ( player , items ) ; for ( ItemStack is : items ) { if ( isDebug ( player ) ) { log ( player . getName ( ) + "<STR_LIT>" + is . getAmount ( ) + "<STR_LIT:U+0020>" + MaterialUtils . getFormattedName ( is ) ) ; } } } } public boolean isDebug ( Player player ) { return getStick ( player ) . isDebug ( ) ; } @ Override public boolean onCommand ( CommandSender sender , Command command , String commandLabel , String [ ] args ) { Player player = null ; if ( sender instanceof Player ) { player = ( Player ) sender ; } else { sender . sendMessage ( "<STR_LIT>" ) ; return false ; } Stick stick = null ; String c = args . length >= <NUM_LIT:1> ? args [ <NUM_LIT:0> ] : "<STR_LIT>" ; CreativeStickCommand cmd = CreativeStickCommand . getCommand ( c ) ; if ( ! permissionHandler . hasPermission ( player , cmd . getPermission ( ) ) ) { MessageUtils . send ( player , cmd . showAccessDenied ( ) ) ; return true ; } stick = getStick ( player ) ; boolean success = true ; switch ( cmd ) { case HELP : MessageUtils . send ( player , CreativeStickCommand . getHelp ( player , command ) ) ; break ; case VERSION : StringBuilder msg = new StringBuilder ( getName ( ) ) ; msg . append ( "<STR_LIT>" ) ; msg . append ( getVersion ( ) ) ; msg . append ( "<STR_LIT>" ) ; msg . append ( getDescription ( ) . getWebsite ( ) ) ; msg . append ( "<STR_LIT>" ) ; for ( String author : getDescription ( ) . getAuthors ( ) ) { msg . append ( author ) ; msg . append ( "<STR_LIT:U+002CU+0020>" ) ; } MessageUtils . send ( player , msg . substring ( <NUM_LIT:0> , msg . length ( ) - <NUM_LIT:2> ) ) ; break ; case TOGGLE_DROPS : stick . toggleDrops ( ) ; MessageUtils . send ( player , "<STR_LIT>" + ( stick . isDrops ( ) ? "<STR_LIT>" : "<STR_LIT>" ) + "<STR_LIT:.>" ) ; break ; case TOGGLE : toggle ( player , stick ) ; break ; case TOGGLE_MODE : if ( ! stick . isEnabled ( ) ) { toggle ( player , stick ) ; } success = toggleMode ( player , stick , getItemFromArgs ( args ) ) ; break ; case BUILD : if ( ! stick . isEnabled ( ) ) { toggle ( player , stick ) ; } success = toggleBuild ( player , stick , getItemFromArgs ( args ) ) ; break ; case REPLACE : if ( ! stick . isEnabled ( ) ) { toggle ( player , stick ) ; } success = toggleReplace ( player , stick , getItemFromArgs ( args ) ) ; break ; case IGNORE : doIgnore ( player , stick , args ) ; break ; case UNDO : doUndo ( player , stick , args . length > <NUM_LIT:1> ? args [ <NUM_LIT:1> ] : "<STR_LIT>" ) ; break ; case CONFIG : success = doConfig ( player , stick , args ) ; break ; default : success = false ; } if ( ! success ) MessageUtils . send ( player , ChatColor . RED + "<STR_LIT>" + CreativeStickCommand . CREATIVE_STICK_COMMAND + "<STR_LIT:U+0020>" + cmd ) ; return true ; } @ Override public void enablePlugin ( ) { setup ( ) ; registerEvents ( ) ; } private void registerEvents ( ) { PluginManager pm = server . getPluginManager ( ) ; pm . registerEvents ( playerListener , this ) ; } public void sendToggleMessage ( Player player , Stick stick ) { StringBuilder msg = new StringBuilder ( ) . append ( "<STR_LIT>" ) . append ( ChatColor . RED ) ; msg . append ( stick . getModeAsString ( ) ) . append ( ChatColor . WHITE ) ; if ( stick . getMode ( ) != Stick . REMOVE_MODE ) msg . append ( "<STR_LIT>" ) . append ( stick . getItemName ( ) ) . append ( "<STR_LIT:.>" ) ; MessageUtils . send ( player , msg . toString ( ) ) ; } public void setup ( ) { server = getServer ( ) ; configLoader = new CSConfigurationService ( this ) ; permissionHandler = configLoader . getPermissionHandler ( ) ; } public void takeAction ( BlockState before , BlockState after , Player player ) { Stick stick = getStick ( player ) ; if ( stick . doItemSwitch ( ) && stick . setItem ( before . getType ( ) , before . getData ( ) ) ) { MessageUtils . send ( player , "<STR_LIT>" + MaterialUtils . getFormattedName ( stick . getItem ( ) ) ) ; } Block target = after . getBlock ( ) ; synchronized ( target ) { target . setType ( Material . AIR ) ; target . setData ( ( byte ) <NUM_LIT:0> ) ; target . setType ( after . getType ( ) ) ; if ( configLoader . useBlockSpawnPermission ( ) && target . getType ( ) != Material . AIR && ! permissionHandler . canSpawnBlocks ( player ) ) { InventoryUtil . remove ( player , stick . getItem ( ) . getStack ( ) ) ; } MaterialData data = after . getData ( ) ; if ( data != null ) { target . setData ( data . getData ( ) ) ; } } if ( stick . isDebug ( ) ) { log ( player . getDisplayName ( ) + "<STR_LIT>" + MaterialUtils . getFormattedName ( before . getType ( ) ) + "<STR_LIT:U+0020toU+0020>" + MaterialUtils . getFormattedName ( after . getType ( ) ) ) ; } stick . addBlock ( before ) ; if ( ! MaterialUtils . isSameMaterial ( before . getType ( ) , Material . AIR ) && player . getGameMode ( ) != GameMode . CREATIVE ) { giveItems ( player , before ) ; } } public void toggle ( Player player , Stick stick ) { stick . toggle ( ) ; MessageUtils . send ( player , getName ( ) + "<STR_LIT>" + ( stick . isEnabled ( ) ? "<STR_LIT>" : "<STR_LIT>" ) + "<STR_LIT:.>" ) ; checkForTool ( player , stick ) ; } public boolean toggleBuild ( Player player , Stick stick , String item ) { if ( ! permissionHandler . hasPermission ( player , CreativeStickCommand . BUILD . getPermission ( ) ) ) return false ; if ( ! checkOptionalItemSwitch ( player , item , stick ) ) return false ; if ( stick . getItem ( ) == null ) { MessageUtils . send ( player , "<STR_LIT>" ) ; return false ; } else { stick . setMode ( <NUM_LIT:2> ) ; sendToggleMessage ( player , stick ) ; } return true ; } public boolean toggleMode ( Player player , Stick stick , String item ) { if ( ! permissionHandler . hasPermission ( player , CreativeStickCommand . TOGGLE_MODE . getPermission ( ) ) ) return false ; if ( ! checkOptionalItemSwitch ( player , item , stick ) ) return false ; if ( ! stick . isEnabled ( ) ) { stick . toggle ( ) ; sendToggleMessage ( player , stick ) ; return true ; } else if ( stick . getMode ( ) == Stick . REMOVE_MODE ) { stick . setMode ( Stick . REPLACE_MODE ) ; } else if ( stick . getMode ( ) == Stick . REPLACE_MODE ) { stick . setMode ( Stick . BUILD_MODE ) ; } else { stick . setMode ( Stick . REMOVE_MODE ) ; } sendToggleMessage ( player , stick ) ; return true ; } public boolean toggleReplace ( Player player , Stick stick , String item ) { if ( ! permissionHandler . hasPermission ( player , CreativeStickCommand . REPLACE . getPermission ( ) ) ) return false ; if ( ! checkOptionalItemSwitch ( player , item , stick ) ) return false ; stick . setMode ( <NUM_LIT:1> ) ; sendToggleMessage ( player , stick ) ; return true ; } } </s>
|
<s> package com . iminurnetz . bukkit . plugin . creativestick ; import java . util . Date ; import java . util . HashSet ; import java . util . Vector ; import org . bukkit . Material ; import org . bukkit . block . BlockState ; import org . bukkit . material . MaterialData ; import com . iminurnetz . bukkit . util . Item ; import com . iminurnetz . bukkit . util . MaterialUtils ; public class Stick { public static final int REMOVE_MODE = <NUM_LIT:0> ; public static final int REPLACE_MODE = <NUM_LIT:1> ; public static final int BUILD_MODE = <NUM_LIT:2> ; private int amount = <NUM_LIT:1> ; private int area = <NUM_LIT:0> ; private Vector < BlockState > blocks = new Vector < BlockState > ( ) ; private int distance ; private boolean drops ; private boolean enabled ; private HashSet < Byte > ignore = new HashSet < Byte > ( ) ; private Item item = new Item ( Material . AIR ) ; private int mode = REMOVE_MODE ; private boolean protectBottom ; private boolean rightClickSwitch ; private boolean rightClickModes ; private boolean debug ; private Material tool ; private int undoAmount ; private boolean naturalDrops ; private boolean announce ; private int maxUndos ; private long lastActionTakenAt ; private boolean isThrowBuild ; public Stick ( CSConfigurationService configService ) { this . ignore = configService . getIgnored ( ) ; this . enabled = configService . isEnabled ( ) ; this . drops = configService . doesDrop ( ) ; this . undoAmount = configService . getUndoAmount ( ) ; this . distance = configService . getDistance ( ) ; this . protectBottom = configService . doProtectBottom ( ) ; this . rightClickSwitch = configService . doRightClickSwitch ( ) ; this . rightClickModes = configService . doRightClickModes ( ) ; this . naturalDrops = configService . doesNaturalDrops ( ) ; this . announce = configService . doAnnounce ( ) ; this . setDebug ( configService . isDebug ( ) ) ; this . tool = configService . getTool ( ) ; this . maxUndos = configService . getMaxUndos ( ) ; this . lastActionTakenAt = new Date ( ) . getTime ( ) ; this . isThrowBuild = configService . isThrowBuild ( ) ; } public void addBlock ( BlockState blockState ) { this . lastActionTakenAt = new Date ( ) . getTime ( ) ; this . blocks . add ( blockState ) ; if ( blocks . size ( ) > maxUndos ) { blocks . remove ( <NUM_LIT:0> ) ; } } public boolean doAnnounce ( ) { return announce ; } public boolean doProtectBottom ( ) { return protectBottom ; } public void doProtectBottom ( boolean protectBottom ) { this . protectBottom = protectBottom ; } public int getAmount ( ) { return this . amount ; } public int getArea ( ) { return this . area ; } public Vector < BlockState > getBlocks ( ) { return this . blocks ; } public int getDistance ( ) { return this . distance ; } public HashSet < Byte > getIgnore ( ) { return this . ignore ; } public Item getItem ( ) { return this . item ; } public int getMode ( ) { return this . mode ; } public String getModeAsString ( ) { if ( getItem ( ) . equals ( Material . FLINT_AND_STEEL ) && getMode ( ) != REMOVE_MODE ) { return "<STR_LIT>" ; } return ( getMode ( ) == REMOVE_MODE ? "<STR_LIT>" : ( getMode ( ) == REPLACE_MODE ? "<STR_LIT>" : "<STR_LIT>" ) ) ; } public Material getTool ( ) { return this . tool ; } public int getUndoAmount ( ) { return undoAmount ; } public void ignore ( Material m ) { if ( m == null ) return ; this . ignore . add ( ( byte ) m . getId ( ) ) ; } public boolean isDrops ( ) { return this . drops ; } public boolean isEnabled ( ) { return this . enabled ; } public boolean doRightClickSwitch ( ) { return rightClickSwitch ; } public boolean doRightClickModes ( ) { return rightClickModes ; } public void setAmount ( int amount ) { this . amount = amount ; } public void setAnnounce ( boolean bool ) { this . announce = bool ; } public void setArea ( int area ) { this . area = area ; } public void setDistance ( int distance ) { this . distance = distance ; } public void setDrops ( boolean drops ) { this . drops = drops ; } public void setEnabled ( boolean enabled ) { this . enabled = enabled ; } public boolean setItem ( Material material ) { return setItem ( material , material . getNewData ( ( byte ) <NUM_LIT:0> ) ) ; } public boolean setItem ( Material material , MaterialData data ) { return setItem ( new Item ( material , data ) ) ; } public boolean setItem ( Item item ) { doItemSwitch = false ; if ( ! MaterialUtils . isSameItem ( getItem ( ) , item ) ) { this . item = item ; return true ; } return false ; } public void setMode ( int mode ) { this . mode = mode ; } public void setRightClickSwitch ( boolean rightClickSwitch ) { this . rightClickSwitch = rightClickSwitch ; } public void setRightClickModes ( boolean rightClickModes ) { this . rightClickModes = rightClickModes ; } public boolean setTool ( String item ) { Material m = MaterialUtils . getMaterial ( item ) ; if ( m == null ) { return false ; } this . tool = m ; return true ; } public void setUndoAmount ( int n ) { undoAmount = n ; } public long getLastActionTakenAt ( ) { return lastActionTakenAt ; } public String showSettings ( ) { StringBuilder s = new StringBuilder ( ) ; s . append ( "<STR_LIT>" ) ; s . append ( ( isEnabled ( ) ? "<STR_LIT>" : "<STR_LIT>" ) ) ; s . append ( "<STR_LIT>" ) ; s . append ( "<STR_LIT>" ) ; s . append ( getToolName ( ) ) ; s . append ( "<STR_LIT>" ) ; s . append ( "<STR_LIT>" ) ; s . append ( getModeAsString ( ) ) ; s . append ( "<STR_LIT:n>" ) ; s . append ( "<STR_LIT>" ) ; s . append ( isDrops ( ) ) ; s . append ( "<STR_LIT>" ) ; s . append ( doesNaturalDrops ( ) ? "<STR_LIT>" : "<STR_LIT>" ) ; s . append ( "<STR_LIT:n>" ) ; s . append ( "<STR_LIT>" ) ; s . append ( getUndoAmount ( ) ) ; s . append ( "<STR_LIT>" ) ; s . append ( getBlocks ( ) . size ( ) ) ; s . append ( "<STR_LIT>" ) ; s . append ( "<STR_LIT>" ) ; s . append ( doProtectBottom ( ) ) ; s . append ( "<STR_LIT:n>" ) ; s . append ( "<STR_LIT>" ) ; s . append ( getDistance ( ) ) ; s . append ( "<STR_LIT:n>" ) ; s . append ( "<STR_LIT>" ) ; s . append ( doRightClickSwitch ( ) ) ; s . append ( "<STR_LIT:n>" ) ; s . append ( "<STR_LIT>" ) ; s . append ( doRightClickModes ( ) ) ; s . append ( "<STR_LIT:n>" ) ; s . append ( "<STR_LIT>" ) ; s . append ( doAnnounce ( ) ) ; s . append ( "<STR_LIT:n>" ) ; s . append ( "<STR_LIT>" ) ; s . append ( isDebug ( ) ) ; s . append ( "<STR_LIT:n>" ) ; s . append ( "<STR_LIT>" ) ; s . append ( MaterialUtils . getFormattedNameList ( getIgnore ( ) ) ) ; s . append ( "<STR_LIT:n>" ) ; return s . toString ( ) ; } public void toggle ( ) { this . enabled = ( ! isEnabled ( ) ) ; } public void toggleDrops ( ) { this . drops = ( ! isDrops ( ) ) ; } public void unignore ( Material material ) { if ( material == null ) return ; this . ignore . remove ( ( byte ) material . getId ( ) ) ; } public String getItemName ( ) { return MaterialUtils . getFormattedName ( getItem ( ) ) ; } public String getToolName ( ) { return MaterialUtils . getFormattedName ( getTool ( ) ) ; } public void setDebug ( boolean debug ) { this . debug = debug ; } public boolean isDebug ( ) { return debug ; } public void setNaturalDrops ( boolean b ) { this . naturalDrops = b ; } public boolean doesNaturalDrops ( ) { return naturalDrops ; } private boolean doItemSwitch = false ; public void setDoItemSwitch ( boolean b ) { doItemSwitch = b && doRightClickSwitch ( ) ; } public boolean doItemSwitch ( ) { return doItemSwitch ; } public void onlyIgnore ( Material material ) { if ( material == null ) return ; this . ignore = new HashSet < Byte > ( ) ; ignore ( Material . AIR ) ; ignore ( material ) ; } public void setThrowBuild ( boolean isThrowBuild ) { this . isThrowBuild = isThrowBuild ; } public boolean isThrowBuild ( ) { return isThrowBuild ; } } </s>
|
<s> package com . iminurnetz . bukkit . plugin . creativestick ; import org . bukkit . ChatColor ; import org . bukkit . command . Command ; import org . bukkit . entity . Player ; import com . iminurnetz . util . EnumUtil ; public enum CreativeStickCommand { HELP ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , CSPermissionHandler . CAN_USE_PERMISSION ) , TOGGLE ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , CSPermissionHandler . CAN_USE_PERMISSION ) , TOGGLE_MODE ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , CSPermissionHandler . CAN_USE_PERMISSION ) , BUILD ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , CSPermissionHandler . CAN_USE_PERMISSION ) , REPLACE ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , CSPermissionHandler . CAN_USE_PERMISSION ) , IGNORE ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , CSPermissionHandler . CAN_USE_PERMISSION ) , TOGGLE_DROPS ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , CSPermissionHandler . CAN_USE_PERMISSION ) , UNDO ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , CSPermissionHandler . CAN_USE_PERMISSION ) , CONFIG ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , CSPermissionHandler . CAN_USE_PERMISSION ) , VERSION ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , CSPermissionHandler . CAN_USE_PERMISSION ) ; public static final String CREATIVE_STICK_COMMAND = "<STR_LIT>" ; private String synonym ; private String helpText ; private String parameters ; private String permission ; private CreativeStickCommand ( String synonym , String helpText , String parameters , String permission ) { this . synonym = synonym ; this . helpText = helpText ; this . parameters = parameters ; this . permission = permission ; } private static int longestCmd = <NUM_LIT:0> ; static { for ( CreativeStickCommand cmd : CreativeStickCommand . values ( ) ) CreativeStickCommand . longestCmd = Math . max ( CreativeStickCommand . longestCmd , cmd . name ( ) . length ( ) + cmd . getParameters ( ) . length ( ) + <NUM_LIT:4> ) ; } public String getSynonym ( ) { return synonym ; } public String getHelpText ( ) { return helpText ; } public String getParameters ( ) { return parameters ; } public String getPermission ( ) { return permission ; } @ Override public String toString ( ) { String param = "<STR_LIT:U+0020>" + getParameters ( ) ; if ( param . length ( ) == <NUM_LIT:1> ) param = "<STR_LIT>" ; String cmd = getSynonym ( ) + "<STR_LIT:|>" + EnumUtil . getSerializationName ( this ) + param ; return cmd + "<STR_LIT:U+0020-U+0020>" + getHelpText ( ) ; } public static CreativeStickCommand getCommand ( String command ) { for ( CreativeStickCommand cmd : CreativeStickCommand . values ( ) ) { if ( EnumUtil . getSerializationName ( cmd ) . equalsIgnoreCase ( command ) || cmd . getSynonym ( ) . equalsIgnoreCase ( command ) ) return cmd ; } return CreativeStickCommand . HELP ; } public static String getHelp ( Player player , Command command ) { StringBuilder help = new StringBuilder ( ) ; help . append ( "<STR_LIT>" ) ; help . append ( command . getName ( ) ) ; for ( String alias : command . getAliases ( ) ) { help . append ( "<STR_LIT:|>" ) ; help . append ( alias ) ; } help . append ( "<STR_LIT>" ) ; for ( CreativeStickCommand cmd : CreativeStickCommand . values ( ) ) { if ( CSPlugin . permissionHandler . hasPermission ( player , cmd . getPermission ( ) ) ) { help . append ( "<STR_LIT>" + cmd ) ; help . append ( "<STR_LIT:n>" ) ; } } if ( help . length ( ) == <NUM_LIT:0> ) help . append ( "<STR_LIT>" ) ; return help . toString ( ) ; } public String showAccessDenied ( ) { return ChatColor . RED + "<STR_LIT:/>" + CREATIVE_STICK_COMMAND + "<STR_LIT:U+0020>" + EnumUtil . getSerializationName ( this ) + "<STR_LIT>" ; } } </s>
|
<s> package com . iminurnetz . bukkit . plugin . creativestick ; import java . util . ArrayList ; import java . util . HashMap ; import org . bukkit . GameMode ; import org . bukkit . entity . Player ; import com . iminurnetz . bukkit . permissions . DefaultPermissions ; import com . iminurnetz . bukkit . permissions . PermissionHandler ; import com . iminurnetz . bukkit . permissions . PermissionHandlerService ; import com . iminurnetz . bukkit . plugin . BukkitPlugin ; public class CSPermissionHandler implements PermissionHandler { public static final String CAN_USE_PERMISSION = "<STR_LIT>" ; public static final String CAN_CONFIGURE_PERMISSION = "<STR_LIT>" ; public static final String CAN_DO_EVERYTHING = "<STR_LIT>" ; private static final String CAN_SPAWN_BLOCKS = "<STR_LIT>" ; private static HashMap < String , ArrayList < String > > permissions = new HashMap < String , ArrayList < String > > ( ) ; private PermissionHandler permissionHandler ; private boolean useOwnPermissions = false ; private boolean enableOps = CSConfigurationService . ALLOW_OPS ; protected CSPermissionHandler ( BukkitPlugin plugin , boolean enableOps ) { permissionHandler = PermissionHandlerService . getHandler ( plugin ) ; if ( permissionHandler instanceof DefaultPermissions ) { ( ( DefaultPermissions ) permissionHandler ) . enableOps ( enableOps ) ; useOwnPermissions = true ; } } protected boolean usesOwnPermissions ( ) { return useOwnPermissions ; } protected void addPermission ( String player , String permission ) { ArrayList < String > perms = permissions . get ( player ) ; if ( perms == null ) perms = new ArrayList < String > ( ) ; if ( permission . equals ( CAN_DO_EVERYTHING ) ) perms . removeAll ( null ) ; if ( ! perms . contains ( permission ) && ! perms . contains ( CAN_DO_EVERYTHING ) ) perms . add ( permission ) ; permissions . put ( player , perms ) ; } public boolean permission ( Player player , String permission ) { String name = player . getName ( ) ; if ( ! permissions . containsKey ( name ) ) { return false ; } return permissions . get ( name ) . contains ( permission ) || permissions . get ( name ) . contains ( CAN_DO_EVERYTHING ) ; } public boolean hasPermission ( Player player , String permission ) { if ( enableOps && player . isOp ( ) ) return true ; return usesOwnPermissions ( ) ? permission ( player , permission ) : permissionHandler . hasPermission ( player , permission ) ; } public boolean canUse ( Player player ) { return hasPermission ( player , CAN_USE_PERMISSION ) ; } public boolean canUse ( Player player , CreativeStickCommand command ) { return hasPermission ( player , command . getPermission ( ) ) ; } public boolean canConfigureAll ( Player player ) { return ( hasPermission ( player , CAN_CONFIGURE_PERMISSION ) || hasPermission ( player , CAN_CONFIGURE_PERMISSION + "<STR_LIT>" ) ) ; } public boolean canDoEverything ( Player player ) { return hasPermission ( player , CAN_DO_EVERYTHING ) ; } public boolean canConfigure ( Player player , String param ) { return canConfigureAll ( player ) || hasPermission ( player , CAN_CONFIGURE_PERMISSION + "<STR_LIT:.>" + param . toLowerCase ( ) ) ; } @ Override public String getGroup ( Player player ) { return permissionHandler . getGroup ( player ) ; } @ Override public boolean parentGroupsInclude ( Player player , String group ) { return permissionHandler . parentGroupsInclude ( player , group ) ; } public boolean canSpawnBlocks ( Player player ) { return ( hasPermission ( player , CAN_SPAWN_BLOCKS ) || player . getGameMode ( ) == GameMode . CREATIVE ) ; } } </s>
|
<s> package com . iminurnetz . bukkit . plugin . creativestick . tests ; import junit . framework . TestCase ; import com . iminurnetz . bukkit . plugin . creativestick . CreativeStickCommand ; public class CreativeStickCommandTest extends TestCase { public void testToString ( ) { assertEquals ( "<STR_LIT>" , CreativeStickCommand . VERSION . toString ( ) . replaceAll ( "<STR_LIT>" , "<STR_LIT:U+0020>" ) ) ; } } </s>
|
<s> package com . iminurnetz . bukkit . plugin . creativestick . tests ; import java . io . File ; import java . io . FileNotFoundException ; import java . io . IOException ; import java . net . URISyntaxException ; import java . net . URL ; import junit . framework . TestCase ; import org . bukkit . configuration . InvalidConfigurationException ; import org . bukkit . configuration . file . YamlConfiguration ; import com . iminurnetz . bukkit . plugin . creativestick . CSConfigurationService ; public class CSConfigurationServiceTest extends TestCase { public void testVersion ( ) throws FileNotFoundException , IOException , InvalidConfigurationException , URISyntaxException { URL topDir = getClass ( ) . getResource ( "<STR_LIT:/>" ) ; File configFile = new File ( new File ( topDir . toURI ( ) ) , "<STR_LIT>" ) ; YamlConfiguration config = new YamlConfiguration ( ) ; config . load ( configFile ) ; assertEquals ( config . getDouble ( "<STR_LIT>" , - <NUM_LIT:1> ) , CSConfigurationService . LAST_CHANGED_IN_VERSION ) ; } } </s>
|
<s> package haveric . woolTrees ; import java . io . File ; import java . io . IOException ; import org . bukkit . configuration . file . FileConfiguration ; import org . bukkit . configuration . file . YamlConfiguration ; public class Config { private static WoolTrees plugin ; private static FileConfiguration config ; private static File configFile ; private static FileConfiguration patternConfig ; private static File patternConfigFile ; private static String cfgTree = "<STR_LIT>" ; private static String cfgWool = "<STR_LIT>" ; private static String cfgBig = "<STR_LIT>" ; private static String cfgCost = "<STR_LIT>" ; private static String cfgHeight = "<STR_LIT>" ; private static String cfgLight = "<STR_LIT>" ; private static String cfgPattern = "<STR_LIT>" ; private static String cfgWoolTrunk = "<STR_LIT>" ; private static final double TREE_DEFAULT = <NUM_LIT> ; private static final double WOOL_DEFAULT = <NUM_LIT> ; private static final double BIG_DEFAULT = <NUM_LIT> ; private static final double COST_DEFAULT = <NUM_LIT> ; private static final boolean HEIGHT_CHECK_DEFAULT = true ; private static final int LIGHT_LEVEL_DEFAULT = <NUM_LIT:9> ; private static final boolean PATTERN_TREES_DEFAULT = true ; private static final boolean WOOL_TRUNKS_DEFAULT = true ; public static void init ( WoolTrees wt ) { plugin = wt ; configFile = new File ( plugin . getDataFolder ( ) + "<STR_LIT>" ) ; patternConfigFile = new File ( plugin . getDataFolder ( ) + "<STR_LIT>" ) ; } public static void setupConfig ( ) { config = YamlConfiguration . loadConfiguration ( configFile ) ; String warn = String . format ( "<STR_LIT>" , plugin . getDescription ( ) . getName ( ) ) ; double treeSpawnPercentage = config . getDouble ( cfgTree , TREE_DEFAULT ) ; if ( treeSpawnPercentage < <NUM_LIT:0> ) { config . set ( cfgTree , <NUM_LIT:0.0> ) ; WoolTrees . log . info ( warn + "<STR_LIT>" ) ; } else if ( treeSpawnPercentage > <NUM_LIT:100> ) { config . set ( cfgTree , <NUM_LIT> ) ; WoolTrees . log . info ( warn + "<STR_LIT>" ) ; } else { config . set ( cfgTree , treeSpawnPercentage ) ; } double woolSpawnPercentage = config . getDouble ( cfgWool , WOOL_DEFAULT ) ; if ( woolSpawnPercentage < <NUM_LIT:0> ) { config . set ( cfgWool , <NUM_LIT:0.0> ) ; WoolTrees . log . info ( warn + "<STR_LIT>" ) ; } else if ( woolSpawnPercentage > <NUM_LIT:100> ) { config . set ( cfgWool , <NUM_LIT> ) ; WoolTrees . log . info ( warn + "<STR_LIT>" ) ; } else { config . set ( cfgWool , woolSpawnPercentage ) ; } double bigChance = config . getDouble ( cfgBig , BIG_DEFAULT ) ; if ( bigChance < <NUM_LIT:0> ) { config . set ( cfgBig , <NUM_LIT:0.0> ) ; WoolTrees . log . info ( warn + "<STR_LIT>" ) ; } else if ( bigChance > <NUM_LIT:100> ) { config . set ( cfgBig , <NUM_LIT> ) ; WoolTrees . log . info ( warn + "<STR_LIT>" ) ; } else { config . set ( cfgBig , bigChance ) ; } double cost = config . getDouble ( cfgCost , COST_DEFAULT ) ; if ( cost < <NUM_LIT:0> ) { config . set ( cfgCost , <NUM_LIT:0.0> ) ; WoolTrees . log . info ( warn + "<STR_LIT>" ) ; } else { config . set ( cfgCost , cost ) ; } if ( ! config . isSet ( cfgHeight ) ) { config . set ( cfgHeight , HEIGHT_CHECK_DEFAULT ) ; } int lightLevel = config . getInt ( cfgLight , LIGHT_LEVEL_DEFAULT ) ; if ( lightLevel < <NUM_LIT:0> ) { config . set ( cfgLight , <NUM_LIT:0> ) ; WoolTrees . log . info ( warn + "<STR_LIT>" ) ; } else if ( lightLevel > <NUM_LIT:15> ) { config . set ( cfgLight , <NUM_LIT:15> ) ; WoolTrees . log . info ( warn + "<STR_LIT>" ) ; } else { config . set ( cfgLight , lightLevel ) ; } if ( ! config . isSet ( cfgPattern ) ) { config . set ( cfgPattern , PATTERN_TREES_DEFAULT ) ; } if ( ! config . isSet ( cfgWoolTrunk ) ) { config . set ( cfgWoolTrunk , WOOL_TRUNKS_DEFAULT ) ; } saveConfig ( ) ; } public static void saveConfig ( ) { try { config . save ( configFile ) ; } catch ( IOException e ) { e . printStackTrace ( ) ; } } public static void setupPatternConfig ( ) { patternConfig = YamlConfiguration . loadConfiguration ( patternConfigFile ) ; try { patternConfig . save ( patternConfigFile ) ; } catch ( IOException e ) { e . printStackTrace ( ) ; } } public static void setPattern ( String loc , String colors ) { patternConfig . set ( loc , colors ) ; try { patternConfig . save ( patternConfigFile ) ; } catch ( IOException e ) { e . printStackTrace ( ) ; } } public static String getPattern ( String loc ) { return patternConfig . getString ( loc ) ; } public static double getTree ( ) { return config . getDouble ( cfgTree ) ; } public static double getWool ( ) { return config . getDouble ( cfgWool ) ; } public static double getBig ( ) { return config . getDouble ( cfgBig ) ; } public static double getCost ( ) { return config . getDouble ( cfgCost ) ; } public static boolean isHeightEnabled ( ) { return config . getBoolean ( cfgHeight ) ; } public static int getLight ( ) { return config . getInt ( cfgLight ) ; } public static boolean isPatternEnabled ( ) { return config . getBoolean ( cfgPattern ) ; } public static boolean isWoolTrunksEnabled ( ) { return config . getBoolean ( cfgWoolTrunk ) ; } public static void setHeight ( String height ) { config . set ( cfgHeight , height ) ; } public static void setPatternEnabled ( boolean enabled ) { config . set ( cfgPattern , enabled ) ; } public static void setWoolTrunk ( String woolTrunk ) { config . set ( cfgWoolTrunk , woolTrunk ) ; } public static void setTree ( Double tree ) { config . set ( cfgTree , tree ) ; } public static void setWool ( Double wool ) { config . set ( cfgWool , wool ) ; } public static void setBig ( Double big ) { config . set ( cfgBig , big ) ; } public static void setCost ( Double cost ) { config . set ( cfgCost , cost ) ; } public static void setLight ( int light ) { config . set ( cfgLight , light ) ; } } </s>
|
<s> package haveric . woolTrees ; import java . util . ArrayList ; import org . bukkit . ChatColor ; import org . bukkit . Material ; import org . bukkit . block . Block ; import org . bukkit . command . Command ; import org . bukkit . command . CommandExecutor ; import org . bukkit . command . CommandSender ; import org . bukkit . entity . Player ; public class Commands implements CommandExecutor { private static String cmdMain = "<STR_LIT>" ; private String cmdMainAlt = "<STR_LIT>" ; private String cmdHelp = "<STR_LIT>" ; private String cmdTree = "<STR_LIT>" ; private String cmdWool = "<STR_LIT>" ; private String cmdBig = "<STR_LIT>" ; private String cmdCost = "<STR_LIT>" ; private String cmdCheck = "<STR_LIT>" ; private String cmdLight = "<STR_LIT>" ; private String cmdPattern = "<STR_LIT>" ; private String cmdWoolTrunk = "<STR_LIT>" ; private String cmdHere = "<STR_LIT>" ; private WoolTrees plugin ; public Commands ( WoolTrees wt ) { plugin = wt ; } public boolean onCommand ( CommandSender sender , Command cmd , String commandLabel , String [ ] args ) { ChatColor msgColor = ChatColor . DARK_AQUA ; ChatColor valColor = ChatColor . GOLD ; ChatColor defColor = ChatColor . WHITE ; String wtTitle = msgColor + "<STR_LIT:[>" + ChatColor . GRAY + "<STR_LIT>" + msgColor + "<STR_LIT>" ; if ( sender . isOp ( ) || Perms . hasAdjust ( ( Player ) sender ) ) { if ( commandLabel . equalsIgnoreCase ( cmdMain ) || commandLabel . equalsIgnoreCase ( cmdMainAlt ) ) { if ( args . length == <NUM_LIT:0> || ( args . length == <NUM_LIT:1> && args [ <NUM_LIT:0> ] . equalsIgnoreCase ( cmdHelp ) ) ) { sender . sendMessage ( wtTitle + "<STR_LIT>" + plugin . getDescription ( ) . getVersion ( ) ) ; sender . sendMessage ( "<STR_LIT:/>" + cmdMain + "<STR_LIT:U+0020>" + cmdTree + "<STR_LIT>" + valColor + Config . getTree ( ) + defColor + "<STR_LIT>" + msgColor + "<STR_LIT>" ) ; sender . sendMessage ( "<STR_LIT:/>" + cmdMain + "<STR_LIT:U+0020>" + cmdWool + "<STR_LIT>" + valColor + Config . getWool ( ) + defColor + "<STR_LIT>" + msgColor + "<STR_LIT>" ) ; sender . sendMessage ( "<STR_LIT:/>" + cmdMain + "<STR_LIT:U+0020>" + cmdBig + "<STR_LIT>" + valColor + Config . getBig ( ) + defColor + "<STR_LIT>" + msgColor + "<STR_LIT>" ) ; sender . sendMessage ( "<STR_LIT:/>" + cmdMain + "<STR_LIT:U+0020>" + cmdCost + "<STR_LIT>" + valColor + Config . getCost ( ) + defColor + "<STR_LIT>" + msgColor + "<STR_LIT>" ) ; sender . sendMessage ( "<STR_LIT:/>" + cmdMain + "<STR_LIT:U+0020>" + cmdCheck + "<STR_LIT>" + valColor + Config . isHeightEnabled ( ) + defColor + "<STR_LIT>" + msgColor + "<STR_LIT>" ) ; sender . sendMessage ( "<STR_LIT:/>" + cmdMain + "<STR_LIT:U+0020>" + cmdLight + "<STR_LIT>" + valColor + Config . getLight ( ) + defColor + "<STR_LIT>" + msgColor + "<STR_LIT>" ) ; sender . sendMessage ( "<STR_LIT:/>" + cmdMain + "<STR_LIT:U+0020>" + cmdPattern + "<STR_LIT>" + valColor + Config . isPatternEnabled ( ) + defColor + "<STR_LIT>" + msgColor + "<STR_LIT>" ) ; sender . sendMessage ( "<STR_LIT:/>" + cmdMain + "<STR_LIT:U+0020>" + cmdWoolTrunk + "<STR_LIT>" + valColor + Config . isWoolTrunksEnabled ( ) + defColor + "<STR_LIT>" + msgColor + "<STR_LIT>" ) ; sender . sendMessage ( "<STR_LIT:/>" + cmdMain + "<STR_LIT:U+0020>" + cmdHere + "<STR_LIT>" + defColor + "<STR_LIT:U+0020-U+0020>" + msgColor + "<STR_LIT>" ) ; } else if ( args . length >= <NUM_LIT:1> && args [ <NUM_LIT:0> ] . equalsIgnoreCase ( cmdHere ) ) { boolean big = false ; ArrayList < Integer > colorArray = new ArrayList < Integer > ( ) ; Double val = <NUM_LIT> ; for ( int i = <NUM_LIT:1> ; i < args . length ; i ++ ) { if ( args [ i ] . equalsIgnoreCase ( "<STR_LIT>" ) ) { big = true ; } else if ( args [ i ] . equalsIgnoreCase ( "<STR_LIT>" ) ) { colorArray . add ( <NUM_LIT:0> ) ; } else if ( args [ i ] . equalsIgnoreCase ( "<STR_LIT>" ) ) { colorArray . add ( <NUM_LIT:1> ) ; } else if ( args [ i ] . equalsIgnoreCase ( "<STR_LIT>" ) ) { colorArray . add ( <NUM_LIT:2> ) ; } else if ( args [ i ] . equalsIgnoreCase ( "<STR_LIT>" ) ) { colorArray . add ( <NUM_LIT:3> ) ; } else if ( args [ i ] . equalsIgnoreCase ( "<STR_LIT>" ) ) { colorArray . add ( <NUM_LIT:4> ) ; } else if ( args [ i ] . equalsIgnoreCase ( "<STR_LIT>" ) ) { colorArray . add ( <NUM_LIT:5> ) ; } else if ( args [ i ] . equalsIgnoreCase ( "<STR_LIT>" ) ) { colorArray . add ( <NUM_LIT:6> ) ; } else if ( args [ i ] . equalsIgnoreCase ( "<STR_LIT>" ) || args [ i ] . equalsIgnoreCase ( "<STR_LIT>" ) ) { colorArray . add ( <NUM_LIT:7> ) ; } else if ( args [ i ] . equalsIgnoreCase ( "<STR_LIT>" ) || args [ i ] . equalsIgnoreCase ( "<STR_LIT>" ) ) { colorArray . add ( <NUM_LIT:8> ) ; } else if ( args [ i ] . equalsIgnoreCase ( "<STR_LIT>" ) ) { colorArray . add ( <NUM_LIT:9> ) ; } else if ( args [ i ] . equalsIgnoreCase ( "<STR_LIT>" ) ) { colorArray . add ( <NUM_LIT:10> ) ; } else if ( args [ i ] . equalsIgnoreCase ( "<STR_LIT>" ) ) { colorArray . add ( <NUM_LIT:11> ) ; } else if ( args [ i ] . equalsIgnoreCase ( "<STR_LIT>" ) ) { colorArray . add ( <NUM_LIT:12> ) ; } else if ( args [ i ] . equalsIgnoreCase ( "<STR_LIT>" ) || args [ i ] . equalsIgnoreCase ( "<STR_LIT>" ) ) { colorArray . add ( <NUM_LIT> ) ; } else if ( args [ i ] . equalsIgnoreCase ( "<STR_LIT>" ) ) { colorArray . add ( <NUM_LIT> ) ; } else if ( args [ i ] . equalsIgnoreCase ( "<STR_LIT>" ) ) { colorArray . add ( <NUM_LIT:15> ) ; } else { try { val = Double . parseDouble ( args [ i ] ) ; } catch ( NumberFormatException e ) { val = <NUM_LIT> ; } if ( val < <NUM_LIT:0> || val > <NUM_LIT:100> ) { val = <NUM_LIT> ; } } } if ( colorArray . isEmpty ( ) ) { colorArray . add ( <NUM_LIT:0> ) ; } Block b = ( ( Player ) sender ) . getTargetBlock ( null , <NUM_LIT:100> ) ; if ( b . getType ( ) == Material . AIR ) { sender . sendMessage ( wtTitle + "<STR_LIT>" ) ; } else { if ( big ) { WTPlayerInteract . makeBigTree ( ( ( Player ) sender ) . getWorld ( ) , <NUM_LIT:0> , <NUM_LIT:0> , b . getX ( ) , b . getY ( ) , b . getZ ( ) , colorArray , val ) ; } else { WTPlayerInteract . makeNormalTree ( ( ( Player ) sender ) . getWorld ( ) , <NUM_LIT:0> , <NUM_LIT:0> , b . getX ( ) , b . getY ( ) , b . getZ ( ) , colorArray , val ) ; } } } else if ( args . length == <NUM_LIT:2> ) { Double val ; String msg = "<STR_LIT>" ; String err = "<STR_LIT>" ; if ( args [ <NUM_LIT:1> ] . equalsIgnoreCase ( "<STR_LIT:true>" ) || args [ <NUM_LIT:1> ] . equalsIgnoreCase ( "<STR_LIT:false>" ) ) { val = - <NUM_LIT:1.0> ; } else { try { val = Double . parseDouble ( args [ <NUM_LIT:1> ] ) ; } catch ( NumberFormatException e ) { val = <NUM_LIT:0.0> ; } } if ( val < <NUM_LIT:0> ) { if ( val == - <NUM_LIT:1.0> && args [ <NUM_LIT:0> ] . equalsIgnoreCase ( cmdCheck ) ) { if ( args [ <NUM_LIT:1> ] . equalsIgnoreCase ( "<STR_LIT:true>" ) ) { Config . setHeight ( args [ <NUM_LIT:1> ] ) ; msg = "<STR_LIT>" ; } else if ( args [ <NUM_LIT:1> ] . equalsIgnoreCase ( "<STR_LIT:false>" ) ) { Config . setHeight ( args [ <NUM_LIT:1> ] ) ; msg = "<STR_LIT>" ; } else { err = "<STR_LIT>" ; } } else if ( val == - <NUM_LIT:1.0> && args [ <NUM_LIT:0> ] . equalsIgnoreCase ( cmdPattern ) ) { if ( args [ <NUM_LIT:1> ] . equalsIgnoreCase ( "<STR_LIT:true>" ) ) { Config . setPatternEnabled ( true ) ; msg = "<STR_LIT>" ; } else if ( args [ <NUM_LIT:1> ] . equalsIgnoreCase ( "<STR_LIT:false>" ) ) { Config . setPatternEnabled ( false ) ; msg = "<STR_LIT>" ; } else { err = "<STR_LIT>" ; } } else if ( val == - <NUM_LIT:1.0> && args [ <NUM_LIT:0> ] . equalsIgnoreCase ( cmdWoolTrunk ) ) { if ( args [ <NUM_LIT:1> ] . equalsIgnoreCase ( "<STR_LIT:true>" ) ) { Config . setWoolTrunk ( args [ <NUM_LIT:1> ] ) ; msg = "<STR_LIT>" ; } else if ( args [ <NUM_LIT:1> ] . equalsIgnoreCase ( "<STR_LIT:false>" ) ) { Config . setWoolTrunk ( args [ <NUM_LIT:1> ] ) ; msg = "<STR_LIT>" ; } else { err = "<STR_LIT>" ; } } else { err = "<STR_LIT>" ; } } else if ( args [ <NUM_LIT:0> ] . equalsIgnoreCase ( cmdTree ) ) { if ( val <= <NUM_LIT:100> ) { Config . setTree ( val ) ; msg = "<STR_LIT>" ; } else { err = "<STR_LIT>" ; } } else if ( args [ <NUM_LIT:0> ] . equalsIgnoreCase ( cmdWool ) ) { if ( val <= <NUM_LIT:100> ) { Config . setWool ( val ) ; msg = "<STR_LIT>" ; } else { err = "<STR_LIT>" ; } } else if ( args [ <NUM_LIT:0> ] . equalsIgnoreCase ( cmdBig ) ) { if ( val <= <NUM_LIT:100> ) { Config . setBig ( val ) ; msg = "<STR_LIT>" ; } else { err = "<STR_LIT>" ; } } else if ( args [ <NUM_LIT:0> ] . equalsIgnoreCase ( cmdCost ) ) { Config . setCost ( val ) ; msg = "<STR_LIT>" ; } else if ( args [ <NUM_LIT:0> ] . equalsIgnoreCase ( cmdLight ) ) { if ( val >= <NUM_LIT:0> && val <= <NUM_LIT:15> ) { Config . setLight ( val . intValue ( ) ) ; msg = "<STR_LIT>" ; } else { err = "<STR_LIT>" ; } } Config . saveConfig ( ) ; if ( msg != "<STR_LIT>" ) { if ( val != - <NUM_LIT:1.0> ) { sender . sendMessage ( wtTitle + ChatColor . WHITE + msg + msgColor + val ) ; } else { sender . sendMessage ( wtTitle + ChatColor . WHITE + msg ) ; } } else if ( err != "<STR_LIT>" ) { sender . sendMessage ( wtTitle + ChatColor . RED + err ) ; } } } } else { if ( args . length == <NUM_LIT:0> || ( args . length == <NUM_LIT:1> && args [ <NUM_LIT:0> ] . equalsIgnoreCase ( cmdHelp ) ) ) { sender . sendMessage ( wtTitle + "<STR_LIT>" + plugin . getDescription ( ) . getVersion ( ) ) ; sender . sendMessage ( "<STR_LIT>" ) ; sender . sendMessage ( "<STR_LIT>" + valColor + Config . getTree ( ) + "<STR_LIT>" + defColor + "<STR_LIT>" ) ; sender . sendMessage ( "<STR_LIT>" + valColor + Config . getWool ( ) + "<STR_LIT>" + defColor + "<STR_LIT>" ) ; if ( plugin . getEcon ( ) != null ) { if ( Perms . hasIC ( ( Player ) sender ) ) { sender . sendMessage ( "<STR_LIT>" + valColor + "<STR_LIT>" ) ; } else { sender . sendMessage ( "<STR_LIT>" + valColor + Config . getCost ( ) ) ; } } } else { sender . sendMessage ( wtTitle + ChatColor . RED + "<STR_LIT>" ) ; } } return false ; } public static String getMain ( ) { return cmdMain ; } } </s>
|
<s> package haveric . woolTrees ; import org . bukkit . Material ; import org . bukkit . block . Block ; import org . bukkit . event . EventHandler ; import org . bukkit . event . Listener ; import org . bukkit . event . block . BlockBreakEvent ; public class WTBlockBreak implements Listener { public WTBlockBreak ( WoolTrees wt ) { } @ EventHandler public void onBlockBreak ( BlockBreakEvent event ) { Block block = event . getBlock ( ) ; if ( block . getType ( ) == Material . SAPLING ) { String patternConfig = block . getWorld ( ) . getName ( ) + "<STR_LIT::>" + block . getX ( ) + "<STR_LIT:U+002C>" + block . getY ( ) + "<STR_LIT:U+002C>" + block . getZ ( ) ; if ( Config . getPattern ( patternConfig ) != null ) { Config . setPattern ( patternConfig , null ) ; } } } } </s>
|
<s> package haveric . woolTrees ; import net . milkbowl . vault . permission . Permission ; import org . bukkit . entity . Player ; public class Perms { private static Permission perm = null ; private static String permAdjust = "<STR_LIT>" ; private static String permAdjustAlt = "<STR_LIT>" ; private static String permPlant = "<STR_LIT>" ; private static String permPlantAlt = "<STR_LIT>" ; private static String permIC = "<STR_LIT>" ; private static String permICAlt1 = "<STR_LIT>" ; private static String permICAlt2 = "<STR_LIT>" ; private static String permICAlt3 = "<STR_LIT>" ; public static void setPerm ( Permission newPerm ) { perm = newPerm ; } public static Permission getPerm ( ) { return perm ; } public static boolean permEnabled ( ) { return ( perm != null ) ; } public static boolean hasAdjust ( Player player ) { if ( permEnabled ( ) ) { return perm . has ( player , permAdjust ) || perm . has ( player , permAdjustAlt ) ; } return false ; } public static boolean hasPlant ( Player player ) { if ( permEnabled ( ) ) { return perm . has ( player , permPlant ) || perm . has ( player , permPlantAlt ) ; } return false ; } public static boolean hasIC ( Player player ) { if ( permEnabled ( ) ) { return perm . has ( player , permIC ) || perm . has ( player , permICAlt1 ) || perm . has ( player , permICAlt2 ) || perm . has ( player , permICAlt3 ) ; } return false ; } } </s>
|
<s> package haveric . woolTrees ; import java . util . ArrayList ; import net . milkbowl . vault . economy . Economy ; import org . bukkit . ChatColor ; import org . bukkit . GameMode ; import org . bukkit . Material ; import org . bukkit . World ; import org . bukkit . block . Block ; import org . bukkit . entity . Player ; import org . bukkit . event . EventHandler ; import org . bukkit . event . Listener ; import org . bukkit . event . block . Action ; import org . bukkit . event . player . PlayerInteractEvent ; import org . bukkit . inventory . ItemStack ; import org . bukkit . inventory . PlayerInventory ; public class WTPlayerInteract implements Listener { private static WoolTrees plugin ; public WTPlayerInteract ( WoolTrees wt ) { plugin = wt ; } @ EventHandler public void onPlayerInteract ( PlayerInteractEvent event ) { Economy econ = plugin . getEcon ( ) ; Player player = event . getPlayer ( ) ; PlayerInventory inventory = player . getInventory ( ) ; World world = player . getWorld ( ) ; Block block = event . getClickedBlock ( ) ; ItemStack holding = player . getItemInHand ( ) ; boolean currencyEnabled = true ; boolean patternsEnabled = Config . isPatternEnabled ( ) ; if ( ! Perms . permEnabled ( ) || Perms . hasPlant ( player ) ) { if ( event . getAction ( ) == Action . RIGHT_CLICK_BLOCK && event . getClickedBlock ( ) . getType ( ) == Material . SAPLING ) { int blockX = block . getX ( ) ; int blockY = block . getY ( ) ; int blockZ = block . getZ ( ) ; if ( world . getBlockAt ( blockX , blockY + <NUM_LIT:1> , blockZ ) . getLightLevel ( ) < Config . getLight ( ) ) { player . sendMessage ( ChatColor . RED + "<STR_LIT>" ) ; return ; } if ( econ == null || Perms . hasIC ( player ) ) { currencyEnabled = false ; } else if ( ! econ . has ( player . getName ( ) , Config . getCost ( ) ) ) { player . sendMessage ( ChatColor . RED + "<STR_LIT>" + Config . getCost ( ) ) ; return ; } int color = <NUM_LIT:0> ; if ( holding . getType ( ) == Material . INK_SACK ) { int dur = holding . getDurability ( ) ; if ( dur == <NUM_LIT:15> ) { return ; } color = <NUM_LIT:15> - dur ; } else if ( holding . getType ( ) == Material . SUGAR ) { color = <NUM_LIT:0> ; } else { return ; } boolean bigTree = ( random ( <NUM_LIT:100> ) <= Config . getBig ( ) ) ; if ( ! Config . isHeightEnabled ( ) || ( bigTree && ! treeBlocked ( world , player , blockX , blockY , blockZ , <NUM_LIT:10> ) ) || ( ! bigTree && ! treeBlocked ( world , player , blockX , blockY , blockZ , <NUM_LIT:6> ) ) ) { if ( random ( <NUM_LIT:100> ) <= Config . getTree ( ) ) { int woodType = event . getClickedBlock ( ) . getData ( ) ; if ( patternsEnabled ) { addPattern ( world , color , blockX , blockY , blockZ ) ; } if ( bigTree ) { makeBigTree ( world , woodType , color , blockX , blockY , blockZ , null , - <NUM_LIT:1> ) ; } else { makeNormalTree ( world , woodType , color , blockX , blockY , blockZ , null , - <NUM_LIT:1> ) ; } if ( patternsEnabled ) { Config . setPattern ( world . getName ( ) + "<STR_LIT::>" + blockX + "<STR_LIT:U+002C>" + blockY + "<STR_LIT:U+002C>" + blockZ , null ) ; } if ( currencyEnabled ) { econ . withdrawPlayer ( player . getName ( ) , Config . getCost ( ) ) ; } if ( player . getGameMode ( ) == GameMode . SURVIVAL ) { int amt = holding . getAmount ( ) ; if ( amt > <NUM_LIT:1> ) { holding . setAmount ( -- amt ) ; } else { inventory . setItemInHand ( null ) ; } } } else { addPattern ( world , color , blockX , blockY , blockZ ) ; if ( player . getGameMode ( ) == GameMode . SURVIVAL ) { int amt = holding . getAmount ( ) ; if ( amt > <NUM_LIT:1> ) { holding . setAmount ( -- amt ) ; } else { inventory . setItemInHand ( null ) ; } } } } } } } private void addPattern ( World w , int color , int blockX , int blockY , int blockZ ) { String colors = Config . getPattern ( w . getName ( ) + "<STR_LIT::>" + blockX + "<STR_LIT:U+002C>" + blockY + "<STR_LIT:U+002C>" + blockZ ) ; if ( colors != null && ! colors . contains ( "<STR_LIT:(>" + color + "<STR_LIT:)>" ) ) { colors += "<STR_LIT:(>" + color + "<STR_LIT:)>" ; Config . setPattern ( w . getName ( ) + "<STR_LIT::>" + blockX + "<STR_LIT:U+002C>" + blockY + "<STR_LIT:U+002C>" + blockZ , colors ) ; } else if ( colors == null ) { colors = "<STR_LIT:(>" + color + "<STR_LIT:)>" ; Config . setPattern ( w . getName ( ) + "<STR_LIT::>" + blockX + "<STR_LIT:U+002C>" + blockY + "<STR_LIT:U+002C>" + blockZ , colors ) ; } } private boolean treeBlocked ( World w , Player p , int x , int y , int z , int height ) { boolean blocked = false ; for ( int i = <NUM_LIT:1> ; i < height && ! blocked ; i ++ ) { if ( w . getBlockAt ( x , y + i , z ) . getType ( ) != Material . AIR ) { p . sendMessage ( ChatColor . RED + "<STR_LIT>" + i + "<STR_LIT>" ) ; blocked = true ; } } return blocked ; } public static void makeNormalTree ( World w , int wood , int color , int x , int y , int z , ArrayList < Integer > colorArray , double leaves ) { if ( colorArray == null ) { colorArray = new ArrayList < Integer > ( ) ; if ( Config . isPatternEnabled ( ) ) { String colors = Config . getPattern ( w . getName ( ) + "<STR_LIT::>" + x + "<STR_LIT:U+002C>" + y + "<STR_LIT:U+002C>" + z ) ; for ( int i = - <NUM_LIT:2> ; i <= <NUM_LIT:15> ; i ++ ) { if ( colors . contains ( "<STR_LIT:(>" + i + "<STR_LIT:)>" ) ) { colorArray . add ( i ) ; } } } else { colorArray . add ( color ) ; } } for ( int i = <NUM_LIT:0> ; i < <NUM_LIT:6> ; i ++ ) { setLog ( w . getBlockAt ( x , y + i , z ) , wood ) ; } for ( int i = - <NUM_LIT:2> ; i <= <NUM_LIT:2> ; i ++ ) { for ( int j = - <NUM_LIT:2> ; j <= <NUM_LIT:2> ; j ++ ) { if ( i == <NUM_LIT:0> && j == <NUM_LIT:0> ) { } else { setColoredBlock ( w . getBlockAt ( x + i , y + <NUM_LIT:3> , z + j ) , getRandomColor ( colorArray ) , leaves ) ; setColoredBlock ( w . getBlockAt ( x + i , y + <NUM_LIT:4> , z + j ) , getRandomColor ( colorArray ) , leaves ) ; if ( i != <NUM_LIT:2> && i != - <NUM_LIT:2> && j != <NUM_LIT:2> && j != - <NUM_LIT:2> ) { setColoredBlock ( w . getBlockAt ( x + i , y + <NUM_LIT:5> , z + j ) , getRandomColor ( colorArray ) , leaves ) ; } } } } setColoredBlock ( w . getBlockAt ( x , y + <NUM_LIT:6> , z ) , getRandomColor ( colorArray ) , leaves ) ; } public static void makeBigTree ( World w , int wood , int color , int x , int y , int z , ArrayList < Integer > colorArray , double leaves ) { if ( colorArray == null ) { colorArray = new ArrayList < Integer > ( ) ; if ( Config . isPatternEnabled ( ) ) { String colors = Config . getPattern ( w . getName ( ) + "<STR_LIT::>" + x + "<STR_LIT:U+002C>" + y + "<STR_LIT:U+002C>" + z ) ; for ( int i = - <NUM_LIT:2> ; i <= <NUM_LIT:15> ; i ++ ) { if ( colors . contains ( "<STR_LIT:(>" + i + "<STR_LIT:)>" ) ) { colorArray . add ( i ) ; } } } else { colorArray . add ( color ) ; } } for ( int i = <NUM_LIT:0> ; i < <NUM_LIT:10> ; i ++ ) { setLog ( w . getBlockAt ( x , y + i , z ) , wood ) ; } for ( int i = - <NUM_LIT:2> ; i <= <NUM_LIT:2> ; i ++ ) { for ( int j = - <NUM_LIT:2> ; j <= <NUM_LIT:2> ; j ++ ) { if ( i == <NUM_LIT:0> && j == <NUM_LIT:0> ) { } else { setColoredBlock ( w . getBlockAt ( x + i , y + <NUM_LIT:6> , z + j ) , getRandomColor ( colorArray ) , leaves ) ; setColoredBlock ( w . getBlockAt ( x + i , y + <NUM_LIT:7> , z + j ) , getRandomColor ( colorArray ) , leaves ) ; setColoredBlock ( w . getBlockAt ( x + i , y + <NUM_LIT:8> , z + j ) , getRandomColor ( colorArray ) , leaves ) ; if ( ( i == <NUM_LIT:2> && j == <NUM_LIT:2> ) || ( i == <NUM_LIT:2> && j == - <NUM_LIT:2> ) || ( i == - <NUM_LIT:2> && j == <NUM_LIT:2> ) || ( i == - <NUM_LIT:2> && j == - <NUM_LIT:2> ) ) { } else { setColoredBlock ( w . getBlockAt ( x + i , y + <NUM_LIT:5> , z + j ) , getRandomColor ( colorArray ) , leaves ) ; setColoredBlock ( w . getBlockAt ( x + i , y + <NUM_LIT:9> , z + j ) , getRandomColor ( colorArray ) , leaves ) ; } if ( i != <NUM_LIT:2> && i != - <NUM_LIT:2> && j != <NUM_LIT:2> && j != - <NUM_LIT:2> ) { setColoredBlock ( w . getBlockAt ( x + i , y + <NUM_LIT:4> , z + j ) , getRandomColor ( colorArray ) , leaves ) ; setColoredBlock ( w . getBlockAt ( x + i , y + <NUM_LIT:10> , z + j ) , getRandomColor ( colorArray ) , leaves ) ; } } } } } private static void setColoredBlock ( Block block , int color , double leaves ) { int wool = random ( <NUM_LIT:100> ) ; if ( leaves == - <NUM_LIT:1> ) { if ( wool < Config . getWool ( ) && block . getType ( ) == Material . AIR ) { if ( color == - <NUM_LIT:1> ) { color = ( int ) ( Math . random ( ) * <NUM_LIT:16> ) ; } block . setType ( Material . WOOL ) ; block . setData ( ( byte ) color ) ; } } else if ( wool < leaves && block . getType ( ) == Material . AIR ) { if ( color == - <NUM_LIT:1> ) { color = ( int ) ( Math . random ( ) * <NUM_LIT:16> ) ; } block . setType ( Material . WOOL ) ; block . setData ( ( byte ) color ) ; } } private static void setLog ( Block block , int type ) { if ( block . getType ( ) == Material . AIR || block . getType ( ) == Material . SAPLING ) { if ( Config . isWoolTrunksEnabled ( ) ) { block . setType ( Material . WOOL ) ; block . setData ( ( byte ) <NUM_LIT:12> ) ; } else { block . setType ( Material . LOG ) ; block . setData ( ( byte ) type ) ; } } } private static int random ( int num ) { return <NUM_LIT:1> + ( int ) ( Math . random ( ) * num ) ; } private static int getRandomColor ( ArrayList < Integer > array ) { int color = <NUM_LIT:0> ; if ( array . contains ( <NUM_LIT:0> ) && array . contains ( <NUM_LIT:15> ) && array . contains ( <NUM_LIT:7> ) ) { color = - <NUM_LIT:1> ; } else { color = array . get ( ( int ) ( Math . random ( ) * array . size ( ) ) ) ; } return color ; } } </s>
|
<s> package haveric . woolTrees ; import org . bukkit . Location ; import org . bukkit . event . EventHandler ; import org . bukkit . event . Listener ; import org . bukkit . event . world . StructureGrowEvent ; public class WTStructureGrow implements Listener { public WTStructureGrow ( WoolTrees wt ) { } @ EventHandler public void onTreeGrowth ( StructureGrowEvent event ) { Location l = event . getLocation ( ) ; String patternConfig = event . getWorld ( ) . getName ( ) + "<STR_LIT::>" + l . getBlockX ( ) + "<STR_LIT:U+002C>" + l . getBlockY ( ) + "<STR_LIT:U+002C>" + l . getBlockZ ( ) ; if ( Config . getPattern ( patternConfig ) != null ) { Config . setPattern ( patternConfig , null ) ; } } } </s>
|
<s> package haveric . woolTrees ; import java . util . logging . Logger ; import net . milkbowl . vault . economy . Economy ; import net . milkbowl . vault . permission . Permission ; import org . bukkit . plugin . PluginManager ; import org . bukkit . plugin . RegisteredServiceProvider ; import org . bukkit . plugin . java . JavaPlugin ; public class WoolTrees extends JavaPlugin { static final Logger log = Logger . getLogger ( "<STR_LIT>" ) ; private Commands commands = new Commands ( this ) ; private final WTPlayerInteract playerInteract = new WTPlayerInteract ( this ) ; private final WTBlockBreak blockBreak = new WTBlockBreak ( this ) ; private final WTStructureGrow structureGrow = new WTStructureGrow ( this ) ; private Economy econ = null ; @ Override public void onEnable ( ) { PluginManager pm = getServer ( ) . getPluginManager ( ) ; pm . registerEvents ( playerInteract , this ) ; pm . registerEvents ( blockBreak , this ) ; pm . registerEvents ( structureGrow , this ) ; Config . init ( this ) ; setupVault ( ) ; Config . setupConfig ( ) ; Config . setupPatternConfig ( ) ; getCommand ( Commands . getMain ( ) ) . setExecutor ( commands ) ; } @ Override public void onDisable ( ) { } private void setupVault ( ) { if ( getServer ( ) . getPluginManager ( ) . getPlugin ( "<STR_LIT>" ) == null ) { log . info ( String . format ( "<STR_LIT>" , getDescription ( ) . getName ( ) ) ) ; return ; } RegisteredServiceProvider < Permission > permProvider = getServer ( ) . getServicesManager ( ) . getRegistration ( net . milkbowl . vault . permission . Permission . class ) ; if ( permProvider != null ) { Perms . setPerm ( permProvider . getProvider ( ) ) ; } RegisteredServiceProvider < Economy > econProvider = getServer ( ) . getServicesManager ( ) . getRegistration ( net . milkbowl . vault . economy . Economy . class ) ; if ( econProvider != null ) { econ = econProvider . getProvider ( ) ; } } public Economy getEcon ( ) { return econ ; } } </s>
|
<s> package com . izforge . izpack . maven . natives ; import org . codehaus . mojo . natives . NativeBuildException ; import org . codehaus . mojo . natives . msvc . AbstractMSVCEnvFactory ; import org . codehaus . mojo . natives . msvc . RegQuery ; import org . codehaus . mojo . natives . util . EnvUtil ; import java . io . File ; import java . io . IOException ; import java . util . HashMap ; import java . util . Map ; import java . util . logging . Level ; import java . util . logging . Logger ; public abstract class AbstractMSVC2010EnvFactory extends AbstractMSVCEnvFactory { private static final String VS100COMNTOOLS_ENV_KEY = "<STR_LIT>" ; private Logger log = Logger . getLogger ( AbstractMSVC2010EnvFactory . class . getName ( ) ) ; @ Override public Map getEnvironmentVariables ( ) throws NativeBuildException { return createEnvs ( ) ; } @ SuppressWarnings ( "<STR_LIT:unchecked>" ) protected Map createEnvs ( ) throws NativeBuildException { Map envs = new HashMap ( ) ; File vsCommonToolDir = getCommonToolsDirectory ( ) ; File vsInstallDir = getVisualStudioInstallDirectory ( vsCommonToolDir ) ; if ( ! vsInstallDir . isDirectory ( ) ) { throw new NativeBuildException ( vsInstallDir . getPath ( ) + "<STR_LIT>" ) ; } if ( log . isLoggable ( Level . INFO ) ) { log . info ( "<STR_LIT>" + vsInstallDir ) ; } File vcInstallDir = getVCInstallDir ( vsInstallDir ) ; if ( ! vcInstallDir . isDirectory ( ) ) { throw new NativeBuildException ( vcInstallDir . getPath ( ) + "<STR_LIT>" ) ; } if ( log . isLoggable ( Level . INFO ) ) { log . info ( "<STR_LIT>" + vcInstallDir ) ; } File frameworkDir = getFrameworkDir ( ) ; File windowsSDKDir = getWindowsSDKDir ( ) ; String [ ] frameworkVersion = getFrameworkVersion ( ) ; String currentPathEnv = System . getProperty ( "<STR_LIT>" ) ; String newPathEnv = getPath ( frameworkDir , frameworkVersion , vsCommonToolDir , vcInstallDir , windowsSDKDir ) ; newPathEnv += "<STR_LIT:;>" + currentPathEnv ; envs . put ( "<STR_LIT>" , newPathEnv ) ; String currentIncludeEnv = EnvUtil . getEnv ( "<STR_LIT>" ) ; String newIncludeEnv = vcInstallDir . getPath ( ) + "<STR_LIT>" + vcInstallDir . getPath ( ) + "<STR_LIT>" + windowsSDKDir . getPath ( ) + "<STR_LIT>" + currentIncludeEnv ; envs . put ( "<STR_LIT>" , newIncludeEnv ) ; String currentLibEnv = EnvUtil . getEnv ( "<STR_LIT>" ) ; String newLibEnv = getLibEnv ( vcInstallDir , windowsSDKDir ) + "<STR_LIT:;>" + currentLibEnv ; envs . put ( "<STR_LIT>" , newLibEnv ) ; String currentLibPathEnv = EnvUtil . getEnv ( "<STR_LIT>" ) ; String newLibPathEnv = getLibPathEnv ( frameworkDir , frameworkVersion , vcInstallDir , windowsSDKDir ) + "<STR_LIT:;>" + currentLibPathEnv ; envs . put ( "<STR_LIT>" , newLibPathEnv ) ; if ( log . isLoggable ( Level . INFO ) ) { for ( Object key : envs . keySet ( ) ) { log . log ( Level . INFO , "<STR_LIT>" + key + "<STR_LIT:U+0020=U+0020>" + envs . get ( key ) ) ; } } return envs ; } protected String getPath ( File frameworkDir , String [ ] frameworkVersions , File vsCommonToolDir , File vcInstallDir , File windowsSDKDir ) { StringBuilder result = new StringBuilder ( ) ; result . append ( getFrameworkPaths ( frameworkDir , frameworkVersions ) ) ; result . append ( vsCommonToolDir ) . append ( "<STR_LIT>" ) ; result . append ( vsCommonToolDir ) . append ( '<CHAR_LIT:;>' ) ; result . append ( getVCBinDir ( vcInstallDir ) ) . append ( '<CHAR_LIT:;>' ) ; result . append ( vcInstallDir ) . append ( "<STR_LIT>" ) . append ( "<STR_LIT>" ) ; result . append ( windowsSDKDir ) . append ( "<STR_LIT>" ) ; return result . toString ( ) ; } protected String [ ] getFrameworkVersion ( ) { return new String [ ] { "<STR_LIT>" , "<STR_LIT>" } ; } protected File getWindowsSDKDir ( ) { File windowsSDKDir = new File ( getProgramFiles ( ) , "<STR_LIT>" ) ; if ( ! windowsSDKDir . exists ( ) ) { String value = RegQuery . getValue ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) ; if ( value != null ) { windowsSDKDir = new File ( value ) ; } } return windowsSDKDir ; } protected File getCommonToolsDirectory ( ) throws NativeBuildException { String envValue = System . getenv ( VS100COMNTOOLS_ENV_KEY ) ; if ( envValue == null ) { throw new NativeBuildException ( "<STR_LIT>" + VS100COMNTOOLS_ENV_KEY + "<STR_LIT>" ) ; } return new File ( envValue ) ; } protected File getVisualStudioInstallDirectory ( File commonToolsDir ) throws NativeBuildException { try { return new File ( commonToolsDir , "<STR_LIT>" ) . getCanonicalFile ( ) ; } catch ( IOException e ) { throw new NativeBuildException ( "<STR_LIT>" + commonToolsDir , e ) ; } } protected File getFrameworkDir ( ) { return new File ( getSystemRoot ( ) + "<STR_LIT>" ) ; } protected File getVCInstallDir ( File vsInstallDir ) { return new File ( vsInstallDir . getPath ( ) + "<STR_LIT>" ) ; } protected String getVCBinDir ( File vcInstallDir ) { return vcInstallDir . getPath ( ) + "<STR_LIT>" ; } protected String getLibEnv ( File vcInstallDir , File windowsSDKDir ) { return vcInstallDir . getPath ( ) + "<STR_LIT>" + vcInstallDir . getPath ( ) + "<STR_LIT>" + windowsSDKDir . getPath ( ) + "<STR_LIT>" ; } protected String getLibPathEnv ( File frameworkDir , String [ ] frameworkVersions , File vcInstallDir , File windowsSDKDir ) { StringBuilder result = new StringBuilder ( ) ; result . append ( getFrameworkPaths ( frameworkDir , frameworkVersions ) ) ; result . append ( vcInstallDir . getPath ( ) ) . append ( "<STR_LIT>" ) ; result . append ( vcInstallDir . getPath ( ) ) . append ( "<STR_LIT>" ) ; return result . toString ( ) ; } protected String getFrameworkPaths ( File frameworkDir , String [ ] frameworkVersions ) { StringBuilder result = new StringBuilder ( ) ; for ( String version : frameworkVersions ) { result . append ( frameworkDir ) . append ( '<STR_LIT:\\>' ) . append ( version ) . append ( '<CHAR_LIT:;>' ) ; } return result . toString ( ) ; } } </s>
|
<s> package com . izforge . izpack . maven . natives ; public class MSVC2010x86EnvFactory extends AbstractMSVC2010EnvFactory { } </s>
|
<s> package com . izforge . izpack . maven . natives ; import java . io . File ; public class MSVC2010x64EnvFactory extends AbstractMSVC2010EnvFactory { @ Override protected File getWindowsSDKDir ( ) { File windowsSDKDir = super . getWindowsSDKDir ( ) ; String path = windowsSDKDir . getPath ( ) ; String x86 = getProgramFilesX86 ( ) ; if ( path . startsWith ( x86 ) ) { path = path . substring ( x86 . length ( ) ) ; } File result = new File ( getProgramFiles ( ) , path ) ; if ( ! result . exists ( ) ) { result = windowsSDKDir ; } return result ; } @ Override protected String getLibEnv ( File vcInstallDir , File windowsSDKDir ) { return vcInstallDir . getPath ( ) + "<STR_LIT>" + vcInstallDir . getPath ( ) + "<STR_LIT>" + windowsSDKDir . getPath ( ) + "<STR_LIT>" ; } @ Override protected String getLibPathEnv ( File frameworkDir , String [ ] frameworkVersions , File vcInstallDir , File windowsSDKDir ) { StringBuilder result = new StringBuilder ( ) ; result . append ( getFrameworkPaths ( frameworkDir , frameworkVersions ) ) ; result . append ( vcInstallDir . getPath ( ) ) . append ( "<STR_LIT>" ) ; result . append ( vcInstallDir . getPath ( ) ) . append ( "<STR_LIT>" ) ; result . append ( windowsSDKDir . getPath ( ) ) . append ( "<STR_LIT>" ) ; return result . toString ( ) ; } @ Override protected String getFrameworkPaths ( File frameworkDir , String [ ] frameworkVersions ) { StringBuilder result = new StringBuilder ( ) ; String framework64Dir = frameworkDir + "<STR_LIT>" ; for ( String version : frameworkVersions ) { result . append ( framework64Dir ) . append ( '<STR_LIT:\\>' ) . append ( version ) . append ( '<CHAR_LIT:;>' ) ; result . append ( frameworkDir ) . append ( '<STR_LIT:\\>' ) . append ( version ) . append ( '<CHAR_LIT:;>' ) ; } return result . toString ( ) ; } @ Override protected String getVCBinDir ( File vcInstallDir ) { return vcInstallDir . getPath ( ) + "<STR_LIT>" ; } } </s>
|
<s> package com . izforge . izpack . ant ; import java . util . Enumeration ; import java . util . Hashtable ; import java . util . Properties ; import org . apache . tools . ant . BuildException ; import com . izforge . izpack . compiler . CompilerConfig ; import com . izforge . izpack . compiler . container . CompilerContainer ; import com . izforge . izpack . compiler . data . CompilerData ; import com . izforge . izpack . compiler . data . PropertyManager ; public class IzpackAntRunnable implements Runnable { private final CompilerData compilerData ; private final String input ; private final Properties properties ; private final Boolean inheritAll ; private Hashtable projectProps ; public IzpackAntRunnable ( String compression , String kind , String input , String configText , String basedir , String output , boolean mkdirs , int compressionLevel , Properties properties , Boolean inheritAll , Hashtable antProjectProperties , String izPackDir ) { this . compilerData = new CompilerData ( compression , kind , input , configText , basedir , output , mkdirs , compressionLevel ) ; this . input = input ; this . properties = properties ; this . inheritAll = inheritAll ; this . projectProps = antProjectProperties ; CompilerData . setIzpackHome ( izPackDir ) ; } @ Override public void run ( ) { CompilerContainer compilerContainer = new CompilerContainer ( ) ; compilerContainer . addConfig ( "<STR_LIT>" , input ) ; compilerContainer . addComponent ( CompilerData . class , compilerData ) ; CompilerConfig compilerConfig = compilerContainer . getComponent ( CompilerConfig . class ) ; PropertyManager propertyManager = compilerContainer . getComponent ( PropertyManager . class ) ; if ( properties != null ) { Enumeration e = properties . keys ( ) ; while ( e . hasMoreElements ( ) ) { String name = ( String ) e . nextElement ( ) ; String value = properties . getProperty ( name ) ; value = fixPathString ( value ) ; propertyManager . addProperty ( name , value ) ; } } if ( inheritAll ) { Enumeration e = projectProps . keys ( ) ; while ( e . hasMoreElements ( ) ) { String name = ( String ) e . nextElement ( ) ; String value = ( String ) projectProps . get ( name ) ; value = fixPathString ( value ) ; propertyManager . addProperty ( name , value ) ; } } try { compilerConfig . executeCompiler ( ) ; } catch ( Exception e ) { throw new BuildException ( e ) ; } } private static String fixPathString ( String path ) { StringBuffer fixpath = new StringBuffer ( path ) ; for ( int q = <NUM_LIT:0> ; q < fixpath . length ( ) ; q ++ ) { if ( fixpath . charAt ( q ) == '<STR_LIT:\\>' ) { fixpath . setCharAt ( q , '<CHAR_LIT:/>' ) ; } } return fixpath . toString ( ) ; } } </s>
|
<s> package com . izforge . izpack . ant ; import org . apache . tools . ant . Project ; import java . util . Properties ; public class Property extends org . apache . tools . ant . taskdefs . Property { protected Properties props = new Properties ( ) ; public Property ( ) { super ( false ) ; } public Properties getProperties ( ) { return props ; } protected void addProperty ( String name , String value ) { if ( props . get ( name ) == null ) { props . put ( name , value ) ; } else { log ( "<STR_LIT>" + name , Project . MSG_VERBOSE ) ; } } } </s>
|
<s> package com . izforge . izpack . ant ; import org . apache . tools . ant . BuildException ; import org . apache . tools . ant . Project ; import java . util . ArrayList ; import java . util . Collections ; import java . util . Enumeration ; import java . util . List ; public class ConfigHolder { private Project project ; private String installText ; static void parseCompileProperties ( String value , List < String > fragments , List < String > propertyRefs ) throws BuildException { int prev = <NUM_LIT:0> ; int pos ; while ( ( pos = value . indexOf ( "<STR_LIT:@>" , prev ) ) >= <NUM_LIT:0> ) { if ( pos > <NUM_LIT:0> ) { fragments . add ( value . substring ( prev , pos ) ) ; } if ( pos == ( value . length ( ) - <NUM_LIT:1> ) ) { fragments . add ( "<STR_LIT:@>" ) ; prev = pos + <NUM_LIT:1> ; } else if ( value . charAt ( pos + <NUM_LIT:1> ) != '<CHAR_LIT>' ) { if ( value . charAt ( pos + <NUM_LIT:1> ) == '<CHAR_LIT>' ) { fragments . add ( "<STR_LIT:@>" ) ; prev = pos + <NUM_LIT:2> ; } else { fragments . add ( value . substring ( pos , pos + <NUM_LIT:2> ) ) ; prev = pos + <NUM_LIT:2> ; } } else { int endName = value . indexOf ( '<CHAR_LIT:}>' , pos ) ; if ( endName < <NUM_LIT:0> ) { throw new BuildException ( "<STR_LIT>" + value ) ; } String propertyName = value . substring ( pos + <NUM_LIT:2> , endName ) ; fragments . add ( null ) ; propertyRefs . add ( propertyName ) ; prev = endName + <NUM_LIT:1> ; } } if ( prev < value . length ( ) ) { fragments . add ( value . substring ( prev ) ) ; } } ConfigHolder ( Project project ) { this . project = project ; } public void addText ( String rawText ) { List < String > fragments = new ArrayList < String > ( ) ; List < String > propertyRefs = new ArrayList < String > ( ) ; parseCompileProperties ( rawText , fragments , propertyRefs ) ; StringBuffer sb = new StringBuffer ( ) ; Enumeration < String > fragmentsEnumeration = Collections . enumeration ( fragments ) ; Enumeration < String > propertyRefsEnumeration = Collections . enumeration ( propertyRefs ) ; while ( fragmentsEnumeration . hasMoreElements ( ) ) { String fragment = fragmentsEnumeration . nextElement ( ) ; if ( fragment == null ) { String propertyName = propertyRefsEnumeration . nextElement ( ) ; String replacement = project . getProperty ( propertyName ) ; if ( replacement == null ) { project . log ( "<STR_LIT>" + propertyName + "<STR_LIT>" , Project . MSG_VERBOSE ) ; } if ( replacement != null ) { fragment = replacement ; } else { fragment = "<STR_LIT>" + propertyName + "<STR_LIT:}>" ; } } sb . append ( fragment ) ; } installText = sb . toString ( ) ; } public String getText ( ) { return installText ; } } </s>
|
<s> package com . izforge . izpack . ant ; import com . izforge . izpack . compiler . data . CompilerData ; import com . izforge . izpack . compiler . listener . PackagerListener ; import com . izforge . izpack . merge . resolve . ResolveUtils ; import org . apache . tools . ant . BuildException ; import org . apache . tools . ant . Project ; import org . apache . tools . ant . Task ; import org . apache . tools . ant . types . EnumeratedAttribute ; import org . apache . tools . ant . types . PropertySet ; import java . io . IOException ; import java . lang . reflect . Constructor ; import java . net . URL ; import java . net . URLClassLoader ; import java . util . * ; public class IzPackTask extends Task implements PackagerListener { private ConfigHolder config ; private String input ; private String basedir ; private String output ; private boolean mkdirs ; private String compression ; private int compressionLevel ; private InstallerType installerType ; private String izPackDir ; private Properties properties ; private Boolean inheritAll = false ; public IzPackTask ( ) { basedir = null ; config = null ; input = null ; output = null ; installerType = null ; izPackDir = null ; compression = "<STR_LIT:default>" ; compressionLevel = - <NUM_LIT:1> ; } public ConfigHolder createConfig ( ) { config = new ConfigHolder ( getProject ( ) ) ; return config ; } public void packagerMsg ( String str ) { packagerMsg ( str , MSG_INFO ) ; } public void packagerMsg ( String str , int priority ) { final int antPriority ; switch ( priority ) { case MSG_DEBUG : antPriority = Project . MSG_DEBUG ; break ; case MSG_ERR : antPriority = Project . MSG_ERR ; break ; case MSG_INFO : antPriority = Project . MSG_INFO ; break ; case MSG_VERBOSE : antPriority = Project . MSG_VERBOSE ; break ; case MSG_WARN : antPriority = Project . MSG_WARN ; break ; default : antPriority = Project . MSG_INFO ; } log ( str , antPriority ) ; } public void packagerStart ( ) { log ( ResourceBundle . getBundle ( "<STR_LIT>" ) . getString ( "<STR_LIT>" ) , Project . MSG_DEBUG ) ; } public void packagerStop ( ) { log ( ResourceBundle . getBundle ( "<STR_LIT>" ) . getString ( "<STR_LIT>" ) , Project . MSG_DEBUG ) ; } public void execute ( ) throws org . apache . tools . ant . BuildException { checkInput ( ) ; String kind = ( installerType == null ? null : installerType . getValue ( ) ) ; String configText = null ; if ( config != null ) { configText = config . getText ( ) ; input = null ; } try { ClassLoader loader = new URLClassLoader ( getUrlsForClassloader ( ) ) ; Class runableClass = loader . loadClass ( "<STR_LIT>" ) ; Constructor constructor = runableClass . getConstructors ( ) [ <NUM_LIT:0> ] ; Object instance = constructor . newInstance ( compression , kind , input , configText , basedir , output , mkdirs , compressionLevel , properties , inheritAll , getProject ( ) . getProperties ( ) , izPackDir ) ; final Thread thread = new Thread ( ( Runnable ) instance ) ; thread . setContextClassLoader ( loader ) ; thread . start ( ) ; Thread . sleep ( <NUM_LIT:100> ) ; thread . join ( ) ; } catch ( Exception e ) { throw new BuildException ( e ) ; } } private URL [ ] getUrlsForClassloader ( ) throws IOException { Collection < URL > result = new HashSet < URL > ( ) ; ClassLoader currentLoader = getClass ( ) . getClassLoader ( ) ; Enumeration < URL > urlEnumeration = currentLoader . getResources ( "<STR_LIT>" ) ; result . addAll ( Collections . list ( urlEnumeration ) ) ; urlEnumeration = currentLoader . getResources ( "<STR_LIT>" ) ; while ( urlEnumeration . hasMoreElements ( ) ) { URL url = urlEnumeration . nextElement ( ) ; result . add ( ResolveUtils . processUrlToJarUrl ( url ) ) ; } URL [ ] urlArray = new URL [ result . size ( ) ] ; return result . toArray ( urlArray ) ; } private void checkInput ( ) { if ( input == null && config == null ) { throw new BuildException ( ResourceBundle . getBundle ( "<STR_LIT>" ) . getString ( "<STR_LIT>" ) ) ; } if ( output == null ) { throw new BuildException ( ResourceBundle . getBundle ( "<STR_LIT>" ) . getString ( "<STR_LIT>" ) ) ; } if ( basedir == null ) { throw new BuildException ( ResourceBundle . getBundle ( "<STR_LIT>" ) . getString ( "<STR_LIT>" ) ) ; } } public void setInput ( String input ) { this . input = input ; } public void setBasedir ( String basedir ) { this . basedir = basedir ; } public void setOutput ( String output ) { this . output = output ; } public void setMkdirs ( boolean mkdirs ) { this . mkdirs = mkdirs ; } public void setInstallerType ( InstallerType installerType ) { this . installerType = installerType ; } public void setIzPackDir ( String izPackDir ) { if ( ! ( izPackDir . endsWith ( "<STR_LIT:/>" ) ) ) { izPackDir += "<STR_LIT:/>" ; } this . izPackDir = izPackDir ; } public void setInheritAll ( boolean value ) { inheritAll = value ; } public void setCompression ( String compression ) { this . compression = compression ; } public void setCompressionLevel ( int compressionLevel ) { this . compressionLevel = compressionLevel ; } public void addConfiguredProperty ( Property property ) { if ( properties == null ) { properties = new Properties ( ) ; } property . execute ( ) ; Properties props = property . getProperties ( ) ; Enumeration e = props . keys ( ) ; while ( e . hasMoreElements ( ) ) { String name = ( String ) e . nextElement ( ) ; String value = props . getProperty ( name ) ; log ( "<STR_LIT>" + property . getClass ( ) + name + "<STR_LIT:=>" + value , Project . MSG_VERBOSE ) ; properties . setProperty ( name , value ) ; } } public void addConfiguredPropertyset ( PropertySet ps ) { if ( properties == null ) { properties = new Properties ( ) ; } properties . putAll ( ps . getProperties ( ) ) ; } public static class InstallerType extends EnumeratedAttribute { public String [ ] getValues ( ) { return new String [ ] { CompilerData . STANDARD , CompilerData . WEB } ; } } } </s>
|
<s> package com . izforge . izpack . ant ; import static org . hamcrest . MatcherAssert . assertThat ; import java . io . File ; import java . io . IOException ; import java . util . zip . ZipFile ; import org . apache . tools . ant . Project ; import org . hamcrest . collection . IsCollectionContaining ; import org . hamcrest . core . Is ; import org . junit . Ignore ; import org . junit . Test ; import com . izforge . izpack . matcher . ZipMatcher ; public class IzPackTaskTest { @ Test @ Ignore public void testExecuteAntAction ( ) throws IllegalAccessException , InterruptedException , IOException { IzPackTask task = new IzPackTask ( ) ; initIzpackTask ( task ) ; task . execute ( ) ; Thread . sleep ( <NUM_LIT> ) ; File file = new File ( "<STR_LIT>" ) ; ZipFile zipFile = new ZipFile ( file ) ; assertThat ( file . exists ( ) , Is . is ( true ) ) ; assertThat ( zipFile , ZipMatcher . isZipMatching ( IsCollectionContaining . hasItems ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) ) ) ; } private void initIzpackTask ( IzPackTask task ) throws IllegalAccessException { File installFile = new File ( getClass ( ) . getClassLoader ( ) . getResource ( "<STR_LIT>" ) . getFile ( ) ) ; task . setInput ( installFile . getAbsolutePath ( ) ) ; task . setBasedir ( getClass ( ) . getClassLoader ( ) . getResource ( "<STR_LIT>" ) . getFile ( ) ) ; task . setOutput ( "<STR_LIT>" ) ; task . setCompression ( "<STR_LIT:default>" ) ; task . setCompressionLevel ( - <NUM_LIT:1> ) ; task . setProject ( new Project ( ) ) ; } } </s>
|
<s> package com . izforge . izpack ; import com . izforge . izpack . gui . TwoColumnConstraints ; import com . izforge . izpack . gui . TwoColumnLayout ; import javax . swing . * ; import java . awt . BorderLayout ; import java . awt . Dimension ; import java . awt . event . ActionEvent ; import java . awt . event . ActionListener ; public class TwoColumnLayoutTestManual implements ActionListener { JFrame converterFrame ; JPanel converterPanel ; JTextField tempText ; JLabel label ; JButton addRow ; JButton removeRow ; boolean removed = false ; public TwoColumnLayoutTestManual ( ) { converterFrame = new JFrame ( "<STR_LIT>" ) ; converterFrame . setDefaultCloseOperation ( JFrame . EXIT_ON_CLOSE ) ; converterFrame . setSize ( new Dimension ( <NUM_LIT> , <NUM_LIT> ) ) ; TwoColumnLayout layout = new TwoColumnLayout ( <NUM_LIT:10> , <NUM_LIT:5> , <NUM_LIT:30> , <NUM_LIT> , TwoColumnLayout . LEFT ) ; converterPanel = new JPanel ( ) ; converterPanel . setLayout ( layout ) ; addWidgets ( ) ; converterFrame . getRootPane ( ) . setDefaultButton ( addRow ) ; converterFrame . getContentPane ( ) . add ( converterPanel , BorderLayout . CENTER ) ; converterFrame . pack ( ) ; converterFrame . setVisible ( true ) ; } private void addWidgets ( ) { tempText = new JTextField ( "<STR_LIT:10>" , <NUM_LIT:30> ) ; TwoColumnConstraints constraints = new TwoColumnConstraints ( ) ; constraints . position = TwoColumnConstraints . EAST ; label = new JLabel ( "<STR_LIT>" ) ; TwoColumnConstraints constraints1 = new TwoColumnConstraints ( ) ; constraints1 . position = TwoColumnConstraints . WEST ; addRow = new JButton ( "<STR_LIT>" ) ; TwoColumnConstraints constraints2 = new TwoColumnConstraints ( ) ; constraints2 . position = TwoColumnConstraints . BOTH ; addRow . addActionListener ( this ) ; converterPanel . add ( tempText , constraints ) ; converterPanel . add ( label , constraints1 ) ; converterPanel . add ( addRow , constraints2 ) ; label . setBorder ( BorderFactory . createEmptyBorder ( <NUM_LIT:5> , <NUM_LIT:5> , <NUM_LIT:5> , <NUM_LIT:5> ) ) ; } public void actionPerformed ( ActionEvent event ) { if ( ! removed ) { converterPanel . remove ( tempText ) ; converterPanel . remove ( label ) ; removed = true ; } else { TwoColumnConstraints constraints = new TwoColumnConstraints ( ) ; constraints . position = TwoColumnConstraints . EAST ; converterPanel . add ( tempText , constraints ) ; TwoColumnConstraints constraints1 = new TwoColumnConstraints ( ) ; constraints1 . position = TwoColumnConstraints . WEST ; converterPanel . add ( label , constraints1 ) ; removed = false ; } converterPanel . repaint ( ) ; } private static void createAndShowGUI ( ) { JFrame . setDefaultLookAndFeelDecorated ( true ) ; TwoColumnLayoutTestManual converter = new TwoColumnLayoutTestManual ( ) ; } public static void main ( String [ ] args ) { javax . swing . SwingUtilities . invokeLater ( new Runnable ( ) { public void run ( ) { createAndShowGUI ( ) ; } } ) ; } } </s>
|
<s> package com . izforge . izpack . installer . multiunpacker ; import static org . junit . Assert . assertFalse ; import static org . junit . Assert . assertTrue ; import java . io . File ; import java . io . FileInputStream ; import java . io . IOException ; import java . io . ObjectInputStream ; import java . io . PrintWriter ; import org . junit . Test ; import com . izforge . izpack . api . data . Blockable ; import com . izforge . izpack . api . data . OverrideType ; import com . izforge . izpack . api . data . PackFile ; import com . izforge . izpack . api . data . XPackFile ; import com . izforge . izpack . api . exception . InstallerException ; import com . izforge . izpack . core . io . FileSpanningInputStream ; import com . izforge . izpack . core . io . FileSpanningOutputStream ; import com . izforge . izpack . core . io . VolumeLocator ; import com . izforge . izpack . installer . unpacker . AbstractFileUnpackerTest ; import com . izforge . izpack . installer . unpacker . FileQueueFactory ; import com . izforge . izpack . installer . unpacker . FileUnpacker ; import com . izforge . izpack . util . IoHelper ; import com . izforge . izpack . util . Platforms ; import com . izforge . izpack . util . os . FileQueue ; public class MultiVolumeFileUnpackerTest extends AbstractFileUnpackerTest { private File volume ; private int volumeCount ; @ Test public void testPromptForNextMedia ( ) throws IOException , InstallerException { File baseDir = temporaryFolder . getRoot ( ) ; File source = createSourceFile ( baseDir ) ; File target = getTargetFile ( baseDir ) ; final File volume1 = new File ( volume . getPath ( ) + "<STR_LIT>" ) ; assertTrue ( volume1 . exists ( ) ) ; final File renamed = new File ( volume1 . getPath ( ) + "<STR_LIT>" ) ; assertTrue ( volume1 . renameTo ( renamed ) ) ; VolumeLocator locator = new VolumeLocator ( ) { @ Override public File getVolume ( String path , boolean corrupt ) throws IOException { assertTrue ( renamed . renameTo ( volume1 ) ) ; return volume1 ; } } ; FileSpanningInputStream stream = new FileSpanningInputStream ( volume , volumeCount ) ; stream . setLocator ( locator ) ; FileQueue queue = new FileQueueFactory ( Platforms . WINDOWS , getLibrarian ( ) ) . create ( ) ; FileUnpacker unpacker = new MultiVolumeFileUnpacker ( stream , getCancellable ( ) , queue ) ; PackFile file = createPackFile ( baseDir , source , target , Blockable . BLOCKABLE_NONE ) ; assertFalse ( target . exists ( ) ) ; ObjectInputStream packStream = createPackStream ( source ) ; unpacker . unpack ( file , packStream , target ) ; assertTrue ( queue . isEmpty ( ) ) ; checkTarget ( source , target ) ; } @ Override protected File createSourceFile ( File baseDir ) throws IOException { File source = new File ( baseDir , "<STR_LIT>" ) ; PrintWriter stream = new PrintWriter ( source ) ; for ( int i = <NUM_LIT:0> ; i < <NUM_LIT> ; ++ i ) { stream . println ( i ) ; } assertFalse ( stream . checkError ( ) ) ; stream . close ( ) ; volume = new File ( temporaryFolder . getRoot ( ) , "<STR_LIT>" ) ; FileSpanningOutputStream out = new FileSpanningOutputStream ( volume , <NUM_LIT> ) ; FileInputStream in = new FileInputStream ( source ) ; IoHelper . copyStream ( in , out ) ; out . close ( ) ; volumeCount = out . getVolumes ( ) ; assertTrue ( volumeCount > <NUM_LIT:1> ) ; in . close ( ) ; return source ; } protected FileUnpacker createUnpacker ( File sourceDir , FileQueue queue ) throws IOException { FileSpanningInputStream stream = new FileSpanningInputStream ( volume , volumeCount ) ; return new MultiVolumeFileUnpacker ( stream , getCancellable ( ) , queue ) ; } @ Override protected PackFile createPackFile ( File baseDir , File source , File target , Blockable blockable ) throws IOException { XPackFile result = new XPackFile ( baseDir , source , target . getName ( ) , null , OverrideType . OVERRIDE_TRUE , null , blockable ) ; result . setArchiveFilePosition ( <NUM_LIT:0> ) ; return result ; } } </s>
|
<s> package com . izforge . izpack . installer . container ; import java . awt . Dimension ; import java . awt . Toolkit ; import java . util . Arrays ; import javax . swing . ImageIcon ; import javax . swing . JFrame ; import org . fest . swing . fixture . DialogFixture ; import org . mockito . Mockito ; import org . picocontainer . Characteristics ; import org . picocontainer . MutablePicoContainer ; import org . picocontainer . PicoException ; import org . picocontainer . injectors . ProviderAdapter ; import org . picocontainer . parameters . ComponentParameter ; import com . izforge . izpack . api . container . Container ; import com . izforge . izpack . api . data . Variables ; import com . izforge . izpack . api . exception . ContainerException ; import com . izforge . izpack . core . container . AbstractContainer ; import com . izforge . izpack . core . data . DefaultVariables ; import com . izforge . izpack . core . resource . DefaultLocales ; import com . izforge . izpack . core . resource . ResourceManager ; import com . izforge . izpack . installer . automation . AutomatedInstaller ; import com . izforge . izpack . installer . container . provider . IconsProvider ; import com . izforge . izpack . installer . data . UninstallData ; import com . izforge . izpack . installer . data . UninstallDataWriter ; import com . izforge . izpack . installer . language . LanguageDialog ; import com . izforge . izpack . installer . requirement . RequirementsChecker ; import com . izforge . izpack . merge . resolve . PathResolver ; import com . izforge . izpack . test . provider . GUIInstallDataMockProvider ; public class TestLanguageContainer extends AbstractContainer { public TestLanguageContainer ( ) { initialise ( ) ; } @ Override protected void fillContainer ( MutablePicoContainer container ) { container . addComponent ( System . getProperties ( ) ) ; ResourceManager resourceManager = Mockito . mock ( ResourceManager . class ) ; Mockito . when ( resourceManager . getObject ( "<STR_LIT>" ) ) . thenReturn ( Arrays . asList ( "<STR_LIT>" , "<STR_LIT>" ) ) ; DefaultLocales locales = new DefaultLocales ( resourceManager ) ; container . addComponent ( Variables . class , DefaultVariables . class ) . addComponent ( resourceManager ) . addComponent ( Mockito . mock ( RequirementsChecker . class ) ) . addComponent ( Mockito . mock ( UninstallData . class ) ) . addComponent ( Mockito . mock ( UninstallDataWriter . class ) ) . addComponent ( Mockito . mock ( AutomatedInstaller . class ) ) . addComponent ( Mockito . mock ( PathResolver . class ) ) . addComponent ( locales ) . addComponent ( DialogFixture . class , DialogFixture . class , new ComponentParameter ( LanguageDialog . class ) ) . addComponent ( Container . class , this ) . as ( Characteristics . USE_NAMES ) . addComponent ( LanguageDialog . class ) . addConfig ( "<STR_LIT>" , initFrame ( ) ) . addConfig ( "<STR_LIT:title>" , "<STR_LIT>" ) ; container . addAdapter ( new ProviderAdapter ( new GUIInstallDataMockProvider ( ) ) ) . addAdapter ( new ProviderAdapter ( new IconsProvider ( ) ) ) ; ImageIcon engFlag = new ImageIcon ( getClass ( ) . getResource ( "<STR_LIT>" ) ) ; ImageIcon frFlag = new ImageIcon ( getClass ( ) . getResource ( "<STR_LIT>" ) ) ; Mockito . when ( resourceManager . getImageIcon ( "<STR_LIT>" ) ) . thenReturn ( engFlag ) ; Mockito . when ( resourceManager . getImageIcon ( "<STR_LIT>" ) ) . thenReturn ( frFlag ) ; Mockito . when ( resourceManager . getInputStream ( Mockito . anyString ( ) ) ) . thenReturn ( getClass ( ) . getResourceAsStream ( "<STR_LIT>" ) ) ; } private JFrame initFrame ( ) { JFrame frame = new JFrame ( ) ; Dimension frameSize = frame . getSize ( ) ; Dimension screenSize = Toolkit . getDefaultToolkit ( ) . getScreenSize ( ) ; frame . setLocation ( ( screenSize . width - frameSize . width ) / <NUM_LIT:2> , ( screenSize . height - frameSize . height ) / <NUM_LIT:2> - <NUM_LIT:10> ) ; return frame ; } } </s>
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.