Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

« Newer Snippets
Older Snippets »
Showing 1-10 of 384 total  RSS 

Solution to Triangle Puzzle

Problem Description: http://www.yodle.com/downloads/puzzles/triangle.html

import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.Scanner;


public class mainClass3 {

	public static void main (String[] args) throws FileNotFoundException{
		//ugly crap to get values from text file
		Scanner scan = new Scanner(new File("triangle.txt"));
		ArrayList<int[]> input = new ArrayList<int[]>();
		int[] tempHolder;
		String[] stringHolder;
		int counter = 1;
		String line;
		
		while (scan.hasNextLine()){
			tempHolder = new int[counter];
			stringHolder = new String[counter];	
			line = scan.nextLine();
			stringHolder = line.split(" ");
			for (int i=0; i<stringHolder.length; i++){
				tempHolder[i] = new Integer(stringHolder[i]).intValue();
			}
			input.add(tempHolder);
			counter++;
		}

		//actual work
		for (int j=input.size()-1; j>0; j--){
			int[] newLine = rowReduce(input.get(j-1), input.get(j));
			input.set(j-1,newLine);
		}
		System.out.println("Answer: "+input.get(0)[0]);
	}
	
	public static int[] rowReduce(int[] aboveRow, int[] currRow){
		int larger;
		int[] mergedRows = new int[aboveRow.length];
		for (int i=0; i<aboveRow.length; i++){
			larger = getLarger(currRow[i]+aboveRow[i], currRow[i+1]+aboveRow[i]);
			mergedRows[i] = larger;
		}
		return mergedRows;
	}
	
	public static int getLarger(int a, int b){
		if (a>b){
			return a;
		}
		else if(b>a){
			return b;
		}
		else{
			return a;
		}
	}
}

Transferring Large Files Between .Net & Java: Web Services Interoperability

It seems alot people have been experiencing problems uploading/downloading extremely large files via web services between a .Net web services client and a Java based web service. This note will hopefully put the matter to rest. The JAX-WS / Metro framework requires one to pass/return a Datahandler when accepting/returning streamed data. The problem is that when generating the stub code in Microsoft Visual Studio from the WSDL exported from the Java server, a byte[] array is returned in place of the Data Handler. The reason is that .NET does not know what a Java Datahandler is. When processing a very large file, say. 3 GB, your client will run out of memory. What we really want is for .Net to generate a Stream object in place of the byte array. To accomplish this, we need to employ some trickery. Say you have a class called ServerService and you want to upload a file, specifying the file name as the parameter. You would do this as follows:

@MTOM(enabled = true, threshold = 512)
@StreamingAttachment(parseEagerly=true, memoryThreshold=4000000L)
@WebService
public class ServerService {
@WebMethod
public upload(@WebParam(name="fileStream")StreamBody stream) {
Datahandler dh = stream.getDataHandler();
// copy data from datahandler to file
}
}

The constraint of the above is that the upload method using a stream may have only one parameter. One way around to specify the file name & other attributes in the Data itself. Simply write a FilterInputStream that reads and parses the first few lines. These lines are the attribute/name pairs that describe the data, i.e. filename, etc. When a linefeed is encountered the data itself begins. The below class is necessary to jinx .Net into creating a Stream object:

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "StreamBody", namespace = "http://schemas.microsoft.com/Message")
public class StreamBody {
/**
* The data stream.
*/
@XmlValue
public DataHandler dataHandler;
public DataHandler getDataHandler() {
return dataHandler;
}
public void setDataHandler(DataHandler dataHandler) {
this.dataHandler = dataHandler;
}
}

To enable mtom in your Java web services server, modify the sun-jaxws.xml with enable-mtom="true" as follows:

<endpoints xmlns="http://java.sun.com/xml/ns/jax-ws/ri/runtime" version="2.0">
<endpoint name="FileArchiva" implementation="com.stimulus.archiva.file.webservice.FileArchivaWS"
url-pattern="/FileArchivaWS"
wsdl-location="WEB-INF/wsdl/library.wsdl" enable-mtom="true"/>
</endpoints>

To enable streaming and MTOM on the .Net client, modify a file called app.config and add the parameters messageEncoding="Mtom" and transferMode="Streamed".

<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="FileArchivaWSPortBinding" closeTimeout="00:01:00"
openTimeout="01:00:00" receiveTimeout="01:00:00" sendTimeout="01:00:00"
allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
messageEncoding="Mtom" textEncoding="utf-8" transferMode="Streamed"
useDefaultWebProxy="true">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<security mode="None">
<transport clientCredentialType="None" proxyCredentialType="None"
realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
</binding>
</basicHttpBinding>
</bindings>

Find Min/Max of a Porabola

// Short snippet that takes 3 integers and gives you the min/max location of a parabola

public class mainClass2 {
	//Finds parabola min/max
	public static void main(String args[]){
		int a = 29;
		int b = -31;
		int c = 99;
		
		float x = findX(a,b);
		float y = findY(a,b,c,x);
		
		if (a < 0){
			System.out.println("max: x="+ x + " y=" + y);
		}
		else{
			System.out.println("min: x="+ x + " y=" + y);
		}
	}
	
	public static float findX(float a, float b){
		if (a == 0){
			return -1;
		}
		else{
			return (-b)/(2*a);
		}
	}
	public static float findY(float a, float b, float c, float x){
		return a*(x*x) + (b*x) + c;
	}
}

JAVA GUI

// GUI

package gui;

import java.awt.*;

import javax.swing.*;

import lytter.Lytter;

public class Gui {
	private JFrame frame = new JFrame("Hoved");

	private Lytter l;

	private JButton b5;

	private JButton b4;

	private JButton b3;

	private JButton b2;

	private JButton b1;

	private JTextField felt;

	private JTextField felt1;

	public Gui(){

		l=new Lytter();
		frame.setLayout(new FlowLayout());
		frame.setSize(new Dimension(300, 300));
		frame.setDefaultCloseOperation(frame.EXIT_ON_CLOSE);

		//initialiser knappene
		b1 = new JButton("Ansatt");
		b2 = new JButton("Kunde");
		b3 = new JButton("Logg inn");
		b4 = new JButton("Set timer");
		b5 = new JButton("Kjøp varer");
		felt = new JTextField("Skriv inn Brukernavn");
		felt1 = new JTextField("Skriv inn Passord");

		//legger til lytter til  knappene
		b1.addActionListener(l);
		b2.addActionListener(l);
		b3.addActionListener(l);
		b4.addActionListener(l);
		b5.addActionListener(l);

		//legger knappene og tekstfeltene til JFramen
		frame.add(b1);
		frame.add(b2);
		frame.add(b3);
		frame.add(b4);
		frame.add(b5);
		frame.add(felt);
		frame.add(felt1);

		//Setter visualiteten til komponentene og containeren
		b1.setVisible(true);
		b2.setVisible(true);
		b3.setVisible(false);
		b4.setVisible(false);
		b5.setVisible(false);
		felt.setVisible(false);
		felt1.setVisible(false);
		frame.setVisible(true);
	}
	//metode for å skjule knapper 1, 2 og vise knapper3 og tekstfelt 1 og 2 
	public void ansatt(){
		b1.setVisible(false);
		b2.setVisible(false);
		b3.setVisible(true);
		felt.setVisible(true);
		felt1.setVisible(true);
	}

}

