/*
 * 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.apache.slide.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 {

	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 Object getIdentifier() {
		return userName;
	}// getIdentifier

	public Vector getGroupsOfUser() {
		return groupsOfUser;
	}
	
	public String getUserName() {
		return userName;
	}
}
