alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

What this is

This file is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Other links

The source code

package org.gjt.mm.mysql;

import java.util.StringTokenizer;

public class PushBackTokenizer extends StringTokenizer
{
	private boolean _push_back = false; // are we pushed back?
	
	private String  _CurrentToken = null;
	
	/**
	 * Create a new StringTokenizer that allows for push back.
	 */
	
	public PushBackTokenizer(String S, String Tokens, boolean return_tokens)
	{
		super(S, Tokens, return_tokens);
	}
	
	/**
	 * The next token to be read will
	 * be the current token
	 */
	
	public synchronized void pushBack()
	{
		_push_back = true;
	}
	
	/**
	 * Does this tokenizer contain any more
	 * tokens?
	 */
	
	public synchronized boolean hasMoreTokens()
	{
		if (_push_back) {
			return true;
		}
		else {
			return super.hasMoreTokens();
		}
	}
	
	/**
	 * Does this tokenizer have any more elements?
	 */
	
	public synchronized boolean hasMoreElements()
	{
		if (_push_back) {
			return true;
		}
		else {
			return super.hasMoreElements();
		}
	}
	
	/**
	 * Retrieve the next token from this
	 * tokenizer.
	 */
	
	public synchronized String nextToken()
	{
		if (_push_back) {
			_push_back = false;
			return _CurrentToken;
		}
		else {
			_CurrentToken = super.nextToken();
			
			return _CurrentToken;
		}
	}
};
... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.