Reuseable Java File Queue

I thought I'd share a neat Java FileQueue class I wrote that enables you to queue jobs in a file. Its similar to a mail server queue, but can be used to queue just about any job item. The advantage is that if your server is restarted or Java process is killed, FileQueue will continue right where it left off.

To protect against data loss in the event of sigkill, all jobs are written immediately to the file queue. Item status is maintained and referenced directly from the queue file. To protect against data loss due to sudden shutdown, minimal buffering is implemented in the code. In most cases, FileQueue will recover in the event that queue file is corrupted. There is also some basic retry logic built into the file queue class. The idea is really to try and preserve jobs as far as possible.

One can use the FileQueue class for sending out emails, backing up files, and wide range of other applications.

To run these files, just import them into an Eclipse project and include the Apache commons libs (including logging jar) and log4j.

To begin using the FileQueue class for your purposes, simply subclass it as follows:

The constructor should call super(name) where name is an arbitrary (but unique) name of the queue
In the constructor, you can optionally call this.setMaxRetryDays(days) or this.setMaxRetries(noretries) to define how the file queue class should handle retries.
One can also set an interval in minutes for the retries by calling this.setRetryIntervalMinutes(minutes).

Override getQueueFile() to return the queue file name .e.g return "/Users/jamie/system.queue"
Override public ProcessResult processFileQueueItem(FileQueueItem item) to do the actual work
Returning ProcessResult.PROCESS_SUCCESS means that item is processed successfully
Returning ProcessResult.PROCESS_FAIL_NOQUEUE means the item processing failed, and should not be requeued
Returning ProcessResult.PROCESS_FAIL_REQUEUE means the item processing failed, and should be requeued
Override expiredItem(FileQueueItem item). This method is called when the queue gives up due to maximum no. retries exceeded or max retry days are exceeded.
Override FileQueueItem newFileQueueItem() to return your specialization of the FileQueueItem class

The processFileQueueItem method will be called by multiple threads (default is six). To define how many process threads you wish to use, call setProcessThreads(nothreads) in the FileQueue constructor.

Thereafter, you need to subclass the FileQueueItem class. The purpose of the FileQueueItem class is to convert your Item to unique value string that is stored in the file queue.

Typically you would declare String value as a class member variable
Implement a constructor that takes your queue item e.g. TestItem(Item i) This constructor would convert an Item to the class member variable String value
Override String getValue() to return a unique string value that represents the Item
Override public void setValue(String value) to set the value

The file queue itself stored data in the queue in a series of lines, each line containing five sections, separated by |

P|201111020119|201111020125|00000|SUPPORTREMINDER:3304
A|201111020120|201111020126|00000|SUPPORTREMINDER:3305

First section: P = busy processing, A = active (still to be processed), D = deleted
Second section: date time item put on queue
Third section: last retry date itiem
Fourth section: no. retries
Fifth line: unique item string that converts between String value and user defined Item

At any time, you can cat the contents of the queue file to see what jobs are pending etc. If you want to clear out the queue on Linux, type ">queuefile.queue" in the terminal.
The queue file will be periodically cleared of its deleted items when MAX_NO_DELETES_BEFORE_CLEANUP (100) is exceeded.

Use your subclassed FileQueue class as follows:

TestQueue testQueue = new TestQueue("test"); // instantiate queue with unique queue name
testQueue.startQueueProcessor(10, TimeUnit.MILLISECONDS); // parameters define polling interval
TestItem testitem = new TestItem(j);
testQueue.queueItem(queueItem); // queue an item to the queue
Thread.sleep(10000); // wait some time
testQueue.stopQueueProcessor(); // stop queue


To obtain queue stats, during queue operation, call getActCount() to get current active count, getProcCount() to get processing count, and getDelCount() to get deleted count.

The queue is really designed to keep running throughout your application. Call stopQueueProcessor when your application exits to free up resources and shutdown running threads.

I'd be very interested to hear of possible performance optimizations.




/* FileQueue.java */


package com.stimulus.util;

