You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by bt...@apache.org on 2015/09/22 12:16:08 UTC
svn commit: r1704517 - in /james/mailbox/trunk:
api/src/main/java/org/apache/james/mailbox/model/
store/src/main/java/org/apache/james/mailbox/store/quota/
store/src/test/java/org/apache/james/mailbox/store/quota/
Author: btellier
Date: Tue Sep 22 10:16:04 2015
New Revision: 1704517
URL: http://svn.apache.org/viewvc?rev=1704517&view=rev
Log:
MAILBOX-64 Enrich QuotaImpl
Added:
james/mailbox/trunk/store/src/test/java/org/apache/james/mailbox/store/quota/
james/mailbox/trunk/store/src/test/java/org/apache/james/mailbox/store/quota/QuotaImplTest.java
Modified:
james/mailbox/trunk/api/src/main/java/org/apache/james/mailbox/model/Quota.java
james/mailbox/trunk/store/src/main/java/org/apache/james/mailbox/store/quota/QuotaImpl.java
Modified: james/mailbox/trunk/api/src/main/java/org/apache/james/mailbox/model/Quota.java
URL: http://svn.apache.org/viewvc/james/mailbox/trunk/api/src/main/java/org/apache/james/mailbox/model/Quota.java?rev=1704517&r1=1704516&r2=1704517&view=diff
==============================================================================
--- james/mailbox/trunk/api/src/main/java/org/apache/james/mailbox/model/Quota.java (original)
+++ james/mailbox/trunk/api/src/main/java/org/apache/james/mailbox/model/Quota.java Tue Sep 22 10:16:04 2015
@@ -20,35 +20,43 @@ package org.apache.james.mailbox.model;
/**
* A {@link Quota} restriction
- *
- *
- *
*/
public interface Quota {
-
+
/**
* Unlimited value
*/
- public final static long UNLIMITED = -1;
-
-
+ long UNLIMITED = -1;
+
/**
* Value not known
*/
- public final static long UNKNOWN = Long.MIN_VALUE;
-
+ long UNKNOWN = Long.MIN_VALUE;
+
/**
* Return the maximum value for the {@link Quota}
- *
+ *
* @return max
*/
long getMax();
-
+
/**
* Return the currently used for the {@link Quota}
- *
+ *
* @return used
*/
long getUsed();
-
-}
+
+ /**
+ * Adds the value to the quota.
+ */
+ void addValueToQuota(long value);
+
+ /**
+ * Tells us if the quota is reached
+ *
+ * @return True if the user over uses the resource of this quota
+ */
+ boolean isOverQuota();
+
+}
\ No newline at end of file
Modified: james/mailbox/trunk/store/src/main/java/org/apache/james/mailbox/store/quota/QuotaImpl.java
URL: http://svn.apache.org/viewvc/james/mailbox/trunk/store/src/main/java/org/apache/james/mailbox/store/quota/QuotaImpl.java?rev=1704517&r1=1704516&r2=1704517&view=diff
==============================================================================
--- james/mailbox/trunk/store/src/main/java/org/apache/james/mailbox/store/quota/QuotaImpl.java (original)
+++ james/mailbox/trunk/store/src/main/java/org/apache/james/mailbox/store/quota/QuotaImpl.java Tue Sep 22 10:16:04 2015
@@ -18,18 +18,27 @@
****************************************************************/
package org.apache.james.mailbox.store.quota;
+import com.google.common.base.Objects;
import org.apache.james.mailbox.model.Quota;
public final class QuotaImpl implements Quota{
-
+
+ private final static Quota UNLIMITED_QUOTA = new QuotaImpl(UNKNOWN, UNLIMITED);
+
+ public static Quota unlimited() {
+ return UNLIMITED_QUOTA;
+ }
+
+ public static Quota quota(long used , long max) {
+ return new QuotaImpl(used, max);
+ }
+
private long max;
private long used;
- private final static Quota UNLIMITED_QUOTA = new QuotaImpl(UNKNOWN, UNLIMITED);
-
private QuotaImpl(long used, long max) {
- this.max = max;
this.used = used;
+ this.max = max;
}
@Override
@@ -41,25 +50,35 @@ public final class QuotaImpl implements
public long getUsed() {
return used;
}
-
- /**
- * Return a {@link Quota} which in fact is unlimited
- *
- * @return unlimited
- */
- public static Quota unlimited() {
- return UNLIMITED_QUOTA;
+
+ @Override
+ public void addValueToQuota(long value) {
+ used += value;
}
-
- /**
- * Return a {@link Quota} for the given values
- *
- * @param max
- * @param used
- * @return quota
- */
- public static Quota quota(long max , long used) {
- return new QuotaImpl(used, max);
+
+ @Override
+ public boolean isOverQuota() {
+ return max != UNLIMITED
+ && used > max;
+ }
+
+ @Override
+ public String toString() {
+ return used + "/" + max;
}
-}
+ @Override
+ public boolean equals(Object o) {
+ if (o == null || ! (o instanceof Quota)) {
+ return false;
+ }
+ Quota other = (Quota) o;
+ return used == other.getUsed()
+ && max == other.getMax();
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hashCode(used, max);
+ }
+}
\ No newline at end of file
Added: james/mailbox/trunk/store/src/test/java/org/apache/james/mailbox/store/quota/QuotaImplTest.java
URL: http://svn.apache.org/viewvc/james/mailbox/trunk/store/src/test/java/org/apache/james/mailbox/store/quota/QuotaImplTest.java?rev=1704517&view=auto
==============================================================================
--- james/mailbox/trunk/store/src/test/java/org/apache/james/mailbox/store/quota/QuotaImplTest.java (added)
+++ james/mailbox/trunk/store/src/test/java/org/apache/james/mailbox/store/quota/QuotaImplTest.java Tue Sep 22 10:16:04 2015
@@ -0,0 +1,54 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one *
+ * or more contributor license agreements. See the NOTICE file *
+ * distributed with this work for additional information *
+ * regarding copyright ownership. The ASF licenses this file *
+ * to you under the Apache License, Version 2.0 (the *
+ * "License"); you may not use this file except in compliance *
+ * with the License. You may obtain a copy of the License at *
+ * *
+ * http://www.apache.org/licenses/LICENSE-2.0 *
+ * *
+ * Unless required by applicable law or agreed to in writing, *
+ * software distributed under the License is distributed on an *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY *
+ * KIND, either express or implied. See the License for the *
+ * specific language governing permissions and limitations *
+ * under the License. *
+ ****************************************************************/
+
+package org.apache.james.mailbox.store.quota;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import org.apache.james.mailbox.model.Quota;
+import org.junit.Test;
+
+public class QuotaImplTest {
+
+ @Test
+ public void unlimitedQuotaShouldNotBeOverQuota() {
+ assertThat(QuotaImpl.unlimited().isOverQuota()).isFalse();
+ }
+
+ @Test
+ public void isOverQuotaShouldReturnFalseWhenQuotaIsNotExceeded() {
+ assertThat(QuotaImpl.quota(36, 360).isOverQuota()).isFalse();
+ }
+
+ @Test
+ public void isOverQuotaShouldReturnFalseWhenMaxValueIsUnlimited() {
+ assertThat(QuotaImpl.quota(36, Quota.UNLIMITED).isOverQuota()).isFalse();
+ }
+
+ @Test
+ public void isOverQuotaShouldReturnFalseWhenUsedValueIsUnknown() {
+ assertThat(QuotaImpl.quota(Quota.UNKNOWN, 36).isOverQuota()).isFalse();
+ }
+
+ @Test
+ public void isOverQuotaShouldReturnTrueWhenQuotaIsExceeded() {
+ assertThat(QuotaImpl.quota(360, 36).isOverQuota()).isTrue();
+ }
+
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org