src/de/pik/lagom/generic/WorkContract.java

00001 
00002 // Copyright 2010 by Carlo Jaeger, Antoine Mandel, Steffen Fuerst and European Climate Forum
00003 // Licensed under the Open Software License version 3.0
00004 // See the file "License-OSL-3.0.txt" in the distribution for more information
00005 // The License text can be also found under http://www.opensource.org/licenses/osl-3.0.php
00007 
00008 package de.pik.lagom.generic;
00009 
00010 import static de.pik.lagom.annotations.Initialization.INDIVIDUAL;
00011 import static de.pik.lagom.annotations.Variability.N_PERIODS;
00012 import static de.pik.lagom.annotations.Variability.SIMULATION;
00013 import static de.pik.lagom.annotations.Variability.VOLATILE;
00014 
00015 import java.util.Comparator;
00016 
00017 import net.sf.oval.constraint.AssertFieldConstraints;
00018 import net.sf.oval.constraint.NotNegative;
00019 import net.sf.oval.constraint.NotNull;
00020 import net.sf.oval.constraint.ValidateWithMethod;
00021 import net.sf.oval.guard.Guarded;
00022 import net.sf.oval.guard.PostValidateThis;
00023 import de.pik.lagom.annotations.Description;
00024 import de.pik.lagom.annotations.Initialization;
00025 import de.pik.lagom.annotations.Variability;
00026 
00027 
00032 @Guarded
00033 public class WorkContract {
00041   enum Status { OFFERED, NO_OFFER, REJECTED, ACCEPTED }
00042 
00052   public static final class WageComparator implements Comparator<WorkContract> {
00053     public int compare(WorkContract pWorkContract0, WorkContract pWorkContract1) {
00054       // first determine the wage of both contracts ...
00055       final double lWage0 = pWorkContract0.getWageFullEmployed();
00056       final double lWage1 = pWorkContract1.getWageFullEmployed();
00057 
00058       // ... then compare it
00059       if (lWage0 < lWage1) {
00060         return -1;
00061       } else if (lWage0 > lWage1) {
00062         return 1;
00063       } else {
00064         return 0;
00065       }
00066     }
00067   }//end WageComparator class
00068 
00074   @Description("The status of the work contract")
00075   @Variability(VOLATILE)
00076   @Initialization(INDIVIDUAL)
00077   private Status status = Status.OFFERED;
00078 
00080   @Description("The employer of the work contract")
00081   @Variability(SIMULATION)
00082   @Initialization(INDIVIDUAL)
00083   private final Firm employer;
00084 
00089   @SuppressWarnings("unused")
00090   private boolean isValidAmount(double pAmountToTest) {
00091     if (status == Status.ACCEPTED) {
00092       return ((amount > 0.d) && (amount <= 1.d));
00093     } else {
00094       return (amount >= 0.d);
00095     }
00096   }
00097   @ValidateWithMethod(methodName = "isValidAmount", parameterType = double.class)
00098   @Description("The fraction of working time that the Household uses for the job of this " +
00099       "contract")
00100   @Variability(N_PERIODS)
00101   @Initialization(INDIVIDUAL)
00102   private double amount = 0.d;
00103 
00109   public WorkContract(@NotNull Firm pEmployer,
00110                       @AssertFieldConstraints("amount") double pAmount) {
00111     employer = pEmployer;
00112     amount = pAmount;
00113   }
00114 
00115   @PostValidateThis
00116   public void reduceAmount(@NotNegative double pAmountToReduce) {
00117     amount -= pAmountToReduce;
00118   }
00119   
00120   public String toFile() {
00121     return "Amount: " + amount + "  Wage: " + employer.getWage();
00122   }
00123 
00124   //getter/setter methods
00125   public double getAmount() {
00126     return amount;
00127   }
00128 
00129   public void setAmount(@AssertFieldConstraints("amount") double pAmount) {
00130     amount = pAmount;
00131   }
00132 
00133   public double getWageFullEmployed() {
00134     return employer.getWage();
00135   }
00136 
00137   public double getWageCurrentWorkAmount() {
00138     return employer.getWage() * amount;
00139   }
00140 
00141   @NotNull
00142   public Firm getEmployer() {
00143     return employer;
00144   }
00145 
00146   public Status getStatus() {
00147     return status;
00148   }
00149 
00150   public void setStatus(Status pStatus) {
00151     status = pStatus;
00152   }
00153 }
00154 
00156 // EOF

Generated on Tue Sep 14 11:11:49 2010 for lagom_generiC by  doxygen 1.5.4