Browse Source

Package refactoring

Tankernn 8 years ago
parent
commit
f9d3242451
31 changed files with 108 additions and 101 deletions
  1. 1 1
      src/main/java/eu/tankernn/chat/client/ChatClient.java
  2. 8 4
      src/main/java/eu/tankernn/chat/client/ChatWindow.java
  3. 2 2
      src/main/java/eu/tankernn/chat/client/Console.java
  4. 3 3
      src/main/java/eu/tankernn/chat/common/InfoPacket.java
  5. 1 1
      src/main/java/eu/tankernn/chat/common/MessagePacket.java
  6. 1 1
      src/main/java/eu/tankernn/chat/common/Packet.java
  7. 1 1
      src/main/java/eu/tankernn/chat/server/BanNote.java
  8. 2 2
      src/main/java/eu/tankernn/chat/server/Channel.java
  9. 4 4
      src/main/java/eu/tankernn/chat/server/Client.java
  10. 2 2
      src/main/java/eu/tankernn/chat/server/ClientCollection.java
  11. 6 6
      src/main/java/eu/tankernn/chat/server/CommandRegistry.java
  12. 3 3
      src/main/java/eu/tankernn/chat/server/LocalClient.java
  13. 2 2
      src/main/java/eu/tankernn/chat/server/Server.java
  14. 7 7
      src/main/java/eu/tankernn/chat/server/command/Ban.java
  15. 2 2
      src/main/java/eu/tankernn/chat/server/command/Command.java
  16. 1 1
      src/main/java/eu/tankernn/chat/server/command/CommandInfo.java
  17. 5 5
      src/main/java/eu/tankernn/chat/server/command/CreateChannel.java
  18. 3 3
      src/main/java/eu/tankernn/chat/server/command/Exit.java
  19. 5 5
      src/main/java/eu/tankernn/chat/server/command/GiveOP.java
  20. 5 5
      src/main/java/eu/tankernn/chat/server/command/Help.java
  21. 6 6
      src/main/java/eu/tankernn/chat/server/command/JoinChannel.java
  22. 5 5
      src/main/java/eu/tankernn/chat/server/command/Kick.java
  23. 6 6
      src/main/java/eu/tankernn/chat/server/command/LeaveChannel.java
  24. 6 6
      src/main/java/eu/tankernn/chat/server/command/List.java
  25. 6 6
      src/main/java/eu/tankernn/chat/server/command/PrivateMessage.java
  26. 1 1
      src/main/java/eu/tankernn/chat/util/ArrayUtil.java
  27. 4 2
      src/test/java/eu/tankernn/chat/client/test/ClientTestCase.java
  28. 1 1
      src/test/java/eu/tankernn/chat/client/test/ClientTestSuite.java
  29. 4 4
      src/test/java/eu/tankernn/chat/common/test/CompleteTestSuite.java
  30. 3 2
      src/test/java/eu/tankernn/chat/server/test/ServerTestCase.java
  31. 2 2
      src/test/java/eu/tankernn/chat/server/test/ServerTestSuite.java

+ 1 - 1
src/main/java/client/ChatClient.java → src/main/java/eu/tankernn/chat/client/ChatClient.java

@@ -1,4 +1,4 @@
-package client;
+package eu.tankernn.chat.client;
 
 import java.io.File;
 import java.io.FileInputStream;

+ 8 - 4
src/main/java/client/ChatWindow.java → src/main/java/eu/tankernn/chat/client/ChatWindow.java

@@ -1,4 +1,4 @@
-package client;
+package eu.tankernn.chat.client;
 
 import java.awt.BorderLayout;
 import java.awt.Dimension;
@@ -31,9 +31,9 @@ import javax.swing.ListSelectionModel;
 import javax.swing.WindowConstants;
 import javax.swing.border.EmptyBorder;
 
-import common.InfoPacket;
-import common.MessagePacket;
-import common.MessagePacket.MessageType;
+import eu.tankernn.chat.common.InfoPacket;
+import eu.tankernn.chat.common.MessagePacket;
+import eu.tankernn.chat.common.MessagePacket.MessageType;
 
 @SuppressWarnings("serial")
 public class ChatWindow extends JFrame implements ActionListener, Runnable, KeyListener {
@@ -241,4 +241,8 @@ public class ChatWindow extends JFrame implements ActionListener, Runnable, KeyL
 	@Override
 	public void keyTyped(KeyEvent arg0) {
 	}
+	
+	public boolean isConnected() {
+		return so.isConnected() && !so.isClosed();
+	}
 }

