/*
 * Created on 26 janv. 2005
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
package org.esupportail.webdavserver.store.uPortal;

import java.util.Calendar;
import java.util.Date;

import fr.univrennes1.cri.util.cacheManagement.Cacheable;

/**
 * @author tbellemb
 *
 * TODO To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
public class CachedGroupName implements Cacheable, CachedObjectsConstants {

	private String groupKey;
	private String groupName;
	private Date endOfLife;
	
	public CachedGroupName(String groupKey, String groupName,  int minutesToLive){
		this.groupKey = groupKey;
		this.groupName = groupName;
		if (minutesToLive == -1) endOfLife = null;
		else {
			endOfLife = new java.util.Date();
		    java.util.Calendar cal = java.util.Calendar.getInstance();
		    cal.setTime(endOfLife);
		    cal.add(Calendar.MINUTE, minutesToLive);
		    endOfLife = cal.getTime();
		}// if (minutesToLive == -1)
	}// CachedGroupName
	
	public boolean isExpired() {
		if (endOfLife != null)
		{
			// date of expiration is compared.
			if (endOfLife.before(new java.util.Date()))	return true;
			else return false;
			
		}
		else return false; // This means it lives forever!
	}

	public String getIdentifier() {
		return CACHED_GROUP_NAME+groupKey;
	}

	public String getGroupKey() {
		return groupKey;
	}
	
	public String getGroupName() {
		return groupName;
	}
	
	public String toString() {
		return groupKey+">"+groupName+"("+endOfLife+")";
	}
	
}// CachedGroupName
