All Downloads are FREE. Search and download functionalities are using the official Maven repository.

se.l4.vibe.internal.builder.AbstractBuilder Maven / Gradle / Ivy

There is a newer version: 0.4.0
Show newest version
package se.l4.vibe.internal.builder;

import se.l4.vibe.builder.Builder;

/**
 * Abstract implementation of a builder.
 * 
 * @author Andreas Holstenson
 *
 * @param 
 */
public class AbstractBuilder
	implements Builder
{
	protected String path;
	
	@Override
	public Self at(String path)
	{
		this.path = path;
		
		return (Self) this;
	}
	
	@Override
	public Self at(String... hierarchy)
	{
		StringBuilder path = new StringBuilder();
		for(int i=0, n=hierarchy.length; i 0) path.append('/');
			
			String segment = hierarchy[i];
			if(segment.indexOf('/') != -1)
			{
				throw new IllegalArgumentException("Segments may not contain /; For " + segment);
			}
			
			path.append(segment);
		}
		
		this.path = path.toString();
		
		return (Self) this;
	}
	
	@Override
	public Self at(Class type)
	{
		if(type == null)
		{
			throw new IllegalArgumentException("Type can not be null");
		}
		
		this.path = type.getName().replace('.', '/');
		
		return (Self) this;
	}
	
	protected void verify()
	{
		if(path == null)
		{
			throw new IllegalStateException("A path is required");
		}
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy