package org.hive2hive.core;

/**
 * Stores the configured time to live values (seconds)
 * 
 * @author Nico
 * 
 */
public class TimeToLiveStore {

	private int chunk = convertDaysToSeconds(180);
	private int metaDocument = convertDaysToSeconds(365);
	private int userProfile = convertDaysToSeconds(2 * 365);
	private int locations = convertDaysToSeconds(2 * 365);
	private int userMessageQueue = convertDaysToSeconds(2 * 365);

	private static TimeToLiveStore instance;

	public static TimeToLiveStore getInstance() {
		if (instance == null) {
			instance = new TimeToLiveStore();
		}

		return instance;
	}

	public int getChunk() {
		return chunk;
	}

	public void setChunk(int chunk) {
		this.chunk = chunk;
	}

	public int getMetaFile() {
		return metaDocument;
	}

	public void setMetaDocument(int metaDocument) {
		this.metaDocument = metaDocument;
	}

	public int getUserProfile() {
		return userProfile;
	}

	public void setUserProfile(int userProfile) {
		this.userProfile = userProfile;
	}

	public int getLocations() {
		return locations;
	}

	public void setLocations(int locations) {
		this.locations = locations;
	}

	public int getUserMessageQueue() {
		return userMessageQueue;
	}

	public void setUserMessageQueue(int userMessageQueue) {
		this.userMessageQueue = userMessageQueue;
	}

	/**
	 * Converts an integer number of days to seconds (which are used by the {@link TimeToLiveStore}
	 * 
	 * @param days
	 * @return seconds
	 */
	public static int convertDaysToSeconds(int days) {
		return days * 24 * 60 * 60;
	}
}

@@ -422,16 +422,76 @@
  365);%0A%0A
+%09private static final int DAY_SECOND_FACTOR = 24 * 60 * 60;%0A
 %09private
@@ -1458,17 +1458,94 @@
 veStore%7D
+). If an%0A%09 * Integer overflow happens, %7B@link Integer#MAX_VALUE%7D is returned.
 %0A
-
 %09 * %0A%09 *
@@ -1640,34 +1640,187 @@
 %7B%0A%09%09
-return days * 24 * 60 * 60
+assert days %3E 0;%0A%09%09if (days %3E Long.MAX_VALUE / DAY_SECOND_FACTOR) %7B%0A%09%09%09// it will overflow, return the max value%0A%09%09%09return Integer.MAX_VALUE;%0A%09%09%7D%0A%09%09return days * DAY_SECOND_FACTOR
 ;%0A%09%7D

Handle integer overflow