ConditionalEnumeration.java :  » Game » gameporting » com » sonyericsson » midp » Android Open Source

Android Open Source » Game » gameporting 
gameporting » com » sonyericsson » midp » ConditionalEnumeration.java
/*********************************************************************
 *  ____                      _____      _                           *
 * / ___|  ___  _ __  _   _  | ____|_ __(_) ___ ___ ___  ___  _ __   *
 * \___ \ / _ \| '_ \| | | | |  _| | '__| |/ __/ __/ __|/ _ \| '_ \  *
 *  ___) | (_) | | | | |_| | | |___| |  | | (__\__ \__ \ (_) | | | | *
 * |____/ \___/|_| |_|\__, | |_____|_|  |_|\___|___/___/\___/|_| |_| *
 *                    |___/                                          *
 *                                                                   *
 *********************************************************************
 * Sony Ericsson Mobile Communications AB, Lund Sweden               *
 * Copyright 2007 Sony Ericsson Mobile Communications AB.            *
 * All rights, including trade secret rights, reserved.              *
 *********************************************************************
 *
 * @file 
 * @ingroup JAVA
 *
 * @copyright_semc
 * @author MIDP
 */
package com.sonyericsson.midp;

import java.util.Enumeration;

public abstract class ConditionalEnumeration implements Enumeration {
  
  private Enumeration elements;
  private Object nextElem;
  
  public ConditionalEnumeration(Enumeration elements) {
    this.elements = elements;
  }
  public boolean hasMoreElements() {
    boolean hasMore = false;
    nextElem = null;
    
    while((hasMore = elements.hasMoreElements()) && 
        !checkCondition(nextElem = elements.nextElement()));

    return hasMore; 
  }
  public abstract boolean checkCondition(Object item);

  public Object nextElement() {
    if(nextElem != null)
      return nextElem;
    
    return elements.nextElement();
  }  
}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.