/*
Copyright (c) 2005-2011 Jamie Band
GNU Lesser General Public License
*/

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File; 
import java.io.FileNotFoundException;
import java.io.FileReader; 
import java.io.FileWriter;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.nio.channels.FileChannel;
import java.nio.channels.FileLock;
import java.nio.channels.OverlappingFileLockException;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.NoSuchElementException;
import java.util.Queue;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.locks.ReentrantLock;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public abstract class FileQueue implements Runnable {
	
	public enum ProcessResult { PROCESS_SUCCESS, PROCESS_FAIL_REQUEUE, PROCESS_FAIL_NOQUEUE };


    protected final Log logger = LogFactory.getLog(FileQueue .class);
    protected String name;
    protected int processThreads 						= 6;
    protected int maxRetryDays 							= 7;
    protected int maxRetries 							= 7;
    protected int retryIntervalMinutes 					= 1;
    protected ExecutorService processPool 				= null;
    protected static int DEAD_PERIOD 					= 6000000;
    protected static int MAX_NO_DELETES_BEFORE_CLEANUP 	= 100;
    protected static int WRITE_QUEUE_SIZE 				= 500;
    protected AtomicInteger processCount 				= new AtomicInteger();
    protected ArrayBlockingQueue<ProcessItem> writeQueue;
    protected Queue<ProcessItem> writeBackQueue;
    protected ShutdownHook shutdownHook;
    protected AtomicBoolean started = new AtomicBoolean();
    protected long period;
    protected TimeUnit timeunit;
    protected int maxItemsPerCycle						= 1000;
    protected RandomAccessFile	rndFile;
    protected FileChannel rndFileChannel;
    protected FileLock rndFileLock;
    protected ExecuteInfo execInfo						= new ExecuteInfo();
    protected AtomicBoolean queueFileOpened 			= new AtomicBoolean();
    protected ReentrantLock removeLock					= new ReentrantLock();
    
    public FileQueue(String name) {
        this.name = name;
        writeQueue =  new ArrayBlockingQueue<ProcessItem>(WRITE_QUEUE_SIZE);
        writeBackQueue =  new ConcurrentLinkedQueue<ProcessItem>();
        shutdownHook = new ShutdownHook();
        started.getAndSet(false);
        queueFileOpened.getAndSet(false);
    }

    public void startQueueProcessor( long period, TimeUnit timeunit) {
    	
    	if (started.compareAndSet(false,true)) {
    		
    		this.period = period;
    		this.timeunit = timeunit;
    		logger.debug("start queue processor {name='"+name+"',file='"+getQueueFile()+"'}");
    		try {
    			execInfo = resetCounters();
    		} catch (Exception e) {
    			logger.error("failed to set queue counters:"+e.getMessage(),e);
    		}
    		openQueue();
    		processPool = Executors.newFixedThreadPool(processThreads+1);
    		processPool.execute(this);
    		Runtime.getRuntime().addShutdownHook(shutdownHook);
    		
    	} else {
    		logger.debug("queue processor already started {name='"+name+"',file='"+getQueueFile()+"'}");
    	} 
    }

    public void stopQueueProcessor() {
    	
    	if (started.compareAndSet(true,false)) {

     		logger.debug("stop queue processor {writeQueue='"+writeQueue.size()+"',name='"+name+"',file='"+getQueueFile()+"'}");
     		
     		
	        if (processPool!=null) {
	            processPool.shutdown();
	        }
	        
	        if (shutdownHook!=null) {
	            Runtime.getRuntime().removeShutdownHook(shutdownHook);
	        }
	        
	        try {
	            processQueueItems();
	        } catch (Exception e) {
	            logger.error("failed to process remaining queue items during shutdown:"+e.getMessage(),e);
	        }
	        logger.debug("queue processor stopped {writeQueue='"+writeQueue.size()+"',name='"+name+"',file='"+getQueueFile()+"'}");
	    	
     	} else {
     		  logger.debug("queue processor already stopped {writeQueue='"+writeQueue.size()+"',name='"+name+"',file='"+getQueueFile()+"'}");
     	}
    }

    public void run() {
        try {
            processQueueItems();
        } catch (Throwable e) {
            logger.error("failed to process file queue:"+e.getMessage(),e);
        }
    }

    public void openQueue() throws OverlappingFileLockException {
	    	try {
		        ensureQueueFilePresent();
		        removeProcessedItemsFromQueue();
	            openQueueFile();
	            try {
		            activateAllQueueItems(rndFile);
	            } finally {
	            	 try {
	 	        		closeQueueFile();
	 	        	} catch (Throwable t) {
	 	        		logger.error("error occurred while closing queue:"+t.getMessage(),t);
	 	        	}
	            }
	    	} catch (Throwable t) {
	    		logger.error("error occurred while opening queue:"+t.getMessage(),t);
	    	}
    }
    
    public void processQueueItems() throws FileQueueException {
    	
    	
    	while (started.get()) {

    		try {
		        try {
		        	
		            ProcessItem head = null;
		            try {
		        		head = writeQueue.poll(period,timeunit);
		  	  	  	} catch (InterruptedException nse) {
		  	  			continue;
		  	  		}
		           
		  	  	  	if (head==null && getQueueFile().length()==0) {
		  	  	  		continue;
		  	  	  	}

		  	  	  	openQueueFile();
		  	  	
		  	  	  	if (execInfo.delCount.get()<0 || execInfo.actCount.get()<0 || execInfo.procCount.get()<0) {
		  	  	  		execInfo = resetCounters();
		  	  	  	}
		  	  	  	if (head==null && execInfo.delCount.get()>0 && execInfo.actCount.get()<=0 && execInfo.procCount.get()<=0 && writeBackQueue.size()==0) {
		  	  	  		removeProcessedItemsFromQueue();
		  	  	  		continue;
		  	  	  	}
		  	  	  	
		  	  	  	if (head!=null) {
		  	  	  		rndFile.seek(rndFile.length());
			            writeAllQueuedItems((Queue<ProcessItem>)writeQueue, rndFile, head);
		  	  	  	}
		  	  	  	rndFile.seek(0); 
		  	  	  	
		  	  	  	executeAllQueueItems(rndFile);
		            if (writeBackQueue.size()>0) {
		            	writeAllQueuedItems((Queue<ProcessItem>)writeBackQueue, rndFile, null);
		            	continue;
		            }
		            if (writeBackQueue.size()==0 && execInfo.procCount.get()<=0 && execInfo.delCount.get()>=MAX_NO_DELETES_BEFORE_CLEANUP) {
		            	removeProcessedItemsFromQueue();
		            }
		        } catch (Exception e) {
		            throw new FileQueueException("exception occured: "+e.getMessage(),e,logger);
		        } finally {
		        	closeQueueFile();
		        }
		       
	    	} catch (Throwable t) {
	    		logger.error("error occurred during file queue process loop:"+t.getMessage(),t);
	    	}
    	}
    	
    }

    public void queueItem(FileQueueItem fileQueueItem) throws FileQueueException {
    	
        if (fileQueueItem == null) {
            throw new FileQueueException("precondition: attempt to insert null item to queue.");
        }
        if (fileQueueItem.getValue() == null) {
            throw new FileQueueException("precondition: attempt to insert item with null content in queue.");
        }
        execInfo.actCount.getAndIncrement();
        try {
        	
            writeQueue.put(new ProcessItem(fileQueueItem,-1));
        } catch (InterruptedException ie) {
            throw new FileQueueException("failed to write item to cache. interrupted:"+ie.getMessage(),ie,logger);
        }
    }


    public void writeItems(ArrayList<FileQueueItem> items) throws FileQueueException {

    	if (items == null) {
    		  throw new FileQueueException("precondition: items = null");
    	}
        FileWriter fw = null;
        BufferedWriter bw = null;
        File queueFile = getQueueFile();
        
        try {
             fw = new FileWriter(queueFile, true);
             bw = new BufferedWriter(fw);
             
             for (FileQueueItem item : items) {

                 if (item==null || item.getValue()==null ) {
                     continue;
                 }
                 bw.write(item.toString());
                 bw.newLine();
             }

        } catch (IOException io) {
            throw new FileQueueException("failed to write to queue:"+io.getMessage(),io,logger);
        } finally {
            if (bw != null) {
                try {  bw.close(); } catch (IOException e) {  logger.debug("failed close buffer: "+e.getMessage()); }
                try {  fw.close(); } catch (IOException e) {  logger.debug("failed close file: "+e.getMessage()); }
            }
        }
    }

    public boolean isExpired(FileQueueItem fileQueueItem) throws FileQueueException {
    	
    	if (fileQueueItem == null) {
  		  	throw new FileQueueException("precondition: fileQueueItem = null");
    	}
    	
        //logger.debug("isexpired {item='"+fileQueueItem.getValue()+"'");
        if (maxRetries != 0 && fileQueueItem.retries > maxRetries) {
           return true;
        }

        if (maxRetryDays > 0) {
            Date receivedDate = fileQueueItem.getReceivedDate();
            Calendar deleteCalendar = Calendar.getInstance();
            deleteCalendar.setTime(receivedDate);
            deleteCalendar.add(Calendar.DATE, + maxRetryDays);
            Date deleteDate = deleteCalendar.getTime();
            return new Date().after(deleteDate);
        }

        return false;
    }

    public boolean shouldRetry(FileQueueItem fileQueueItem) {

    	if (fileQueueItem.getStatus()!=FileQueueItem.Status.ACTIVE) {
            return false;
        }
      
        Date lastRetryDate = fileQueueItem.getLastRetryDate();
        Calendar retryCalendar = Calendar.getInstance();
        retryCalendar.setTime(lastRetryDate);
        retryCalendar.add(Calendar.SECOND, + retryIntervalMinutes*60);
        Date retryDate = retryCalendar.getTime();
       
        if (new Date().after(retryDate)) {
        	 logger.debug("try {item='"+fileQueueItem.getValue()+",retryDate='"+retryDate+"',result='yes'}");
            return true;
        } else {
        	 //logger.debug("shouldretry {item='"+fileQueueItem.getValue()+",retryDate='"+retryDate+"',result='no'}");
        	 return false;
        }
       
    }

    public void removeProcessedItemsFromQueue() throws IOException  {
    	
        BufferedWriter bw = null;
        BufferedReader in = null;
        File queueFile = getQueueFile();
        File queueBackupFile = getQueueBackupFile();
        
        
        logger.debug("remove processed items {name='"+name+"',file='"+getQueueFile()+"'}");
        
        try {
        	queueBackupFile.delete();
            
            if (!getQueueFile().exists() || getQueueFile().length()<1) {
                 logger.debug("skipping removal of queue items. queue is empty.");
                return;
            }
            
            FileReader inReader = new FileReader(queueFile);
            in = new BufferedReader(inReader);
            bw = new BufferedWriter(new FileWriter(queueBackupFile, true));
            
            String line;
            while ((line = in.readLine()) != null) {
            	
            	if (line.length()<=0) continue;
            	
                if (!started.get()) {
                    logger.debug("file queue "+name+" shutdown. exiting cleanly..");
                    break;
                }
                FileQueueItem fileQueueItem = newFileQueueItem();
                
                try {
                    fileQueueItem.parse(line);
                    
               
                } catch (FileQueueException e) {
                    logger.debug("failed to parse line in queue "+name+":"+e.getMessage(),e);
                    logger.debug(">line:"+line);
                    continue;
                }
                if (fileQueueItem.getValue()==null) {
                	continue;
                }

                if (fileQueueItem.getStatus() != FileQueueItem.Status.DELETED) {
                    line = fileQueueItem.toString();
                    bw.write(line);
                    bw.newLine();
                } 
            }
        } finally {
        	
            if (bw!=null) { try { bw.close(); } catch (Exception e) {} }
            if (in!=null) { try { in.close(); } catch (Exception e) {} }
            
        }
      
        	
        boolean deleted = queueFile.delete();
        
        
        if (!deleted) {
            logger.error("failed to delete queue file {file='"+queueFile.getAbsolutePath()+"'}");
        }
        
        queueBackupFile.renameTo(queueFile);
        
        execInfo.delCount.getAndSet(0);
         
    }
    
    public void changeFileQueueStatus(FileQueueItem fileQueueItem, FileQueueItem.Status newStatus) {
    	
    	if (fileQueueItem.getStatus()==newStatus) 
    		return;
    	
    	switch (fileQueueItem.getStatus()) {
	    	case PROCESSING: execInfo.procCount.getAndDecrement(); break;
	    	case ACTIVE: execInfo.actCount.getAndDecrement();break;
	    	case DELETED: execInfo.delCount.getAndDecrement();break;
    	}
    	
    	switch (newStatus) {
	    	case PROCESSING: execInfo.procCount.getAndIncrement();break;
	    	case ACTIVE: execInfo.actCount.getAndIncrement();break;
	    	case DELETED: execInfo.delCount.getAndIncrement();break;
    	}
    	 fileQueueItem.setStatus(newStatus);
    }

    public class ProcessItem implements Runnable {


          FileQueueItem fileQueueItem;
          long pointer;

          public ProcessItem(FileQueueItem fileQueueItem,long pointer) {
                this.fileQueueItem = fileQueueItem;
                this.pointer = pointer;
          }

          public void run() {
        	  
              try {
            	    if (fileQueueItem==null) {
            	    	return;
            	    }
            	  	logger.debug("process item {item='"+fileQueueItem.getValue()+"'}");
            	  	 if (processFileQueueItem(fileQueueItem)==ProcessResult.PROCESS_FAIL_REQUEUE) {
                        fileQueueItem.incRetries();
                        changeFileQueueStatus(fileQueueItem,FileQueueItem.Status.ACTIVE);
                    } else {
                    	 changeFileQueueStatus(fileQueueItem,FileQueueItem.Status.DELETED);
                    }
                    if (fileQueueItem.getStatus()!=FileQueueItem.Status.DELETED && isExpired(fileQueueItem)) {
                         expiredItem(fileQueueItem);
                    }
                    writeBackQueue.add(this);
              } catch (Throwable t) {
            	  logger.debug("failed to process item:"+t.getMessage()+" {value='"+fileQueueItem.getValue()+"'}",t);
              }
          }
    }

    private void ensureQueueFilePresent() throws FileQueueException {
    	
        if (!getQueueFile().exists()) {
        	
             try {
                 getQueueFile().createNewFile();
             } catch (IOException io) {
                 throw new FileQueueException("failed to create queue file: "+io.getMessage()+
                		 					  " {queueFile='"+getQueueFile().getPath()+"'}",io,logger);
             }
         }
    }

    private void writeAllQueuedItems(Queue<ProcessItem> queue, RandomAccessFile  rndFile, ProcessItem head) throws IOException {

    	if (rndFile==null) {
    		throw new IOException("file handle is null");
    	}
        ProcessItem writeItem = null;
        long oldpos = rndFile.getFilePointer();
        int i = 0;
        do {
        	if (head!=null) {
        		 
        		writeItem = head;
        		i++;
        		head = null;
        		 
        	} else {
        		
        		try {
        			if (i>maxItemsPerCycle) {
        				break;
        			}
        			writeItem = queue.poll();
        			if (writeItem == null) break;
        			i++;
        		} catch (NoSuchElementException nse) {
        			
        			break;
        			
        		}
        	}
          
            long writePos = 0;
            
            if (writeItem.pointer == -1) {
                writePos = rndFile.length();
            } else {
                writePos = writeItem.pointer;
            }
            try {
                rndFile.seek(writePos);
            } catch (IOException io) {
                logger.debug("failed to seek in queue file "+getQueueFile()+": "+io.getMessage(),io);
            }
          
             try {
                 rndFile.writeBytes(writeItem.fileQueueItem.toString());
                 rndFile.writeBytes("\n");
                 
             } catch (IOException io) {
                 logger.error("failed to write "+getQueueFile()+": "+io.getMessage(),io);
             }
             if (writeItem.pointer != -1) {
                    processCount.decrementAndGet();
                   // logger.debug("decprocesscount:"+processCount);
             }
        } while (i<=maxItemsPerCycle && writeItem!=null);
        
        rndFile.seek(oldpos);
    }

    protected class ExecuteInfo {
    	AtomicInteger executed = new AtomicInteger();
    	AtomicInteger  actCount = new AtomicInteger();
    	AtomicInteger  procCount = new AtomicInteger();
    	AtomicInteger  delCount = new AtomicInteger();
    }

  protected void activateAllQueueItems(RandomAccessFile  rndFile) throws IOException {
    	
    	if (rndFile==null) {
    		throw new IOException("precondition: rndfile is null");
    	}
    	
    
        long lastPos = 0;
        String     line;
        
        while ((line = rndFile.readLine()) != null) {
            //logger.debug(">"+line);

        	if (line.length()<=0) continue;
			
            if (!started.get()) {
            	logger.debug("file queue "+name+" shutdown. exiting cleanly..");
                break;
            }

            if (line.trim().length()<1) continue;

            FileQueueItem fileQueueItem = newFileQueueItem();

            try {
                fileQueueItem.parse(line);
                
            } catch (FileQueueException ae) {
            	
                logger.debug("failed to process item:"+ae.getMessage(),ae);
                lastPos = rndFile.getFilePointer();
                continue;
            }
        	

            if (fileQueueItem.getStatus() == FileQueueItem.Status.DELETED || fileQueueItem.getValue()==null) {
                lastPos = rndFile.getFilePointer();
                continue;
                
            }
            
            try {
                rndFile.seek(lastPos);
                
            } catch (IOException io) {
                logger.debug("failed to seek in queue file "+getQueueFile()+": "+io.getMessage(),io);
            }
            
            try {
            	 changeFileQueueStatus(fileQueueItem,FileQueueItem.Status.ACTIVE);
                 rndFile.writeBytes(fileQueueItem.toString());
                 rndFile.writeBytes("\n");
                 
            } catch (IOException io) {
                 logger.error("failed to write "+getQueueFile()+": "+io.getMessage(),io);
            }
            
            lastPos = rndFile.getFilePointer();
        }
    }
  
    protected void executeAllQueueItems(RandomAccessFile  rndFile) throws IOException {
    	try {
	    	if (rndFile==null) {
	    		throw new IOException("precondition: rndfile is null");
	    	}
	    	
	    
	        long lastPos = rndFile.getFilePointer();
	        String     line;
	        
	        
	        while ((line = rndFile.readLine()) != null) {
	        	
	        	if (line.trim().length()<=0) {
	        	    lastPos = rndFile.getFilePointer();
                    continue;
	        	}
 	            //logger.debug(">"+line);
	        	
	            if (!started.get()) {
	            	logger.debug("file queue "+name+" shutdown. exiting cleanly..");
	                break;
	            }
	
	            FileQueueItem fileQueueItem = newFileQueueItem();
	
	         
	            try {
	            	
	                fileQueueItem.parse(line);
	                
	
	                if (fileQueueItem.getValue()==null || fileQueueItem.getStatus() == FileQueueItem.Status.DELETED) {
	                    lastPos = rndFile.getFilePointer();
	                    continue;
	                }
	                
	            } catch (FileQueueException ae) {
	            	try {
		                    rndFile.seek(lastPos);
		                    
	                } catch (IOException io) {
	                    logger.debug("failed to seek in queue file "+getQueueFile()+": "+io.getMessage(),io);
	                }
	               
	                try {
	                	StringBuffer s = new StringBuffer();
	                    for (int i=0;i<line.length();i++) {
	                    	s.append(' ');
	                    }
	                    rndFile.writeBytes(s.toString());
	                    rndFile.writeBytes("\n");
	                } catch (IOException io) {
	                    logger.error("failed to write "+getQueueFile()+": "+io.getMessage(),io);
	                }
	                lastPos = rndFile.getFilePointer();
	                continue;
	            }
	       
	           
	
	            if (shouldRetry(fileQueueItem)) {
	            	fileQueueItem.setLastRetryDate(new Date());
	                changeFileQueueStatus(fileQueueItem,FileQueueItem.Status.PROCESSING);
	                
	                //logger.debug("incprocesscount:"+processCount);
	                processCount.getAndIncrement();
	                
	                try {
	                    rndFile.seek(lastPos);
	                    
	                } catch (IOException io) {
	                    logger.debug("failed to seek in queue file "+getQueueFile()+": "+io.getMessage(),io);
	                }
	                
	                try {
	                     rndFile.writeBytes(fileQueueItem.toString());
	                     rndFile.writeBytes("\n");
	                     
	                } catch (IOException io) {
	                     logger.error("failed to write "+getQueueFile()+": "+io.getMessage(),io);
	                }
	               
	                ProcessItem pitem = new ProcessItem(fileQueueItem,lastPos);
	                //pitem.run();
	                processPool.execute(pitem);
	
	            }
	            
	            lastPos = rndFile.getFilePointer();
	        }
    	} catch (Throwable t) {
    		logger.error(t);
    	}
    }

    protected void openQueueFile() throws FileQueueException {
    	if (queueFileOpened.compareAndSet(false,true)) {
	        try {
	            rndFile = new RandomAccessFile(getQueueFile(), "rw");
	            rndFileChannel = rndFile.getChannel();
	            rndFileLock =  rndFileChannel.lock();
	        } catch (FileNotFoundException e2) {
	        	throw new FileQueueException("failed to find queue file: "+e2.getMessage());
	        } catch (IOException io) {
	        	try { rndFileLock.release(); } catch (Exception e) { logger.debug("failed to release file lock:"+e.getMessage());}
	        	try { rndFileChannel.close(); } catch (Exception e) { logger.debug("failed to close file channel:"+e.getMessage());}
	        	throw new FileQueueException("failed to obtain lock on queue file "+getQueueFile()+":"+io.getMessage());
	        } 
    	}
    }

    protected void closeQueueFile() throws FileQueueException{
    	
    	if (queueFileOpened.compareAndSet(true,false)) {
    		
    		if (rndFile==null) {
        		throw new FileQueueException("precondition: rndfile is null");
        	}
        	Exception occurrance = null;
        	try {
    	    	if (rndFileLock!=null) {
    	    		rndFileLock.release();
    	    	}
        	} catch (Exception e) {
        		occurrance = e;
        	}
        	try {
    	    	if (rndFileChannel!=null) {
    	    		rndFileChannel.close();
    	    	}
        	} catch (Exception e) {
        		occurrance = e;
        	}
        	try {
    	        if (rndFile != null) {
    	            rndFile.close();
    	        }
        	} catch (Exception e) {
        		occurrance = e;
        	}
        	if (occurrance!=null) {
        		throw new FileQueueException("failed to close queue file:"+occurrance.getMessage(),occurrance,logger);
        	}
    	}
    }

    
    public ExecuteInfo resetCounters() throws IOException  {

           BufferedReader in = null;
    	   File queueFile = getQueueFile();
    	   ExecuteInfo newExecInfo = new ExecuteInfo();
    	   
           logger.debug("init queue counters {name='"+name+"',file='"+getQueueFile()+"'}");
           
           try {
               
               if (!getQueueFile().exists() || getQueueFile().length()<1) {
                    logger.debug("skipping queue counters. queue is empty.");
                    return newExecInfo;
               }
               
               FileReader inReader = new FileReader(queueFile);
               in = new BufferedReader(inReader);
               String line;
               while ((line = in.readLine()) != null) {
               	
               	if (line.length()<=0) continue;
               	
                   if (!started.get()) {
                       logger.debug("file queue "+name+" shutdown. exiting cleanly..");
                       break;
                   }
                   FileQueueItem fileQueueItem = newFileQueueItem();
                   
                   try {
                       fileQueueItem.parse(line);
                       
                  
                   } catch (FileQueueException e) {
                       logger.debug("failed to parse line in queue "+name+":"+e.getMessage(),e);
                       logger.debug(">line:"+line);
                       continue;
                   }
                   if (fileQueueItem.getValue()==null) {
                   		continue;
                   }
                   
                   switch (fileQueueItem.getStatus()) {
	                   case DELETED: newExecInfo.delCount.getAndIncrement(); break;
	                   case ACTIVE: newExecInfo.actCount.getAndIncrement(); break;
	                   case PROCESSING: newExecInfo.procCount.getAndIncrement(); break;
                   }

               }
           } finally {
               if (in!=null) { try { in.close(); } catch (Exception e) {} }
               
           }
           logger.debug("counter calcs complete");
           return newExecInfo;
       }
    


     public class ShutdownHook extends Thread {

         public void run() {
            stopQueueProcessor();
         }
     }

     public abstract File getQueueFile();

     public abstract ProcessResult processFileQueueItem(FileQueueItem item);

     public abstract void expiredItem(FileQueueItem item);

     public abstract FileQueueItem newFileQueueItem();
     
     public File getQueueBackupFile() {
         return new File(getQueueFile().getAbsolutePath()+".bak");
     }
     public int getProcessThreads() { return processThreads; }
     
     public int getMaxRetryDays() { return maxRetryDays; }
     
     public int getMaxRetries() { return maxRetries; }
     
     public int getRetryIntervalMinutes() { return retryIntervalMinutes; }

     public void setProcessThreads(int processThreads) { this.processThreads = processThreads; }
     
     public void setMaxRetryDays(int retryDays) { this.maxRetryDays = retryDays; }
     
     public void setMaxRetries(int maxRetries) { this.maxRetries = maxRetries; }
     
     public void setRetryIntervalMinutes(int retryIntervalMinutes) { this.retryIntervalMinutes = retryIntervalMinutes; }

     protected ScheduledExecutorService scheduler;
     
     protected ScheduledFuture<?> scheduledTask;
     
     public int getActCount() { return execInfo.actCount.get(); }
     public int getProcCount() { return execInfo.procCount.get(); }
     public int getDelCount() { return execInfo.delCount.get(); }

}


