diff --git a/.idea/compiler.xml b/.idea/compiler.xml index 96cc43e..8acb7a2 100644 --- a/.idea/compiler.xml +++ b/.idea/compiler.xml @@ -1,6 +1,7 @@ + - \ No newline at end of file + + diff --git a/.idea/misc.xml b/.idea/misc.xml index 8d8dc8d..3007b14 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -3,13 +3,7 @@ - - - + @@ -20,23 +14,8 @@ - + - - - - - 1.8 - - - - - - - - \ No newline at end of file + + diff --git a/.idea/modules.xml b/.idea/modules.xml index e9ca48f..6395196 100644 --- a/.idea/modules.xml +++ b/.idea/modules.xml @@ -5,4 +5,5 @@ - \ No newline at end of file + + diff --git a/.idea/uiDesigner.xml b/.idea/uiDesigner.xml new file mode 100644 index 0000000..3b00020 --- /dev/null +++ b/.idea/uiDesigner.xml @@ -0,0 +1,125 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/.idea/vcs.xml b/.idea/vcs.xml index 94a25f7..c80f219 100644 --- a/.idea/vcs.xml +++ b/.idea/vcs.xml @@ -3,4 +3,5 @@ - \ No newline at end of file + + diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 3b202a0..e15da8f 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -2,25 +2,12 @@ - - - - - - - - - - - - - + - + + + + + @@ -113,22 +142,17 @@ - - @@ -137,14 +161,21 @@ true - - + + + + + - @@ -153,9 +184,14 @@ + + + + @@ -170,8 +206,6 @@ - - @@ -187,7 +221,51 @@ + + + + + + + + + + + + + + + + + + + + + + + + @@ -197,19 +275,25 @@ + + + + @@ -217,28 +301,134 @@ + + + + + + + + + + + - + + + + + + + + + + + + + + + + + + + + + + + + + - + + - + + + + + + + @@ -276,23 +466,29 @@ - - - + + + 1445584035779 - + + 1446551913447 + 1446551913447 + + - + + + + + + + + + + + + + + - - + + - - - - - - - - - - - - - + + + + + + - - + + + + + + + + + + + + + + + - + + - - + + + + + + + + - + + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - + - + @@ -520,7 +841,7 @@ - + @@ -528,15 +849,178 @@ - + - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + No facets are configured + + + + + + + + + + + + + + + 1.7 + + + + + + + + HomeTaskWeek3 + + + + + + + + 1.8 + + + + + + + + + + + + + - \ No newline at end of file + + diff --git a/HomeTaskWeek3.iml b/HomeTaskWeek3.iml index c1d1a28..bcf7900 100644 --- a/HomeTaskWeek3.iml +++ b/HomeTaskWeek3.iml @@ -213,4 +213,5 @@ - \ No newline at end of file + + diff --git a/src/com/geekhub/hw3/auth/AuthException.java b/src/com/geekhub/hw3/auth/AuthException.java new file mode 100644 index 0000000..bccb77f --- /dev/null +++ b/src/com/geekhub/hw3/auth/AuthException.java @@ -0,0 +1,10 @@ +package com.geekhub.hw3.auth; + +/** + * Created by developer on 02.11.2015. + */ +public class AuthException extends Exception { + public AuthException(String message){ + super(message); + } +} diff --git a/src/com/geekhub/hw3/auth/AuthenticationService.java b/src/com/geekhub/hw3/auth/AuthenticationService.java index f7dc14f..33c3302 100644 --- a/src/com/geekhub/hw3/auth/AuthenticationService.java +++ b/src/com/geekhub/hw3/auth/AuthenticationService.java @@ -7,14 +7,27 @@ public static void main(String[] args) { try { User blah = authService.auth("blah", "blah"); - } catch (AuthException e) { - //TODO: react + } catch (Exception e) { + e.printStackTrace(); } try { User batman = authService.auth("Batman", "catwoman"); - } catch (AuthException e) { + } catch (Exception e) { //TODO: react + e.printStackTrace(); + } + try { + User testing = authService.auth("", ""); + } catch (Exception e) { + //TODO: react + e.printStackTrace(); + } + try { + User bambala = authService.auth("Batman", "catwssdoman"); + } catch (Exception e) { + //TODO: react + e.printStackTrace(); } } @@ -23,8 +36,23 @@ public static void main(String[] args) { new User("Batman", "catwoman") }; - private User auth(String login, String password) throws AuthException { + private User auth(String login, String password) throws AuthException, WrongPasswrodException, WrongCredentialsException, UserNotFoundException { //TODO: Implement me - return null; + + for(int i = 0; i < users.length; i++){ + User user = users[i]; + if(user.getLogin().equals(login) && user.getPassword().equals(password)){ + return user; + } else if(user.getLogin().equals(login) && user.getPassword().equals("")){ + throw new WrongPasswrodException ("Password is incorrect"); + } + else if(user.getLogin().equals("") && user.getPassword().equals("")){ + throw new WrongCredentialsException ("You have entered wrong credentials"); + } + else { + throw new UserNotFoundException ("User does not exists"); + } + } + return null; } } diff --git a/src/com/geekhub/hw3/auth/User.java b/src/com/geekhub/hw3/auth/User.java index 75d2dd8..bf987f6 100644 --- a/src/com/geekhub/hw3/auth/User.java +++ b/src/com/geekhub/hw3/auth/User.java @@ -13,10 +13,12 @@ public User(String login, String password) { } public String getLogin() { + return login; } public String getPassword() { + return password; } } diff --git a/src/com/geekhub/hw3/auth/UserNotFoundException.java b/src/com/geekhub/hw3/auth/UserNotFoundException.java new file mode 100644 index 0000000..3f22289 --- /dev/null +++ b/src/com/geekhub/hw3/auth/UserNotFoundException.java @@ -0,0 +1,10 @@ +package com.geekhub.hw3.auth; + +/** + * Created by developer on 02.11.2015. + */ +public class UserNotFoundException extends Exception { + public UserNotFoundException(String message){ + super(message); + } +} diff --git a/src/com/geekhub/hw3/auth/WrongCredentialsException.java b/src/com/geekhub/hw3/auth/WrongCredentialsException.java new file mode 100644 index 0000000..ebb539d --- /dev/null +++ b/src/com/geekhub/hw3/auth/WrongCredentialsException.java @@ -0,0 +1,10 @@ +package com.geekhub.hw3.auth; + +/** + * Created by developer on 02.11.2015. + */ +public class WrongCredentialsException extends Exception { + public WrongCredentialsException(String message){ + super(message); + } +} diff --git a/src/com/geekhub/hw3/auth/WrongPasswrodException.java b/src/com/geekhub/hw3/auth/WrongPasswrodException.java new file mode 100644 index 0000000..fc5407f --- /dev/null +++ b/src/com/geekhub/hw3/auth/WrongPasswrodException.java @@ -0,0 +1,10 @@ +package com.geekhub.hw3.auth; + +/** + * Created by developer on 02.11.2015. + */ +public class WrongPasswrodException extends AuthException { + public WrongPasswrodException(String message){ + super(message); + } +} diff --git a/src/com/geekhub/hw3/comparable/ArraySorter.java b/src/com/geekhub/hw3/comparable/ArraySorter.java index 9dcdc22..caec0ad 100644 --- a/src/com/geekhub/hw3/comparable/ArraySorter.java +++ b/src/com/geekhub/hw3/comparable/ArraySorter.java @@ -8,9 +8,11 @@ public class ArraySorter { public static void main(String[] args) { Comparable[] sortedIntegers = sort(new Integer[]{2343, 2, 6, 1, 0, -1}); Comparable[] sortedStrings = sort(new String[]{ "abc", "54", "op" }); + Comparable[] sortedStrings1 = sort(new String[]{"abc", "54", "op", "1", "645", "123"}); System.out.println("Sorted integers: " + Arrays.toString(sortedIntegers)); System.out.println("Sorted strings: " + Arrays.toString(sortedStrings)); + System.out.println("Sorted strings: " + Arrays.toString(sortedStrings1)); } /** @@ -19,6 +21,18 @@ public static void main(String[] args) { */ public static Comparable[] sort(Comparable[] elements) { //TODO: Implement without using Arrays.sort method - return elements; + Comparable[] copy = Arrays.copyOf(elements, elements.length); + + for (int i = 0; i < elements.length; i++){ + for(int j = i; j < elements.length; j++){ + if (copy[i].compareTo(copy[j]) > 0){ + Comparable element = copy[j]; + copy[j] = copy[i]; + copy[i] = element; + } + } + + } + return copy; } } diff --git a/src/com/geekhub/hw3/string/StringPerformance.java b/src/com/geekhub/hw3/string/StringPerformance.java index 7ed516f..ac58433 100644 --- a/src/com/geekhub/hw3/string/StringPerformance.java +++ b/src/com/geekhub/hw3/string/StringPerformance.java @@ -14,6 +14,11 @@ private static void testStringPerformance() { long beginTime = System.currentTimeMillis(); //TODO: Do CONCAT_CYCLES times of string concatenation + String test = "test text"; + for (int i = 0; i < CONCAT_CYCLES; i++) + { + test += test; + } long timePastMs = System.currentTimeMillis() - beginTime; System.out.println("String concatenation took " + timePastMs + "ms");