Code example for ListIterator

Methods: hasNextnextset

0
public class NamePlanet extends AbstractOrderCommand 
{ 
	@Override 
	public void exec( Race race, ListIterator<String> cmd, PrintWriter out ) throws GalaxyException
	{ 
		if( !cmd.hasNext() )
			throw new GalaxyException( "Required planet name" ); 
 
		Galaxy galaxy = race.getGalaxy();
		String planetName = galaxy.validIdentifier( cmd.next() );
		cmd.set( planetName );
		Planet planet = race.getOwnPlanet( planetName );
 
		if( !cmd.hasNext() )
			throw new GalaxyException( "Required new planet name" ); 
 
		String newName = galaxy.validIdentifier( cmd.next() );
		cmd.set( newName );
		if( !galaxy.isValidIdentifier( newName ) )
			throw new GalaxyException( "Invalid name for planet: {0}", newName );
 
		if( galaxy.findPlanetByName( newName ) != null )
			throw new GalaxyException( "Planet name {0} already in use", newName );
Experience pair programming with AI  Get Codota for Java