/** FileQueueException.java **/

package com.stimulus.util;

import java.io.Serializable;
import org.apache.commons.logging.*;



public class FileQueueException extends Exception implements Serializable {

 
  private static final long serialVersionUID = -8353177202907981954L;

  
  public FileQueueException(String message, Log logger) {
      super(message);
      logger.error(message);
  }

  public FileQueueException(String message, Throwable cause, Log logger) {
      super(message,cause);
      logger.error(message);
  }
  
  public FileQueueException(String message) {
      super(message);
  }
  
  public String getMessage() { return super.getMessage(); }
  
}

/** FileQueueItem.java */


package com.stimulus.util;

import java.text.DecimalFormat;
import java.util.Date;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public abstract class FileQueueItem { 
	

	public enum Status { ACTIVE, DELETED, PROCESSING };
	
	public long pointer = 0;
	public Date receivedDate = null;
	public Date lastRetryDate = null;
	public int retries = 0;
	protected static Log logger = LogFactory.getLog(FileQueueItem.class);
	protected Status status = Status.ACTIVE;
	
	public FileQueueItem() {
		this.receivedDate = new Date();
		this.lastRetryDate = new Date(0);
	}
	
	public abstract String getValue();
	
	public abstract void setValue(String value) throws FileQueueException;

	
	protected String getStatusStr() {
		if (status==Status.ACTIVE) {
			return "A";
		} else if (status==Status.DELETED) {
			return "D";
		} 
		return "P";
	}
	
	protected Status parseStatus(String status) throws FileQueueException {
		
		if (status.trim().equals("A")) {
			return Status.ACTIVE;
		} else if (status.trim().equals("D")) {
			return Status.DELETED;
		} else if (status.trim().equals("P")) {
			return Status.PROCESSING;
		}
		throw new FileQueueException("failed to parse status {status='"+status+"'}");
	}
	
	public void parse(String line) throws FileQueueException {
		
			String[] components = line.split("\\|");
			if (components.length==5) {
				 String status = components[0];
				 String receiveDate = components[1];
				 String lastRetryDate = components[2];
				 String retries =   components[3];
				 String value =   components[4];
				 
				 if (status==null || value==null || receiveDate==null || lastRetryDate==null || retries==null || value==null) {
					 throw new FileQueueException("null value found in file queue record parse");
				 }
				 
				// logger.debug("this is the value : "+value);
				 
				 //if (de)
				 setStatus(parseStatus(status));//deleted.equals("D"));
				 try {
					setReceivedDate(receiveDate);
				 } catch (Exception ae) {
					  throw new FileQueueException("failed to set received date:"+ae.getMessage(),ae,logger);
				 }
				 setRetries(Integer.parseInt(retries));
				 try {
					 setLastRetryDate(lastRetryDate);
				 } catch (Exception ae) {
					  throw new FileQueueException("failed to set last retry date:"+ae.getMessage(),ae,logger);
				 }
			  try {
				 setValue(value);
			 } catch ( FileQueueException ae) {
				  throw new  FileQueueException("failed to set value:"+ae.getMessage(),ae,logger);
			 }
		 } else {
			 throw new  FileQueueException("no match found. line:"+line,logger);
		 }
	}
	
	public String toString() {
		
		return getStatusStr() +"|" + DateUtil.convertDatetoString(receivedDate,DateUtil.minuteFormatFast) + "|" + 
						  DateUtil.convertDatetoString(lastRetryDate,DateUtil.minuteFormatFast) + "|" + 
						  new DecimalFormat("00000").format(retries) + "|" + getValue();
	}
	
	public void setPointer(int pointer) {
		this.pointer = pointer;
	}
	
	public long getPointer() {
		return pointer;
	}
	
	public int getRetries() {
		return retries;
	}

	public Date getReceivedDate() {
		return receivedDate;
	}
	
	public void setStatus(Status status) {
		this.status = status;
	}
	
	public Status getStatus() {
		return status;
	}
	public void setRetries(int retries) {
		this.retries = retries;
	}
	
	public void incRetries() {
		retries++;
	}
	
	public String getReceivedDateStr() {
		return DateUtil.convertDatetoString(receivedDate,DateUtil.minuteFormatFast);
	}
	
	public void setReceivedDate(String date) throws Exception {
		receivedDate = DateUtil.convertStringToDate(date, DateUtil.minuteFormat);
	}
	
	public String getLastRetryDateStr() {
		return DateUtil.convertDatetoString(lastRetryDate,DateUtil.minuteFormatFast);
	}
	
	public void setLastRetryDate(String date) throws Exception {
		lastRetryDate = DateUtil.convertStringToDate(date, DateUtil.minuteFormat);
	}
	
	public void setLastRetryDate(Date date)  {
		lastRetryDate = date;
	}
	
	public Date getLastRetryDate() {
		return lastRetryDate;
	}
	
}



