Created
December 3, 2010 08:40
-
-
Save mgenov/726725 to your computer and use it in GitHub Desktop.
Device Prototype
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.evo.adm; | |
import com.evo.adm.service.server.DeviceTypeSpecification; | |
import com.google.code.twig.annotation.Embedded; | |
import org.junit.Test; | |
import java.util.ArrayList; | |
import java.util.List; | |
/** | |
* | |
* @author Miroslav Genov ([email protected]) | |
*/ | |
public class DevicePrototypeTest { | |
public enum DeviceType { | |
ONU, STB | |
} | |
static class ProvidedService { | |
@Embedded | |
private List<DeviceDetails> deviceDetails; | |
public void addDeviceTypeFromSpecification(DeviceTypeSpecification specification) { | |
if (deviceDetails == null) { | |
deviceDetails = new ArrayList<DeviceDetails>(); | |
} | |
Integer nextNumber = deviceDetails.size() + 1; | |
deviceDetails.add(DeviceDetails.from(specification, nextNumber)); | |
} | |
public Rent getRent(DeviceType deviceType) { | |
for (DeviceDetails detail : deviceDetails) { | |
if (detail.deviceType.equals(deviceType)) { | |
return detail.rent; | |
} | |
} | |
throw new IllegalStateException("Rent was not found for the provided type:" + deviceType); | |
} | |
} | |
public static class DeviceDetails { | |
public static DeviceDetails from(DeviceTypeSpecification deviceTypeSpecification, Integer number) { | |
return new DeviceDetails(DeviceType.ONU, 0); | |
} | |
private DeviceType deviceType; | |
private Integer number; | |
private Rent rent; | |
public static DeviceDetails onu() { | |
return new DeviceDetails(DeviceType.ONU,0); | |
} | |
public static DeviceDetails onu(Integer number) { | |
return new DeviceDetails(DeviceType.ONU,number); | |
} | |
public static DeviceDetails stb() { | |
return new DeviceDetails(DeviceType.STB,0); | |
} | |
private DeviceDetails(DeviceType deviceType, Integer number) { | |
this.deviceType = deviceType; | |
this.number = number; | |
} | |
DeviceDetails() { | |
} | |
} | |
class Rent { | |
private Double amount; | |
Rent(Double amount) { | |
this.amount = amount; | |
} | |
} | |
public class ServiceManager { | |
public Rent getServiceRent(ProvidedService service, DeviceType type) { | |
// retrieve service from datastore | |
// get type of that service | |
// return rent for that service | |
return new Rent(0d); | |
} | |
} | |
@Test | |
public void addDeviceFromSpecification() { | |
ProvidedService service = new ProvidedService(); | |
service.addDeviceTypeFromSpecification(new DeviceTypeSpecification()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment