package ch.ntb.inf.deep.config;

public class Segment implements IAttributes {
	public Segment subSegments;
	private Segment lastSubSegment;
	public Segment next;
	
	int attributes = 0;
	int baseAddress = -1;
	int size = 0;
	int width = 0;
	
	public Segment() {}
	
	public Segment(int baseAddress) {
		this.baseAddress = baseAddress;
	}
	
	public Segment(int baseAddress, int size) {
		this.baseAddress = baseAddress;
		this.size = size;
	}
	
	public Segment(int baseAddress, int size, int attributes) {
		this.baseAddress = baseAddress;
		this.size = size;
		this.attributes = attributes;
	}
	
	public Segment(int baseAddress, int size, int width, int attributes) {
		this.baseAddress = baseAddress;
		this.size = size;
		this.width = width;
		this.attributes = attributes;
	}

	public void setAttribute(int attributes) {
		this.attributes = attributes;
	}
	
	public void addAttributes(int attributes) {
		this.attributes |= attributes;
	}
	
	public void removeAttributes(int attributes) {
		this.attributes &= ~attributes;
	}
	
	public void setBaseAddress(int baseAddress) {
		this.baseAddress = baseAddress;
	}
	
	public void setSize(int size) {
		this.size = size;
	}
	
	public void setEndAddress(int endAddress) {
		if(this.baseAddress >= 0) {
			this.size = endAddress - this.baseAddress;
		}
	}
	
	public int getBaseAddress() {
		return this.baseAddress;
	}
	
	public int getSize() {
		return this.size;
	}
	
	public boolean addSubSegment(Segment s) {
		s.attributes |= this.attributes;
		if(s.width == 0) s.width = this.width;
		if(s.width == this.width) {
			if(this.subSegments == null) {
				this.subSegments = s;
				this.lastSubSegment = this.subSegments;
			}
			else {
				this.lastSubSegment.next = s;
				this.lastSubSegment = this.subSegments.next;
			}
			return true;
		}
		return false;
	}
}

@@ -223,24 +223,48 @@
  size = 0;%0D%0A
+%09int requiredSize = 0;%0D%0A
 %09int width =
@@ -1914,11 +1914,272 @@
 e;%0D%0A%09%7D%0D%0A
+%09%0D%0A%09/**%0D%0A%09 * Add Size to requiredSize.%0D%0A%09 * @param size%0D%0A%09 */%0D%0A%09public void addToRequiredSize(int size)%7B%0D%0A%09%09requiredSize += size;%0D%0A%09%7D%0D%0A%09%0D%0A%09%0D%0A%09/**%0D%0A%09 * @return the required size of the Segement.%0D%0A%09 */%0D%0A%09public int getRequiredSize()%7B%0D%0A%09%09return requiredSize;%0D%0A%09%7D%0D%0A
 %7D%0D%0A

add variable requriedSize with getter and setter