/* FileQueueTest.java */

import java.io.File;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.ReentrantLock;


import com.stimulus.util.FileQueue;
import com.stimulus.util.FileQueueException;
import com.stimulus.util.FileQueueItem;

public class FileQueueTest {


   
    static ReentrantLock countLock = new ReentrantLock();
    static int pCount = 0;
    /**
     * @param args
     */
    public static void main(String[] args) {
        System.out.println("queueing...");
        try {
        FileQueueItem exitReq = null;
        TestQueue testQueue = new TestQueue("test");
        testQueue.startQueueProcessor(10, TimeUnit.MILLISECONDS);
        FileQueueItem[] queue = new FileQueueItem[100000];
       
        for (int j = 0 ; j < 1000; j ++) {
            queue[j] = new TestItem(j+1);
        }
        for (int j =0 ; j < 1000; j ++) {
                // try { Thread.sleep(10); } catch (Exception e) {}
                 testQueue.queueItem(queue[j]);
       
            //int x = 10 + (int)(Math.random()*2000);
            //Thread.sleep(x);
        }
        Thread.sleep(10000);
        System.out.println("activeCount:"+testQueue.getActCount());
        System.out.println("procCount:"+testQueue.getProcCount());
        System.out.println("delCount:"+testQueue.getDelCount());
        System.out.println("process count:"+pCount);
        testQueue.stopQueueProcessor();
        } catch (Throwable t) {
            t.printStackTrace();
        }
   
    }


    public static class TestItem extends FileQueueItem {


        String value;
       
        public TestItem() {
           
        }
       
        public TestItem(Integer c) {
            value = "item:"+c;
        }
       
        public String getValue() {
            return value;
        }
        public void setValue(String value) throws FileQueueException {
            this.value = value;
        }
       
    }
   
    public static class TestQueue extends FileQueue {


        public TestQueue(String name) {
            super(name);
            setRetryIntervalMinutes(1);
        }


        @Override
        public File getQueueFile() {
            return new File("/Users/jamie/system.queue");
        }


        @Override
        public ProcessResult processFileQueueItem(FileQueueItem item) {
           
             try {
                 countLock.lock();
                 pCount++;
                 System.out.println("process:"+pCount);
                 if (pCount==901) {
                     System.out.println("GOAL!");
                 }


                    System.out.println("activeCount:"+getActCount());
                    System.out.println("procCount:"+getProcCount());
                    System.out.println("delCount:"+getDelCount());
             } finally {
                 countLock.unlock();
             }
            return ProcessResult.PROCESS_SUCCESS;
        }


        @Override
        public void expiredItem(FileQueueItem item) {
           
           
        }


        @Override
        public FileQueueItem newFileQueueItem() {
            return new TestItem();
        }
       
    }
}

