Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MAILBOX-261 Message now have a unique MessageId
git-svn-id: https://svn.apache.org/repos/asf/james/project/trunk@1724222 13f79535-47bb-0310-9956-ffa450edef68
- Loading branch information
Showing
8 changed files
with
146 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/DefaultMessageId.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/**************************************************************** | ||
* 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.mail.model; | ||
|
||
import com.google.common.base.Objects; | ||
import com.google.common.base.Preconditions; | ||
|
||
public class DefaultMessageId implements MessageId { | ||
|
||
private final MailboxId mailboxId; | ||
private final long messageUid; | ||
|
||
public DefaultMessageId(MailboxId mailboxId, long messageUid) { | ||
Preconditions.checkNotNull(mailboxId); | ||
this.mailboxId = mailboxId; | ||
this.messageUid = messageUid; | ||
} | ||
|
||
@Override | ||
public String serialize() { | ||
return String.format("%s-%d", mailboxId.serialize(), messageUid); | ||
} | ||
|
||
@Override | ||
public final boolean equals(Object obj) { | ||
if (obj instanceof DefaultMessageId) { | ||
DefaultMessageId other = (DefaultMessageId) obj; | ||
return Objects.equal(mailboxId, other.mailboxId) && | ||
Objects.equal(messageUid, other.messageUid); | ||
|
||
} | ||
return false; | ||
} | ||
|
||
@Override | ||
public final int hashCode() { | ||
return Objects.hashCode(mailboxId, messageUid); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/MessageId.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/**************************************************************** | ||
* 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.mail.model; | ||
|
||
public interface MessageId { | ||
String serialize(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
...x/store/src/test/java/org/apache/james/mailbox/store/mail/model/DefaultMessageIdTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/**************************************************************** | ||
* 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.mail.model; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import org.apache.james.mailbox.store.TestId; | ||
import org.junit.Test; | ||
|
||
import nl.jqno.equalsverifier.EqualsVerifier; | ||
|
||
public class DefaultMessageIdTest { | ||
|
||
@Test(expected=NullPointerException.class) | ||
public void constructorShouldThrowWhenNullMailboxId() { | ||
new DefaultMessageId(null, 1); | ||
} | ||
|
||
@Test | ||
public void serializeShouldFormatMailboxIdAndUid() { | ||
DefaultMessageId id = new DefaultMessageId(TestId.of(12l), 1); | ||
assertThat(id.serialize()).isEqualTo("12-1"); | ||
} | ||
|
||
@Test | ||
public void shouldRespectJavaBeanContract() { | ||
EqualsVerifier.forClass(DefaultMessageId.class).verify(); | ||
} | ||
|
||
} |