All pastes #951601 Raw Edit

Miscellany

public text v1 · immutable
·published 2008-03-21 14:56 UTC
rendered paste body
package funala.domain.entity.ad.residenceoffer;

import javax.persistence.Embeddable;
import javax.persistence.Transient;

/**
 * Utilities included in the rent. "The stupid bills you have to pay at the end
 * of the month."
 * 
 * @author Sami Dalouche (sami.dalouche@gmail.com)
 * 
 */
@Embeddable
public final class Utilities {

    public static final class UtilitiesBuilder {
	private boolean cableTv = false;
	private boolean electricity = false;
	private boolean heat = false;
	private boolean highSpeedInternetAccess = false;
	private boolean phoneLine = false;
	private boolean satelliteTv = false;
	private boolean securitySystem = false;
	private boolean trashPickup = false;
	private boolean unlimitedPhonePlan = false;
	private boolean water = false;

	private UtilitiesBuilder() {}

	public UtilitiesBuilder withCableTv(boolean b) {
	    this.cableTv = b;
	    return this;
	}
	public UtilitiesBuilder withElectricity(boolean b) {
	    this.electricity = b;
	    return this;
	}
	public UtilitiesBuilder withHeat(boolean b) {
	    this.heat = b;
	    return this;
	}
	public UtilitiesBuilder withHighSpeedInternetAccess(boolean b) {
	    this.highSpeedInternetAccess = b;
	    return this;
	}
	public UtilitiesBuilder withPhoneLine(boolean b) {
	    this.phoneLine = b;
	    return this;
	}
	public UtilitiesBuilder withSatelliteTv(boolean b) {
	    this.satelliteTv = b;
	    return this;
	}
	public UtilitiesBuilder withSecuritySystem(boolean b) {
	    this.securitySystem = b;
	    return this;
	}
	public UtilitiesBuilder withTrashPickup(boolean b) {
	    this.trashPickup = b;
	    return this;
	}
	public UtilitiesBuilder withUnlimitedPhonePlan(boolean b) {
	    this.unlimitedPhonePlan = b;
	    return this;
	}
	public UtilitiesBuilder withWater(boolean b) {
	    this.water = b;
	    return this;
	}

	public Utilities build() {
	    return new Utilities()
	    	.withCableTv(cableTv)
	    	.withElectricity(electricity)
	    	.withHeat(heat)
	    	.withHighSpeedInternetAccess(highSpeedInternetAccess)
	    	.withPhoneLine(phoneLine)
	    	.withSatelliteTv(satelliteTv)
	    	.withSecuritySystem(securitySystem)
	    	.withTrashPickup(trashPickup)
	    	.withUnlimitedPhonePlan(unlimitedPhonePlan)
	    	.withWater(water);
	}
    }

    public static final UtilitiesBuilder utilities() {
	return new UtilitiesBuilder();
    }
    
    private boolean cableTv = false;
    private boolean electricity = false;
    private boolean heat = false;
    private boolean highSpeedInternetAccess = false;
    private boolean phoneLine = false;
    private boolean satelliteTv = false;
    private boolean securitySystem = false;
    private boolean trashPickup = false;
    private boolean unlimitedPhonePlan = false;
    private boolean water = false;

    private Utilities() {
	
    }
    
    @Transient
    private Utilities withCableTv(boolean b) {
	this.cableTv = b;
	return this;
    }
    @Transient
    private Utilities withElectricity(boolean b) {
	this.electricity = b;
	return this;
    }
    @Transient
    private Utilities withHeat(boolean b) {
	this.heat = b;
	return this;
    }
    @Transient
    private Utilities withHighSpeedInternetAccess(boolean b) {
	this.highSpeedInternetAccess = b;
	return this;
    }
    @Transient
    private Utilities withPhoneLine(boolean b) {
	this.phoneLine = b;
	return this;
    }
    @Transient
    private Utilities withSatelliteTv(boolean b) {
	this.satelliteTv = b;
	return this;
    }
    @Transient
    private Utilities withSecuritySystem(boolean b) {
	this.securitySystem = b;
	return this;
    }
    @Transient
    private Utilities withTrashPickup(boolean b) {
	this.trashPickup = b;
	return this;
    }
    @Transient
    private Utilities withUnlimitedPhonePlan(boolean b) {
	this.unlimitedPhonePlan = b;
	return this;
    }
    @Transient
    private Utilities withWater(boolean b) {
	this.water = b;
	return this;
    }
    
    @Override
    public boolean equals(Object obj) {
	if (this == obj)
	    return true;
	if (obj == null)
	    return false;
	if (getClass() != obj.getClass())
	    return false;
	final Utilities other = (Utilities) obj;
	if (cableTv != other.cableTv)
	    return false;
	if (electricity != other.electricity)
	    return false;
	if (heat != other.heat)
	    return false;
	if (highSpeedInternetAccess != other.highSpeedInternetAccess)
	    return false;
	if (phoneLine != other.phoneLine)
	    return false;
	if (satelliteTv != other.satelliteTv)
	    return false;
	if (securitySystem != other.securitySystem)
	    return false;
	if (trashPickup != other.trashPickup)
	    return false;
	if (unlimitedPhonePlan != other.unlimitedPhonePlan)
	    return false;
	if (water != other.water)
	    return false;
	return true;
    }

    @Override
    public int hashCode() {
	final int PRIME = 31;
	int result = 1;
	result = PRIME * result + (cableTv ? 1231 : 1237);
	result = PRIME * result + (electricity ? 1231 : 1237);
	result = PRIME * result + (heat ? 1231 : 1237);
	result = PRIME * result + (highSpeedInternetAccess ? 1231 : 1237);
	result = PRIME * result + (phoneLine ? 1231 : 1237);
	result = PRIME * result + (satelliteTv ? 1231 : 1237);
	result = PRIME * result + (securitySystem ? 1231 : 1237);
	result = PRIME * result + (trashPickup ? 1231 : 1237);
	result = PRIME * result + (unlimitedPhonePlan ? 1231 : 1237);
	result = PRIME * result + (water ? 1231 : 1237);
	return result;
    }

    @Transient
    public boolean isAtLeastOneUtility() {
	int count = 0;
	if (this.cableTv)
	    ++count;
	if (this.electricity)
	    ++count;
	if (this.heat)
	    ++count;
	if (this.highSpeedInternetAccess)
	    ++count;
	if (this.phoneLine)
	    ++count;
	if (this.satelliteTv)
	    ++count;
	if (this.securitySystem)
	    ++count;
	if (this.trashPickup)
	    ++count;
	if (this.unlimitedPhonePlan)
	    ++count;
	return count > 0;
    }

    public boolean isCableTv() {
	return cableTv;
    }

    public boolean isElectricity() {
	return electricity;
    }

    public boolean isHeat() {
	return heat;
    }

    public boolean isHighSpeedInternetAccess() {
	return highSpeedInternetAccess;
    }

    public boolean isPhoneLine() {
	return phoneLine;
    }

    public boolean isSatelliteTv() {
	return satelliteTv;
    }

    public boolean isSecuritySystem() {
	return securitySystem;
    }

    public boolean isTrashPickup() {
	return trashPickup;
    }

    public boolean isUnlimitedPhonePlan() {
	return unlimitedPhonePlan;
    }

    public boolean isWater() {
	return water;
    }

}