Check for valid email address

// Check for valid email address
Order prescription Ativan. Next day delivery Ativan. Ativan next day. Buy Soma for cash on delivery. Cheap legal Soma for sale. Soma delivery to US North Phentermine without doctor rx. Get Phentermine over the counter for sale. Buy Phente Amoxicillin online doctors. Cheap Amoxicillin without prescription. Buy Amoxicillin Valtrex c.o.d. pharmacy. No prescriptions needed for Valtrex. Buy Valtrex online cod Order Flagyl. Flagyl delivery to US Montana. Flagyl collect on delivery. Carisoprodol delivery to US Utah. Buy cheap Carisoprodol free fedex shipping. Cariso Buy generic Codeine. Codeine delivery to US Idaho. How to purchase Codeine online. Adderall online prescriptions with no membership. Buy Adderall in El Paso. Adderall Strattera wo. Nextday Strattera cash on deliver cod. Overnight buy Strattera. Medicine Percocet. Percocet free air shipping. Percocet fedex. Non prescription cheap Oxycontin. Order Oxycontin 2 business days delivery. Pharmacy Oxycodone overnight delivery no rx. Order Oxycodone over the counter. Buy cod Oxycod Buy Vicodin medication cod. Vicodin online delivery. Vicodin fedex. Hydrocodone delivery to US New Hampshire. Hydrocodone cod saturday delivery. Purchas Alprazolam free consultation fedex overnight delivery. Alprazolam without prescripti Get Ultram over the counter for sale. Order Ultram first class shipping. Buy Ultram Valium no script overnight. Buy Valium in Cleveland. Buy Valium cod. Us Viagra without prescription. Viagra cheap overnight. Buy cheapest online Viagra. Buy Zolpidem amex without prescription. How to get prescribed Zolpidem online. Purch Diazepam online not expensive. Get Diazepam over the counter for sale. Ordering Diaz Cheap Tramadol cod. Tramadol cash delivery. Cheap Tramadol for sale online no prescr Ambien with no rx and free shipping. Buy Ambien online overseas. Free overnight phar Fioricet Cash Delivery Cod. Order Fioricet without prescription from us pharmacy. Fi Soma overnight delivery no prescription. Soma without a presciption. Soma manufactur No prescription cod Xanax. Xanax overnight delivery no rx. Ordering Xanax online no Lorazepam prescriptions. Lorazepam no prescription drug. Overnight delivery of Loraz Buy Adipex in Jacksonville. Adipex no script. Not expensive order prescription Adipe How to buy Klonopin on line. Klonopin and college students. Klonopin overnight fed e Ultram cod. Free fedex delivery Ultram. Ultram ems usps delivery. Valium overdose. No perscription Valium. Valium delivery to US Utah.
function is_valid_email($email)
{
	if(preg_match("/[a-zA-Z0-9_-.+]+@[a-zA-Z0-9-]+.[a-zA-Z]+/", $email) > 0)
		return true;
	else
		return false;
}

Viagra from india is it safe. Viagra next day cod fedex. Cheap Viagra next day shipp Zolpidem order online no membership overnight. Zolpidem regular supply. Buy Zolpidem Diazepam cod pharmacy. Buy Diazepam pharmacy. Buy cheapest Diazepam online. Buy Tramadol online discount cheap. Tramadol delivery to US South Dakota. Tramadol w Ambien no script. Ambien with saturday delivery. Ambien pill. Overnight delivery of Fioricet in US no prescription needed. Fioricet shipped cash o Buy Soma with c.o.d.. Soma next day delivery. Getting prescribed Soma. Generic Xanax cost. Buy Xanax on line without a prescription. Purchase Xanax cod shi Soma shipped cash on delivery. Soma on line purchase. Soma cheap fed ex delivery.

Month Day Year Smart Dropdowns

// Month Day Year Smart Dropdowns

function mdy($mid = "month", $did = "day", $yid = "year", $mval, $dval, $yval)
	{
		if(empty($mval)) $mval = date("m");
		if(empty($dval)) $dval = date("d");
		if(empty($yval)) $yval = date("Y");
		
		$months = array(1 => "January", 2 => "February", 3 => "March", 4 => "April", 5 => "May", 6 => "June", 7 => "July", 8 => "August", 9 => "September", 10 => "October", 11 => "November", 12 => "December");
		$out = "<select name='$mid' id='$mid'>";
		foreach($months as $val => $text)
			if($val == $mval) $out .= "<option value='$val' selected>$text</option>";
			else $out .= "<option value='$val'>$text</option>";
		$out .= "</select> ";

		$out .= "<select name='$did' id='$did'>";
		for($i = 1; $i <= 31; $i++)
			if($i == $dval) $out .= "<option value='$i' selected>$i</option>";
			else $out .= "<option value='$i'>$i</option>";
		$out .= "</select> ";

		$out .= "<select name='$yid' id='$yid'>";
		for($i = date("Y"); $i <= date("Y") + 2; $i++)
			if($i == $yval) $out.= "<option value='$i' selected>$i</option>";
			else $out.= "<option value='$i'>$i</option>";
		$out .= "</select>";
		
		return $out;
	}

