From c7b7c69484e3d0f53fd2b667af01d61511096f8a Mon Sep 17 00:00:00 2001 From: theli Date: Fri, 30 Sep 2005 15:41:01 +0000 Subject: [PATCH] *) adding some functions to userDB.Entry git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@826 6c8d7289-2bf4-0310-a012-ef5d649a1542 --- source/de/anomic/data/userDB.java | 40 +++++++++++++++++++++++++++---- 1 file changed, 35 insertions(+), 5 deletions(-) diff --git a/source/de/anomic/data/userDB.java b/source/de/anomic/data/userDB.java index 2dd64d1c1..d8d0f1182 100644 --- a/source/de/anomic/data/userDB.java +++ b/source/de/anomic/data/userDB.java @@ -154,6 +154,8 @@ public class userDB { public static final String LAST_ACCESS = "lastAccess"; public static final String TIME_USED = "timeUsed"; public static final String TIME_LIMIT = "timeLimit"; + public static final String TRAFFIC_SIZE = "trafficSize"; + public static final String TRAFFIC_LIMIT = "trafficLimit"; // this is a simple record structure that hold all properties of a user private Map mem; @@ -164,7 +166,7 @@ public class userDB { throw new IllegalArgumentException(); this.userName = userName.trim(); - if (userName.length() < USERNAME_MIN_LENGTH) + if (this.userName.length() < USERNAME_MIN_LENGTH) throw new IllegalArgumentException("Username to short. Length should be >= " + USERNAME_MIN_LENGTH); if (mem == null) this.mem = new HashMap(); @@ -189,10 +191,6 @@ public class userDB { return (this.mem.containsKey(USER_ADDRESS)?(String)this.mem.get(USER_ADDRESS):null); } - public Long getLastAccess() { - return (this.mem.containsKey(LAST_ACCESS)?Long.valueOf((String)this.mem.get(LAST_ACCESS)):null); - } - public long getTimeUsed() { if (this.mem.containsKey(TIME_USED)) { return Long.valueOf((String)this.mem.get(TIME_USED)).longValue(); @@ -209,6 +207,38 @@ public class userDB { return (this.mem.containsKey(TIME_LIMIT)?Long.valueOf((String)this.mem.get(TIME_LIMIT)):null); } + public long getTrafficSize() { + if (this.mem.containsKey(TRAFFIC_SIZE)) { + return Long.valueOf((String)this.mem.get(TRAFFIC_SIZE)).longValue(); + } + try { + this.setProperty(TRAFFIC_SIZE,"0"); + } catch (IOException e) { + e.printStackTrace(); + } + return 0; + } + + public Long getTrafficLimit() { + return (this.mem.containsKey(TRAFFIC_LIMIT)?Long.valueOf((String)this.mem.get(TRAFFIC_LIMIT)):null); + } + + public long updateTrafficSize(long responseSize) { + if (responseSize < 0) throw new IllegalArgumentException("responseSize must be greater or equal zero."); + + long currentTrafficSize = getTrafficSize(); + long newTrafficSize = currentTrafficSize + responseSize; + try { + this.setProperty(TRAFFIC_SIZE,Long.toString(newTrafficSize)); + } catch (IOException e) { + e.printStackTrace(); + } + return newTrafficSize; + } + + public Long getLastAccess() { + return (this.mem.containsKey(LAST_ACCESS)?Long.valueOf((String)this.mem.get(LAST_ACCESS)):null); + } public long updateLastAccess(long timeStamp, boolean decrementTimeUsed) { if (timeStamp < 0) throw new IllegalArgumentException();