/*
 * Created on 19 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 java.util.Vector;

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 CachedUserInformation implements Cacheable, CachedObjectsConstants {

	private Vector groupsOfUser;
	private String userName;
	private Date endOfLife;
	
	public CachedUserInformation(Vector groupsOfUser, String userName,  int minutesToLive){
		this.groupsOfUser = groupsOfUser;
		this.userName = userName;
		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)
	}// CachedSubjectNode
		
	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!
	}// isExpired
	
	public String getIdentifier() {
		return CACHED_USER_INFORMATION+userName;
	}// getIdentifier

	public Vector getGroupsOfUser() {
		return groupsOfUser;
	}
	
	public String getUserName() {
		return userName;
	}
	
	public String toString() {
		return userName+">"+groupsOfUser+"("+endOfLife+")";
	}
}