+ 2 - 2
src/main/java/client/Console.java → src/main/java/eu/tankernn/chat/client/Console.java

@@ -1,11 +1,11 @@
-package client;
+package eu.tankernn.chat.client;
 
 import javax.swing.JTextPane;
 import javax.swing.SwingUtilities;
 import javax.swing.text.SimpleAttributeSet;
 import javax.swing.text.StyledDocument;
 
-import common.MessagePacket;
+import eu.tankernn.chat.common.MessagePacket;
 
 @SuppressWarnings("serial")
 public class Console extends JTextPane {

+ 3 - 3
src/main/java/common/InfoPacket.java → src/main/java/eu/tankernn/chat/common/InfoPacket.java

@@ -1,9 +1,9 @@
-package common;
+package eu.tankernn.chat.common;
 
 import java.util.List;
 
-import server.Client;
-import server.Server;
+import eu.tankernn.chat.server.Client;
+import eu.tankernn.chat.server.Server;
 
 public class InfoPacket implements Packet {
 	/**

+ 1 - 1
src/main/java/common/MessagePacket.java → src/main/java/eu/tankernn/chat/common/MessagePacket.java

@@ -1,4 +1,4 @@
-package common;
+package eu.tankernn.chat.common;
 
 import java.awt.Color;
 import java.text.DateFormat;

+ 1 - 1
src/main/java/common/Packet.java → src/main/java/eu/tankernn/chat/common/Packet.java

@@ -1,4 +1,4 @@
-package common;
+package eu.tankernn.chat.common;
 
 public interface Packet extends java.io.Serializable {
 	

+ 1 - 1
src/main/java/server/BanNote.java → src/main/java/eu/tankernn/chat/server/BanNote.java

@@ -1,4 +1,4 @@
-package server;
+package eu.tankernn.chat.server;
 
 import java.time.LocalDateTime;
 import java.time.format.DateTimeFormatter;

+ 2 - 2
src/main/java/server/Channel.java → src/main/java/eu/tankernn/chat/server/Channel.java

@@ -1,6 +1,6 @@
-package server;
+package eu.tankernn.chat.server;
 
-import common.MessagePacket;
+import eu.tankernn.chat.common.MessagePacket;
 
 public class Channel extends ClientCollection {
 	public String name;

+ 4 - 4
src/main/java/server/Client.java → src/main/java/eu/tankernn/chat/server/Client.java

@@ -1,4 +1,4 @@
-package server;
+package eu.tankernn.chat.server;
 
 import java.io.BufferedReader;
 import java.io.IOException;
@@ -12,9 +12,9 @@ import java.util.List;
 import java.util.Timer;
 import java.util.TimerTask;
 
-import common.InfoPacket;
-import common.MessagePacket;
-import common.Packet;
+import eu.tankernn.chat.common.InfoPacket;
+import eu.tankernn.chat.common.MessagePacket;
+import eu.tankernn.chat.common.Packet;
 
 public class Client implements Runnable {
 	protected Thread readuser = new Thread(this);

+ 2 - 2
src/main/java/server/ClientCollection.java → src/main/java/eu/tankernn/chat/server/ClientCollection.java

@@ -1,10 +1,10 @@
-package server;
+package eu.tankernn.chat.server;
 
 import java.util.List;
 import java.util.Optional;
 import java.util.concurrent.CopyOnWriteArrayList;
 
-import common.MessagePacket;
+import eu.tankernn.chat.common.MessagePacket;
 
 /**
  * A collection of clients.

+ 6 - 6
src/main/java/server/CommandRegistry.java → src/main/java/eu/tankernn/chat/server/CommandRegistry.java

@@ -1,4 +1,4 @@
-package server;
+package eu.tankernn.chat.server;
 
 import java.util.Arrays;
 import java.util.HashMap;
@@ -10,11 +10,11 @@ import java.util.stream.Stream;
 
 import org.reflections.Reflections;
 
-import common.MessagePacket;
-import common.MessagePacket.MessageType;
-import server.command.Command;
-import server.command.CommandInfo;
-import util.ArrayUtil;
+import eu.tankernn.chat.common.MessagePacket;
+import eu.tankernn.chat.common.MessagePacket.MessageType;
+import eu.tankernn.chat.server.command.Command;
+import eu.tankernn.chat.server.command.CommandInfo;
+import eu.tankernn.chat.util.ArrayUtil;
 
 public class CommandRegistry  {
 	private static final Logger LOG = Logger.getLogger(CommandRegistry.class.getName());

+ 3 - 3
src/main/java/server/LocalClient.java → src/main/java/eu/tankernn/chat/server/LocalClient.java

@@ -1,11 +1,11 @@
-package server;
+package eu.tankernn.chat.server;
 
 import java.io.BufferedReader;
 import java.io.InputStreamReader;
 import java.util.Arrays;
 
-import common.MessagePacket;
-import common.Packet;
+import eu.tankernn.chat.common.MessagePacket;
+import eu.tankernn.chat.common.Packet;
 
 public class LocalClient extends Client {
 	

+ 2 - 2
src/main/java/server/Server.java → src/main/java/eu/tankernn/chat/server/Server.java

@@ -1,4 +1,4 @@
-package server;
+package eu.tankernn.chat.server;
 
 import java.io.File;
 import java.io.FileNotFoundException;
@@ -15,7 +15,7 @@ import java.util.logging.Level;
 import java.util.logging.LogManager;
 import java.util.logging.Logger;
 
-import common.MessagePacket;
+import eu.tankernn.chat.common.MessagePacket;
 
 public class Server {
 	private static Thread clientListener;

+ 7 - 7
src/main/java/server/command/Ban.java → src/main/java/eu/tankernn/chat/server/command/Ban.java

@@ -1,16 +1,16 @@
-package server.command;
+package eu.tankernn.chat.server.command;
 
 import java.io.IOException;
 import java.util.Arrays;
 import java.util.InputMismatchException;
 import java.util.Optional;
 
-import common.MessagePacket;
-import common.MessagePacket.MessageType;
-import server.BanNote;
-import server.Client;
-import server.Server;
-import util.ArrayUtil;
+import eu.tankernn.chat.common.MessagePacket;
+import eu.tankernn.chat.common.MessagePacket.MessageType;
+import eu.tankernn.chat.server.BanNote;
+import eu.tankernn.chat.server.Client;
+import eu.tankernn.chat.server.Server;
+import eu.tankernn.chat.util.ArrayUtil;
 
 @CommandInfo(desc = "Bans a user. (/ban <username> [seconds] [reason])", name = "ban", permission = "admin.ban", minArg = 1)
 public class Ban implements Command {

+ 2 - 2
src/main/java/server/command/Command.java → src/main/java/eu/tankernn/chat/server/command/Command.java

@@ -1,6 +1,6 @@
-package server.command;
+package eu.tankernn.chat.server.command;
 
-import server.Client;
+import eu.tankernn.chat.server.Client;
 
 public interface Command {
 	public void execute(String[] args, Client caller) throws Exception;

+ 1 - 1
src/main/java/server/command/CommandInfo.java → src/main/java/eu/tankernn/chat/server/command/CommandInfo.java

@@ -1,4 +1,4 @@
-package server.command;
+package eu.tankernn.chat.server.command;
 
 import java.lang.annotation.ElementType;
 import java.lang.annotation.Retention;

+ 5 - 5
src/main/java/server/command/CreateChannel.java → src/main/java/eu/tankernn/chat/server/command/CreateChannel.java

@@ -1,9 +1,9 @@
-package server.command;
+package eu.tankernn.chat.server.command;
 
-import common.MessagePacket;
-import server.Channel;
-import server.Client;
-import server.Server;
+import eu.tankernn.chat.common.MessagePacket;
+import eu.tankernn.chat.server.Channel;
+import eu.tankernn.chat.server.Client;
+import eu.tankernn.chat.server.Server;
 
 @CommandInfo(desc = "Creates a channel with specified settings. (/createchannel <name>)", name = "create", permission = "admin.create.channel", minArg = 1)
 public class CreateChannel implements Command {

+ 3 - 3
src/main/java/server/command/Exit.java → src/main/java/eu/tankernn/chat/server/command/Exit.java

@@ -1,7 +1,7 @@
-package server.command;
+package eu.tankernn.chat.server.command;
 
-import server.Client;
-import server.Server;
+import eu.tankernn.chat.server.Client;
+import eu.tankernn.chat.server.Server;
 
 @CommandInfo(desc = "Stops the server.", name = "stop", permission = "server.exit")
 public class Exit implements Command {

+ 5 - 5
src/main/java/server/command/GiveOP.java → src/main/java/eu/tankernn/chat/server/command/GiveOP.java

@@ -1,9 +1,9 @@
-package server.command;
+package eu.tankernn.chat.server.command;
 
-import common.MessagePacket;
-import common.MessagePacket.MessageType;
-import server.Client;
-import server.Server;
+import eu.tankernn.chat.common.MessagePacket;
+import eu.tankernn.chat.common.MessagePacket.MessageType;
+import eu.tankernn.chat.server.Client;
+import eu.tankernn.chat.server.Server;
 
 @CommandInfo(desc = "Give a client OP permissions.", name = "op", permission = "admin.op", minArg = 1)
 public class GiveOP implements Command {

+ 5 - 5
src/main/java/server/command/Help.java → src/main/java/eu/tankernn/chat/server/command/Help.java

@@ -1,9 +1,9 @@
-package server.command;
+package eu.tankernn.chat.server.command;
 
-import common.MessagePacket;
-import common.MessagePacket.MessageType;
-import server.Client;
-import server.Server;
+import eu.tankernn.chat.common.MessagePacket;
+import eu.tankernn.chat.common.MessagePacket.MessageType;
+import eu.tankernn.chat.server.Client;
+import eu.tankernn.chat.server.Server;
 
 @CommandInfo(desc = "Writes the descriptions for all commands.", name = "help", permission = "user.help")
 public class Help implements Command {

+ 6 - 6
src/main/java/server/command/JoinChannel.java → src/main/java/eu/tankernn/chat/server/command/JoinChannel.java

@@ -1,12 +1,12 @@
-package server.command;
+package eu.tankernn.chat.server.command;
 
 import java.util.Optional;
 
-import server.Channel;
-import server.Client;
-import server.Server;
-import common.MessagePacket;
-import common.MessagePacket.MessageType;
+import eu.tankernn.chat.common.MessagePacket;
+import eu.tankernn.chat.common.MessagePacket.MessageType;
+import eu.tankernn.chat.server.Channel;
+import eu.tankernn.chat.server.Client;
+import eu.tankernn.chat.server.Server;
 
 @CommandInfo(desc = "Sets specified channel as primary (/join <channel>)", name = "join", permission = "user.join", minArg = 1)
 public class JoinChannel implements Command {

+ 5 - 5
src/main/java/server/command/Kick.java → src/main/java/eu/tankernn/chat/server/command/Kick.java

@@ -1,11 +1,11 @@
-package server.command;
+package eu.tankernn.chat.server.command;
 
 import java.util.Optional;
 
-import common.MessagePacket;
-import common.MessagePacket.MessageType;
-import server.Client;
-import server.Server;
+import eu.tankernn.chat.common.MessagePacket;
+import eu.tankernn.chat.common.MessagePacket.MessageType;
+import eu.tankernn.chat.server.Client;
+import eu.tankernn.chat.server.Server;
 
 @CommandInfo(desc = "Kicks a user. (/kick <username>)", name = "kick", permission = "admin.kick")
 public class Kick implements Command {

+ 6 - 6
src/main/java/server/command/LeaveChannel.java → src/main/java/eu/tankernn/chat/server/command/LeaveChannel.java

@@ -1,12 +1,12 @@
-package server.command;
+package eu.tankernn.chat.server.command;
 
 import java.util.Optional;
 
-import common.MessagePacket;
-import common.MessagePacket.MessageType;
-import server.Channel;
-import server.Client;
-import server.Server;
+import eu.tankernn.chat.common.MessagePacket;
+import eu.tankernn.chat.common.MessagePacket.MessageType;
+import eu.tankernn.chat.server.Channel;
+import eu.tankernn.chat.server.Client;
+import eu.tankernn.chat.server.Server;
 
 @CommandInfo(desc = "Removes caller from specified channel. (/leave <channel>)", name = "leave", permission = "user.leave", minArg = 1)
 public class LeaveChannel implements Command {

+ 6 - 6
src/main/java/server/command/List.java → src/main/java/eu/tankernn/chat/server/command/List.java

@@ -1,12 +1,12 @@
-package server.command;
+package eu.tankernn.chat.server.command;
 
 import java.util.Optional;
 
-import server.Channel;
-import server.Client;
-import server.Server;
-import common.MessagePacket;
-import common.MessagePacket.MessageType;
+import eu.tankernn.chat.common.MessagePacket;
+import eu.tankernn.chat.common.MessagePacket.MessageType;
+import eu.tankernn.chat.server.Channel;
+import eu.tankernn.chat.server.Client;
+import eu.tankernn.chat.server.Server;
 
 @CommandInfo(desc = "Lists all users online. (/list [channel])", name = "list", permission = "user.list")
 public class List implements Command {

+ 6 - 6
src/main/java/server/command/PrivateMessage.java → src/main/java/eu/tankernn/chat/server/command/PrivateMessage.java

@@ -1,13 +1,13 @@
-package server.command;
+package eu.tankernn.chat.server.command;
 
 import java.util.Arrays;
 import java.util.Optional;
 
-import server.Client;
-import server.Server;
-import util.ArrayUtil;
-import common.MessagePacket;
-import common.MessagePacket.MessageType;
+import eu.tankernn.chat.common.MessagePacket;
+import eu.tankernn.chat.common.MessagePacket.MessageType;
+import eu.tankernn.chat.server.Client;
+import eu.tankernn.chat.server.Server;
+import eu.tankernn.chat.util.ArrayUtil;
 
 @CommandInfo(desc = "Sends a private message to a user", name = "pm", permission = "user.pm", minArg = 2)
 public class PrivateMessage implements Command {

+ 1 - 1
src/main/java/util/ArrayUtil.java → src/main/java/eu/tankernn/chat/util/ArrayUtil.java

@@ -1,4 +1,4 @@
-package util;
+package eu.tankernn.chat.util;
 
 import java.util.Arrays;
 

+ 4 - 2
src/test/java/client/ClientTestCase.java → src/test/java/eu/tankernn/chat/client/test/ClientTestCase.java

@@ -1,4 +1,4 @@
-package client;
+package eu.tankernn.chat.client.test;
 
 import static org.junit.Assert.*;
 
@@ -6,6 +6,8 @@ import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
 
+import eu.tankernn.chat.client.ChatWindow;
+
 public class ClientTestCase {
 	private ChatWindow user1;
 	private ChatWindow user2;
@@ -19,7 +21,7 @@ public class ClientTestCase {
 	@Test
 	public void testSend() {
 		user1.send("Hello!");
-		assertFalse(user1.so.isClosed());
+		assertTrue(user1.isConnected());
 	}
 
 	@Test

+ 1 - 1
src/test/java/client/ClientTestSuite.java → src/test/java/eu/tankernn/chat/client/test/ClientTestSuite.java

@@ -1,4 +1,4 @@
-package client;
+package eu.tankernn.chat.client.test;
 
 import org.junit.runner.RunWith;
 import org.junit.runners.Suite;

+ 4 - 4
src/test/java/common/CompleteTestSuite.java → src/test/java/eu/tankernn/chat/common/test/CompleteTestSuite.java

@@ -1,4 +1,4 @@
-package common;
+package eu.tankernn.chat.common.test;
 
 import org.junit.AfterClass;
 import org.junit.BeforeClass;
@@ -6,11 +6,11 @@ import org.junit.runner.RunWith;
 import org.junit.runners.Suite;
 import org.junit.runners.Suite.SuiteClasses;
 
-import server.Server;
-import server.ServerTestSuite;
+import eu.tankernn.chat.server.Server;
+import eu.tankernn.chat.server.test.ServerTestSuite;
 
 @RunWith(Suite.class)
-@SuiteClasses({ServerTestSuite.class, client.ClientTestSuite.class})
+@SuiteClasses({ServerTestSuite.class, eu.tankernn.chat.client.test.ClientTestSuite.class})
 public class CompleteTestSuite {
 	
 	@BeforeClass

+ 3 - 2
src/test/java/server/ServerTestCase.java → src/test/java/eu/tankernn/chat/server/test/ServerTestCase.java

@@ -1,9 +1,10 @@
-package server;
+package eu.tankernn.chat.server.test;
 
 import org.junit.Assert;
 import org.junit.Test;
 
-import util.ArrayUtil;
+import eu.tankernn.chat.server.CommandRegistry;
+import eu.tankernn.chat.util.ArrayUtil;
 
 public class ServerTestCase {
 	

+ 2 - 2
src/test/java/server/ServerTestSuite.java → src/test/java/eu/tankernn/chat/server/test/ServerTestSuite.java

@@ -1,10 +1,10 @@
-package server;
+package eu.tankernn.chat.server.test;
 
 import org.junit.runner.RunWith;
 import org.junit.runners.Suite;
 import org.junit.runners.Suite.SuiteClasses;
 
 @RunWith(value = Suite.class)
-@SuiteClasses(value = {client.ClientTestSuite.class})
+@SuiteClasses(value = {eu.tankernn.chat.client.test.ClientTestSuite.class})
 public class ServerTestSuite {
 }