Change AccountSession to use lombok features

- Change AccountSession to use lombok @Data annotation
- Make UUID and created final

Signed-off-by: Tomas Slusny <slusnucky@gmail.com>
This commit is contained in:
Tomas Slusny
2018-01-23 11:05:10 +01:00
committed by Adam
parent c157c0df75
commit 8d81e82177
3 changed files with 12 additions and 82 deletions

View File

@@ -25,73 +25,15 @@
package net.runelite.client.account;
import java.time.Instant;
import java.util.Objects;
import java.util.UUID;
import lombok.Data;
import lombok.EqualsAndHashCode;
@Data
@EqualsAndHashCode(of = "uuid")
public class AccountSession
{
private UUID uuid;
private final UUID uuid;
private final Instant created;
private String username;
private Instant created;
@Override
public int hashCode()
{
int hash = 3;
hash = 29 * hash + Objects.hashCode(this.uuid);
return hash;
}
@Override
public boolean equals(Object obj)
{
if (this == obj)
{
return true;
}
if (obj == null)
{
return false;
}
if (getClass() != obj.getClass())
{
return false;
}
final AccountSession other = (AccountSession) obj;
if (!Objects.equals(this.uuid, other.uuid))
{
return false;
}
return true;
}
public UUID getUuid()
{
return uuid;
}
public void setUuid(UUID uuid)
{
this.uuid = uuid;
}
public String getUsername()
{
return username;
}
public void setUsername(String username)
{
this.username = username;
}
public Instant getCreated()
{
return created;
}
public void setCreated(Instant created)
{
this.created = created;
}
}
}

View File

@@ -132,11 +132,7 @@ public class AccountPlugin extends Plugin
}
// Create new session
AccountSession session = new AccountSession();
session.setUuid(login.getUid());
session.setCreated(Instant.now());
sessionManager.openSession(session);
sessionManager.openSession(new AccountSession(login.getUid(), Instant.now()));
if (!Desktop.isDesktopSupported())
{

View File

@@ -68,10 +68,8 @@ public class ConfigManagerTest
@Test
public void testGetConfig() throws IOException
{
AccountSession accountSession = new AccountSession();
accountSession.setUuid(UUID.randomUUID());
AccountSession accountSession = new AccountSession(UUID.randomUUID(), Instant.now());
accountSession.setUsername("test");
accountSession.setCreated(Instant.now());
manager.setConfiguration("test", "key", "moo");
@@ -82,10 +80,8 @@ public class ConfigManagerTest
@Test
public void testGetConfigDefault() throws IOException
{
AccountSession accountSession = new AccountSession();
accountSession.setUuid(UUID.randomUUID());
AccountSession accountSession = new AccountSession(UUID.randomUUID(), Instant.now());
accountSession.setUsername("test");
accountSession.setCreated(Instant.now());
TestConfig conf = manager.getConfig(TestConfig.class);
Assert.assertEquals("default", conf.key());
@@ -94,10 +90,8 @@ public class ConfigManagerTest
@Test
public void testSetConfig() throws IOException
{
AccountSession accountSession = new AccountSession();
accountSession.setUuid(UUID.randomUUID());
AccountSession accountSession = new AccountSession(UUID.randomUUID(), Instant.now());
accountSession.setUsername("test");
accountSession.setCreated(Instant.now());
TestConfig conf = manager.getConfig(TestConfig.class);
conf.key("new value");
@@ -108,10 +102,8 @@ public class ConfigManagerTest
@Test
public void testGetConfigDescriptor() throws IOException
{
AccountSession accountSession = new AccountSession();
accountSession.setUuid(UUID.randomUUID());
AccountSession accountSession = new AccountSession(UUID.randomUUID(), Instant.now());
accountSession.setUsername("test");
accountSession.setCreated(Instant.now());
TestConfig conf = manager.getConfig(TestConfig.class);
ConfigDescriptor descriptor = manager.getConfigDescriptor(conf);