001: /**
002: * Copyright (c) 2000-2008 Liferay, Inc. All rights reserved.
003: *
004: * Permission is hereby granted, free of charge, to any person obtaining a copy
005: * of this software and associated documentation files (the "Software"), to deal
006: * in the Software without restriction, including without limitation the rights
007: * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
008: * copies of the Software, and to permit persons to whom the Software is
009: * furnished to do so, subject to the following conditions:
010: *
011: * The above copyright notice and this permission notice shall be included in
012: * all copies or substantial portions of the Software.
013: *
014: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
015: * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
016: * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
017: * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
018: * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
019: * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
020: * SOFTWARE.
021: */package com.liferay.lock.model.impl;
022:
023: import com.liferay.lock.model.Lock;
024:
025: import java.util.Date;
026:
027: /**
028: * <a href="LockImpl.java.html"><b><i>View Source</i></b></a>
029: *
030: * @author Brian Wing Shun Chan
031: *
032: */
033: public class LockImpl implements Lock {
034:
035: public LockImpl(String className, Comparable pk, long companyId,
036: long userId, long expirationTime) {
037:
038: _className = className;
039: _pk = pk;
040: _companyId = companyId;
041: _userId = userId;
042: _expirationTime = expirationTime;
043: _date = new Date();
044: }
045:
046: public String getClassName() {
047: return _className;
048: }
049:
050: public Comparable getPrimaryKey() {
051: return _pk;
052: }
053:
054: public long getCompanyId() {
055: return _companyId;
056: }
057:
058: public long getUserId() {
059: return _userId;
060: }
061:
062: public long getExpirationTime() {
063: return _expirationTime;
064: }
065:
066: public void setExpirationTime(long expirationTime) {
067: _expirationTime = expirationTime;
068: _date = new Date();
069: }
070:
071: public boolean isExpired() {
072: Date now = new Date();
073:
074: if (now.getTime() > _date.getTime() + _expirationTime) {
075: return true;
076: } else {
077: return false;
078: }
079: }
080:
081: public Date getDate() {
082: return _date;
083: }
084:
085: public int compareTo(Object obj) {
086: if (obj == null) {
087: return -1;
088: }
089:
090: Lock lock = (Lock) obj;
091:
092: int value = 0;
093: value = getClassName().compareTo(lock.getClassName());
094:
095: if (value != 0) {
096: return value;
097: }
098:
099: value = getPrimaryKey().compareTo(lock.getPrimaryKey());
100:
101: if (value != 0) {
102: return value;
103: }
104:
105: value = getDate().compareTo(lock.getDate());
106:
107: if (value != 0) {
108: return value;
109: }
110:
111: return 0;
112: }
113:
114: public boolean equals(Object obj) {
115: if (obj == null) {
116: return false;
117: }
118:
119: Lock lock = (Lock) obj;
120:
121: if (getClassName().equals(lock.getClassName())
122: && getPrimaryKey().equals(lock.getPrimaryKey())) {
123:
124: return true;
125: } else {
126: return false;
127: }
128: }
129:
130: public int hashCode() {
131: return getClassName().hashCode() + getPrimaryKey().hashCode();
132: }
133:
134: private String _className;
135: private Comparable _pk;
136: private long _companyId;
137: private long _userId;
138: private long _expirationTime;
139: private Date _date;
140:
141: }
|