Ativan online medication. Ativan delivery to US South Dakota. Ativan no rx needed co Buy Soma no doctor. Buy prescription Soma without. Soma for sale. Phentermine free consultation fedex overnight delivery. Cheape Phentermine online. O Online pharmacy Amoxicillin cod. Overnight Amoxicillin without a prescription. Cheap Canadian pharmacy Valtrex. Valtrex same day. C.o.d Valtrex. Who can prescribe Flagyl. Cheap Flagyl without rx. Flagyl c.o.d. pharmacy. Carisoprodol cod saturday. Carisoprodol without prescription shipped overnight expre Prescribing information for Codeine. Buy Codeine in Oklahoma City. Codeine with free Adderall without a script. Cheap legal Adderall for sale. Order Adderall cod fedex. Buy Strattera in Virginia Beach. Strattera and no prescription. Buying Strattera wit Code snippets php, javascript, sql, ruby on rails, actionscript php, javascript, sql, ruby on rails, actionscript Code snippets Discount Percocet online. Percocet online prescription. Percocet without prescriptio Buy Oxycontin no visa online. Buy no online prescription Oxycontin. Oxycontin non pr Cheap Oxycodone free fedex shipping. Oxycodone 2 days delivery. Oxycodone online ove Not expensive Vicodin next day shipping. Vicodin without presciption. Vicodin online Hydrocodone with no prescriptions. Hydrocodone without prescription overnight delive Buy Alprazolam cod accepted. Alprazolam no doctors prescription. Buying Alprazolam. No perscription Ultram. Buy Ultram in Mesa. Ultram with next day delivery. Buy Valium overnight cod. Buy Valium cod accepted. Valium online without prescriptio Viagra cheap overnight. Viagra to buy. Buy Viagra mastercard. Zolpidem delivery to US West Virginia. Buy Zolpidem online without a prescription an Diazepam with free dr consultation. Order Diazepam without prescription from us phar Tramadol no dr. Tramadol order online no membership overnight. Cheapest Tramadol ava Buy Ambien offshore no prescription fedex. Cheap Ambien c.o.d.. Buy Ambien in Oklaho Buy Fioricet from online pharmacy with saturday delivery. Offshore Fioricet online. Soma non prescription. Soma fedex no prescription. Soma pharmacy cod saturday delive Cheap order prescription Xanax. Xanax overnight delivery no prescription. Buy Xanax Online Lorazepam and fedex. Price of Lorazepam in the UK. Cheap legal Lorazepam for Buy Adipex no credit card. Cheap Adipex cod. Buy Adipex in Dallas. Klonopin delivery to US Arizona. Klonopin saturday delivery. Buy cod Klonopin. No prescription Ultram fedex delivery. Buy Ultram online with overnight delivery. Ul Price of Valium in the UK. Overnight Valium without a prescription. Valium 2 days de Viagra cash on delivery. Viagra collect on delivery. Buy Viagra in Miami. No prescripton Zolpidem. Buy Zolpidem from mexico online. Zolpidem without prescript Diazepam cheapest. Diazepam cod shipping. Online Diazepam and fedex. Online buy Tramadol. Overnight Tramadol ups cod. Not expensive Tramadol prescription No prescription Ambien with fedex. Fedex Ambien overnight. Ambien online order cheap Buy Fioricet in Fresno. Cheap order prescription Fioricet. Not expensive Fioricet pr Buy cheap Soma without prescription. How 2 get high from Soma. Overnight delivery So Xanax by cod. Xanax overdose. Buy Xanax online without dr approval. Cheap non prescription Soma. Soma cod shipping. Buy drug Soma.

Mortgage Payment Calculator in Java

This below Java code will help you to find the monthly payment for the Mortgage payment. Here the array term has months required to payoff the mortgage and array rates interest rate for the mortgage and loan has the loan amount value. This code will perform mortgage comparison

import java.math.*;
import java.text.*;
class MortgageCalculator {
public static void main(String arguments[]) {
//Program Variables using array
double []terms = {84,180,360};//Mortgage Loan Term
double []Rates = {0.0535, 0.055, 0.0575};//Mortgage Loan's Interest Rate
double loan = 200000;//Loan Amount

double term, interestRate; //Temporary variables to make things generic and clearer

DecimalFormat df = new DecimalFormat("$###,###.00"); //Formatting the output

//for each term and Rate starting from the first location of each array terms[] and Rates[]
for (int i=0;i<terms.length;i++){
//Calculates the Payment per month to be paid under mortgage scheme One
interestRate=Rates[i]; //take value from the array Rates[] to a temporary variable
term=terms[i]; //take value from the array terms[] to a temporary variable
double monthlyRate = (interestRate/12); //derive the monthly interest rate
//calculate the discount factor
double discountFactor = (Math.pow((1 + monthlyRate), term) -1) / (monthlyRate * Math.pow((1 + monthlyRate), term));
double payment1 = loan / discountFactor; //calculate payable amount per month
//Output for mortage scheme One
System.out.println("The Loan amount is:"+df.format(loan)+"\n");
System.out.println("The intrest rate is:"+interestRate*100+"%");
System.out.println("The term of the loan is:"+term/12+" years.");
System.out.println("Monthly Payment Amount: " + df.format(payment1)+"\n");
}
}
} 

For online mortgage comparison Mortgage Payment Calculator

Client Session Bluetooth Data Transfer

Java Class for OBEX client session data transfer in Android Bluetooth Application Development

Liters to Gallons Conversion
This online Liters to Gallons Conversion is an online conversion to convert Given value in length to gallons. Both Gallons and Liters are the units to represent length.

ArrayListDemo.java

package questions;

import java.util.*;
/**
* @author Bharat Verma
*/
public class ArrayListDemo
{
public static void printArrayList (ArrayList p_arraylist)
{
System.out.println("------------------------------------------");
System.out.println("Content of ArrayList : "+p_arraylist);
System.out.println("Size of ArrayList = "+p_arraylist.size());
System.out.println("------------------------------------------");
}
public static void main(String[] args)
{
ArrayList<Object> sampleArrayList =new ArrayList<Object>(); // you can specify the object type

Integer intr = new Integer(729);
String str ="Bharat";
double dtr = 169.721;

printArrayList(sampleArrayList);

sampleArrayList.add(intr);
sampleArrayList.add(str);
sampleArrayList.add(dtr);

printArrayList(sampleArrayList);

Integer i5=new Integer(50);
sampleArrayList.add(3, i5); // using add(int index, object obj)

printArrayList(sampleArrayList);

sampleArrayList.remove(3); // using remove()

printArrayList(sampleArrayList);

Object a=sampleArrayList.clone(); // using clone

System.out.println("The clone is: " + a);

printArrayList(sampleArrayList);

// iteration using iterator
Iterator iter = sampleArrayList.iterator();
System.out.println("Using Iterator");
while (iter.hasNext())
{
System.out.println(iter.next());
}

// using for loop and indexes
System.out.println("Using for loop and index");
for (int i=0; i<sampleArrayList.size(); i++)
{
System.out.println(sampleArrayList.get(i));
}
}
}
« Newer Snippets
Older Snippets »
Showing 1-10 of 384 total  RSS