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 2020/04/22 07:24:33 UTC

[james-project] 01/10: JAMES-3138 Move CurrentQuotas to mailbox-api

This is an automated email from the ASF dual-hosted git repository.

btellier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git

commit da779b56e6059d24cff2e71ba77568bf0d37cbae
Author: Rene Cordier <rc...@linagora.com>
AuthorDate: Fri Apr 10 10:58:49 2020 +0700

    JAMES-3138 Move CurrentQuotas to mailbox-api
---
 .../apache/james/mailbox/model/CurrentQuotas.java  | 71 ++++++++++++++++++++++
 .../james/mailbox/model/CurrentQuotasTest.java     | 32 ++++++++++
 .../quota/InMemoryCurrentQuotaManager.java         |  2 +-
 .../quota/InMemoryCurrentQuotaManagerTest.java     |  2 +-
 .../store/quota/CurrentQuotaCalculator.java        | 32 +---------
 5 files changed, 106 insertions(+), 33 deletions(-)

diff --git a/mailbox/api/src/main/java/org/apache/james/mailbox/model/CurrentQuotas.java b/mailbox/api/src/main/java/org/apache/james/mailbox/model/CurrentQuotas.java
new file mode 100644
index 0000000..e155841
--- /dev/null
+++ b/mailbox/api/src/main/java/org/apache/james/mailbox/model/CurrentQuotas.java
@@ -0,0 +1,71 @@
+/****************************************************************
+ * 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.model;
+
+import java.util.Objects;
+
+import org.apache.james.core.quota.QuotaCountUsage;
+import org.apache.james.core.quota.QuotaSizeUsage;
+
+public class CurrentQuotas {
+    private final QuotaCountUsage count;
+    private final QuotaSizeUsage size;
+
+    public CurrentQuotas(QuotaCountUsage count, QuotaSizeUsage size) {
+        this.count = count;
+        this.size = size;
+    }
+
+    public QuotaCountUsage count() {
+        return count;
+    }
+
+    public QuotaSizeUsage size() {
+        return size;
+    }
+
+    public CurrentQuotas increase(CurrentQuotas updateQuotas) {
+        return new CurrentQuotas(
+            QuotaCountUsage.count(this.count.asLong() + updateQuotas.count.asLong()),
+            QuotaSizeUsage.size(this.size.asLong() + updateQuotas.size.asLong()));
+    }
+
+    public CurrentQuotas decrease(CurrentQuotas updateQuotas) {
+        return new CurrentQuotas(
+            QuotaCountUsage.count(this.count.asLong() - updateQuotas.count.asLong()),
+            QuotaSizeUsage.size(this.size.asLong() - updateQuotas.size.asLong()));
+    }
+
+    @Override
+    public final boolean equals(Object o) {
+        if (o instanceof CurrentQuotas) {
+            CurrentQuotas currentQuotas = (CurrentQuotas) o;
+
+            return Objects.equals(this.count, currentQuotas.count)
+                && Objects.equals(this.size, currentQuotas.size);
+        }
+        return false;
+    }
+
+    @Override
+    public final int hashCode() {
+        return Objects.hash(count, size);
+    }
+}
diff --git a/mailbox/api/src/test/java/org/apache/james/mailbox/model/CurrentQuotasTest.java b/mailbox/api/src/test/java/org/apache/james/mailbox/model/CurrentQuotasTest.java
new file mode 100644
index 0000000..2037d0b
--- /dev/null
+++ b/mailbox/api/src/test/java/org/apache/james/mailbox/model/CurrentQuotasTest.java
@@ -0,0 +1,32 @@
+/****************************************************************
+ * 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.model;
+
+import org.junit.jupiter.api.Test;
+
+import nl.jqno.equalsverifier.EqualsVerifier;
+
+class CurrentQuotasTest {
+    @Test
+    void shouldRespectBeanContract() {
+        EqualsVerifier.forClass(CurrentQuotas.class)
+            .verify();
+    }
+}
diff --git a/mailbox/memory/src/main/java/org/apache/james/mailbox/inmemory/quota/InMemoryCurrentQuotaManager.java b/mailbox/memory/src/main/java/org/apache/james/mailbox/inmemory/quota/InMemoryCurrentQuotaManager.java
index fcbe5ff..326640c 100644
--- a/mailbox/memory/src/main/java/org/apache/james/mailbox/inmemory/quota/InMemoryCurrentQuotaManager.java
+++ b/mailbox/memory/src/main/java/org/apache/james/mailbox/inmemory/quota/InMemoryCurrentQuotaManager.java
@@ -29,10 +29,10 @@ import org.apache.james.core.quota.QuotaCountUsage;
 import org.apache.james.core.quota.QuotaSizeUsage;
 import org.apache.james.mailbox.SessionProvider;
 import org.apache.james.mailbox.exception.MailboxException;
+import org.apache.james.mailbox.model.CurrentQuotas;
 import org.apache.james.mailbox.model.QuotaOperation;
 import org.apache.james.mailbox.model.QuotaRoot;
 import org.apache.james.mailbox.store.quota.CurrentQuotaCalculator;
-import org.apache.james.mailbox.store.quota.CurrentQuotaCalculator.CurrentQuotas;
 import org.apache.james.mailbox.store.quota.StoreCurrentQuotaManager;
 
 import com.google.common.cache.CacheBuilder;
diff --git a/mailbox/memory/src/test/java/org/apache/james/mailbox/inmemory/quota/InMemoryCurrentQuotaManagerTest.java b/mailbox/memory/src/test/java/org/apache/james/mailbox/inmemory/quota/InMemoryCurrentQuotaManagerTest.java
index 26e2b1f..9320964 100644
--- a/mailbox/memory/src/test/java/org/apache/james/mailbox/inmemory/quota/InMemoryCurrentQuotaManagerTest.java
+++ b/mailbox/memory/src/test/java/org/apache/james/mailbox/inmemory/quota/InMemoryCurrentQuotaManagerTest.java
@@ -28,10 +28,10 @@ import java.util.Optional;
 import org.apache.james.core.quota.QuotaCountUsage;
 import org.apache.james.core.quota.QuotaSizeUsage;
 import org.apache.james.mailbox.SessionProvider;
+import org.apache.james.mailbox.model.CurrentQuotas;
 import org.apache.james.mailbox.model.QuotaOperation;
 import org.apache.james.mailbox.model.QuotaRoot;
 import org.apache.james.mailbox.store.quota.CurrentQuotaCalculator;
-import org.apache.james.mailbox.store.quota.CurrentQuotaCalculator.CurrentQuotas;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
 
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/quota/CurrentQuotaCalculator.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/quota/CurrentQuotaCalculator.java
index 4dfbf0f..7c01a09 100644
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/quota/CurrentQuotaCalculator.java
+++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/quota/CurrentQuotaCalculator.java
@@ -30,6 +30,7 @@ import org.apache.james.core.quota.QuotaCountUsage;
 import org.apache.james.core.quota.QuotaSizeUsage;
 import org.apache.james.mailbox.MailboxSession;
 import org.apache.james.mailbox.exception.MailboxException;
+import org.apache.james.mailbox.model.CurrentQuotas;
 import org.apache.james.mailbox.model.Mailbox;
 import org.apache.james.mailbox.model.MessageRange;
 import org.apache.james.mailbox.model.QuotaRoot;
@@ -64,35 +65,4 @@ public class CurrentQuotaCalculator {
         }
         return new CurrentQuotas(QuotaCountUsage.count(messageCount), QuotaSizeUsage.size(messagesSizes));
     }
-
-    public static class CurrentQuotas {
-        private final QuotaCountUsage count;
-        private final QuotaSizeUsage size;
-
-        public CurrentQuotas(QuotaCountUsage count, QuotaSizeUsage size) {
-            this.count = count;
-            this.size = size;
-        }
-
-        public QuotaCountUsage count() {
-            return count;
-        }
-
-        public QuotaSizeUsage size() {
-            return size;
-        }
-
-        public CurrentQuotas increase(CurrentQuotas updateQuotas) {
-            return new CurrentQuotas(
-                QuotaCountUsage.count(this.count.asLong() + updateQuotas.count.asLong()),
-                QuotaSizeUsage.size(this.size.asLong() + updateQuotas.size.asLong()));
-        }
-
-        public CurrentQuotas decrease(CurrentQuotas updateQuotas) {
-            return new CurrentQuotas(
-                QuotaCountUsage.count(this.count.asLong() - updateQuotas.count.asLong()),
-                QuotaSizeUsage.size(this.size.asLong() - updateQuotas.size.asLong()));
-        }
-    }
-
 }
\ No newline at end of file


---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org