001
014
015 package com.liferay.portlet.social.model;
016
017 import com.liferay.portal.kernel.util.Time;
018
019 import java.util.Calendar;
020 import java.util.GregorianCalendar;
021
022
025 public class SocialEquityValue {
026
027 public SocialEquityValue(double k, double b) {
028 _k = k;
029 _b = b;
030 }
031
032 public void add(SocialEquityValue socialEquityValue) {
033 _k = _k + socialEquityValue._k;
034 _b = _b + socialEquityValue._b;
035 }
036
037 public double getB() {
038 return _b;
039 }
040
041 public double getK() {
042 return _k;
043 }
044
045 public double getValue() {
046 return getValue(getEquityDate());
047 }
048
049 public double getValue(int equityDate) {
050 return _k * equityDate + _b;
051 }
052
053 public void subtract(SocialEquityValue socialEquityValue) {
054 _k = _k - socialEquityValue._k;
055 _b = _b - socialEquityValue._b;
056 }
057
058 protected int getEquityDate() {
059 long d = System.currentTimeMillis() - _BASE_TIME;
060
061 return (int)(d / Time.DAY);
062 }
063
064 private static final long _BASE_TIME =
065 new GregorianCalendar(2010, Calendar.JANUARY, 1).getTimeInMillis();
066
067 private double _b;
068 private double _k;
069
070 }