diff --git a/README.md b/README.md index 4cad075cc3..5307efa008 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,4 @@ +**UPDATE**: The price of "Learn Spring Security OAuth" will permanently change on the 11th of December, along with the upcoming OAuth2 material: http://bit.ly/github-lss The Courses ============================== diff --git a/akka-http/pom.xml b/akka-http/pom.xml index 6d73f2f2e6..e276ef1aa4 100644 --- a/akka-http/pom.xml +++ b/akka-http/pom.xml @@ -1,47 +1,46 @@ - - + + + 4.0.0 + akka-http + akka-http - 4.0.0 - akka-http - akka-http + + com.baeldung + parent-modules + 1.0.0-SNAPSHOT + - - parent-modules - com.baeldung - 1.0.0-SNAPSHOT - + + + com.typesafe.akka + akka-http_2.12 + ${akka.http.version} + + + com.typesafe.akka + akka-stream_2.12 + ${akka.stream.version} + + + com.typesafe.akka + akka-http-jackson_2.12 + ${akka.http.version} + + + com.typesafe.akka + akka-http-testkit_2.12 + ${akka.http.version} + test + + - - - com.typesafe.akka - akka-http_2.12 - ${akka.http.version} - - - com.typesafe.akka - akka-stream_2.12 - ${akka.stream.version} - - - com.typesafe.akka - akka-http-jackson_2.12 - ${akka.http.version} - - - com.typesafe.akka - akka-http-testkit_2.12 - ${akka.http.version} - test - - + + UTF-8 + UTF-8 + 10.0.11 + 2.5.11 + - - UTF-8 - UTF-8 - 10.0.11 - 2.5.11 - diff --git a/akka-streams/pom.xml b/akka-streams/pom.xml index 7719bb7351..967556d976 100644 --- a/akka-streams/pom.xml +++ b/akka-streams/pom.xml @@ -1,13 +1,13 @@ + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 akka-streams akka-streams - parent-modules com.baeldung + parent-modules 1.0.0-SNAPSHOT diff --git a/algorithms-genetic/pom.xml b/algorithms-genetic/pom.xml index 56f6a31525..eeccb89d6f 100644 --- a/algorithms-genetic/pom.xml +++ b/algorithms-genetic/pom.xml @@ -1,10 +1,11 @@ + + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 algorithms-genetic 0.0.1-SNAPSHOT algorithms-genetic - + com.baeldung parent-modules @@ -60,5 +61,4 @@ 1.11 - diff --git a/algorithms-miscellaneous-1/README.md b/algorithms-miscellaneous-1/README.md index 6a25f8cac8..25e2733538 100644 --- a/algorithms-miscellaneous-1/README.md +++ b/algorithms-miscellaneous-1/README.md @@ -7,8 +7,6 @@ This module contains articles about algorithms. Some classes of algorithms, e.g. - [Validating Input With Finite Automata in Java](https://www.baeldung.com/java-finite-automata) - [Example of Hill Climbing Algorithm](https://www.baeldung.com/java-hill-climbing-algorithm) -- [Monte Carlo Tree Search for Tic-Tac-Toe Game](https://www.baeldung.com/java-monte-carlo-tree-search) -- [Binary Search Algorithm in Java](https://www.baeldung.com/java-binary-search) - [Introduction to Minimax Algorithm](https://www.baeldung.com/java-minimax-algorithm) - [How to Calculate Levenshtein Distance in Java?](https://www.baeldung.com/java-levenshtein-distance) - [How to Find the Kth Largest Element in Java](https://www.baeldung.com/java-kth-largest-element) diff --git a/algorithms-miscellaneous-1/pom.xml b/algorithms-miscellaneous-1/pom.xml index affa66f147..a2183f7474 100644 --- a/algorithms-miscellaneous-1/pom.xml +++ b/algorithms-miscellaneous-1/pom.xml @@ -1,10 +1,11 @@ + + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 algorithms-miscellaneous-1 0.0.1-SNAPSHOT algorithms-miscellaneous-1 - + com.baeldung parent-modules @@ -43,7 +44,7 @@ com.github.dpaukov combinatoricslib3 ${combinatoricslib3.version} - + diff --git a/algorithms-miscellaneous-2/pom.xml b/algorithms-miscellaneous-2/pom.xml index e85dd456a3..e4f4e5c2ea 100644 --- a/algorithms-miscellaneous-2/pom.xml +++ b/algorithms-miscellaneous-2/pom.xml @@ -1,5 +1,6 @@ + + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 algorithms-miscellaneous-2 0.0.1-SNAPSHOT @@ -34,9 +35,9 @@ ${org.jgrapht.core.version} - org.jgrapht - jgrapht-ext - ${org.jgrapht.ext.version} + org.jgrapht + jgrapht-ext + ${org.jgrapht.ext.version} pl.allegro.finance diff --git a/algorithms-miscellaneous-3/README.md b/algorithms-miscellaneous-3/README.md index 93426b3e0d..23a10258a3 100644 --- a/algorithms-miscellaneous-3/README.md +++ b/algorithms-miscellaneous-3/README.md @@ -14,8 +14,6 @@ This module contains articles about algorithms. Some classes of algorithms, e.g. - [A Guide to the Folding Technique in Java](https://www.baeldung.com/folding-hashing-technique) - [Creating a Triangle with for Loops in Java](https://www.baeldung.com/java-print-triangle) - [Efficient Word Frequency Calculator in Java](https://www.baeldung.com/java-word-frequency) -- [Interpolation Search in Java](https://www.baeldung.com/java-interpolation-search) - [The K-Means Clustering Algorithm in Java](https://www.baeldung.com/java-k-means-clustering-algorithm) - [Creating a Custom Annotation in Java](https://www.baeldung.com/java-custom-annotation) -- [Breadth-First Search Algorithm in Java](https://www.baeldung.com/java-breadth-first-search) - More articles: [[<-- prev]](/algorithms-miscellaneous-2) [[next -->]](/algorithms-miscellaneous-4) diff --git a/algorithms-miscellaneous-3/pom.xml b/algorithms-miscellaneous-3/pom.xml index 67923d37d7..a893f0a045 100644 --- a/algorithms-miscellaneous-3/pom.xml +++ b/algorithms-miscellaneous-3/pom.xml @@ -1,3 +1,4 @@ + 4.0.0 @@ -91,4 +92,5 @@ 1.19 1.19 + \ No newline at end of file diff --git a/algorithms-miscellaneous-4/README.md b/algorithms-miscellaneous-4/README.md index df2eafb733..fd33b58d72 100644 --- a/algorithms-miscellaneous-4/README.md +++ b/algorithms-miscellaneous-4/README.md @@ -5,10 +5,10 @@ This module contains articles about algorithms. Some classes of algorithms, e.g. ### Relevant articles: - [Multi-Swarm Optimization Algorithm in Java](https://www.baeldung.com/java-multi-swarm-algorithm) -- [String Search Algorithms for Large Texts](https://www.baeldung.com/java-full-text-search-algorithms) - [Check If a String Contains All The Letters of The Alphabet](https://www.baeldung.com/java-string-contains-all-letters) - [Find the Middle Element of a Linked List](https://www.baeldung.com/java-linked-list-middle-element) - [Find Substrings That Are Palindromes in Java](https://www.baeldung.com/java-palindrome-substrings) - [Find the Longest Substring without Repeating Characters](https://www.baeldung.com/java-longest-substring-without-repeated-characters) - [Permutations of an Array in Java](https://www.baeldung.com/java-array-permutations) +- [Find the Smallest Missing Integer in an Array](https://www.baeldung.com/java-smallest-missing-integer-in-array) - More articles: [[<-- prev]](/algorithms-miscellaneous-3) [[next -->]](/algorithms-miscellaneous-5) diff --git a/algorithms-miscellaneous-4/pom.xml b/algorithms-miscellaneous-4/pom.xml index 8fd8f807ba..682234ad07 100644 --- a/algorithms-miscellaneous-4/pom.xml +++ b/algorithms-miscellaneous-4/pom.xml @@ -1,10 +1,11 @@ + + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 algorithms-miscellaneous-4 0.0.1-SNAPSHOT algorithms-miscellaneous-4 - + com.baeldung parent-modules diff --git a/algorithms-miscellaneous-4/src/test/java/com/baeldung/algorithms/StringSearchAlgorithmsUnitTest.java b/algorithms-miscellaneous-4/src/test/java/com/baeldung/algorithms/StringSearchAlgorithmsUnitTest.java deleted file mode 100755 index dfe015aad2..0000000000 --- a/algorithms-miscellaneous-4/src/test/java/com/baeldung/algorithms/StringSearchAlgorithmsUnitTest.java +++ /dev/null @@ -1,25 +0,0 @@ -package com.baeldung.algorithms; - - -import org.junit.Assert; -import org.junit.Test; - -import com.baeldung.algorithms.string.search.StringSearchAlgorithms; - -public class StringSearchAlgorithmsUnitTest { - - - @Test - public void testStringSearchAlgorithms(){ - String text = "This is some nice text."; - String pattern = "some"; - - int realPosition = text.indexOf(pattern); - Assert.assertTrue(realPosition == StringSearchAlgorithms.simpleTextSearch(pattern.toCharArray(), text.toCharArray())); - Assert.assertTrue(realPosition == StringSearchAlgorithms.RabinKarpMethod(pattern.toCharArray(), text.toCharArray())); - Assert.assertTrue(realPosition == StringSearchAlgorithms.KnuthMorrisPrattSearch(pattern.toCharArray(), text.toCharArray())); - Assert.assertTrue(realPosition == StringSearchAlgorithms.BoyerMooreHorspoolSimpleSearch(pattern.toCharArray(), text.toCharArray())); - Assert.assertTrue(realPosition == StringSearchAlgorithms.BoyerMooreHorspoolSearch(pattern.toCharArray(), text.toCharArray())); - } - -} diff --git a/algorithms-miscellaneous-4/src/test/java/com/baeldung/algorithms/smallestinteger/SmallestMissingPositiveIntegerUnitTest.java b/algorithms-miscellaneous-4/src/test/java/com/baeldung/algorithms/smallestinteger/SmallestMissingPositiveIntegerUnitTest.java index 8bb7151b41..a1b1bfaa25 100644 --- a/algorithms-miscellaneous-4/src/test/java/com/baeldung/algorithms/smallestinteger/SmallestMissingPositiveIntegerUnitTest.java +++ b/algorithms-miscellaneous-4/src/test/java/com/baeldung/algorithms/smallestinteger/SmallestMissingPositiveIntegerUnitTest.java @@ -85,4 +85,13 @@ class SmallestMissingPositiveIntegerUnitTest { assertThat(result).isEqualTo(input.length); } + + @Test + void givenArrayWithoutZero_whenSearchInUnsortedArrayBooleanArray_thenZero() { + int[] input = new int[] {11, 13, 14, 15}; + + int result = SmallestMissingPositiveInteger.searchInUnsortedArrayBooleanArray(input); + + assertThat(result).isEqualTo(0); + } } \ No newline at end of file diff --git a/algorithms-miscellaneous-5/README.md b/algorithms-miscellaneous-5/README.md index 598fbab8b5..27ab303210 100644 --- a/algorithms-miscellaneous-5/README.md +++ b/algorithms-miscellaneous-5/README.md @@ -9,4 +9,5 @@ This module contains articles about algorithms. Some classes of algorithms, e.g. - [Reversing a Binary Tree in Java](https://www.baeldung.com/java-reversing-a-binary-tree) - [Find If Two Numbers Are Relatively Prime in Java](https://www.baeldung.com/java-two-relatively-prime-numbers) - [Knapsack Problem Implementation in Java](https://www.baeldung.com/java-knapsack) +- [How to Determine if a Binary Tree is Balanced](https://www.baeldung.com/java-balanced-binary-tree) - More articles: [[<-- prev]](/../algorithms-miscellaneous-4) diff --git a/algorithms-miscellaneous-5/pom.xml b/algorithms-miscellaneous-5/pom.xml index d17f93e6e0..2f530958e3 100644 --- a/algorithms-miscellaneous-5/pom.xml +++ b/algorithms-miscellaneous-5/pom.xml @@ -1,5 +1,6 @@ + + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 algorithms-miscellaneous-5 0.0.1-SNAPSHOT @@ -17,6 +18,11 @@ commons-codec ${commons-codec.version} + + org.apache.commons + commons-math3 + ${commons-math3.version} + org.projectlombok lombok @@ -28,6 +34,7 @@ tradukisto ${tradukisto.version} + org.assertj assertj-core @@ -52,6 +59,7 @@ 1.0.1 3.9.0 1.11 + 3.6.1 \ No newline at end of file diff --git a/algorithms-miscellaneous-5/src/main/java/com/baeldung/algorithms/caesarcipher/CaesarCipher.java b/algorithms-miscellaneous-5/src/main/java/com/baeldung/algorithms/caesarcipher/CaesarCipher.java new file mode 100644 index 0000000000..5ee913d251 --- /dev/null +++ b/algorithms-miscellaneous-5/src/main/java/com/baeldung/algorithms/caesarcipher/CaesarCipher.java @@ -0,0 +1,83 @@ +package com.baeldung.algorithms.caesarcipher; + +import org.apache.commons.math3.stat.inference.ChiSquareTest; + +import java.util.Arrays; +import java.util.stream.IntStream; + +public class CaesarCipher { + private static final char LETTER_A = 'a'; + private static final char LETTER_Z = 'z'; + private static final int ALPHABET_SIZE = LETTER_Z - LETTER_A + 1; + private static final double[] ENGLISH_LETTERS_PROBABILITIES = {0.073, 0.009, 0.030, 0.044, 0.130, 0.028, 0.016, 0.035, 0.074, 0.002, 0.003, 0.035, 0.025, 0.078, 0.074, 0.027, 0.003, 0.077, 0.063, 0.093, 0.027, 0.013, 0.016, 0.005, 0.019, 0.001}; + + public String cipher(String message, int offset) { + StringBuilder result = new StringBuilder(); + + for (char character : message.toCharArray()) { + if (character != ' ') { + int originalAlphabetPosition = character - LETTER_A; + int newAlphabetPosition = (originalAlphabetPosition + offset) % ALPHABET_SIZE; + char newCharacter = (char) (LETTER_A + newAlphabetPosition); + result.append(newCharacter); + } else { + result.append(character); + } + } + + return result.toString(); + } + + public String decipher(String message, int offset) { + return cipher(message, ALPHABET_SIZE - (offset % ALPHABET_SIZE)); + } + + public int breakCipher(String message) { + return probableOffset(chiSquares(message)); + } + + private double[] chiSquares(String message) { + double[] expectedLettersFrequencies = expectedLettersFrequencies(message.length()); + + double[] chiSquares = new double[ALPHABET_SIZE]; + + for (int offset = 0; offset < chiSquares.length; offset++) { + String decipheredMessage = decipher(message, offset); + long[] lettersFrequencies = observedLettersFrequencies(decipheredMessage); + double chiSquare = new ChiSquareTest().chiSquare(expectedLettersFrequencies, lettersFrequencies); + chiSquares[offset] = chiSquare; + } + + return chiSquares; + } + + private long[] observedLettersFrequencies(String message) { + return IntStream.rangeClosed(LETTER_A, LETTER_Z) + .mapToLong(letter -> countLetter((char) letter, message)) + .toArray(); + } + + private long countLetter(char letter, String message) { + return message.chars() + .filter(character -> character == letter) + .count(); + } + + private double[] expectedLettersFrequencies(int messageLength) { + return Arrays.stream(ENGLISH_LETTERS_PROBABILITIES) + .map(probability -> probability * messageLength) + .toArray(); + } + + private int probableOffset(double[] chiSquares) { + int probableOffset = 0; + for (int offset = 0; offset < chiSquares.length; offset++) { + System.out.println(String.format("Chi-Square for offset %d: %.2f", offset, chiSquares[offset])); + if (chiSquares[offset] < chiSquares[probableOffset]) { + probableOffset = offset; + } + } + + return probableOffset; + } +} diff --git a/algorithms-miscellaneous-5/src/main/java/com/baeldung/algorithms/combinatorics/Combinatorics.java b/algorithms-miscellaneous-5/src/main/java/com/baeldung/algorithms/combinatorics/Combinatorics.java new file mode 100644 index 0000000000..a5c4b325a4 --- /dev/null +++ b/algorithms-miscellaneous-5/src/main/java/com/baeldung/algorithms/combinatorics/Combinatorics.java @@ -0,0 +1,67 @@ +package com.baeldung.algorithms.combinatorics; + +import java.util.*; + +import static java.util.Collections.swap; + +public class Combinatorics { + + public static List> permutations(List sequence) { + List> results = new ArrayList<>(); + permutationsInternal(sequence, results, 0); + return results; + } + + private static void permutationsInternal(List sequence, List> results, int index) { + if (index == sequence.size() - 1) { + results.add(new ArrayList<>(sequence)); + } + + for (int i = index; i < sequence.size(); i++) { + swap(sequence, i, index); + permutationsInternal(sequence, results, index + 1); + swap(sequence, i, index); + } + } + + public static List> combinations(List inputSet, int k) { + List> results = new ArrayList<>(); + combinationsInternal(inputSet, k, results, new ArrayList<>(), 0); + return results; + } + + private static void combinationsInternal( + List inputSet, int k, List> results, ArrayList accumulator, int index) { + int leftToAccumulate = k - accumulator.size(); + int possibleToAcculumate = inputSet.size() - index; + + if (accumulator.size() == k) { + results.add(new ArrayList<>(accumulator)); + } else if (leftToAccumulate <= possibleToAcculumate) { + combinationsInternal(inputSet, k, results, accumulator, index + 1); + + accumulator.add(inputSet.get(index)); + combinationsInternal(inputSet, k, results, accumulator, index + 1); + accumulator.remove(accumulator.size() - 1); + } + } + + public static List> powerSet(List sequence) { + List> results = new ArrayList<>(); + powerSetInternal(sequence, results, new ArrayList<>(), 0); + return results; + } + + private static void powerSetInternal( + List set, List> powerSet, List accumulator, int index) { + if (index == set.size()) { + powerSet.add(new ArrayList<>(accumulator)); + } else { + accumulator.add(set.get(index)); + + powerSetInternal(set, powerSet, accumulator, index + 1); + accumulator.remove(accumulator.size() - 1); + powerSetInternal(set, powerSet, accumulator, index + 1); + } + } +} diff --git a/algorithms-miscellaneous-5/src/main/java/com/baeldung/algorithms/maximumsubarray/BruteForceAlgorithm.java b/algorithms-miscellaneous-5/src/main/java/com/baeldung/algorithms/maximumsubarray/BruteForceAlgorithm.java new file mode 100644 index 0000000000..932ded5018 --- /dev/null +++ b/algorithms-miscellaneous-5/src/main/java/com/baeldung/algorithms/maximumsubarray/BruteForceAlgorithm.java @@ -0,0 +1,35 @@ +package com.baeldung.algorithms.maximumsubarray; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class BruteForceAlgorithm { + + private Logger logger = LoggerFactory.getLogger(BruteForceAlgorithm.class.getName()); + + public int maxSubArray(int[] arr) { + + int size = arr.length; + int maximumSubArraySum = Integer.MIN_VALUE; + int start = 0; + int end = 0; + + for (int left = 0; left < size; left++) { + + int runningWindowSum = 0; + + for (int right = left; right < size; right++) { + runningWindowSum += arr[right]; + + if (runningWindowSum > maximumSubArraySum) { + maximumSubArraySum = runningWindowSum; + start = left; + end = right; + } + } + } + logger.info("Found Maximum Subarray between {} and {}", start, end); + return maximumSubArraySum; + } + +} diff --git a/algorithms-miscellaneous-5/src/main/java/com/baeldung/algorithms/maximumsubarray/KadaneAlgorithm.java b/algorithms-miscellaneous-5/src/main/java/com/baeldung/algorithms/maximumsubarray/KadaneAlgorithm.java new file mode 100644 index 0000000000..0aaa1b6c23 --- /dev/null +++ b/algorithms-miscellaneous-5/src/main/java/com/baeldung/algorithms/maximumsubarray/KadaneAlgorithm.java @@ -0,0 +1,34 @@ +package com.baeldung.algorithms.maximumsubarray; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class KadaneAlgorithm { + + private Logger logger = LoggerFactory.getLogger(BruteForceAlgorithm.class.getName()); + + public int maxSubArraySum(int[] arr) { + + int size = arr.length; + int start = 0; + int end = 0; + + int maxSoFar = 0, maxEndingHere = 0; + + for (int i = 0; i < size; i++) { + + if (arr[i] > maxEndingHere + arr[i]) { + start = i; + maxEndingHere = arr[i]; + } else + maxEndingHere = maxEndingHere + arr[i]; + + if (maxSoFar < maxEndingHere) { + maxSoFar = maxEndingHere; + end = i; + } + } + logger.info("Found Maximum Subarray between {} and {}", start, end); + return maxSoFar; + } +} diff --git a/algorithms-miscellaneous-5/src/main/java/com/baeldung/algorithms/mergesortedarrays/SortedArrays.java b/algorithms-miscellaneous-5/src/main/java/com/baeldung/algorithms/mergesortedarrays/SortedArrays.java new file mode 100644 index 0000000000..5d1c4af650 --- /dev/null +++ b/algorithms-miscellaneous-5/src/main/java/com/baeldung/algorithms/mergesortedarrays/SortedArrays.java @@ -0,0 +1,33 @@ +package com.baeldung.algorithms.mergesortedarrays; + +public class SortedArrays { + + public static int[] merge(int[] foo, int[] bar) { + + int fooLength = foo.length; + int barLength = bar.length; + + int[] merged = new int[fooLength + barLength]; + + int fooPosition, barPosition, mergedPosition; + fooPosition = barPosition = mergedPosition = 0; + + while (fooPosition < fooLength && barPosition < barLength) { + if (foo[fooPosition] < bar[barPosition]) { + merged[mergedPosition++] = foo[fooPosition++]; + } else { + merged[mergedPosition++] = bar[barPosition++]; + } + } + + while (fooPosition < fooLength) { + merged[mergedPosition++] = foo[fooPosition++]; + } + + while (barPosition < barLength) { + merged[mergedPosition++] = bar[barPosition++]; + } + + return merged; + } +} diff --git a/algorithms-miscellaneous-5/src/main/java/com/baeldung/algorithms/prim/Edge.java b/algorithms-miscellaneous-5/src/main/java/com/baeldung/algorithms/prim/Edge.java new file mode 100644 index 0000000000..52ec4ef534 --- /dev/null +++ b/algorithms-miscellaneous-5/src/main/java/com/baeldung/algorithms/prim/Edge.java @@ -0,0 +1,36 @@ +package com.baeldung.algorithms.prim; + +public class Edge { + + private int weight; + private boolean isIncluded = false; + private boolean isPrinted = false; + + public Edge(int weight) { + this.weight = weight; + } + + public int getWeight() { + return weight; + } + + public void setWeight(int weight) { + this.weight = weight; + } + + public boolean isIncluded() { + return isIncluded; + } + + public void setIncluded(boolean included) { + isIncluded = included; + } + + public boolean isPrinted() { + return isPrinted; + } + + public void setPrinted(boolean printed) { + isPrinted = printed; + } +} diff --git a/algorithms-miscellaneous-5/src/main/java/com/baeldung/algorithms/prim/Prim.java b/algorithms-miscellaneous-5/src/main/java/com/baeldung/algorithms/prim/Prim.java new file mode 100644 index 0000000000..365dca6b62 --- /dev/null +++ b/algorithms-miscellaneous-5/src/main/java/com/baeldung/algorithms/prim/Prim.java @@ -0,0 +1,73 @@ +package com.baeldung.algorithms.prim; + +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +import org.apache.commons.math3.util.Pair; + +public class Prim { + + private List graph; + + public Prim(List graph){ + this.graph = graph; + } + + public void run(){ + if (graph.size() > 0){ + graph.get(0).setVisited(true); + } + while (isDisconnected()){ + Edge nextMinimum = new Edge(Integer.MAX_VALUE); + Vertex nextVertex = graph.get(0); + for (Vertex vertex : graph){ + if (vertex.isVisited()){ + Pair candidate = vertex.nextMinimum(); + if (candidate.getValue().getWeight() < nextMinimum.getWeight()){ + nextMinimum = candidate.getValue(); + nextVertex = candidate.getKey(); + } + } + } + nextMinimum.setIncluded(true); + nextVertex.setVisited(true); + } + } + + private boolean isDisconnected(){ + for (Vertex vertex : graph){ + if (!vertex.isVisited()){ + return true; + } + } + return false; + } + + public String originalGraphToString(){ + StringBuilder sb = new StringBuilder(); + for (Vertex vertex : graph){ + sb.append(vertex.originalToString()); + } + return sb.toString(); + } + + public void resetPrintHistory(){ + for (Vertex vertex : graph){ + Iterator> it = vertex.getEdges().entrySet().iterator(); + while (it.hasNext()) { + Map.Entry pair = it.next(); + pair.getValue().setPrinted(false); + } + } + } + + public String minimumSpanningTreeToString(){ + StringBuilder sb = new StringBuilder(); + for (Vertex vertex : graph){ + sb.append(vertex.includedToString()); + } + return sb.toString(); + } + +} diff --git a/algorithms-miscellaneous-5/src/main/java/com/baeldung/algorithms/prim/Vertex.java b/algorithms-miscellaneous-5/src/main/java/com/baeldung/algorithms/prim/Vertex.java new file mode 100644 index 0000000000..982d9331bc --- /dev/null +++ b/algorithms-miscellaneous-5/src/main/java/com/baeldung/algorithms/prim/Vertex.java @@ -0,0 +1,106 @@ +package com.baeldung.algorithms.prim; + +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; + +import org.apache.commons.math3.util.Pair; + +public class Vertex { + + private String label = null; + private Map edges = new HashMap<>(); + private boolean isVisited = false; + + public Vertex(String label){ + this.label = label; + } + + public String getLabel() { + return label; + } + + public void setLabel(String label) { + this.label = label; + } + + public Map getEdges() { + return edges; + } + + public void addEdge(Vertex vertex, Edge edge){ + if (this.edges.containsKey(vertex)){ + if (edge.getWeight() < this.edges.get(vertex).getWeight()){ + this.edges.replace(vertex, edge); + } + } else { + this.edges.put(vertex, edge); + } + } + + public boolean isVisited() { + return isVisited; + } + + public void setVisited(boolean visited) { + isVisited = visited; + } + + public Pair nextMinimum(){ + Edge nextMinimum = new Edge(Integer.MAX_VALUE); + Vertex nextVertex = this; + Iterator> it = edges.entrySet().iterator(); + while (it.hasNext()) { + Map.Entry pair = it.next(); + if (!pair.getKey().isVisited()){ + if (!pair.getValue().isIncluded()) { + if (pair.getValue().getWeight() < nextMinimum.getWeight()) { + nextMinimum = pair.getValue(); + nextVertex = pair.getKey(); + } + } + } + } + return new Pair<>(nextVertex, nextMinimum); + } + + public String originalToString(){ + StringBuilder sb = new StringBuilder(); + Iterator> it = edges.entrySet().iterator(); + while (it.hasNext()) { + Map.Entry pair = it.next(); + if (!pair.getValue().isPrinted()) { + sb.append(getLabel()); + sb.append(" --- "); + sb.append(pair.getValue().getWeight()); + sb.append(" --- "); + sb.append(pair.getKey().getLabel()); + sb.append("\n"); + pair.getValue().setPrinted(true); + } + } + return sb.toString(); + } + + public String includedToString(){ + StringBuilder sb = new StringBuilder(); + if (isVisited()) { + Iterator> it = edges.entrySet().iterator(); + while (it.hasNext()) { + Map.Entry pair = it.next(); + if (pair.getValue().isIncluded()) { + if (!pair.getValue().isPrinted()) { + sb.append(getLabel()); + sb.append(" --- "); + sb.append(pair.getValue().getWeight()); + sb.append(" --- "); + sb.append(pair.getKey().getLabel()); + sb.append("\n"); + pair.getValue().setPrinted(true); + } + } + } + } + return sb.toString(); + } +} diff --git a/algorithms-miscellaneous-5/src/test/java/com/baeldung/algorithms/caesarcipher/CaesarCipherUnitTest.java b/algorithms-miscellaneous-5/src/test/java/com/baeldung/algorithms/caesarcipher/CaesarCipherUnitTest.java new file mode 100644 index 0000000000..c3a22a8978 --- /dev/null +++ b/algorithms-miscellaneous-5/src/test/java/com/baeldung/algorithms/caesarcipher/CaesarCipherUnitTest.java @@ -0,0 +1,83 @@ +package com.baeldung.algorithms.caesarcipher; + +import org.junit.jupiter.api.Test; + +import static org.assertj.core.api.Assertions.assertThat; + +class CaesarCipherUnitTest { + private static final String SENTENCE = "he told me i could never teach a llama to drive"; + private static final String SENTENCE_SHIFTED_THREE = "kh wrog ph l frxog qhyhu whdfk d oodpd wr gulyh"; + private static final String SENTENCE_SHIFTED_TEN = "ro dyvn wo s myevn xofob dokmr k vvkwk dy nbsfo"; + + private CaesarCipher algorithm = new CaesarCipher(); + + @Test + void givenSentenceAndShiftThree_whenCipher_thenCipheredMessageWithoutOverflow() { + String cipheredSentence = algorithm.cipher(SENTENCE, 3); + + assertThat(cipheredSentence) + .isEqualTo(SENTENCE_SHIFTED_THREE); + } + + @Test + void givenSentenceAndShiftTen_whenCipher_thenCipheredMessageWithOverflow() { + String cipheredSentence = algorithm.cipher(SENTENCE, 10); + + assertThat(cipheredSentence) + .isEqualTo(SENTENCE_SHIFTED_TEN); + } + + @Test + void givenSentenceAndShiftThirtySix_whenCipher_thenCipheredLikeTenMessageWithOverflow() { + String cipheredSentence = algorithm.cipher(SENTENCE, 36); + + assertThat(cipheredSentence) + .isEqualTo(SENTENCE_SHIFTED_TEN); + } + + @Test + void givenSentenceShiftedThreeAndShiftThree_whenDecipher_thenOriginalSentenceWithoutOverflow() { + String decipheredSentence = algorithm.decipher(SENTENCE_SHIFTED_THREE, 3); + + assertThat(decipheredSentence) + .isEqualTo(SENTENCE); + } + + @Test + void givenSentenceShiftedTenAndShiftTen_whenDecipher_thenOriginalSentenceWithOverflow() { + String decipheredSentence = algorithm.decipher(SENTENCE_SHIFTED_TEN, 10); + + assertThat(decipheredSentence) + .isEqualTo(SENTENCE); + } + + @Test + void givenSentenceShiftedTenAndShiftThirtySix_whenDecipher_thenOriginalSentenceWithOverflow() { + String decipheredSentence = algorithm.decipher(SENTENCE_SHIFTED_TEN, 36); + + assertThat(decipheredSentence) + .isEqualTo(SENTENCE); + } + + @Test + void givenSentenceShiftedThree_whenBreakCipher_thenOriginalSentence() { + int offset = algorithm.breakCipher(SENTENCE_SHIFTED_THREE); + + assertThat(offset) + .isEqualTo(3); + + assertThat(algorithm.decipher(SENTENCE_SHIFTED_THREE, offset)) + .isEqualTo(SENTENCE); + } + + @Test + void givenSentenceShiftedTen_whenBreakCipher_thenOriginalSentence() { + int offset = algorithm.breakCipher(SENTENCE_SHIFTED_TEN); + + assertThat(offset) + .isEqualTo(10); + + assertThat(algorithm.decipher(SENTENCE_SHIFTED_TEN, offset)) + .isEqualTo(SENTENCE); + } +} \ No newline at end of file diff --git a/algorithms-miscellaneous-5/src/test/java/com/baeldung/algorithms/combinatorics/CombinatoricsUnitTest.java b/algorithms-miscellaneous-5/src/test/java/com/baeldung/algorithms/combinatorics/CombinatoricsUnitTest.java new file mode 100644 index 0000000000..95ffdec239 --- /dev/null +++ b/algorithms-miscellaneous-5/src/test/java/com/baeldung/algorithms/combinatorics/CombinatoricsUnitTest.java @@ -0,0 +1,80 @@ +package com.baeldung.algorithms.combinatorics; + +import java.util.Arrays; +import java.util.HashSet; +import java.util.List; + +import org.junit.Test; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertSame; + +public class CombinatoricsUnitTest { + + @Test + public void givenEmptySequence_whenCallingPermutations_ShouldReturnEmptyList() { + List sequence = Arrays.asList(); + + List> permutations = Combinatorics.permutations(sequence); + + assertEquals(0, permutations.size()); + } + + @Test + public void givenOneElementSequence_whenCallingPermutations_ShouldReturnPermutations() { + List sequence = Arrays.asList(1); + + List> permutations = Combinatorics.permutations(sequence); + + assertEquals(1, permutations.size()); + assertEquals(1, permutations.get(0).size()); + assertSame(1, permutations.get(0).get(0)); + } + + @Test + public void givenFourElementsSequence_whenCallingPermutations_ShouldReturnPermutations() { + List sequence = Arrays.asList(1, 2, 3, 4); + + List> permutations = Combinatorics.permutations(sequence); + + assertEquals(24, permutations.size()); + assertEquals(24, new HashSet<>(permutations).size()); + } + + @Test + public void givenTwoElements_whenCalling3Combinations_ShouldReturnEmptyList() { + List set = Arrays.asList(1, 2); + + List> combinations = Combinatorics.combinations(set, 3); + + assertEquals(0, combinations.size()); + } + + @Test + public void givenThreeElements_whenCalling3Combinations_ShouldReturnOneCombination() { + List set = Arrays.asList(1, 2, 3); + + List> combinations = Combinatorics.combinations(set, 3); + + assertEquals(1, combinations.size()); + assertEquals(combinations.get(0), Arrays.asList(1, 2, 3)); + } + + @Test + public void givenFourElements_whenCalling2Combinations_ShouldReturnCombinations() { + List set = Arrays.asList(1, 2, 3, 4); + + List> combinations = Combinatorics.combinations(set, 2); + + assertEquals(6, combinations.size()); + assertEquals(6, new HashSet<>(combinations).size()); + } + + @Test + public void givenFourElements_whenCallingPowerSet_ShouldReturn15Sets() { + List sequence = Arrays.asList('a', 'b', 'c', 'd'); + + List> combinations = Combinatorics.powerSet(sequence); + + assertEquals(16, combinations.size()); + } +} diff --git a/algorithms-miscellaneous-5/src/test/java/com/baeldung/algorithms/maximumsubarray/BruteForceAlgorithmUnitTest.java b/algorithms-miscellaneous-5/src/test/java/com/baeldung/algorithms/maximumsubarray/BruteForceAlgorithmUnitTest.java new file mode 100644 index 0000000000..b818046b2a --- /dev/null +++ b/algorithms-miscellaneous-5/src/test/java/com/baeldung/algorithms/maximumsubarray/BruteForceAlgorithmUnitTest.java @@ -0,0 +1,19 @@ +package com.baeldung.algorithms.maximumsubarray; + +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +class BruteForceAlgorithmUnitTest { + + @Test + void givenArrayWithNegativeNumberWhenMaximumSubarrayThenReturns6() { + //given + int[] arr = new int[]{-3, 1, -8, 4, -1, 2, 1, -5, 5}; + //when + BruteForceAlgorithm algorithm = new BruteForceAlgorithm(); + int maximumSum = algorithm.maxSubArray(arr); + //then + assertEquals(6, maximumSum); + } +} \ No newline at end of file diff --git a/algorithms-miscellaneous-5/src/test/java/com/baeldung/algorithms/maximumsubarray/KadaneAlgorithmUnitTest.java b/algorithms-miscellaneous-5/src/test/java/com/baeldung/algorithms/maximumsubarray/KadaneAlgorithmUnitTest.java new file mode 100644 index 0000000000..9bece56f5b --- /dev/null +++ b/algorithms-miscellaneous-5/src/test/java/com/baeldung/algorithms/maximumsubarray/KadaneAlgorithmUnitTest.java @@ -0,0 +1,19 @@ +package com.baeldung.algorithms.maximumsubarray; + +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +class KadaneAlgorithmUnitTest { + + @Test + void givenArrayWithNegativeNumberWhenMaximumSubarrayThenReturns6() { + //given + int[] arr = new int[]{-3, 1, -8, 4, -1, 2, 1, -5, 5}; + //when + KadaneAlgorithm algorithm = new KadaneAlgorithm(); + int maxSum = algorithm.maxSubArraySum(arr); + //then + assertEquals(6, maxSum); + } +} \ No newline at end of file diff --git a/algorithms-miscellaneous-5/src/test/java/com/baeldung/algorithms/mergesortedarrays/SortedArraysUnitTest.java b/algorithms-miscellaneous-5/src/test/java/com/baeldung/algorithms/mergesortedarrays/SortedArraysUnitTest.java new file mode 100644 index 0000000000..76eeb7b116 --- /dev/null +++ b/algorithms-miscellaneous-5/src/test/java/com/baeldung/algorithms/mergesortedarrays/SortedArraysUnitTest.java @@ -0,0 +1,29 @@ +package com.baeldung.algorithms.mergesortedarrays; + +import static org.junit.jupiter.api.Assertions.assertArrayEquals; +import org.junit.jupiter.api.Test; + +import com.baeldung.algorithms.mergesortedarrays.SortedArrays; + +public class SortedArraysUnitTest { + + @Test + public void givenTwoSortedArrays_whenMerged_thenReturnMergedSortedArray() { + + int[] foo = { 3, 7 }; + int[] bar = { 4, 8, 11 }; + int[] merged = { 3, 4, 7, 8, 11 }; + + assertArrayEquals(merged, SortedArrays.merge(foo, bar)); + } + + @Test + public void givenTwoSortedArraysWithDuplicates_whenMerged_thenReturnMergedSortedArray() { + + int[] foo = { 3, 3, 7 }; + int[] bar = { 4, 8, 8, 11 }; + int[] merged = { 3, 3, 4, 7, 8, 8, 11 }; + + assertArrayEquals(merged, SortedArrays.merge(foo, bar)); + } +} diff --git a/algorithms-miscellaneous-5/src/test/java/com/baeldung/algorithms/prim/PrimUnitTest.java b/algorithms-miscellaneous-5/src/test/java/com/baeldung/algorithms/prim/PrimUnitTest.java new file mode 100644 index 0000000000..41e53fc9f2 --- /dev/null +++ b/algorithms-miscellaneous-5/src/test/java/com/baeldung/algorithms/prim/PrimUnitTest.java @@ -0,0 +1,54 @@ +package com.baeldung.algorithms.prim; + +import java.util.ArrayList; +import java.util.List; + +import org.junit.Test; + +public class PrimUnitTest { + + @Test + public void givenAGraph_whenPrimRuns_thenPrintMST() { + Prim prim = new Prim(createGraph()); + System.out.println(prim.originalGraphToString()); + System.out.println("----------------"); + prim.run(); + System.out.println(); + prim.resetPrintHistory(); + System.out.println(prim.minimumSpanningTreeToString()); + } + + public static List createGraph() { + List graph = new ArrayList<>(); + Vertex a = new Vertex("A"); + Vertex b = new Vertex("B"); + Vertex c = new Vertex("C"); + Vertex d = new Vertex("D"); + Vertex e = new Vertex("E"); + Edge ab = new Edge(2); + a.addEdge(b, ab); + b.addEdge(a, ab); + Edge ac = new Edge(3); + a.addEdge(c, ac); + c.addEdge(a, ac); + Edge bc = new Edge(2); + b.addEdge(c, bc); + c.addEdge(b, bc); + Edge be = new Edge(5); + b.addEdge(e, be); + e.addEdge(b, be); + Edge cd = new Edge(1); + c.addEdge(d, cd); + d.addEdge(c, cd); + Edge ce = new Edge(1); + c.addEdge(e, ce); + e.addEdge(c, ce); + graph.add(a); + graph.add(b); + graph.add(c); + graph.add(d); + graph.add(e); + return graph; + } + +} diff --git a/algorithms-searching/README.md b/algorithms-searching/README.md new file mode 100644 index 0000000000..d86c3e3de8 --- /dev/null +++ b/algorithms-searching/README.md @@ -0,0 +1,11 @@ +## Algorithms - Searching + +This module contains articles about searching algorithms. + +### Relevant articles: +- [Binary Search Algorithm in Java](https://www.baeldung.com/java-binary-search) +- [Depth First Search in Java](https://www.baeldung.com/java-depth-first-search) +- [Interpolation Search in Java](https://www.baeldung.com/java-interpolation-search) +- [Breadth-First Search Algorithm in Java](https://www.baeldung.com/java-breadth-first-search) +- [String Search Algorithms for Large Texts](https://www.baeldung.com/java-full-text-search-algorithms) +- [Monte Carlo Tree Search for Tic-Tac-Toe Game](https://www.baeldung.com/java-monte-carlo-tree-search) diff --git a/algorithms-searching/pom.xml b/algorithms-searching/pom.xml new file mode 100644 index 0000000000..da32874a18 --- /dev/null +++ b/algorithms-searching/pom.xml @@ -0,0 +1,38 @@ + + + 4.0.0 + algorithms-searching + 0.0.1-SNAPSHOT + algorithms-searching + + + com.baeldung + parent-modules + 1.0.0-SNAPSHOT + + + + + org.assertj + assertj-core + ${org.assertj.core.version} + test + + + + + algorithms-searching + + + src/main/resources + true + + + + + + 3.9.0 + + + \ No newline at end of file diff --git a/algorithms-miscellaneous-1/src/main/java/com/baeldung/algorithms/binarysearch/BinarySearch.java b/algorithms-searching/src/main/java/com/baeldung/algorithms/binarysearch/BinarySearch.java similarity index 96% rename from algorithms-miscellaneous-1/src/main/java/com/baeldung/algorithms/binarysearch/BinarySearch.java rename to algorithms-searching/src/main/java/com/baeldung/algorithms/binarysearch/BinarySearch.java index 5b2ac49d4e..82aefe282b 100644 --- a/algorithms-miscellaneous-1/src/main/java/com/baeldung/algorithms/binarysearch/BinarySearch.java +++ b/algorithms-searching/src/main/java/com/baeldung/algorithms/binarysearch/BinarySearch.java @@ -1,55 +1,55 @@ -package com.baeldung.algorithms.binarysearch; - -import java.util.Arrays; -import java.util.Collections; -import java.util.List; - -public class BinarySearch { - - public int runBinarySearchIteratively(int[] sortedArray, int key, int low, int high) { - - int index = Integer.MAX_VALUE; - - while (low <= high) { - - int mid = (low + high) / 2; - - if (sortedArray[mid] < key) { - low = mid + 1; - } else if (sortedArray[mid] > key) { - high = mid - 1; - } else if (sortedArray[mid] == key) { - index = mid; - break; - } - } - return index; - } - - public int runBinarySearchRecursively(int[] sortedArray, int key, int low, int high) { - - int middle = (low + high) / 2; - if (high < low) { - return -1; - } - - if (key == sortedArray[middle]) { - return middle; - } else if (key < sortedArray[middle]) { - return runBinarySearchRecursively(sortedArray, key, low, middle - 1); - } else { - return runBinarySearchRecursively(sortedArray, key, middle + 1, high); - } - } - - public int runBinarySearchUsingJavaArrays(int[] sortedArray, Integer key) { - int index = Arrays.binarySearch(sortedArray, key); - return index; - } - - public int runBinarySearchUsingJavaCollections(List sortedList, Integer key) { - int index = Collections.binarySearch(sortedList, key); - return index; - } - -} +package com.baeldung.algorithms.binarysearch; + +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + +public class BinarySearch { + + public int runBinarySearchIteratively(int[] sortedArray, int key, int low, int high) { + + int index = Integer.MAX_VALUE; + + while (low <= high) { + + int mid = (low + high) / 2; + + if (sortedArray[mid] < key) { + low = mid + 1; + } else if (sortedArray[mid] > key) { + high = mid - 1; + } else if (sortedArray[mid] == key) { + index = mid; + break; + } + } + return index; + } + + public int runBinarySearchRecursively(int[] sortedArray, int key, int low, int high) { + + int middle = (low + high) / 2; + if (high < low) { + return -1; + } + + if (key == sortedArray[middle]) { + return middle; + } else if (key < sortedArray[middle]) { + return runBinarySearchRecursively(sortedArray, key, low, middle - 1); + } else { + return runBinarySearchRecursively(sortedArray, key, middle + 1, high); + } + } + + public int runBinarySearchUsingJavaArrays(int[] sortedArray, Integer key) { + int index = Arrays.binarySearch(sortedArray, key); + return index; + } + + public int runBinarySearchUsingJavaCollections(List sortedList, Integer key) { + int index = Collections.binarySearch(sortedList, key); + return index; + } + +} diff --git a/algorithms-miscellaneous-3/src/main/java/com/baeldung/algorithms/breadthfirstsearch/BreadthFirstSearchAlgorithm.java b/algorithms-searching/src/main/java/com/baeldung/algorithms/breadthfirstsearch/BreadthFirstSearchAlgorithm.java similarity index 100% rename from algorithms-miscellaneous-3/src/main/java/com/baeldung/algorithms/breadthfirstsearch/BreadthFirstSearchAlgorithm.java rename to algorithms-searching/src/main/java/com/baeldung/algorithms/breadthfirstsearch/BreadthFirstSearchAlgorithm.java diff --git a/algorithms-miscellaneous-3/src/main/java/com/baeldung/algorithms/breadthfirstsearch/Node.java b/algorithms-searching/src/main/java/com/baeldung/algorithms/breadthfirstsearch/Node.java similarity index 100% rename from algorithms-miscellaneous-3/src/main/java/com/baeldung/algorithms/breadthfirstsearch/Node.java rename to algorithms-searching/src/main/java/com/baeldung/algorithms/breadthfirstsearch/Node.java diff --git a/algorithms-miscellaneous-3/src/main/java/com/baeldung/algorithms/breadthfirstsearch/Tree.java b/algorithms-searching/src/main/java/com/baeldung/algorithms/breadthfirstsearch/Tree.java similarity index 100% rename from algorithms-miscellaneous-3/src/main/java/com/baeldung/algorithms/breadthfirstsearch/Tree.java rename to algorithms-searching/src/main/java/com/baeldung/algorithms/breadthfirstsearch/Tree.java diff --git a/algorithms-searching/src/main/java/com/baeldung/algorithms/dfs/BinaryTree.java b/algorithms-searching/src/main/java/com/baeldung/algorithms/dfs/BinaryTree.java new file mode 100644 index 0000000000..a6019ea9f9 --- /dev/null +++ b/algorithms-searching/src/main/java/com/baeldung/algorithms/dfs/BinaryTree.java @@ -0,0 +1,227 @@ +package com.baeldung.algorithms.dfs; + +import java.util.LinkedList; +import java.util.Queue; +import java.util.Stack; + +public class BinaryTree { + + Node root; + + public void add(int value) { + root = addRecursive(root, value); + } + + private Node addRecursive(Node current, int value) { + + if (current == null) { + return new Node(value); + } + + if (value < current.value) { + current.left = addRecursive(current.left, value); + } else if (value > current.value) { + current.right = addRecursive(current.right, value); + } + + return current; + } + + public boolean isEmpty() { + return root == null; + } + + public int getSize() { + return getSizeRecursive(root); + } + + private int getSizeRecursive(Node current) { + return current == null ? 0 : getSizeRecursive(current.left) + 1 + getSizeRecursive(current.right); + } + + public boolean containsNode(int value) { + return containsNodeRecursive(root, value); + } + + private boolean containsNodeRecursive(Node current, int value) { + if (current == null) { + return false; + } + + if (value == current.value) { + return true; + } + + return value < current.value + ? containsNodeRecursive(current.left, value) + : containsNodeRecursive(current.right, value); + } + + public void delete(int value) { + root = deleteRecursive(root, value); + } + + private Node deleteRecursive(Node current, int value) { + if (current == null) { + return null; + } + + if (value == current.value) { + // Case 1: no children + if (current.left == null && current.right == null) { + return null; + } + + // Case 2: only 1 child + if (current.right == null) { + return current.left; + } + + if (current.left == null) { + return current.right; + } + + // Case 3: 2 children + int smallestValue = findSmallestValue(current.right); + current.value = smallestValue; + current.right = deleteRecursive(current.right, smallestValue); + return current; + } + if (value < current.value) { + current.left = deleteRecursive(current.left, value); + return current; + } + + current.right = deleteRecursive(current.right, value); + return current; + } + + private int findSmallestValue(Node root) { + return root.left == null ? root.value : findSmallestValue(root.left); + } + + public void traverseInOrder(Node node) { + if (node != null) { + traverseInOrder(node.left); + visit(node.value); + traverseInOrder(node.right); + } + } + + public void traversePreOrder(Node node) { + if (node != null) { + visit(node.value); + traversePreOrder(node.left); + traversePreOrder(node.right); + } + } + + public void traversePostOrder(Node node) { + if (node != null) { + traversePostOrder(node.left); + traversePostOrder(node.right); + visit(node.value); + } + } + + public void traverseLevelOrder() { + if (root == null) { + return; + } + + Queue nodes = new LinkedList<>(); + nodes.add(root); + + while (!nodes.isEmpty()) { + + Node node = nodes.remove(); + + System.out.print(" " + node.value); + + if (node.left != null) { + nodes.add(node.left); + } + + if (node.left != null) { + nodes.add(node.right); + } + } + } + + + public void traverseInOrderWithoutRecursion() { + Stack stack = new Stack(); + Node current = root; + stack.push(root); + while(! stack.isEmpty()) { + while(current.left != null) { + current = current.left; + stack.push(current); + } + current = stack.pop(); + visit(current.value); + if(current.right != null) { + current = current.right; + stack.push(current); + } + } + } + + public void traversePreOrderWithoutRecursion() { + Stack stack = new Stack(); + Node current = root; + stack.push(root); + while(! stack.isEmpty()) { + current = stack.pop(); + visit(current.value); + + if(current.right != null) + stack.push(current.right); + + if(current.left != null) + stack.push(current.left); + } + } + + public void traversePostOrderWithoutRecursion() { + Stack stack = new Stack(); + Node prev = root; + Node current = root; + stack.push(root); + + while (!stack.isEmpty()) { + current = stack.peek(); + boolean hasChild = (current.left != null || current.right != null); + boolean isPrevLastChild = (prev == current.right || (prev == current.left && current.right == null)); + + if (!hasChild || isPrevLastChild) { + current = stack.pop(); + visit(current.value); + prev = current; + } else { + if (current.right != null) { + stack.push(current.right); + } + if (current.left != null) { + stack.push(current.left); + } + } + } + } + + private void visit(int value) { + System.out.print(" " + value); + } + + class Node { + int value; + Node left; + Node right; + + Node(int value) { + this.value = value; + right = null; + left = null; + } + } +} diff --git a/data-structures/src/main/java/com/baeldung/graph/Graph.java b/algorithms-searching/src/main/java/com/baeldung/algorithms/dfs/Graph.java similarity index 98% rename from data-structures/src/main/java/com/baeldung/graph/Graph.java rename to algorithms-searching/src/main/java/com/baeldung/algorithms/dfs/Graph.java index 40df2c713a..d2cc723cf9 100644 --- a/data-structures/src/main/java/com/baeldung/graph/Graph.java +++ b/algorithms-searching/src/main/java/com/baeldung/algorithms/dfs/Graph.java @@ -1,4 +1,4 @@ -package com.baeldung.graph; +package com.baeldung.algorithms.dfs; import java.util.ArrayList; import java.util.HashMap; diff --git a/algorithms-miscellaneous-3/src/main/java/com/baeldung/algorithms/interpolationsearch/InterpolationSearch.java b/algorithms-searching/src/main/java/com/baeldung/algorithms/interpolationsearch/InterpolationSearch.java similarity index 100% rename from algorithms-miscellaneous-3/src/main/java/com/baeldung/algorithms/interpolationsearch/InterpolationSearch.java rename to algorithms-searching/src/main/java/com/baeldung/algorithms/interpolationsearch/InterpolationSearch.java diff --git a/algorithms-miscellaneous-1/src/main/java/com/baeldung/algorithms/mcts/montecarlo/MonteCarloTreeSearch.java b/algorithms-searching/src/main/java/com/baeldung/algorithms/mcts/montecarlo/MonteCarloTreeSearch.java similarity index 100% rename from algorithms-miscellaneous-1/src/main/java/com/baeldung/algorithms/mcts/montecarlo/MonteCarloTreeSearch.java rename to algorithms-searching/src/main/java/com/baeldung/algorithms/mcts/montecarlo/MonteCarloTreeSearch.java diff --git a/algorithms-miscellaneous-1/src/main/java/com/baeldung/algorithms/mcts/montecarlo/State.java b/algorithms-searching/src/main/java/com/baeldung/algorithms/mcts/montecarlo/State.java similarity index 100% rename from algorithms-miscellaneous-1/src/main/java/com/baeldung/algorithms/mcts/montecarlo/State.java rename to algorithms-searching/src/main/java/com/baeldung/algorithms/mcts/montecarlo/State.java diff --git a/algorithms-miscellaneous-1/src/main/java/com/baeldung/algorithms/mcts/montecarlo/UCT.java b/algorithms-searching/src/main/java/com/baeldung/algorithms/mcts/montecarlo/UCT.java similarity index 100% rename from algorithms-miscellaneous-1/src/main/java/com/baeldung/algorithms/mcts/montecarlo/UCT.java rename to algorithms-searching/src/main/java/com/baeldung/algorithms/mcts/montecarlo/UCT.java diff --git a/algorithms-miscellaneous-1/src/main/java/com/baeldung/algorithms/mcts/tictactoe/Board.java b/algorithms-searching/src/main/java/com/baeldung/algorithms/mcts/tictactoe/Board.java similarity index 100% rename from algorithms-miscellaneous-1/src/main/java/com/baeldung/algorithms/mcts/tictactoe/Board.java rename to algorithms-searching/src/main/java/com/baeldung/algorithms/mcts/tictactoe/Board.java diff --git a/algorithms-miscellaneous-1/src/main/java/com/baeldung/algorithms/mcts/tictactoe/Position.java b/algorithms-searching/src/main/java/com/baeldung/algorithms/mcts/tictactoe/Position.java similarity index 100% rename from algorithms-miscellaneous-1/src/main/java/com/baeldung/algorithms/mcts/tictactoe/Position.java rename to algorithms-searching/src/main/java/com/baeldung/algorithms/mcts/tictactoe/Position.java diff --git a/algorithms-miscellaneous-1/src/main/java/com/baeldung/algorithms/mcts/tree/Node.java b/algorithms-searching/src/main/java/com/baeldung/algorithms/mcts/tree/Node.java similarity index 100% rename from algorithms-miscellaneous-1/src/main/java/com/baeldung/algorithms/mcts/tree/Node.java rename to algorithms-searching/src/main/java/com/baeldung/algorithms/mcts/tree/Node.java diff --git a/algorithms-miscellaneous-1/src/main/java/com/baeldung/algorithms/mcts/tree/Tree.java b/algorithms-searching/src/main/java/com/baeldung/algorithms/mcts/tree/Tree.java similarity index 100% rename from algorithms-miscellaneous-1/src/main/java/com/baeldung/algorithms/mcts/tree/Tree.java rename to algorithms-searching/src/main/java/com/baeldung/algorithms/mcts/tree/Tree.java diff --git a/algorithms-miscellaneous-4/src/main/java/com/baeldung/algorithms/string/search/StringSearchAlgorithms.java b/algorithms-searching/src/main/java/com/baeldung/algorithms/textsearch/TextSearchAlgorithms.java old mode 100755 new mode 100644 similarity index 94% rename from algorithms-miscellaneous-4/src/main/java/com/baeldung/algorithms/string/search/StringSearchAlgorithms.java rename to algorithms-searching/src/main/java/com/baeldung/algorithms/textsearch/TextSearchAlgorithms.java index 45ac53e039..16b45ed886 --- a/algorithms-miscellaneous-4/src/main/java/com/baeldung/algorithms/string/search/StringSearchAlgorithms.java +++ b/algorithms-searching/src/main/java/com/baeldung/algorithms/textsearch/TextSearchAlgorithms.java @@ -1,194 +1,194 @@ -package com.baeldung.algorithms.string.search; - -import java.math.BigInteger; -import java.util.Random; - -public class StringSearchAlgorithms { - public static long getBiggerPrime(int m) { - BigInteger prime = BigInteger.probablePrime(getNumberOfBits(m) + 1, new Random()); - return prime.longValue(); - } - - public static long getLowerPrime(long number) { - BigInteger prime = BigInteger.probablePrime(getNumberOfBits(number) - 1, new Random()); - return prime.longValue(); - } - - private static int getNumberOfBits(final int number) { - return Integer.SIZE - Integer.numberOfLeadingZeros(number); - } - - private static int getNumberOfBits(final long number) { - return Long.SIZE - Long.numberOfLeadingZeros(number); - } - - public static int simpleTextSearch(char[] pattern, char[] text) { - int patternSize = pattern.length; - int textSize = text.length; - - int i = 0; - - while ((i + patternSize) <= textSize) { - int j = 0; - while (text[i + j] == pattern[j]) { - j += 1; - if (j >= patternSize) - return i; - } - i += 1; - } - - return -1; - } - - public static int RabinKarpMethod(char[] pattern, char[] text) { - int patternSize = pattern.length; // m - int textSize = text.length; // n - - long prime = getBiggerPrime(patternSize); - - long r = 1; - for (int i = 0; i < patternSize - 1; i++) { - r *= 2; - r = r % prime; - } - - long[] t = new long[textSize]; - t[0] = 0; - - long pfinger = 0; - - for (int j = 0; j < patternSize; j++) { - t[0] = (2 * t[0] + text[j]) % prime; - pfinger = (2 * pfinger + pattern[j]) % prime; - } - - int i = 0; - boolean passed = false; - - int diff = textSize - patternSize; - for (i = 0; i <= diff; i++) { - if (t[i] == pfinger) { - passed = true; - for (int k = 0; k < patternSize; k++) { - if (text[i + k] != pattern[k]) { - passed = false; - break; - } - } - - if (passed) { - return i; - } - } - - if (i < diff) { - long value = 2 * (t[i] - r * text[i]) + text[i + patternSize]; - t[i + 1] = ((value % prime) + prime) % prime; - } - } - return -1; - - } - - public static int KnuthMorrisPrattSearch(char[] pattern, char[] text) { - int patternSize = pattern.length; // m - int textSize = text.length; // n - - int i = 0, j = 0; - - int[] shift = KnuthMorrisPrattShift(pattern); - - while ((i + patternSize) <= textSize) { - while (text[i + j] == pattern[j]) { - j += 1; - if (j >= patternSize) - return i; - } - - if (j > 0) { - i += shift[j - 1]; - j = Math.max(j - shift[j - 1], 0); - } else { - i++; - j = 0; - } - } - return -1; - } - - public static int[] KnuthMorrisPrattShift(char[] pattern) { - int patternSize = pattern.length; - - int[] shift = new int[patternSize]; - shift[0] = 1; - - int i = 1, j = 0; - - while ((i + j) < patternSize) { - if (pattern[i + j] == pattern[j]) { - shift[i + j] = i; - j++; - } else { - if (j == 0) - shift[i] = i + 1; - - if (j > 0) { - i = i + shift[j - 1]; - j = Math.max(j - shift[j - 1], 0); - } else { - i = i + 1; - j = 0; - } - } - } - return shift; - } - - public static int BoyerMooreHorspoolSimpleSearch(char[] pattern, char[] text) { - int patternSize = pattern.length; - int textSize = text.length; - - int i = 0, j = 0; - - while ((i + patternSize) <= textSize) { - j = patternSize - 1; - while (text[i + j] == pattern[j]) { - j--; - if (j < 0) - return i; - } - i++; - } - return -1; - } - - public static int BoyerMooreHorspoolSearch(char[] pattern, char[] text) { - - int shift[] = new int[256]; - - for (int k = 0; k < 256; k++) { - shift[k] = pattern.length; - } - - for (int k = 0; k < pattern.length - 1; k++) { - shift[pattern[k]] = pattern.length - 1 - k; - } - - int i = 0, j = 0; - - while ((i + pattern.length) <= text.length) { - j = pattern.length - 1; - - while (text[i + j] == pattern[j]) { - j -= 1; - if (j < 0) - return i; - } - - i = i + shift[text[i + pattern.length - 1]]; - - } - return -1; - } -} +package com.baeldung.algorithms.textsearch; + +import java.math.BigInteger; +import java.util.Random; + +public class TextSearchAlgorithms { + public static long getBiggerPrime(int m) { + BigInteger prime = BigInteger.probablePrime(getNumberOfBits(m) + 1, new Random()); + return prime.longValue(); + } + + public static long getLowerPrime(long number) { + BigInteger prime = BigInteger.probablePrime(getNumberOfBits(number) - 1, new Random()); + return prime.longValue(); + } + + private static int getNumberOfBits(final int number) { + return Integer.SIZE - Integer.numberOfLeadingZeros(number); + } + + private static int getNumberOfBits(final long number) { + return Long.SIZE - Long.numberOfLeadingZeros(number); + } + + public static int simpleTextSearch(char[] pattern, char[] text) { + int patternSize = pattern.length; + int textSize = text.length; + + int i = 0; + + while ((i + patternSize) <= textSize) { + int j = 0; + while (text[i + j] == pattern[j]) { + j += 1; + if (j >= patternSize) + return i; + } + i += 1; + } + + return -1; + } + + public static int RabinKarpMethod(char[] pattern, char[] text) { + int patternSize = pattern.length; // m + int textSize = text.length; // n + + long prime = getBiggerPrime(patternSize); + + long r = 1; + for (int i = 0; i < patternSize - 1; i++) { + r *= 2; + r = r % prime; + } + + long[] t = new long[textSize]; + t[0] = 0; + + long pfinger = 0; + + for (int j = 0; j < patternSize; j++) { + t[0] = (2 * t[0] + text[j]) % prime; + pfinger = (2 * pfinger + pattern[j]) % prime; + } + + int i = 0; + boolean passed = false; + + int diff = textSize - patternSize; + for (i = 0; i <= diff; i++) { + if (t[i] == pfinger) { + passed = true; + for (int k = 0; k < patternSize; k++) { + if (text[i + k] != pattern[k]) { + passed = false; + break; + } + } + + if (passed) { + return i; + } + } + + if (i < diff) { + long value = 2 * (t[i] - r * text[i]) + text[i + patternSize]; + t[i + 1] = ((value % prime) + prime) % prime; + } + } + return -1; + + } + + public static int KnuthMorrisPrattSearch(char[] pattern, char[] text) { + int patternSize = pattern.length; // m + int textSize = text.length; // n + + int i = 0, j = 0; + + int[] shift = KnuthMorrisPrattShift(pattern); + + while ((i + patternSize) <= textSize) { + while (text[i + j] == pattern[j]) { + j += 1; + if (j >= patternSize) + return i; + } + + if (j > 0) { + i += shift[j - 1]; + j = Math.max(j - shift[j - 1], 0); + } else { + i++; + j = 0; + } + } + return -1; + } + + public static int[] KnuthMorrisPrattShift(char[] pattern) { + int patternSize = pattern.length; + + int[] shift = new int[patternSize]; + shift[0] = 1; + + int i = 1, j = 0; + + while ((i + j) < patternSize) { + if (pattern[i + j] == pattern[j]) { + shift[i + j] = i; + j++; + } else { + if (j == 0) + shift[i] = i + 1; + + if (j > 0) { + i = i + shift[j - 1]; + j = Math.max(j - shift[j - 1], 0); + } else { + i = i + 1; + j = 0; + } + } + } + return shift; + } + + public static int BoyerMooreHorspoolSimpleSearch(char[] pattern, char[] text) { + int patternSize = pattern.length; + int textSize = text.length; + + int i = 0, j = 0; + + while ((i + patternSize) <= textSize) { + j = patternSize - 1; + while (text[i + j] == pattern[j]) { + j--; + if (j < 0) + return i; + } + i++; + } + return -1; + } + + public static int BoyerMooreHorspoolSearch(char[] pattern, char[] text) { + + int shift[] = new int[256]; + + for (int k = 0; k < 256; k++) { + shift[k] = pattern.length; + } + + for (int k = 0; k < pattern.length - 1; k++) { + shift[pattern[k]] = pattern.length - 1 - k; + } + + int i = 0, j = 0; + + while ((i + pattern.length) <= text.length) { + j = pattern.length - 1; + + while (text[i + j] == pattern[j]) { + j -= 1; + if (j < 0) + return i; + } + + i = i + shift[text[i + pattern.length - 1]]; + + } + return -1; + } +} diff --git a/jackson-2/src/main/resources/logback.xml b/algorithms-searching/src/main/resources/logback.xml similarity index 100% rename from jackson-2/src/main/resources/logback.xml rename to algorithms-searching/src/main/resources/logback.xml diff --git a/algorithms-miscellaneous-1/src/test/java/com/baeldung/algorithms/binarysearch/BinarySearchUnitTest.java b/algorithms-searching/src/test/java/com/baeldung/algorithms/binarysearch/BinarySearchUnitTest.java similarity index 94% rename from algorithms-miscellaneous-1/src/test/java/com/baeldung/algorithms/binarysearch/BinarySearchUnitTest.java rename to algorithms-searching/src/test/java/com/baeldung/algorithms/binarysearch/BinarySearchUnitTest.java index 826682d373..eb3fb4f718 100644 --- a/algorithms-miscellaneous-1/src/test/java/com/baeldung/algorithms/binarysearch/BinarySearchUnitTest.java +++ b/algorithms-searching/src/test/java/com/baeldung/algorithms/binarysearch/BinarySearchUnitTest.java @@ -1,43 +1,41 @@ -package com.baeldung.algorithms.binarysearch; - -import java.util.Arrays; -import java.util.List; - -import org.junit.Assert; -import org.junit.Test; -import com.baeldung.algorithms.binarysearch.BinarySearch; - -public class BinarySearchUnitTest { - - int[] sortedArray = { 0, 1, 2, 3, 4, 5, 5, 6, 7, 8, 9, 9 }; - int key = 6; - int expectedIndexForSearchKey = 7; - int low = 0; - int high = sortedArray.length - 1; - List sortedList = Arrays.asList(0, 1, 2, 3, 4, 5, 5, 6, 7, 8, 9, 9); - - @Test - public void givenASortedArrayOfIntegers_whenBinarySearchRunIterativelyForANumber_thenGetIndexOfTheNumber() { - BinarySearch binSearch = new BinarySearch(); - Assert.assertEquals(expectedIndexForSearchKey, binSearch.runBinarySearchIteratively(sortedArray, key, low, high)); - } - - @Test - public void givenASortedArrayOfIntegers_whenBinarySearchRunRecursivelyForANumber_thenGetIndexOfTheNumber() { - BinarySearch binSearch = new BinarySearch(); - Assert.assertEquals(expectedIndexForSearchKey, binSearch.runBinarySearchRecursively(sortedArray, key, low, high)); - } - - @Test - public void givenASortedArrayOfIntegers_whenBinarySearchRunUsingArraysClassStaticMethodForANumber_thenGetIndexOfTheNumber() { - BinarySearch binSearch = new BinarySearch(); - Assert.assertEquals(expectedIndexForSearchKey, binSearch.runBinarySearchUsingJavaArrays(sortedArray, key)); - } - - @Test - public void givenASortedListOfIntegers_whenBinarySearchRunUsingCollectionsClassStaticMethodForANumber_thenGetIndexOfTheNumber() { - BinarySearch binSearch = new BinarySearch(); - Assert.assertEquals(expectedIndexForSearchKey, binSearch.runBinarySearchUsingJavaCollections(sortedList, key)); - } - -} +package com.baeldung.algorithms.binarysearch; + +import java.util.Arrays; +import java.util.List; +import org.junit.Assert; +import org.junit.Test; + +public class BinarySearchUnitTest { + + int[] sortedArray = { 0, 1, 2, 3, 4, 5, 5, 6, 7, 8, 9, 9 }; + int key = 6; + int expectedIndexForSearchKey = 7; + int low = 0; + int high = sortedArray.length - 1; + List sortedList = Arrays.asList(0, 1, 2, 3, 4, 5, 5, 6, 7, 8, 9, 9); + + @Test + public void givenASortedArrayOfIntegers_whenBinarySearchRunIterativelyForANumber_thenGetIndexOfTheNumber() { + BinarySearch binSearch = new BinarySearch(); + Assert.assertEquals(expectedIndexForSearchKey, binSearch.runBinarySearchIteratively(sortedArray, key, low, high)); + } + + @Test + public void givenASortedArrayOfIntegers_whenBinarySearchRunRecursivelyForANumber_thenGetIndexOfTheNumber() { + BinarySearch binSearch = new BinarySearch(); + Assert.assertEquals(expectedIndexForSearchKey, binSearch.runBinarySearchRecursively(sortedArray, key, low, high)); + } + + @Test + public void givenASortedArrayOfIntegers_whenBinarySearchRunUsingArraysClassStaticMethodForANumber_thenGetIndexOfTheNumber() { + BinarySearch binSearch = new BinarySearch(); + Assert.assertEquals(expectedIndexForSearchKey, binSearch.runBinarySearchUsingJavaArrays(sortedArray, key)); + } + + @Test + public void givenASortedListOfIntegers_whenBinarySearchRunUsingCollectionsClassStaticMethodForANumber_thenGetIndexOfTheNumber() { + BinarySearch binSearch = new BinarySearch(); + Assert.assertEquals(expectedIndexForSearchKey, binSearch.runBinarySearchUsingJavaCollections(sortedList, key)); + } + +} diff --git a/algorithms-miscellaneous-3/src/test/java/com/baeldung/algorithms/breadthfirstsearch/BreadthFirstSearchAlgorithmUnitTest.java b/algorithms-searching/src/test/java/com/baeldung/algorithms/breadthfirstsearch/BreadthFirstSearchAlgorithmUnitTest.java similarity index 100% rename from algorithms-miscellaneous-3/src/test/java/com/baeldung/algorithms/breadthfirstsearch/BreadthFirstSearchAlgorithmUnitTest.java rename to algorithms-searching/src/test/java/com/baeldung/algorithms/breadthfirstsearch/BreadthFirstSearchAlgorithmUnitTest.java diff --git a/algorithms-searching/src/test/java/com/baeldung/algorithms/dfs/BinaryTreeUnitTest.java b/algorithms-searching/src/test/java/com/baeldung/algorithms/dfs/BinaryTreeUnitTest.java new file mode 100644 index 0000000000..076da14f81 --- /dev/null +++ b/algorithms-searching/src/test/java/com/baeldung/algorithms/dfs/BinaryTreeUnitTest.java @@ -0,0 +1,136 @@ +package com.baeldung.algorithms.dfs; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import org.junit.Test; + +public class BinaryTreeUnitTest { + + @Test + public void givenABinaryTree_WhenAddingElements_ThenTreeNotEmpty() { + + BinaryTree bt = createBinaryTree(); + + assertTrue(!bt.isEmpty()); + } + + @Test + public void givenABinaryTree_WhenAddingElements_ThenTreeContainsThoseElements() { + + BinaryTree bt = createBinaryTree(); + + assertTrue(bt.containsNode(6)); + assertTrue(bt.containsNode(4)); + + assertFalse(bt.containsNode(1)); + } + + @Test + public void givenABinaryTree_WhenAddingExistingElement_ThenElementIsNotAdded() { + + BinaryTree bt = createBinaryTree(); + + int initialSize = bt.getSize(); + + assertTrue(bt.containsNode(3)); + bt.add(3); + assertEquals(initialSize, bt.getSize()); + } + + @Test + public void givenABinaryTree_WhenLookingForNonExistingElement_ThenReturnsFalse() { + + BinaryTree bt = createBinaryTree(); + + assertFalse(bt.containsNode(99)); + } + + @Test + public void givenABinaryTree_WhenDeletingElements_ThenTreeDoesNotContainThoseElements() { + + BinaryTree bt = createBinaryTree(); + + assertTrue(bt.containsNode(9)); + bt.delete(9); + assertFalse(bt.containsNode(9)); + } + + @Test + public void givenABinaryTree_WhenDeletingNonExistingElement_ThenTreeDoesNotDelete() { + + BinaryTree bt = createBinaryTree(); + + int initialSize = bt.getSize(); + + assertFalse(bt.containsNode(99)); + bt.delete(99); + assertFalse(bt.containsNode(99)); + assertEquals(initialSize, bt.getSize()); + } + + @Test + public void it_deletes_the_root() { + int value = 12; + BinaryTree bt = new BinaryTree(); + bt.add(value); + + assertTrue(bt.containsNode(value)); + bt.delete(value); + assertFalse(bt.containsNode(value)); + } + + @Test + public void givenABinaryTree_WhenTraversingInOrder_ThenPrintValues() { + + BinaryTree bt = createBinaryTree(); + + bt.traverseInOrder(bt.root); + System.out.println(); + bt.traverseInOrderWithoutRecursion(); + } + + @Test + public void givenABinaryTree_WhenTraversingPreOrder_ThenPrintValues() { + + BinaryTree bt = createBinaryTree(); + + bt.traversePreOrder(bt.root); + System.out.println(); + bt.traversePreOrderWithoutRecursion(); + } + + @Test + public void givenABinaryTree_WhenTraversingPostOrder_ThenPrintValues() { + + BinaryTree bt = createBinaryTree(); + + bt.traversePostOrder(bt.root); + System.out.println(); + bt.traversePostOrderWithoutRecursion(); + } + + @Test + public void givenABinaryTree_WhenTraversingLevelOrder_ThenPrintValues() { + + BinaryTree bt = createBinaryTree(); + + bt.traverseLevelOrder(); + } + + private BinaryTree createBinaryTree() { + BinaryTree bt = new BinaryTree(); + + bt.add(6); + bt.add(4); + bt.add(8); + bt.add(3); + bt.add(5); + bt.add(7); + bt.add(9); + + return bt; + } + +} diff --git a/data-structures/src/test/java/com/baeldung/graph/GraphUnitTest.java b/algorithms-searching/src/test/java/com/baeldung/algorithms/dfs/GraphUnitTest.java similarity index 92% rename from data-structures/src/test/java/com/baeldung/graph/GraphUnitTest.java rename to algorithms-searching/src/test/java/com/baeldung/algorithms/dfs/GraphUnitTest.java index 09b92115d2..715bb55fcb 100644 --- a/data-structures/src/test/java/com/baeldung/graph/GraphUnitTest.java +++ b/algorithms-searching/src/test/java/com/baeldung/algorithms/dfs/GraphUnitTest.java @@ -1,7 +1,8 @@ -package com.baeldung.graph; +package com.baeldung.algorithms.dfs; import java.util.List; +import com.baeldung.algorithms.dfs.Graph; import org.junit.Test; public class GraphUnitTest { diff --git a/algorithms-miscellaneous-3/src/test/java/com/baeldung/algorithms/interpolationsearch/InterpolationSearchUnitTest.java b/algorithms-searching/src/test/java/com/baeldung/algorithms/interpolationsearch/InterpolationSearchUnitTest.java similarity index 100% rename from algorithms-miscellaneous-3/src/test/java/com/baeldung/algorithms/interpolationsearch/InterpolationSearchUnitTest.java rename to algorithms-searching/src/test/java/com/baeldung/algorithms/interpolationsearch/InterpolationSearchUnitTest.java index 8ad962055e..cabedcefad 100644 --- a/algorithms-miscellaneous-3/src/test/java/com/baeldung/algorithms/interpolationsearch/InterpolationSearchUnitTest.java +++ b/algorithms-searching/src/test/java/com/baeldung/algorithms/interpolationsearch/InterpolationSearchUnitTest.java @@ -1,10 +1,10 @@ package com.baeldung.algorithms.interpolationsearch; -import static org.junit.jupiter.api.Assertions.assertEquals; - import org.junit.Before; import org.junit.Test; +import static org.junit.jupiter.api.Assertions.assertEquals; + public class InterpolationSearchUnitTest { private int[] myData; diff --git a/algorithms-miscellaneous-1/src/test/java/com/baeldung/algorithms/mcts/MCTSUnitTest.java b/algorithms-searching/src/test/java/com/baeldung/algorithms/mcts/MCTSUnitTest.java similarity index 100% rename from algorithms-miscellaneous-1/src/test/java/com/baeldung/algorithms/mcts/MCTSUnitTest.java rename to algorithms-searching/src/test/java/com/baeldung/algorithms/mcts/MCTSUnitTest.java diff --git a/algorithms-searching/src/test/java/com/baeldung/algorithms/textsearch/TextSearchAlgorithmsUnitTest.java b/algorithms-searching/src/test/java/com/baeldung/algorithms/textsearch/TextSearchAlgorithmsUnitTest.java new file mode 100644 index 0000000000..543ccb912f --- /dev/null +++ b/algorithms-searching/src/test/java/com/baeldung/algorithms/textsearch/TextSearchAlgorithmsUnitTest.java @@ -0,0 +1,23 @@ +package com.baeldung.algorithms.textsearch; + + +import org.junit.Assert; +import org.junit.Test; + +public class TextSearchAlgorithmsUnitTest { + + + @Test + public void testStringSearchAlgorithms() { + String text = "This is some nice text."; + String pattern = "some"; + + int realPosition = text.indexOf(pattern); + Assert.assertTrue(realPosition == TextSearchAlgorithms.simpleTextSearch(pattern.toCharArray(), text.toCharArray())); + Assert.assertTrue(realPosition == TextSearchAlgorithms.RabinKarpMethod(pattern.toCharArray(), text.toCharArray())); + Assert.assertTrue(realPosition == TextSearchAlgorithms.KnuthMorrisPrattSearch(pattern.toCharArray(), text.toCharArray())); + Assert.assertTrue(realPosition == TextSearchAlgorithms.BoyerMooreHorspoolSimpleSearch(pattern.toCharArray(), text.toCharArray())); + Assert.assertTrue(realPosition == TextSearchAlgorithms.BoyerMooreHorspoolSearch(pattern.toCharArray(), text.toCharArray())); + } + +} diff --git a/algorithms-sorting/pom.xml b/algorithms-sorting/pom.xml index 5bb19a8069..84856235d9 100644 --- a/algorithms-sorting/pom.xml +++ b/algorithms-sorting/pom.xml @@ -1,5 +1,6 @@ + + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 algorithms-sorting 0.0.1-SNAPSHOT diff --git a/animal-sniffer-mvn-plugin/pom.xml b/animal-sniffer-mvn-plugin/pom.xml index fd8f6d3d8c..d04581aaac 100644 --- a/animal-sniffer-mvn-plugin/pom.xml +++ b/animal-sniffer-mvn-plugin/pom.xml @@ -1,5 +1,6 @@ + + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> 4.0.0 animal-sniffer-mvn-plugin 1.0-SNAPSHOT @@ -43,4 +44,5 @@ 1.16 1.0 + \ No newline at end of file diff --git a/annotations/annotation-processing/pom.xml b/annotations/annotation-processing/pom.xml index d9aca6040d..645bbd7a0f 100644 --- a/annotations/annotation-processing/pom.xml +++ b/annotations/annotation-processing/pom.xml @@ -1,10 +1,10 @@ + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 annotation-processing annotation-processing - + com.baeldung 1.0.0-SNAPSHOT diff --git a/annotations/annotation-user/pom.xml b/annotations/annotation-user/pom.xml index 422cc7f119..ae47e19f05 100644 --- a/annotations/annotation-user/pom.xml +++ b/annotations/annotation-user/pom.xml @@ -1,13 +1,13 @@ + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 annotation-user annotation-user - annotations com.baeldung + annotations 1.0.0-SNAPSHOT ../ diff --git a/annotations/pom.xml b/annotations/pom.xml index 5fe89adf0a..41e1e8735b 100644 --- a/annotations/pom.xml +++ b/annotations/pom.xml @@ -1,14 +1,14 @@ + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 annotations annotations pom - + - parent-modules com.baeldung + parent-modules 1.0.0-SNAPSHOT diff --git a/antlr/pom.xml b/antlr/pom.xml index 91b939a882..641382d450 100644 --- a/antlr/pom.xml +++ b/antlr/pom.xml @@ -1,5 +1,6 @@ + + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> 4.0.0 antlr antlr @@ -52,9 +53,10 @@ - + 4.7.1 3.0.0 + \ No newline at end of file diff --git a/apache-avro/pom.xml b/apache-avro/pom.xml index 6baae9c541..35898711c8 100644 --- a/apache-avro/pom.xml +++ b/apache-avro/pom.xml @@ -5,7 +5,7 @@ 4.0.0 apache-avro 0.0.1-SNAPSHOT - apache-avro + apache-avro com.baeldung @@ -67,5 +67,5 @@ 1.8.2 1.7.25 - + diff --git a/apache-bval/pom.xml b/apache-bval/pom.xml index 786f587fb1..4254242e55 100644 --- a/apache-bval/pom.xml +++ b/apache-bval/pom.xml @@ -1,11 +1,11 @@ + + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 - apache-bval apache-bval 0.0.1-SNAPSHOT apache-bval - + com.baeldung parent-modules diff --git a/apache-curator/pom.xml b/apache-curator/pom.xml index 259319d547..ea8fb358ad 100644 --- a/apache-curator/pom.xml +++ b/apache-curator/pom.xml @@ -1,9 +1,10 @@ + + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 apache-curator 0.0.1-SNAPSHOT - apache-curator + apache-curator jar diff --git a/apache-cxf/cxf-aegis/README.md b/apache-cxf/cxf-aegis/README.md new file mode 100644 index 0000000000..e055826554 --- /dev/null +++ b/apache-cxf/cxf-aegis/README.md @@ -0,0 +1,3 @@ +### Relevant Articles + +- [Introduction to Apache CXF Aegis Data Binding](https://www.baeldung.com/aegis-data-binding-in-apache-cxf) diff --git a/apache-cxf/cxf-aegis/pom.xml b/apache-cxf/cxf-aegis/pom.xml index 1d36178b82..6e6c5b093c 100644 --- a/apache-cxf/cxf-aegis/pom.xml +++ b/apache-cxf/cxf-aegis/pom.xml @@ -1,9 +1,10 @@ + + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> 4.0.0 cxf-aegis - cxf-aegis - + cxf-aegis + com.baeldung apache-cxf diff --git a/apache-cxf/cxf-introduction/pom.xml b/apache-cxf/cxf-introduction/pom.xml index 17f03afd25..0572b01a9d 100644 --- a/apache-cxf/cxf-introduction/pom.xml +++ b/apache-cxf/cxf-introduction/pom.xml @@ -1,11 +1,10 @@ - + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> 4.0.0 cxf-introduction - cxf-introduction - + cxf-introduction + com.baeldung apache-cxf diff --git a/apache-cxf/cxf-jaxrs-implementation/pom.xml b/apache-cxf/cxf-jaxrs-implementation/pom.xml index 03d0f67c90..37b81882bb 100644 --- a/apache-cxf/cxf-jaxrs-implementation/pom.xml +++ b/apache-cxf/cxf-jaxrs-implementation/pom.xml @@ -1,11 +1,10 @@ - + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> 4.0.0 cxf-jaxrs-implementation - cxf-jaxrs-implementation - + cxf-jaxrs-implementation + com.baeldung apache-cxf diff --git a/apache-cxf/cxf-spring/README.md b/apache-cxf/cxf-spring/README.md new file mode 100644 index 0000000000..c4d55a5c94 --- /dev/null +++ b/apache-cxf/cxf-spring/README.md @@ -0,0 +1,3 @@ +### Relevant Articles: + +- [A Guide to Apache CXF with Spring](https://www.baeldung.com/apache-cxf-with-spring) diff --git a/apache-cxf/cxf-spring/pom.xml b/apache-cxf/cxf-spring/pom.xml index 97715af54c..01ee7d9411 100644 --- a/apache-cxf/cxf-spring/pom.xml +++ b/apache-cxf/cxf-spring/pom.xml @@ -1,9 +1,10 @@ + + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> 4.0.0 cxf-spring + cxf-spring war - cxf-spring com.baeldung @@ -98,7 +99,6 @@ - diff --git a/apache-cxf/pom.xml b/apache-cxf/pom.xml index 0016f33d70..c993eff3a5 100644 --- a/apache-cxf/pom.xml +++ b/apache-cxf/pom.xml @@ -1,3 +1,4 @@ + 4.0.0 diff --git a/apache-cxf/sse-jaxrs/pom.xml b/apache-cxf/sse-jaxrs/pom.xml index cb5c96660a..89bd5d4191 100644 --- a/apache-cxf/sse-jaxrs/pom.xml +++ b/apache-cxf/sse-jaxrs/pom.xml @@ -16,6 +16,6 @@ sse-jaxrs-server sse-jaxrs-client - + diff --git a/apache-cxf/sse-jaxrs/sse-jaxrs-client/pom.xml b/apache-cxf/sse-jaxrs/sse-jaxrs-client/pom.xml index be2138e172..37a068003c 100644 --- a/apache-cxf/sse-jaxrs/sse-jaxrs-client/pom.xml +++ b/apache-cxf/sse-jaxrs/sse-jaxrs-client/pom.xml @@ -5,7 +5,7 @@ 4.0.0 sse-jaxrs-client sse-jaxrs-client - + com.baeldung sse-jaxrs diff --git a/apache-fop/pom.xml b/apache-fop/pom.xml index 150756d51d..41a6761eaf 100644 --- a/apache-fop/pom.xml +++ b/apache-fop/pom.xml @@ -1,5 +1,6 @@ + + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 apache-fop 0.1-SNAPSHOT diff --git a/apache-geode/pom.xml b/apache-geode/pom.xml index 195dfadd20..78c6390f80 100644 --- a/apache-geode/pom.xml +++ b/apache-geode/pom.xml @@ -6,7 +6,7 @@ apache-geode 1.0-SNAPSHOT apache-geode - + com.baeldung parent-modules @@ -20,8 +20,9 @@ ${geode.core} - + 1.6.0 + \ No newline at end of file diff --git a/apache-meecrowave/pom.xml b/apache-meecrowave/pom.xml index 51c6514992..9e79780e22 100644 --- a/apache-meecrowave/pom.xml +++ b/apache-meecrowave/pom.xml @@ -1,11 +1,12 @@ + + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 apache-meecrowave 0.0.1 apache-meecrowave A sample REST API application with Meecrowave - + com.baeldung parent-modules @@ -38,7 +39,7 @@ test - + @@ -48,14 +49,15 @@ - + 1.8 1.8 - 1.2.0 - 3.10.0 - 1.2.1 - 1.2.1 - 1.2.1 + 1.2.0 + 3.10.0 + 1.2.1 + 1.2.1 + 1.2.1 + \ No newline at end of file diff --git a/apache-olingo/olingo2/README.md b/apache-olingo/olingo2/README.md new file mode 100644 index 0000000000..b1cb23d822 --- /dev/null +++ b/apache-olingo/olingo2/README.md @@ -0,0 +1,4 @@ +### Relevant Articles: + +- [OData Protocol Guide](https://www.baeldung.com/odata) +- [Intro to OData with Olingo](https://www.baeldung.com/olingo) diff --git a/apache-olingo/olingo2/pom.xml b/apache-olingo/olingo2/pom.xml index 95b123efbc..fdbc9b4390 100644 --- a/apache-olingo/olingo2/pom.xml +++ b/apache-olingo/olingo2/pom.xml @@ -1,87 +1,87 @@ - 4.0.0 - org.baeldung.examples.olingo2 - olingo2 - olingo2 - Sample Olingo 2 Project + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + 4.0.0 + org.baeldung.examples.olingo2 + olingo2 + olingo2 + Sample Olingo 2 Project - parent-boot-2 com.baeldung + parent-boot-2 0.0.1-SNAPSHOT ../../parent-boot-2 - - - org.springframework.boot - spring-boot-starter-jersey - - - org.springframework.boot - spring-boot-starter-data-jpa - - - com.h2database - h2 - runtime - - - org.springframework.boot - spring-boot-configuration-processor - true - - - org.springframework.boot - spring-boot-starter-test - test - + + + org.springframework.boot + spring-boot-starter-jersey + + + org.springframework.boot + spring-boot-starter-data-jpa + + + com.h2database + h2 + runtime + + + org.springframework.boot + spring-boot-configuration-processor + true + + + org.springframework.boot + spring-boot-starter-test + test + - - - org.apache.olingo - olingo-odata2-core - ${olingo2.version} - - - - javax.ws.rs - javax.ws.rs-api - - - - - org.apache.olingo - olingo-odata2-jpa-processor-core - ${olingo2.version} - - - org.apache.olingo - olingo-odata2-jpa-processor-ref - ${olingo2.version} - - - org.eclipse.persistence - eclipselink - - - - + + + org.apache.olingo + olingo-odata2-core + ${olingo2.version} + + + + javax.ws.rs + javax.ws.rs-api + + + + + org.apache.olingo + olingo-odata2-jpa-processor-core + ${olingo2.version} + + + org.apache.olingo + olingo-odata2-jpa-processor-ref + ${olingo2.version} + + + org.eclipse.persistence + eclipselink + + + + - - - - org.springframework.boot - spring-boot-maven-plugin - - - + + + + org.springframework.boot + spring-boot-maven-plugin + + + - - 2.0.11 - + + 2.0.11 + diff --git a/apache-opennlp/pom.xml b/apache-opennlp/pom.xml index 6b2e6a9729..701d33c6fd 100644 --- a/apache-opennlp/pom.xml +++ b/apache-opennlp/pom.xml @@ -1,6 +1,6 @@ + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 apache-opennlp 1.0-SNAPSHOT diff --git a/apache-poi/pom.xml b/apache-poi/pom.xml index 54c3e8e928..a114946c47 100644 --- a/apache-poi/pom.xml +++ b/apache-poi/pom.xml @@ -1,5 +1,6 @@ + + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 apache-poi 0.0.1-SNAPSHOT diff --git a/apache-pulsar/pom.xml b/apache-pulsar/pom.xml index fdd9ae1e95..206e1ab74d 100644 --- a/apache-pulsar/pom.xml +++ b/apache-pulsar/pom.xml @@ -1,6 +1,6 @@ + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 4.0.0 com.baeldung.pulsar apache-pulsar @@ -22,8 +22,9 @@ compile - + - 2.1.1-incubating + 2.1.1-incubating + diff --git a/apache-shiro/pom.xml b/apache-shiro/pom.xml index 7f0d07589c..0458ba783f 100644 --- a/apache-shiro/pom.xml +++ b/apache-shiro/pom.xml @@ -6,10 +6,10 @@ apache-shiro 1.0-SNAPSHOT apache-shiro - + - parent-boot-1 com.baeldung + parent-boot-1 0.0.1-SNAPSHOT ../parent-boot-1 diff --git a/apache-solrj/pom.xml b/apache-solrj/pom.xml index b19ceb1e48..b25fd0fb04 100644 --- a/apache-solrj/pom.xml +++ b/apache-solrj/pom.xml @@ -1,5 +1,6 @@ + + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 apache-solrj 0.0.1-SNAPSHOT diff --git a/apache-spark/pom.xml b/apache-spark/pom.xml index 41fd51d9fd..59843adc71 100644 --- a/apache-spark/pom.xml +++ b/apache-spark/pom.xml @@ -1,90 +1,112 @@ + - 4.0.0 - apache-spark - 1.0-SNAPSHOT - apache-spark - jar - http://maven.apache.org + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + 4.0.0 + apache-spark + 1.0-SNAPSHOT + apache-spark + jar + http://maven.apache.org - - com.baeldung - parent-modules - 1.0.0-SNAPSHOT - + + com.baeldung + parent-modules + 1.0.0-SNAPSHOT + - - - org.apache.spark - spark-core_2.11 - ${org.apache.spark.spark-core.version} - provided - - - org.apache.spark - spark-sql_2.11 - ${org.apache.spark.spark-sql.version} - provided - - - org.apache.spark - spark-streaming_2.11 - ${org.apache.spark.spark-streaming.version} - provided - - - org.apache.spark - spark-mllib_2.11 - ${org.apache.spark.spark-mllib.version} - provided - - - org.apache.spark - spark-streaming-kafka-0-10_2.11 - ${org.apache.spark.spark-streaming-kafka.version} - - - com.datastax.spark - spark-cassandra-connector_2.11 - ${com.datastax.spark.spark-cassandra-connector.version} - - - com.datastax.spark - spark-cassandra-connector-java_2.11 - ${com.datastax.spark.spark-cassandra-connector-java.version} - - + + + org.apache.spark + spark-core_2.11 + ${org.apache.spark.spark-core.version} + provided + + + org.apache.spark + spark-sql_2.11 + ${org.apache.spark.spark-sql.version} + provided + + + org.apache.spark + spark-graphx_2.11 + ${org.apache.spark.spark-graphx.version} + provided + + + graphframes + graphframes + ${graphframes.version} + provided + + + org.apache.spark + spark-streaming_2.11 + ${org.apache.spark.spark-streaming.version} + provided + + + org.apache.spark + spark-mllib_2.11 + ${org.apache.spark.spark-mllib.version} + provided + + + org.apache.spark + spark-streaming-kafka-0-10_2.11 + ${org.apache.spark.spark-streaming-kafka.version} + + + com.datastax.spark + spark-cassandra-connector_2.11 + ${com.datastax.spark.spark-cassandra-connector.version} + + + com.datastax.spark + spark-cassandra-connector-java_2.11 + ${com.datastax.spark.spark-cassandra-connector-java.version} + + - - - - maven-assembly-plugin - - - package - - single - - - - - - jar-with-dependencies - - - - - + + + + maven-assembly-plugin + + + package + + single + + + + + + jar-with-dependencies + + + + + - - 2.3.0 - 2.3.0 - 2.3.0 - 2.3.0 - 2.3.0 - 2.3.0 - 1.5.2 - + + + SparkPackagesRepo + http://dl.bintray.com/spark-packages/maven + + + + + 2.3.0 + 2.3.0 + 2.3.0 + 2.3.0 + 2.3.0 + 0.7.0-spark2.4-s_2.11 + 2.3.0 + 2.3.0 + 1.5.2 + diff --git a/apache-spark/src/main/java/com/baeldung/graphframes/GraphExperiments.java b/apache-spark/src/main/java/com/baeldung/graphframes/GraphExperiments.java new file mode 100644 index 0000000000..30524a8c8b --- /dev/null +++ b/apache-spark/src/main/java/com/baeldung/graphframes/GraphExperiments.java @@ -0,0 +1,52 @@ +package com.baeldung.graphframes; + +import org.apache.log4j.Level; +import org.apache.log4j.Logger; +import org.apache.spark.api.java.function.VoidFunction; +import org.apache.spark.graphx.Edge; +import org.apache.spark.graphx.Graph; +import org.apache.spark.graphx.VertexRDD; +import org.graphframes.GraphFrame; +import scala.Tuple2; + +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; + +public class GraphExperiments { + public static Map USERS = new HashMap<>(); + + public static void main(String[] args) throws IOException { + Logger.getLogger("org").setLevel(Level.OFF); + GraphLoader loader = new GraphLoader(); + GraphFrame graph = loader.getGraphFrameUserRelationship(); + + GraphExperiments experiments = new GraphExperiments(); + experiments.doGraphFrameOperations(graph); + experiments.doGraphFrameAlgorithms(graph); + } + + private void doGraphFrameOperations(GraphFrame graph) { + graph.vertices().show(); + graph.edges().show(); + + graph.vertices().filter("name = 'Martin'").show(); + + graph.filterEdges("type = 'Friend'") + .dropIsolatedVertices().vertices().show(); + + graph.degrees().show(); + graph.inDegrees().show(); + graph.outDegrees().show(); + } + + private void doGraphFrameAlgorithms(GraphFrame graph) { + + graph.pageRank().maxIter(20).resetProbability(0.15).run().vertices().show(); + + graph.connectedComponents().run().show(); + + graph.triangleCount().run().show(); + } + +} diff --git a/apache-spark/src/main/java/com/baeldung/graphframes/GraphLoader.java b/apache-spark/src/main/java/com/baeldung/graphframes/GraphLoader.java new file mode 100644 index 0000000000..cad1fb4e26 --- /dev/null +++ b/apache-spark/src/main/java/com/baeldung/graphframes/GraphLoader.java @@ -0,0 +1,72 @@ +package com.baeldung.graphframes; + +import org.apache.spark.SparkConf; +import org.apache.spark.api.java.JavaSparkContext; +import org.apache.spark.sql.Dataset; +import org.apache.spark.sql.Row; +import org.apache.spark.sql.SparkSession; +import org.graphframes.GraphFrame; + +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.ArrayList; +import java.util.List; + +public class GraphLoader { + + public JavaSparkContext getSparkContext() throws IOException { + Path temp = Files.createTempDirectory("sparkGraphFrames"); + SparkConf sparkConf = new SparkConf().setAppName("SparkGraphX").setMaster("local[*]"); + JavaSparkContext javaSparkContext = new JavaSparkContext(sparkConf); + javaSparkContext.setCheckpointDir(temp.toString()); + return javaSparkContext; + } + + public GraphFrame getGraphFrameUserRelationship() throws IOException { + Path temp = Files.createTempDirectory("sparkGraphFrames"); + SparkSession session = SparkSession.builder() + .appName("SparkGraphFrameSample") + .config("spark.sql.warehouse.dir", temp.toString()) + .sparkContext(getSparkContext().sc()) + .master("local[*]") + .getOrCreate(); + List users = loadUsers(); + + Dataset userDataset = session.createDataFrame(users, User.class); + + List relationshipsList = getRelations(); + Dataset relationshipDataset = session.createDataFrame(relationshipsList, Relationship.class); + + GraphFrame graphFrame = new GraphFrame(userDataset, relationshipDataset); + + return graphFrame; + } + + public List getRelations() { + List relationships = new ArrayList<>(); + relationships.add(new Relationship("Friend", "1", "2")); + relationships.add(new Relationship("Following", "1", "4")); + relationships.add(new Relationship("Friend", "2", "4")); + relationships.add(new Relationship("Relative", "3", "1")); + relationships.add(new Relationship("Relative", "3", "4")); + + return relationships; + } + + private List loadUsers() { + User john = new User(1L, "John"); + User martin = new User(2L, "Martin"); + User peter = new User(3L, "Peter"); + User alicia = new User(4L, "Alicia"); + + List users = new ArrayList<>(); + + users.add(new User(1L, "John")); + users.add(new User(2L, "Martin")); + users.add(new User(3L, "Peter")); + users.add(new User(4L, "Alicia")); + + return users; + } +} diff --git a/apache-spark/src/main/java/com/baeldung/graphframes/Relationship.java b/apache-spark/src/main/java/com/baeldung/graphframes/Relationship.java new file mode 100644 index 0000000000..ce1780ea3f --- /dev/null +++ b/apache-spark/src/main/java/com/baeldung/graphframes/Relationship.java @@ -0,0 +1,39 @@ +package com.baeldung.graphframes; + +import java.io.Serializable; +import java.util.UUID; + +public class Relationship implements Serializable { + private String type; + private String src; + private String dst; + private UUID id; + + public Relationship(String type, String src, String dst) { + this.type = type; + this.src = src; + this.dst = dst; + this.id = UUID.randomUUID(); + } + + public String getId() { + return id.toString(); + } + + public String getType() { + return type; + } + + public String getSrc() { + return src; + } + + public String getDst() { + return dst; + } + + @Override + public String toString() { + return getSrc() + " -- " + getType() + " --> " + getDst(); + } +} diff --git a/apache-spark/src/main/java/com/baeldung/graphframes/User.java b/apache-spark/src/main/java/com/baeldung/graphframes/User.java new file mode 100644 index 0000000000..50022a1da1 --- /dev/null +++ b/apache-spark/src/main/java/com/baeldung/graphframes/User.java @@ -0,0 +1,27 @@ +package com.baeldung.graphframes; + +import java.io.Serializable; + +public class User implements Serializable { + + private Long id; + private String name; + + public User(long id, String name) { + this.id = id; + this.name = name; + } + + public String getId() { + return id.toString(); + } + + public String getName() { + return name; + } + + @Override + public String toString() { + return "<" + id + "," + name + ">"; + } +} diff --git a/apache-tapestry/pom.xml b/apache-tapestry/pom.xml new file mode 100644 index 0000000000..e306b56b4a --- /dev/null +++ b/apache-tapestry/pom.xml @@ -0,0 +1,149 @@ + + + 4.0.0 + com.baeldung + apache-tapestry + 0.0.1-SNAPSHOT + apache-tapestry + war + + + + + org.apache.tapestry + tapestry-core + ${tapestry-release-version} + + + + + org.slf4j + slf4j-log4j12 + ${slf4j-release-version} + + + + org.apache.tapestry + tapestry-webresources + ${tapestry-release-version} + + + + + + + + org.testng + testng + ${testng-release-version} + test + + + + org.apache.tapestry + tapestry-test + ${tapestry-release-version} + test + + + + + javax.servlet + servlet-api + ${servlet-api-release-version} + provided + + + + + org.apache.tapestry + tapestry-javadoc + ${tapestry-release-version} + provided + + + + + apache-tapestry + + + org.apache.maven.plugins + maven-compiler-plugin + 2.3.2 + + 1.8 + 1.8 + true + + + + + org.apache.maven.plugins + maven-surefire-plugin + 2.7.2 + + + Qa + + + + + + + org.mortbay.jetty + maven-jetty-plugin + 6.1.16 + + + + + true + + + + tapestry.execution-mode + development + + + + + + + + + + + + jboss + http://repository.jboss.org/nexus/content/groups/public/ + + + + + apache-staging + https://repository.apache.org/content/groups/staging/ + + + + + 5.4.5 + 2.5 + 6.8.21 + 1.7.19 + + + diff --git a/apache-tapestry/src/main/java/com/baeldung/tapestry/components/Layout.java b/apache-tapestry/src/main/java/com/baeldung/tapestry/components/Layout.java new file mode 100644 index 0000000000..5316bd9722 --- /dev/null +++ b/apache-tapestry/src/main/java/com/baeldung/tapestry/components/Layout.java @@ -0,0 +1,16 @@ +package com.baeldung.tapestry.components; + +import org.apache.tapestry5.BindingConstants; +import org.apache.tapestry5.annotations.Parameter; +import org.apache.tapestry5.annotations.Property; + +/** + * Layout component for pages of application. + */ +public class Layout { + + @Property + @Parameter(required = true, defaultPrefix = BindingConstants.LITERAL) + private String title; + +} diff --git a/apache-tapestry/src/main/java/com/baeldung/tapestry/pages/Error404.java b/apache-tapestry/src/main/java/com/baeldung/tapestry/pages/Error404.java new file mode 100644 index 0000000000..c629b82d01 --- /dev/null +++ b/apache-tapestry/src/main/java/com/baeldung/tapestry/pages/Error404.java @@ -0,0 +1,5 @@ +package com.baeldung.tapestry.pages; + +public class Error404 { + +} diff --git a/apache-tapestry/src/main/java/com/baeldung/tapestry/pages/Home.java b/apache-tapestry/src/main/java/com/baeldung/tapestry/pages/Home.java new file mode 100644 index 0000000000..34e99a9cce --- /dev/null +++ b/apache-tapestry/src/main/java/com/baeldung/tapestry/pages/Home.java @@ -0,0 +1,36 @@ +package com.baeldung.tapestry.pages; + +import java.util.Date; + +import org.apache.tapestry5.Block; +import org.apache.tapestry5.annotations.Log; +import org.apache.tapestry5.annotations.Property; +import org.apache.tapestry5.ioc.annotations.Inject; +import org.apache.tapestry5.services.ajax.AjaxResponseRenderer; +import org.slf4j.Logger; + +public class Home { + + @Property + private String appName = "apache-tapestry"; + + public Date getCurrentTime() { + return new Date(); + } + + @Inject + private Logger logger; + + @Inject + private AjaxResponseRenderer ajaxResponseRenderer; + + @Inject + private Block ajaxBlock; + + @Log + void onCallAjax() { + logger.info("Ajax call"); + ajaxResponseRenderer.addRender("ajaxZone", ajaxBlock); + } + +} diff --git a/apache-tapestry/src/main/java/com/baeldung/tapestry/pages/Index.java b/apache-tapestry/src/main/java/com/baeldung/tapestry/pages/Index.java new file mode 100644 index 0000000000..7d9e9a1aaa --- /dev/null +++ b/apache-tapestry/src/main/java/com/baeldung/tapestry/pages/Index.java @@ -0,0 +1,59 @@ +package com.baeldung.tapestry.pages; + + +import org.apache.tapestry5.Block; +import org.apache.tapestry5.EventContext; +import org.apache.tapestry5.SymbolConstants; +import org.apache.tapestry5.annotations.InjectPage; +import org.apache.tapestry5.annotations.Log; +import org.apache.tapestry5.annotations.Property; +import org.apache.tapestry5.ioc.annotations.Inject; +import org.apache.tapestry5.ioc.annotations.Symbol; +import org.apache.tapestry5.services.HttpError; +import org.apache.tapestry5.services.ajax.AjaxResponseRenderer; +import org.slf4j.Logger; + +import java.util.Date; + +/** + * Start page of application apache-tapestry. + */ +public class Index { + @Inject + private Logger logger; + + @Inject + private AjaxResponseRenderer ajaxResponseRenderer; + + @Property + @Inject + @Symbol(SymbolConstants.TAPESTRY_VERSION) + private String tapestryVersion; + + @Inject + private Block block; + + // Handle call with an unwanted context + Object onActivate(EventContext eventContext) { + return eventContext.getCount() > 0 ? + new HttpError(404, "Resource not found") : + null; + } + + @Log + void onComplete() { + logger.info("Complete call on Index page"); + } + + @Log + void onAjax() { + logger.info("Ajax call on Index page"); + + ajaxResponseRenderer.addRender("middlezone", block); + } + + public Date getCurrentTime() { + return new Date(); + } + +} diff --git a/apache-tapestry/src/main/java/com/baeldung/tapestry/pages/Login.java b/apache-tapestry/src/main/java/com/baeldung/tapestry/pages/Login.java new file mode 100644 index 0000000000..c5005f11f5 --- /dev/null +++ b/apache-tapestry/src/main/java/com/baeldung/tapestry/pages/Login.java @@ -0,0 +1,42 @@ +package com.baeldung.tapestry.pages; + +import org.apache.tapestry5.alerts.AlertManager; +import org.apache.tapestry5.annotations.InjectComponent; +import org.apache.tapestry5.annotations.Property; +import org.apache.tapestry5.corelib.components.Form; +import org.apache.tapestry5.ioc.annotations.Inject; +import org.slf4j.Logger; + +public class Login { + @Inject + private Logger logger; + + @Inject + private AlertManager alertManager; + + @InjectComponent + private Form login; + + @Property + private String email; + + @Property + private String password; + + void onValidateFromLogin() { + if(email == null || password == null) { + alertManager.error("Email/Password is null"); + login.recordError("Validation failed"); + } + } + + Object onSuccessFromLogin() { + alertManager.success("Welcome! Login Successful"); + return Home.class; + } + + void onFailureFromLogin() { + alertManager.error("Please try again with correct credentials"); + } + +} diff --git a/apache-tapestry/src/main/java/com/baeldung/tapestry/services/AppModule.java b/apache-tapestry/src/main/java/com/baeldung/tapestry/services/AppModule.java new file mode 100644 index 0000000000..c4d57d5b86 --- /dev/null +++ b/apache-tapestry/src/main/java/com/baeldung/tapestry/services/AppModule.java @@ -0,0 +1,128 @@ +package com.baeldung.tapestry.services; + +import java.io.IOException; + +import org.apache.tapestry5.SymbolConstants; +import org.apache.tapestry5.ioc.MappedConfiguration; +import org.apache.tapestry5.ioc.OrderedConfiguration; +import org.apache.tapestry5.ioc.ServiceBinder; +import org.apache.tapestry5.ioc.annotations.Contribute; +import org.apache.tapestry5.ioc.annotations.Local; +import org.apache.tapestry5.ioc.services.ApplicationDefaults; +import org.apache.tapestry5.ioc.services.SymbolProvider; +import org.apache.tapestry5.services.Request; +import org.apache.tapestry5.services.RequestFilter; +import org.apache.tapestry5.services.RequestHandler; +import org.apache.tapestry5.services.Response; +import org.slf4j.Logger; + +/** + * This module is automatically included as part of the Tapestry IoC Registry, it's a good place to + * configure and extend Tapestry, or to place your own service definitions. + */ +public class AppModule { + public static void bind(ServiceBinder binder) { + // binder.bind(MyServiceInterface.class, MyServiceImpl.class); + + // Make bind() calls on the binder object to define most IoC services. + // Use service builder methods (example below) when the implementation + // is provided inline, or requires more initialization than simply + // invoking the constructor. + } + + public static void contributeFactoryDefaults( + MappedConfiguration configuration) { + // The values defined here (as factory default overrides) are themselves + // overridden with application defaults by DevelopmentModule and QaModule. + + // The application version is primarily useful as it appears in + // any exception reports (HTML or textual). + configuration.override(SymbolConstants.APPLICATION_VERSION, "0.0.1-SNAPSHOT"); + + // This is something that should be removed when going to production, but is useful + // in the early stages of development. + configuration.override(SymbolConstants.PRODUCTION_MODE, false); + } + + public static void contributeApplicationDefaults( + MappedConfiguration configuration) { + // Contributions to ApplicationDefaults will override any contributions to + // FactoryDefaults (with the same key). Here we're restricting the supported + // locales to just "en" (English). As you add localised message catalogs and other assets, + // you can extend this list of locales (it's a comma separated series of locale names; + // the first locale name is the default when there's no reasonable match). + configuration.add(SymbolConstants.SUPPORTED_LOCALES, "en"); + + // You should change the passphrase immediately; the HMAC passphrase is used to secure + // the hidden field data stored in forms to encrypt and digitally sign client-side data. + configuration.add(SymbolConstants.HMAC_PASSPHRASE, "change this immediately"); + } + + /** + * Use annotation or method naming convention: contributeApplicationDefaults + */ + @Contribute(SymbolProvider.class) + @ApplicationDefaults + public static void setupEnvironment(MappedConfiguration configuration) { + // Support for jQuery is new in Tapestry 5.4 and will become the only supported + // option in 5.5. + configuration.add(SymbolConstants.JAVASCRIPT_INFRASTRUCTURE_PROVIDER, "jquery"); + configuration.add(SymbolConstants.BOOTSTRAP_ROOT, "context:mybootstrap"); + } + + + /** + * This is a service definition, the service will be named "TimingFilter". The interface, + * RequestFilter, is used within the RequestHandler service pipeline, which is built from the + * RequestHandler service configuration. Tapestry IoC is responsible for passing in an + * appropriate Logger instance. Requests for static resources are handled at a higher level, so + * this filter will only be invoked for Tapestry related requests. + * + * + * Service builder methods are useful when the implementation is inline as an inner class + * (as here) or require some other kind of special initialization. In most cases, + * use the static bind() method instead. + * + * + * If this method was named "build", then the service id would be taken from the + * service interface and would be "RequestFilter". Since Tapestry already defines + * a service named "RequestFilter" we use an explicit service id that we can reference + * inside the contribution method. + */ + public RequestFilter buildTimingFilter(final Logger log) { + return new RequestFilter() { + public boolean service(Request request, Response response, RequestHandler handler) + throws IOException { + long startTime = System.currentTimeMillis(); + + try { + // The responsibility of a filter is to invoke the corresponding method + // in the handler. When you chain multiple filters together, each filter + // received a handler that is a bridge to the next filter. + + return handler.service(request, response); + } finally { + long elapsed = System.currentTimeMillis() - startTime; + + log.info("Request time: {} ms", elapsed); + } + } + }; + } + + /** + * This is a contribution to the RequestHandler service configuration. This is how we extend + * Tapestry using the timing filter. A common use for this kind of filter is transaction + * management or security. The @Local annotation selects the desired service by type, but only + * from the same module. Without @Local, there would be an error due to the other service(s) + * that implement RequestFilter (defined in other modules). + */ + @Contribute(RequestHandler.class) + public void addTimingFilter(OrderedConfiguration configuration, @Local RequestFilter filter) { + // Each contribution to an ordered configuration has a name, When necessary, you may + // set constraints to precisely control the invocation order of the contributed filter + // within the pipeline. + + configuration.add("Timing", filter); + } +} diff --git a/apache-tapestry/src/main/java/com/baeldung/tapestry/services/DevelopmentModule.java b/apache-tapestry/src/main/java/com/baeldung/tapestry/services/DevelopmentModule.java new file mode 100644 index 0000000000..d9c8493e39 --- /dev/null +++ b/apache-tapestry/src/main/java/com/baeldung/tapestry/services/DevelopmentModule.java @@ -0,0 +1,24 @@ +package com.baeldung.tapestry.services; + +import org.apache.tapestry5.SymbolConstants; +import org.apache.tapestry5.ioc.MappedConfiguration; + +/** + * This module is automatically included as part of the Tapestry IoC Registry if tapestry.execution-mode + * includes development. + */ +public class DevelopmentModule { + public static void contributeApplicationDefaults( + MappedConfiguration configuration) { + // The factory default is true but during the early stages of an application + // overriding to false is a good idea. In addition, this is often overridden + // on the command line as -Dtapestry.production-mode=false + configuration.add(SymbolConstants.PRODUCTION_MODE, false); + + // The application version number is incorprated into URLs for some + // assets. Web browsers will cache assets because of the far future expires + // header. If existing assets are changed, the version number should also + // change, to force the browser to download new versions. + configuration.add(SymbolConstants.APPLICATION_VERSION, "0.0.1-SNAPSHOT-DEV"); + } +} diff --git a/apache-tapestry/src/main/java/com/baeldung/tapestry/services/QaModule.java b/apache-tapestry/src/main/java/com/baeldung/tapestry/services/QaModule.java new file mode 100644 index 0000000000..fc6fb595e9 --- /dev/null +++ b/apache-tapestry/src/main/java/com/baeldung/tapestry/services/QaModule.java @@ -0,0 +1,34 @@ +package com.baeldung.tapestry.services; + +import org.apache.tapestry5.SymbolConstants; +import org.apache.tapestry5.ioc.MappedConfiguration; +import org.apache.tapestry5.ioc.ServiceBinder; + +/** + * This module is automatically included as part of the Tapestry IoC Registry if tapestry.execution-mode + * includes qa ("quality assurance"). + */ +public class QaModule +{ + public static void bind(ServiceBinder binder) + { + // Bind any services needed by the QA team to produce their reports + // binder.bind(MyServiceMonitorInterface.class, MyServiceMonitorImpl.class); + } + + + public static void contributeApplicationDefaults( + MappedConfiguration configuration) + { + // The factory default is true but during the early stages of an application + // overriding to false is a good idea. In addition, this is often overridden + // on the command line as -Dtapestry.production-mode=false + configuration.add(SymbolConstants.PRODUCTION_MODE, false); + + // The application version number is incorprated into URLs for some + // assets. Web browsers will cache assets because of the far future expires + // header. If existing assets are changed, the version number should also + // change, to force the browser to download new versions. + configuration.add(SymbolConstants.APPLICATION_VERSION, "0.0.1-SNAPSHOT-QA"); + } +} diff --git a/apache-tapestry/src/main/resources/com/baeldung/tapestry/components/Layout.tml b/apache-tapestry/src/main/resources/com/baeldung/tapestry/components/Layout.tml new file mode 100644 index 0000000000..baa17aef8e --- /dev/null +++ b/apache-tapestry/src/main/resources/com/baeldung/tapestry/components/Layout.tml @@ -0,0 +1,21 @@ + + + ${title} + + +
+
+
+ +
+
+
+
+ +
+
+

© Your Company

+
+
+ + diff --git a/apache-tapestry/src/main/resources/com/baeldung/tapestry/logback.xml b/apache-tapestry/src/main/resources/com/baeldung/tapestry/logback.xml new file mode 100644 index 0000000000..2997ecb099 --- /dev/null +++ b/apache-tapestry/src/main/resources/com/baeldung/tapestry/logback.xml @@ -0,0 +1,13 @@ + + + + %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n + + + + + + + + + diff --git a/apache-tapestry/src/main/resources/com/baeldung/tapestry/pages/Error404.tml b/apache-tapestry/src/main/resources/com/baeldung/tapestry/pages/Error404.tml new file mode 100644 index 0000000000..b18492221e --- /dev/null +++ b/apache-tapestry/src/main/resources/com/baeldung/tapestry/pages/Error404.tml @@ -0,0 +1,11 @@ + + +
+
+

Requested page not found!

+
+
+ + diff --git a/apache-tapestry/src/main/resources/com/baeldung/tapestry/pages/Home.properties b/apache-tapestry/src/main/resources/com/baeldung/tapestry/pages/Home.properties new file mode 100644 index 0000000000..4647845163 --- /dev/null +++ b/apache-tapestry/src/main/resources/com/baeldung/tapestry/pages/Home.properties @@ -0,0 +1 @@ +introMsg=Welcome to the Apache Tapestry Tutorial diff --git a/apache-tapestry/src/main/resources/com/baeldung/tapestry/pages/Home.tml b/apache-tapestry/src/main/resources/com/baeldung/tapestry/pages/Home.tml new file mode 100644 index 0000000000..3dafb63f0a --- /dev/null +++ b/apache-tapestry/src/main/resources/com/baeldung/tapestry/pages/Home.tml @@ -0,0 +1,14 @@ + + +

Home! ${appName}

+

${message:introMsg}

+

${currentTime}

+

Call Ajax

+ + +
+

Rendered through Ajax

+

The current time is: ${currentTime}

+
+ + diff --git a/apache-tapestry/src/main/resources/com/baeldung/tapestry/pages/Index.properties b/apache-tapestry/src/main/resources/com/baeldung/tapestry/pages/Index.properties new file mode 100644 index 0000000000..bc49edd53f --- /dev/null +++ b/apache-tapestry/src/main/resources/com/baeldung/tapestry/pages/Index.properties @@ -0,0 +1 @@ +greeting=Welcome to Tapestry 5! We hope that this project template will get you going in style. diff --git a/apache-tapestry/src/main/resources/com/baeldung/tapestry/pages/Index.tml b/apache-tapestry/src/main/resources/com/baeldung/tapestry/pages/Index.tml new file mode 100644 index 0000000000..625a3c2fcc --- /dev/null +++ b/apache-tapestry/src/main/resources/com/baeldung/tapestry/pages/Index.tml @@ -0,0 +1,46 @@ + + + + + +
+

+ ${message:greeting} +

+

${message:greeting}

+

The current time is: ${currentTime}

+

+ This is a template for a simple marketing or informational website. It includes a large callout called + the hero unit and three supporting pieces of content. Use it as a starting point to create something + more unique. +

+

Learn more »

+
+ + +
+
+

Normal link

+

Clink the bottom link and the page refresh with event complete

+

Complete»

+
+ + + +
+

Ajax link

+

Click the bottom link to update just the middle column with Ajax call with event ajax

+

Ajax»

+
+
+ + +

Ajax updated

+

I'v been updated through AJAX call

+

The current time is: ${currentTime}

+
+ + diff --git a/apache-tapestry/src/main/resources/com/baeldung/tapestry/pages/Login.tml b/apache-tapestry/src/main/resources/com/baeldung/tapestry/pages/Login.tml new file mode 100644 index 0000000000..ac78a55341 --- /dev/null +++ b/apache-tapestry/src/main/resources/com/baeldung/tapestry/pages/Login.tml @@ -0,0 +1,16 @@ + + +
+
+ +

Please sign in

+ + + +
+
+
+ + diff --git a/apache-tapestry/src/main/resources/log4j.properties b/apache-tapestry/src/main/resources/log4j.properties new file mode 100644 index 0000000000..bd90a762ca --- /dev/null +++ b/apache-tapestry/src/main/resources/log4j.properties @@ -0,0 +1,44 @@ +# Default to info level output; this is very handy if you eventually use Hibernate as well. +log4j.rootCategory=info, A1 + +# A1 is set to be a ConsoleAppender. +log4j.appender.A1=org.apache.log4j.ConsoleAppender + +# A1 uses PatternLayout. +log4j.appender.A1.layout=org.apache.log4j.PatternLayout +log4j.appender.A1.layout.ConversionPattern=[%p] %c{2} %m%n + +# Service category names are the name of the defining module class +# and then the service id. +log4j.category.com.baeldung.tapestry.services.AppModule.TimingFilter=info + +# Outputs a list of pages, components and mixins at startup. +log4j.category.org.apache.tapestry5.modules.TapestryModule.ComponentClassResolver=info + +# Outputs startup statistics; elapsed time to setup and initialize the registry, a list of +# available services, and a launch banner that includes the Tapestry version number. +log4j.category.org.apache.tapestry5.TapestryFilter=info + + +# Turning on debug mode for a page's or component's transformer logger +# will show all of the code changes that occur when the +# class is loaded. + +# log4j.category.tapestry.transformer.com.baeldung.tapestry.pages.Index=debug + +# Turning on debug mode for a component's events logger will show all the events triggered on the +# component, and which component methods are invoked as a result. + +# log4j.category.tapestry.events.com.baeldung.tapestry.pages.Index=debug + +# Turning on trace mode for a page's render logger provides extended information about every step +# in rendering (this is not generally helpful). Turning on debug mode will add a one-line +# summary that includes the elapsed render time, which can be useful in tracking down +# performance issues. + +# log4j.category.tapestry.render.com.baeldung.tapestry.pages.Index=debug + +# Turn on some verbose debugging about everything in the application. This is nice initially, +# while getting everything set up. You'll probably want to remove this once you are +# up and running, replacing it with more selective debugging output. +log4j.category.com.baeldung.tapestry=debug diff --git a/apache-tapestry/src/main/webapp/WEB-INF/app.properties b/apache-tapestry/src/main/webapp/WEB-INF/app.properties new file mode 100644 index 0000000000..1c299311bb --- /dev/null +++ b/apache-tapestry/src/main/webapp/WEB-INF/app.properties @@ -0,0 +1,4 @@ +# This is where global application properties go. +# You can also have individual message catalogs for each page and each +# component that override these defaults. +# The name of this file is based on the element in web. \ No newline at end of file diff --git a/apache-tapestry/src/main/webapp/WEB-INF/web.xml b/apache-tapestry/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 0000000000..c5bdfd415c --- /dev/null +++ b/apache-tapestry/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,54 @@ + + + + + apache-tapestry Tapestry 5 Application + + + tapestry.app-package + com.baeldung.tapestry + + + + + tapestry.development-modules + + com.baeldung.tapestry.services.DevelopmentModule + + + + tapestry.qa-modules + + com.baeldung.tapestry.services.QaModule + + + + + + + app + org.apache.tapestry5.TapestryFilter + + + + app + /* + REQUEST + ERROR + + + + 404 + /error404 + + + \ No newline at end of file diff --git a/apache-tapestry/src/main/webapp/favicon.ico b/apache-tapestry/src/main/webapp/favicon.ico new file mode 100644 index 0000000000..b9715a2aed Binary files /dev/null and b/apache-tapestry/src/main/webapp/favicon.ico differ diff --git a/apache-tapestry/src/main/webapp/images/tapestry.png b/apache-tapestry/src/main/webapp/images/tapestry.png new file mode 100644 index 0000000000..eba58883c6 Binary files /dev/null and b/apache-tapestry/src/main/webapp/images/tapestry.png differ diff --git a/jhipster/jhipster-microservice/gateway-app/src/main/webapp/bower_components/bootstrap/dist/css/bootstrap-theme.css b/apache-tapestry/src/main/webapp/mybootstrap/css/bootstrap-theme.css similarity index 84% rename from jhipster/jhipster-microservice/gateway-app/src/main/webapp/bower_components/bootstrap/dist/css/bootstrap-theme.css rename to apache-tapestry/src/main/webapp/mybootstrap/css/bootstrap-theme.css index 31d8882661..374a7e314a 100644 --- a/jhipster/jhipster-microservice/gateway-app/src/main/webapp/bower_components/bootstrap/dist/css/bootstrap-theme.css +++ b/apache-tapestry/src/main/webapp/mybootstrap/css/bootstrap-theme.css @@ -1,8 +1,9 @@ /*! - * Bootstrap v3.3.7 (http://getbootstrap.com) - * Copyright 2011-2016 Twitter, Inc. + * Bootstrap v3.3.4 (http://getbootstrap.com) + * Copyright 2011-2015 Twitter, Inc. * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE) */ + .btn-default, .btn-primary, .btn-success, @@ -28,27 +29,6 @@ -webkit-box-shadow: inset 0 3px 5px rgba(0, 0, 0, .125); box-shadow: inset 0 3px 5px rgba(0, 0, 0, .125); } -.btn-default.disabled, -.btn-primary.disabled, -.btn-success.disabled, -.btn-info.disabled, -.btn-warning.disabled, -.btn-danger.disabled, -.btn-default[disabled], -.btn-primary[disabled], -.btn-success[disabled], -.btn-info[disabled], -.btn-warning[disabled], -.btn-danger[disabled], -fieldset[disabled] .btn-default, -fieldset[disabled] .btn-primary, -fieldset[disabled] .btn-success, -fieldset[disabled] .btn-info, -fieldset[disabled] .btn-warning, -fieldset[disabled] .btn-danger { - -webkit-box-shadow: none; - box-shadow: none; -} .btn-default .badge, .btn-primary .badge, .btn-success .badge, @@ -84,23 +64,8 @@ fieldset[disabled] .btn-danger { border-color: #dbdbdb; } .btn-default.disabled, -.btn-default[disabled], -fieldset[disabled] .btn-default, -.btn-default.disabled:hover, -.btn-default[disabled]:hover, -fieldset[disabled] .btn-default:hover, -.btn-default.disabled:focus, -.btn-default[disabled]:focus, -fieldset[disabled] .btn-default:focus, -.btn-default.disabled.focus, -.btn-default[disabled].focus, -fieldset[disabled] .btn-default.focus, -.btn-default.disabled:active, -.btn-default[disabled]:active, -fieldset[disabled] .btn-default:active, -.btn-default.disabled.active, -.btn-default[disabled].active, -fieldset[disabled] .btn-default.active { +.btn-default:disabled, +.btn-default[disabled] { background-color: #e0e0e0; background-image: none; } @@ -125,23 +90,8 @@ fieldset[disabled] .btn-default.active { border-color: #245580; } .btn-primary.disabled, -.btn-primary[disabled], -fieldset[disabled] .btn-primary, -.btn-primary.disabled:hover, -.btn-primary[disabled]:hover, -fieldset[disabled] .btn-primary:hover, -.btn-primary.disabled:focus, -.btn-primary[disabled]:focus, -fieldset[disabled] .btn-primary:focus, -.btn-primary.disabled.focus, -.btn-primary[disabled].focus, -fieldset[disabled] .btn-primary.focus, -.btn-primary.disabled:active, -.btn-primary[disabled]:active, -fieldset[disabled] .btn-primary:active, -.btn-primary.disabled.active, -.btn-primary[disabled].active, -fieldset[disabled] .btn-primary.active { +.btn-primary:disabled, +.btn-primary[disabled] { background-color: #265a88; background-image: none; } @@ -166,23 +116,8 @@ fieldset[disabled] .btn-primary.active { border-color: #3e8f3e; } .btn-success.disabled, -.btn-success[disabled], -fieldset[disabled] .btn-success, -.btn-success.disabled:hover, -.btn-success[disabled]:hover, -fieldset[disabled] .btn-success:hover, -.btn-success.disabled:focus, -.btn-success[disabled]:focus, -fieldset[disabled] .btn-success:focus, -.btn-success.disabled.focus, -.btn-success[disabled].focus, -fieldset[disabled] .btn-success.focus, -.btn-success.disabled:active, -.btn-success[disabled]:active, -fieldset[disabled] .btn-success:active, -.btn-success.disabled.active, -.btn-success[disabled].active, -fieldset[disabled] .btn-success.active { +.btn-success:disabled, +.btn-success[disabled] { background-color: #419641; background-image: none; } @@ -207,23 +142,8 @@ fieldset[disabled] .btn-success.active { border-color: #28a4c9; } .btn-info.disabled, -.btn-info[disabled], -fieldset[disabled] .btn-info, -.btn-info.disabled:hover, -.btn-info[disabled]:hover, -fieldset[disabled] .btn-info:hover, -.btn-info.disabled:focus, -.btn-info[disabled]:focus, -fieldset[disabled] .btn-info:focus, -.btn-info.disabled.focus, -.btn-info[disabled].focus, -fieldset[disabled] .btn-info.focus, -.btn-info.disabled:active, -.btn-info[disabled]:active, -fieldset[disabled] .btn-info:active, -.btn-info.disabled.active, -.btn-info[disabled].active, -fieldset[disabled] .btn-info.active { +.btn-info:disabled, +.btn-info[disabled] { background-color: #2aabd2; background-image: none; } @@ -248,23 +168,8 @@ fieldset[disabled] .btn-info.active { border-color: #e38d13; } .btn-warning.disabled, -.btn-warning[disabled], -fieldset[disabled] .btn-warning, -.btn-warning.disabled:hover, -.btn-warning[disabled]:hover, -fieldset[disabled] .btn-warning:hover, -.btn-warning.disabled:focus, -.btn-warning[disabled]:focus, -fieldset[disabled] .btn-warning:focus, -.btn-warning.disabled.focus, -.btn-warning[disabled].focus, -fieldset[disabled] .btn-warning.focus, -.btn-warning.disabled:active, -.btn-warning[disabled]:active, -fieldset[disabled] .btn-warning:active, -.btn-warning.disabled.active, -.btn-warning[disabled].active, -fieldset[disabled] .btn-warning.active { +.btn-warning:disabled, +.btn-warning[disabled] { background-color: #eb9316; background-image: none; } @@ -289,23 +194,8 @@ fieldset[disabled] .btn-warning.active { border-color: #b92c28; } .btn-danger.disabled, -.btn-danger[disabled], -fieldset[disabled] .btn-danger, -.btn-danger.disabled:hover, -.btn-danger[disabled]:hover, -fieldset[disabled] .btn-danger:hover, -.btn-danger.disabled:focus, -.btn-danger[disabled]:focus, -fieldset[disabled] .btn-danger:focus, -.btn-danger.disabled.focus, -.btn-danger[disabled].focus, -fieldset[disabled] .btn-danger.focus, -.btn-danger.disabled:active, -.btn-danger[disabled]:active, -fieldset[disabled] .btn-danger:active, -.btn-danger.disabled.active, -.btn-danger[disabled].active, -fieldset[disabled] .btn-danger.active { +.btn-danger:disabled, +.btn-danger[disabled] { background-color: #c12e2a; background-image: none; } @@ -370,7 +260,6 @@ fieldset[disabled] .btn-danger.active { filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#ff3c3c3c', endColorstr='#ff222222', GradientType=0); filter: progid:DXImageTransform.Microsoft.gradient(enabled = false); background-repeat: repeat-x; - border-radius: 4px; } .navbar-inverse .navbar-nav > .open > a, .navbar-inverse .navbar-nav > .active > a { @@ -584,4 +473,4 @@ fieldset[disabled] .btn-danger.active { -webkit-box-shadow: inset 0 1px 3px rgba(0, 0, 0, .05), 0 1px 0 rgba(255, 255, 255, .1); box-shadow: inset 0 1px 3px rgba(0, 0, 0, .05), 0 1px 0 rgba(255, 255, 255, .1); } -/*# sourceMappingURL=bootstrap-theme.css.map */ + diff --git a/jhipster/jhipster-microservice/gateway-app/src/main/webapp/bower_components/bootstrap/dist/css/bootstrap.css b/apache-tapestry/src/main/webapp/mybootstrap/css/bootstrap.css similarity index 94% rename from jhipster/jhipster-microservice/gateway-app/src/main/webapp/bower_components/bootstrap/dist/css/bootstrap.css rename to apache-tapestry/src/main/webapp/mybootstrap/css/bootstrap.css index 6167622cec..057ff46dae 100644 --- a/jhipster/jhipster-microservice/gateway-app/src/main/webapp/bower_components/bootstrap/dist/css/bootstrap.css +++ b/apache-tapestry/src/main/webapp/mybootstrap/css/bootstrap.css @@ -1,9 +1,10 @@ /*! - * Bootstrap v3.3.7 (http://getbootstrap.com) - * Copyright 2011-2016 Twitter, Inc. + * Bootstrap v3.3.4 (http://getbootstrap.com) + * Copyright 2011-2015 Twitter, Inc. * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE) */ -/*! normalize.css v3.0.3 | MIT License | github.com/necolas/normalize.css */ + +/*! normalize.css v3.0.2 | MIT License | git.io/normalize */ html { font-family: sans-serif; -webkit-text-size-adjust: 100%; @@ -238,6 +239,9 @@ th { h3 { page-break-after: avoid; } + select { + background: #fff !important; + } .navbar { display: none; } @@ -279,10 +283,10 @@ th { -moz-osx-font-smoothing: grayscale; } .glyphicon-asterisk:before { - content: "\002a"; + content: "\2a"; } .glyphicon-plus:before { - content: "\002b"; + content: "\2b"; } .glyphicon-euro:before, .glyphicon-eur:before { @@ -1106,6 +1110,7 @@ a:focus { text-decoration: underline; } a:focus { + outline: thin dotted; outline: 5px auto -webkit-focus-ring-color; outline-offset: -2px; } @@ -1339,72 +1344,62 @@ mark, .text-primary { color: #337ab7; } -a.text-primary:hover, -a.text-primary:focus { +a.text-primary:hover { color: #286090; } .text-success { color: #3c763d; } -a.text-success:hover, -a.text-success:focus { +a.text-success:hover { color: #2b542c; } .text-info { color: #31708f; } -a.text-info:hover, -a.text-info:focus { +a.text-info:hover { color: #245269; } .text-warning { color: #8a6d3b; } -a.text-warning:hover, -a.text-warning:focus { +a.text-warning:hover { color: #66512c; } .text-danger { color: #a94442; } -a.text-danger:hover, -a.text-danger:focus { +a.text-danger:hover { color: #843534; } .bg-primary { color: #fff; background-color: #337ab7; } -a.bg-primary:hover, -a.bg-primary:focus { +a.bg-primary:hover { background-color: #286090; } .bg-success { background-color: #dff0d8; } -a.bg-success:hover, -a.bg-success:focus { +a.bg-success:hover { background-color: #c1e2b3; } .bg-info { background-color: #d9edf7; } -a.bg-info:hover, -a.bg-info:focus { +a.bg-info:hover { background-color: #afd9ee; } .bg-warning { background-color: #fcf8e3; } -a.bg-warning:hover, -a.bg-warning:focus { +a.bg-warning:hover { background-color: #f7ecb5; } .bg-danger { background-color: #f2dede; } -a.bg-danger:hover, -a.bg-danger:focus { +a.bg-danger:hover { background-color: #e4b9b9; } .page-header { @@ -2536,6 +2531,7 @@ select[size] { input[type="file"]:focus, input[type="radio"]:focus, input[type="checkbox"]:focus { + outline: thin dotted; outline: 5px auto -webkit-focus-ring-color; outline-offset: -2px; } @@ -2580,10 +2576,6 @@ output { .form-control::-webkit-input-placeholder { color: #999; } -.form-control::-ms-expand { - background-color: transparent; - border: 0; -} .form-control[disabled], .form-control[readonly], fieldset[disabled] .form-control { @@ -2601,10 +2593,10 @@ input[type="search"] { -webkit-appearance: none; } @media screen and (-webkit-min-device-pixel-ratio: 0) { - input[type="date"].form-control, - input[type="time"].form-control, - input[type="datetime-local"].form-control, - input[type="month"].form-control { + input[type="date"], + input[type="time"], + input[type="datetime-local"], + input[type="month"] { line-height: 34px; } input[type="date"].input-sm, @@ -2726,18 +2718,18 @@ select[multiple].input-sm { line-height: 1.5; border-radius: 3px; } -.form-group-sm select.form-control { +select.form-group-sm .form-control { height: 30px; line-height: 30px; } -.form-group-sm textarea.form-control, -.form-group-sm select[multiple].form-control { +textarea.form-group-sm .form-control, +select[multiple].form-group-sm .form-control { height: auto; } .form-group-sm .form-control-static { height: 30px; min-height: 32px; - padding: 6px 10px; + padding: 5px 10px; font-size: 12px; line-height: 1.5; } @@ -2763,18 +2755,18 @@ select[multiple].input-lg { line-height: 1.3333333; border-radius: 6px; } -.form-group-lg select.form-control { +select.form-group-lg .form-control { height: 46px; line-height: 46px; } -.form-group-lg textarea.form-control, -.form-group-lg select[multiple].form-control { +textarea.form-group-lg .form-control, +select[multiple].form-group-lg .form-control { height: auto; } .form-group-lg .form-control-static { height: 46px; min-height: 38px; - padding: 11px 16px; + padding: 10px 16px; font-size: 18px; line-height: 1.3333333; } @@ -2796,16 +2788,12 @@ select[multiple].input-lg { text-align: center; pointer-events: none; } -.input-lg + .form-control-feedback, -.input-group-lg + .form-control-feedback, -.form-group-lg .form-control + .form-control-feedback { +.input-lg + .form-control-feedback { width: 46px; height: 46px; line-height: 46px; } -.input-sm + .form-control-feedback, -.input-group-sm + .form-control-feedback, -.form-group-sm .form-control + .form-control-feedback { +.input-sm + .form-control-feedback { width: 30px; height: 30px; line-height: 30px; @@ -2990,14 +2978,12 @@ select[multiple].input-lg { } @media (min-width: 768px) { .form-horizontal .form-group-lg .control-label { - padding-top: 11px; - font-size: 18px; + padding-top: 14.333333px; } } @media (min-width: 768px) { .form-horizontal .form-group-sm .control-label { padding-top: 6px; - font-size: 12px; } } .btn { @@ -3027,6 +3013,7 @@ select[multiple].input-lg { .btn.focus, .btn:active.focus, .btn.active.focus { + outline: thin dotted; outline: 5px auto -webkit-focus-ring-color; outline-offset: -2px; } @@ -3046,32 +3033,21 @@ select[multiple].input-lg { .btn.disabled, .btn[disabled], fieldset[disabled] .btn { + pointer-events: none; cursor: not-allowed; filter: alpha(opacity=65); -webkit-box-shadow: none; box-shadow: none; opacity: .65; } -a.btn.disabled, -fieldset[disabled] a.btn { - pointer-events: none; -} .btn-default { color: #333; background-color: #fff; border-color: #ccc; } +.btn-default:hover, .btn-default:focus, -.btn-default.focus { - color: #333; - background-color: #e6e6e6; - border-color: #8c8c8c; -} -.btn-default:hover { - color: #333; - background-color: #e6e6e6; - border-color: #adadad; -} +.btn-default.focus, .btn-default:active, .btn-default.active, .open > .dropdown-toggle.btn-default { @@ -3079,24 +3055,14 @@ fieldset[disabled] a.btn { background-color: #e6e6e6; border-color: #adadad; } -.btn-default:active:hover, -.btn-default.active:hover, -.open > .dropdown-toggle.btn-default:hover, -.btn-default:active:focus, -.btn-default.active:focus, -.open > .dropdown-toggle.btn-default:focus, -.btn-default:active.focus, -.btn-default.active.focus, -.open > .dropdown-toggle.btn-default.focus { - color: #333; - background-color: #d4d4d4; - border-color: #8c8c8c; -} .btn-default:active, .btn-default.active, .open > .dropdown-toggle.btn-default { background-image: none; } +.btn-default.disabled, +.btn-default[disabled], +fieldset[disabled] .btn-default, .btn-default.disabled:hover, .btn-default[disabled]:hover, fieldset[disabled] .btn-default:hover, @@ -3105,7 +3071,13 @@ fieldset[disabled] .btn-default:hover, fieldset[disabled] .btn-default:focus, .btn-default.disabled.focus, .btn-default[disabled].focus, -fieldset[disabled] .btn-default.focus { +fieldset[disabled] .btn-default.focus, +.btn-default.disabled:active, +.btn-default[disabled]:active, +fieldset[disabled] .btn-default:active, +.btn-default.disabled.active, +.btn-default[disabled].active, +fieldset[disabled] .btn-default.active { background-color: #fff; border-color: #ccc; } @@ -3118,17 +3090,9 @@ fieldset[disabled] .btn-default.focus { background-color: #337ab7; border-color: #2e6da4; } +.btn-primary:hover, .btn-primary:focus, -.btn-primary.focus { - color: #fff; - background-color: #286090; - border-color: #122b40; -} -.btn-primary:hover { - color: #fff; - background-color: #286090; - border-color: #204d74; -} +.btn-primary.focus, .btn-primary:active, .btn-primary.active, .open > .dropdown-toggle.btn-primary { @@ -3136,24 +3100,14 @@ fieldset[disabled] .btn-default.focus { background-color: #286090; border-color: #204d74; } -.btn-primary:active:hover, -.btn-primary.active:hover, -.open > .dropdown-toggle.btn-primary:hover, -.btn-primary:active:focus, -.btn-primary.active:focus, -.open > .dropdown-toggle.btn-primary:focus, -.btn-primary:active.focus, -.btn-primary.active.focus, -.open > .dropdown-toggle.btn-primary.focus { - color: #fff; - background-color: #204d74; - border-color: #122b40; -} .btn-primary:active, .btn-primary.active, .open > .dropdown-toggle.btn-primary { background-image: none; } +.btn-primary.disabled, +.btn-primary[disabled], +fieldset[disabled] .btn-primary, .btn-primary.disabled:hover, .btn-primary[disabled]:hover, fieldset[disabled] .btn-primary:hover, @@ -3162,7 +3116,13 @@ fieldset[disabled] .btn-primary:hover, fieldset[disabled] .btn-primary:focus, .btn-primary.disabled.focus, .btn-primary[disabled].focus, -fieldset[disabled] .btn-primary.focus { +fieldset[disabled] .btn-primary.focus, +.btn-primary.disabled:active, +.btn-primary[disabled]:active, +fieldset[disabled] .btn-primary:active, +.btn-primary.disabled.active, +.btn-primary[disabled].active, +fieldset[disabled] .btn-primary.active { background-color: #337ab7; border-color: #2e6da4; } @@ -3175,17 +3135,9 @@ fieldset[disabled] .btn-primary.focus { background-color: #5cb85c; border-color: #4cae4c; } +.btn-success:hover, .btn-success:focus, -.btn-success.focus { - color: #fff; - background-color: #449d44; - border-color: #255625; -} -.btn-success:hover { - color: #fff; - background-color: #449d44; - border-color: #398439; -} +.btn-success.focus, .btn-success:active, .btn-success.active, .open > .dropdown-toggle.btn-success { @@ -3193,24 +3145,14 @@ fieldset[disabled] .btn-primary.focus { background-color: #449d44; border-color: #398439; } -.btn-success:active:hover, -.btn-success.active:hover, -.open > .dropdown-toggle.btn-success:hover, -.btn-success:active:focus, -.btn-success.active:focus, -.open > .dropdown-toggle.btn-success:focus, -.btn-success:active.focus, -.btn-success.active.focus, -.open > .dropdown-toggle.btn-success.focus { - color: #fff; - background-color: #398439; - border-color: #255625; -} .btn-success:active, .btn-success.active, .open > .dropdown-toggle.btn-success { background-image: none; } +.btn-success.disabled, +.btn-success[disabled], +fieldset[disabled] .btn-success, .btn-success.disabled:hover, .btn-success[disabled]:hover, fieldset[disabled] .btn-success:hover, @@ -3219,7 +3161,13 @@ fieldset[disabled] .btn-success:hover, fieldset[disabled] .btn-success:focus, .btn-success.disabled.focus, .btn-success[disabled].focus, -fieldset[disabled] .btn-success.focus { +fieldset[disabled] .btn-success.focus, +.btn-success.disabled:active, +.btn-success[disabled]:active, +fieldset[disabled] .btn-success:active, +.btn-success.disabled.active, +.btn-success[disabled].active, +fieldset[disabled] .btn-success.active { background-color: #5cb85c; border-color: #4cae4c; } @@ -3232,17 +3180,9 @@ fieldset[disabled] .btn-success.focus { background-color: #5bc0de; border-color: #46b8da; } +.btn-info:hover, .btn-info:focus, -.btn-info.focus { - color: #fff; - background-color: #31b0d5; - border-color: #1b6d85; -} -.btn-info:hover { - color: #fff; - background-color: #31b0d5; - border-color: #269abc; -} +.btn-info.focus, .btn-info:active, .btn-info.active, .open > .dropdown-toggle.btn-info { @@ -3250,24 +3190,14 @@ fieldset[disabled] .btn-success.focus { background-color: #31b0d5; border-color: #269abc; } -.btn-info:active:hover, -.btn-info.active:hover, -.open > .dropdown-toggle.btn-info:hover, -.btn-info:active:focus, -.btn-info.active:focus, -.open > .dropdown-toggle.btn-info:focus, -.btn-info:active.focus, -.btn-info.active.focus, -.open > .dropdown-toggle.btn-info.focus { - color: #fff; - background-color: #269abc; - border-color: #1b6d85; -} .btn-info:active, .btn-info.active, .open > .dropdown-toggle.btn-info { background-image: none; } +.btn-info.disabled, +.btn-info[disabled], +fieldset[disabled] .btn-info, .btn-info.disabled:hover, .btn-info[disabled]:hover, fieldset[disabled] .btn-info:hover, @@ -3276,7 +3206,13 @@ fieldset[disabled] .btn-info:hover, fieldset[disabled] .btn-info:focus, .btn-info.disabled.focus, .btn-info[disabled].focus, -fieldset[disabled] .btn-info.focus { +fieldset[disabled] .btn-info.focus, +.btn-info.disabled:active, +.btn-info[disabled]:active, +fieldset[disabled] .btn-info:active, +.btn-info.disabled.active, +.btn-info[disabled].active, +fieldset[disabled] .btn-info.active { background-color: #5bc0de; border-color: #46b8da; } @@ -3289,17 +3225,9 @@ fieldset[disabled] .btn-info.focus { background-color: #f0ad4e; border-color: #eea236; } +.btn-warning:hover, .btn-warning:focus, -.btn-warning.focus { - color: #fff; - background-color: #ec971f; - border-color: #985f0d; -} -.btn-warning:hover { - color: #fff; - background-color: #ec971f; - border-color: #d58512; -} +.btn-warning.focus, .btn-warning:active, .btn-warning.active, .open > .dropdown-toggle.btn-warning { @@ -3307,24 +3235,14 @@ fieldset[disabled] .btn-info.focus { background-color: #ec971f; border-color: #d58512; } -.btn-warning:active:hover, -.btn-warning.active:hover, -.open > .dropdown-toggle.btn-warning:hover, -.btn-warning:active:focus, -.btn-warning.active:focus, -.open > .dropdown-toggle.btn-warning:focus, -.btn-warning:active.focus, -.btn-warning.active.focus, -.open > .dropdown-toggle.btn-warning.focus { - color: #fff; - background-color: #d58512; - border-color: #985f0d; -} .btn-warning:active, .btn-warning.active, .open > .dropdown-toggle.btn-warning { background-image: none; } +.btn-warning.disabled, +.btn-warning[disabled], +fieldset[disabled] .btn-warning, .btn-warning.disabled:hover, .btn-warning[disabled]:hover, fieldset[disabled] .btn-warning:hover, @@ -3333,7 +3251,13 @@ fieldset[disabled] .btn-warning:hover, fieldset[disabled] .btn-warning:focus, .btn-warning.disabled.focus, .btn-warning[disabled].focus, -fieldset[disabled] .btn-warning.focus { +fieldset[disabled] .btn-warning.focus, +.btn-warning.disabled:active, +.btn-warning[disabled]:active, +fieldset[disabled] .btn-warning:active, +.btn-warning.disabled.active, +.btn-warning[disabled].active, +fieldset[disabled] .btn-warning.active { background-color: #f0ad4e; border-color: #eea236; } @@ -3346,17 +3270,9 @@ fieldset[disabled] .btn-warning.focus { background-color: #d9534f; border-color: #d43f3a; } +.btn-danger:hover, .btn-danger:focus, -.btn-danger.focus { - color: #fff; - background-color: #c9302c; - border-color: #761c19; -} -.btn-danger:hover { - color: #fff; - background-color: #c9302c; - border-color: #ac2925; -} +.btn-danger.focus, .btn-danger:active, .btn-danger.active, .open > .dropdown-toggle.btn-danger { @@ -3364,24 +3280,14 @@ fieldset[disabled] .btn-warning.focus { background-color: #c9302c; border-color: #ac2925; } -.btn-danger:active:hover, -.btn-danger.active:hover, -.open > .dropdown-toggle.btn-danger:hover, -.btn-danger:active:focus, -.btn-danger.active:focus, -.open > .dropdown-toggle.btn-danger:focus, -.btn-danger:active.focus, -.btn-danger.active.focus, -.open > .dropdown-toggle.btn-danger.focus { - color: #fff; - background-color: #ac2925; - border-color: #761c19; -} .btn-danger:active, .btn-danger.active, .open > .dropdown-toggle.btn-danger { background-image: none; } +.btn-danger.disabled, +.btn-danger[disabled], +fieldset[disabled] .btn-danger, .btn-danger.disabled:hover, .btn-danger[disabled]:hover, fieldset[disabled] .btn-danger:hover, @@ -3390,7 +3296,13 @@ fieldset[disabled] .btn-danger:hover, fieldset[disabled] .btn-danger:focus, .btn-danger.disabled.focus, .btn-danger[disabled].focus, -fieldset[disabled] .btn-danger.focus { +fieldset[disabled] .btn-danger.focus, +.btn-danger.disabled:active, +.btn-danger[disabled]:active, +fieldset[disabled] .btn-danger:active, +.btn-danger.disabled.active, +.btn-danger[disabled].active, +fieldset[disabled] .btn-danger.active { background-color: #d9534f; border-color: #d43f3a; } @@ -3506,7 +3418,6 @@ tbody.collapse.in { margin-left: 2px; vertical-align: middle; border-top: 4px dashed; - border-top: 4px solid \9; border-right: 4px solid transparent; border-left: 4px solid transparent; } @@ -3623,8 +3534,7 @@ tbody.collapse.in { .navbar-fixed-bottom .dropdown .caret { content: ""; border-top: 0; - border-bottom: 4px dashed; - border-bottom: 4px solid \9; + border-bottom: 4px solid; } .dropup .dropdown-menu, .navbar-fixed-bottom .dropdown .dropdown-menu { @@ -3672,7 +3582,6 @@ tbody.collapse.in { .btn-toolbar { margin-left: -5px; } -.btn-toolbar .btn, .btn-toolbar .btn-group, .btn-toolbar .input-group { float: left; @@ -3764,7 +3673,6 @@ tbody.collapse.in { border-radius: 0; } .btn-group-vertical > .btn:first-child:not(:last-child) { - border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 0; border-bottom-left-radius: 0; @@ -3772,7 +3680,6 @@ tbody.collapse.in { .btn-group-vertical > .btn:last-child:not(:first-child) { border-top-left-radius: 0; border-top-right-radius: 0; - border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; } .btn-group-vertical > .btn-group:not(:first-child):not(:last-child) > .btn { @@ -3830,9 +3737,6 @@ tbody.collapse.in { width: 100%; margin-bottom: 0; } -.input-group .form-control:focus { - z-index: 3; -} .input-group-lg > .form-control, .input-group-lg > .input-group-addon, .input-group-lg > .input-group-btn > .btn { @@ -3968,7 +3872,6 @@ select[multiple].input-group-sm > .input-group-btn > .btn { } .input-group-btn:last-child > .btn, .input-group-btn:last-child > .btn-group { - z-index: 2; margin-left: -1px; } .nav { @@ -4744,7 +4647,6 @@ fieldset[disabled] .navbar-inverse .btn-link:focus { .pagination > li > span:hover, .pagination > li > a:focus, .pagination > li > span:focus { - z-index: 2; color: #23527c; background-color: #eee; border-color: #ddd; @@ -4755,7 +4657,7 @@ fieldset[disabled] .navbar-inverse .btn-link:focus { .pagination > .active > span:hover, .pagination > .active > a:focus, .pagination > .active > span:focus { - z-index: 3; + z-index: 2; color: #fff; cursor: default; background-color: #337ab7; @@ -4776,7 +4678,6 @@ fieldset[disabled] .navbar-inverse .btn-link:focus { .pagination-lg > li > span { padding: 10px 16px; font-size: 18px; - line-height: 1.3333333; } .pagination-lg > li:first-child > a, .pagination-lg > li:first-child > span { @@ -4792,7 +4693,6 @@ fieldset[disabled] .navbar-inverse .btn-link:focus { .pagination-sm > li > span { padding: 5px 10px; font-size: 12px; - line-height: 1.5; } .pagination-sm > li:first-child > a, .pagination-sm > li:first-child > span { @@ -4919,7 +4819,7 @@ a.label:focus { color: #fff; text-align: center; white-space: nowrap; - vertical-align: middle; + vertical-align: baseline; background-color: #777; border-radius: 10px; } @@ -4956,8 +4856,7 @@ a.badge:focus { margin-left: 3px; } .jumbotron { - padding-top: 30px; - padding-bottom: 30px; + padding: 30px 15px; margin-bottom: 30px; color: inherit; background-color: #eee; @@ -4976,8 +4875,6 @@ a.badge:focus { } .container .jumbotron, .container-fluid .jumbotron { - padding-right: 15px; - padding-left: 15px; border-radius: 6px; } .jumbotron .container { @@ -4985,8 +4882,7 @@ a.badge:focus { } @media screen and (min-width: 768px) { .jumbotron { - padding-top: 48px; - padding-bottom: 48px; + padding: 48px 0; } .container .jumbotron, .container-fluid .jumbotron { @@ -5210,9 +5106,6 @@ a.thumbnail.active { .media-object { display: block; } -.media-object.img-thumbnail { - max-width: none; -} .media-right, .media > .pull-right { padding-left: 10px; @@ -5262,26 +5155,18 @@ a.thumbnail.active { border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; } -a.list-group-item, -button.list-group-item { +a.list-group-item { color: #555; } -a.list-group-item .list-group-item-heading, -button.list-group-item .list-group-item-heading { +a.list-group-item .list-group-item-heading { color: #333; } a.list-group-item:hover, -button.list-group-item:hover, -a.list-group-item:focus, -button.list-group-item:focus { +a.list-group-item:focus { color: #555; text-decoration: none; background-color: #f5f5f5; } -button.list-group-item { - width: 100%; - text-align: left; -} .list-group-item.disabled, .list-group-item.disabled:hover, .list-group-item.disabled:focus { @@ -5327,27 +5212,20 @@ button.list-group-item { color: #3c763d; background-color: #dff0d8; } -a.list-group-item-success, -button.list-group-item-success { +a.list-group-item-success { color: #3c763d; } -a.list-group-item-success .list-group-item-heading, -button.list-group-item-success .list-group-item-heading { +a.list-group-item-success .list-group-item-heading { color: inherit; } a.list-group-item-success:hover, -button.list-group-item-success:hover, -a.list-group-item-success:focus, -button.list-group-item-success:focus { +a.list-group-item-success:focus { color: #3c763d; background-color: #d0e9c6; } a.list-group-item-success.active, -button.list-group-item-success.active, a.list-group-item-success.active:hover, -button.list-group-item-success.active:hover, -a.list-group-item-success.active:focus, -button.list-group-item-success.active:focus { +a.list-group-item-success.active:focus { color: #fff; background-color: #3c763d; border-color: #3c763d; @@ -5356,27 +5234,20 @@ button.list-group-item-success.active:focus { color: #31708f; background-color: #d9edf7; } -a.list-group-item-info, -button.list-group-item-info { +a.list-group-item-info { color: #31708f; } -a.list-group-item-info .list-group-item-heading, -button.list-group-item-info .list-group-item-heading { +a.list-group-item-info .list-group-item-heading { color: inherit; } a.list-group-item-info:hover, -button.list-group-item-info:hover, -a.list-group-item-info:focus, -button.list-group-item-info:focus { +a.list-group-item-info:focus { color: #31708f; background-color: #c4e3f3; } a.list-group-item-info.active, -button.list-group-item-info.active, a.list-group-item-info.active:hover, -button.list-group-item-info.active:hover, -a.list-group-item-info.active:focus, -button.list-group-item-info.active:focus { +a.list-group-item-info.active:focus { color: #fff; background-color: #31708f; border-color: #31708f; @@ -5385,27 +5256,20 @@ button.list-group-item-info.active:focus { color: #8a6d3b; background-color: #fcf8e3; } -a.list-group-item-warning, -button.list-group-item-warning { +a.list-group-item-warning { color: #8a6d3b; } -a.list-group-item-warning .list-group-item-heading, -button.list-group-item-warning .list-group-item-heading { +a.list-group-item-warning .list-group-item-heading { color: inherit; } a.list-group-item-warning:hover, -button.list-group-item-warning:hover, -a.list-group-item-warning:focus, -button.list-group-item-warning:focus { +a.list-group-item-warning:focus { color: #8a6d3b; background-color: #faf2cc; } a.list-group-item-warning.active, -button.list-group-item-warning.active, a.list-group-item-warning.active:hover, -button.list-group-item-warning.active:hover, -a.list-group-item-warning.active:focus, -button.list-group-item-warning.active:focus { +a.list-group-item-warning.active:focus { color: #fff; background-color: #8a6d3b; border-color: #8a6d3b; @@ -5414,27 +5278,20 @@ button.list-group-item-warning.active:focus { color: #a94442; background-color: #f2dede; } -a.list-group-item-danger, -button.list-group-item-danger { +a.list-group-item-danger { color: #a94442; } -a.list-group-item-danger .list-group-item-heading, -button.list-group-item-danger .list-group-item-heading { +a.list-group-item-danger .list-group-item-heading { color: inherit; } a.list-group-item-danger:hover, -button.list-group-item-danger:hover, -a.list-group-item-danger:focus, -button.list-group-item-danger:focus { +a.list-group-item-danger:focus { color: #a94442; background-color: #ebcccc; } a.list-group-item-danger.active, -button.list-group-item-danger.active, a.list-group-item-danger.active:hover, -button.list-group-item-danger.active:hover, -a.list-group-item-danger.active:focus, -button.list-group-item-danger.active:focus { +a.list-group-item-danger.active:focus { color: #fff; background-color: #a94442; border-color: #a94442; @@ -5508,10 +5365,6 @@ button.list-group-item-danger.active:focus { border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; } -.panel > .panel-heading + .panel-collapse > .list-group .list-group-item:first-child { - border-top-left-radius: 0; - border-top-right-radius: 0; -} .panel-heading + .list-group .list-group-item:first-child { border-top-width: 0; } @@ -5932,6 +5785,7 @@ button.close { opacity: .5; } .modal-header { + min-height: 16.42857143px; padding: 15px; border-bottom: 1px solid #e5e5e5; } @@ -5992,23 +5846,10 @@ button.close { display: block; font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; font-size: 12px; - font-style: normal; font-weight: normal; - line-height: 1.42857143; - text-align: left; - text-align: start; - text-decoration: none; - text-shadow: none; - text-transform: none; - letter-spacing: normal; - word-break: normal; - word-spacing: normal; - word-wrap: normal; - white-space: normal; + line-height: 1.4; filter: alpha(opacity=0); opacity: 0; - - line-break: auto; } .tooltip.in { filter: alpha(opacity=90); @@ -6035,6 +5876,7 @@ button.close { padding: 3px 8px; color: #fff; text-align: center; + text-decoration: none; background-color: #000; border-radius: 4px; } @@ -6111,18 +5953,9 @@ button.close { padding: 1px; font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; font-size: 14px; - font-style: normal; font-weight: normal; line-height: 1.42857143; text-align: left; - text-align: start; - text-decoration: none; - text-shadow: none; - text-transform: none; - letter-spacing: normal; - word-break: normal; - word-spacing: normal; - word-wrap: normal; white-space: normal; background-color: #fff; -webkit-background-clip: padding-box; @@ -6132,8 +5965,6 @@ button.close { border-radius: 6px; -webkit-box-shadow: 0 5px 10px rgba(0, 0, 0, .2); box-shadow: 0 5px 10px rgba(0, 0, 0, .2); - - line-break: auto; } .popover.top { margin-top: -10px; @@ -6261,8 +6092,8 @@ button.close { -webkit-backface-visibility: hidden; backface-visibility: hidden; - -webkit-perspective: 1000px; - perspective: 1000px; + -webkit-perspective: 1000; + perspective: 1000; } .carousel-inner > .item.next, .carousel-inner > .item.active.right { @@ -6324,7 +6155,6 @@ button.close { color: #fff; text-align: center; text-shadow: 0 1px 2px rgba(0, 0, 0, .6); - background-color: rgba(0, 0, 0, 0); filter: alpha(opacity=50); opacity: .5; } @@ -6362,7 +6192,6 @@ button.close { top: 50%; z-index: 5; display: inline-block; - margin-top: -10px; } .carousel-control .icon-prev, .carousel-control .glyphicon-chevron-left { @@ -6378,6 +6207,7 @@ button.close { .carousel-control .icon-next { width: 20px; height: 20px; + margin-top: -10px; font-family: serif; line-height: 1; } @@ -6438,16 +6268,16 @@ button.close { .carousel-control .icon-next { width: 30px; height: 30px; - margin-top: -10px; + margin-top: -15px; font-size: 30px; } .carousel-control .glyphicon-chevron-left, .carousel-control .icon-prev { - margin-left: -10px; + margin-left: -15px; } .carousel-control .glyphicon-chevron-right, .carousel-control .icon-next { - margin-right: -10px; + margin-right: -15px; } .carousel-caption { right: 20%; @@ -6486,8 +6316,6 @@ button.close { .pager:after, .panel-body:before, .panel-body:after, -.modal-header:before, -.modal-header:after, .modal-footer:before, .modal-footer:after { display: table; @@ -6507,7 +6335,6 @@ button.close { .navbar-collapse:after, .pager:after, .panel-body:after, -.modal-header:after, .modal-footer:after { clear: both; } @@ -6572,7 +6399,7 @@ button.close { display: block !important; } table.visible-xs { - display: table !important; + display: table; } tr.visible-xs { display: table-row !important; @@ -6602,7 +6429,7 @@ button.close { display: block !important; } table.visible-sm { - display: table !important; + display: table; } tr.visible-sm { display: table-row !important; @@ -6632,7 +6459,7 @@ button.close { display: block !important; } table.visible-md { - display: table !important; + display: table; } tr.visible-md { display: table-row !important; @@ -6662,7 +6489,7 @@ button.close { display: block !important; } table.visible-lg { - display: table !important; + display: table; } tr.visible-lg { display: table-row !important; @@ -6715,7 +6542,7 @@ button.close { display: block !important; } table.visible-print { - display: table !important; + display: table; } tr.visible-print { display: table-row !important; @@ -6754,4 +6581,8 @@ button.close { display: none !important; } } -/*# sourceMappingURL=bootstrap.css.map */ + +/* tapestry-quickstart customizations start here: */ + +body { padding-top: 70px; } + diff --git a/apache-tapestry/src/main/webapp/mybootstrap/fonts/glyphicons-halflings-regular.eot b/apache-tapestry/src/main/webapp/mybootstrap/fonts/glyphicons-halflings-regular.eot new file mode 100644 index 0000000000..9879fec538 Binary files /dev/null and b/apache-tapestry/src/main/webapp/mybootstrap/fonts/glyphicons-halflings-regular.eot differ diff --git a/jhipster/jhipster-microservice/gateway-app/src/main/webapp/bower_components/bootstrap/dist/fonts/glyphicons-halflings-regular.svg b/apache-tapestry/src/main/webapp/mybootstrap/fonts/glyphicons-halflings-regular.svg similarity index 100% rename from jhipster/jhipster-microservice/gateway-app/src/main/webapp/bower_components/bootstrap/dist/fonts/glyphicons-halflings-regular.svg rename to apache-tapestry/src/main/webapp/mybootstrap/fonts/glyphicons-halflings-regular.svg diff --git a/apache-tapestry/src/main/webapp/mybootstrap/fonts/glyphicons-halflings-regular.ttf b/apache-tapestry/src/main/webapp/mybootstrap/fonts/glyphicons-halflings-regular.ttf new file mode 100644 index 0000000000..c0e841e44b Binary files /dev/null and b/apache-tapestry/src/main/webapp/mybootstrap/fonts/glyphicons-halflings-regular.ttf differ diff --git a/apache-tapestry/src/main/webapp/mybootstrap/fonts/glyphicons-halflings-regular.woff b/apache-tapestry/src/main/webapp/mybootstrap/fonts/glyphicons-halflings-regular.woff new file mode 100644 index 0000000000..59d837ee61 Binary files /dev/null and b/apache-tapestry/src/main/webapp/mybootstrap/fonts/glyphicons-halflings-regular.woff differ diff --git a/apache-tapestry/src/main/webapp/mybootstrap/fonts/glyphicons-halflings-regular.woff2 b/apache-tapestry/src/main/webapp/mybootstrap/fonts/glyphicons-halflings-regular.woff2 new file mode 100644 index 0000000000..006d10650b Binary files /dev/null and b/apache-tapestry/src/main/webapp/mybootstrap/fonts/glyphicons-halflings-regular.woff2 differ diff --git a/jhipster/jhipster-microservice/gateway-app/src/main/webapp/bower_components/bootstrap/js/affix.js b/apache-tapestry/src/main/webapp/mybootstrap/js/affix.js similarity index 96% rename from jhipster/jhipster-microservice/gateway-app/src/main/webapp/bower_components/bootstrap/js/affix.js rename to apache-tapestry/src/main/webapp/mybootstrap/js/affix.js index 7f6516818a..98197642aa 100644 --- a/jhipster/jhipster-microservice/gateway-app/src/main/webapp/bower_components/bootstrap/js/affix.js +++ b/apache-tapestry/src/main/webapp/mybootstrap/js/affix.js @@ -1,8 +1,8 @@ /* ======================================================================== - * Bootstrap: affix.js v3.3.7 + * Bootstrap: affix.js v3.3.4 * http://getbootstrap.com/javascript/#affix * ======================================================================== - * Copyright 2011-2016 Twitter, Inc. + * Copyright 2011-2015 Twitter, Inc. * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE) * ======================================================================== */ @@ -28,7 +28,7 @@ this.checkPosition() } - Affix.VERSION = '3.3.7' + Affix.VERSION = '3.3.4' Affix.RESET = 'affix affix-top affix-bottom' @@ -78,7 +78,7 @@ var offset = this.options.offset var offsetTop = offset.top var offsetBottom = offset.bottom - var scrollHeight = Math.max($(document).height(), $(document.body).height()) + var scrollHeight = $(document.body).height() if (typeof offset != 'object') offsetBottom = offsetTop = offset if (typeof offsetTop == 'function') offsetTop = offset.top(this.$element) diff --git a/jhipster/jhipster-microservice/gateway-app/src/main/webapp/bower_components/bootstrap/js/alert.js b/apache-tapestry/src/main/webapp/mybootstrap/js/alert.js similarity index 93% rename from jhipster/jhipster-microservice/gateway-app/src/main/webapp/bower_components/bootstrap/js/alert.js rename to apache-tapestry/src/main/webapp/mybootstrap/js/alert.js index db97f3b02b..1925ef011c 100644 --- a/jhipster/jhipster-microservice/gateway-app/src/main/webapp/bower_components/bootstrap/js/alert.js +++ b/apache-tapestry/src/main/webapp/mybootstrap/js/alert.js @@ -1,8 +1,8 @@ /* ======================================================================== - * Bootstrap: alert.js v3.3.7 + * Bootstrap: alert.js v3.3.4 * http://getbootstrap.com/javascript/#alerts * ======================================================================== - * Copyright 2011-2016 Twitter, Inc. + * Copyright 2011-2015 Twitter, Inc. * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE) * ======================================================================== */ @@ -18,7 +18,7 @@ $(el).on('click', dismiss, this.close) } - Alert.VERSION = '3.3.7' + Alert.VERSION = '3.3.4' Alert.TRANSITION_DURATION = 150 @@ -31,7 +31,7 @@ selector = selector && selector.replace(/.*(?=#[^\s]*$)/, '') // strip for ie7 } - var $parent = $(selector === '#' ? [] : selector) + var $parent = $(selector) if (e) e.preventDefault() diff --git a/jhipster/jhipster-microservice/gateway-app/src/main/webapp/bower_components/bootstrap/js/button.js b/apache-tapestry/src/main/webapp/mybootstrap/js/button.js similarity index 69% rename from jhipster/jhipster-microservice/gateway-app/src/main/webapp/bower_components/bootstrap/js/button.js rename to apache-tapestry/src/main/webapp/mybootstrap/js/button.js index 843b39c9d2..7c7c021f95 100644 --- a/jhipster/jhipster-microservice/gateway-app/src/main/webapp/bower_components/bootstrap/js/button.js +++ b/apache-tapestry/src/main/webapp/mybootstrap/js/button.js @@ -1,8 +1,8 @@ /* ======================================================================== - * Bootstrap: button.js v3.3.7 + * Bootstrap: button.js v3.3.4 * http://getbootstrap.com/javascript/#buttons * ======================================================================== - * Copyright 2011-2016 Twitter, Inc. + * Copyright 2011-2015 Twitter, Inc. * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE) * ======================================================================== */ @@ -19,7 +19,7 @@ this.isLoading = false } - Button.VERSION = '3.3.7' + Button.VERSION = '3.3.4' Button.DEFAULTS = { loadingText: 'loading...' @@ -31,7 +31,7 @@ var val = $el.is('input') ? 'val' : 'html' var data = $el.data() - state += 'Text' + state = state + 'Text' if (data.resetText == null) $el.data('resetText', $el[val]()) @@ -41,10 +41,10 @@ if (state == 'loadingText') { this.isLoading = true - $el.addClass(d).attr(d, d).prop(d, true) + $el.addClass(d).attr(d, d) } else if (this.isLoading) { this.isLoading = false - $el.removeClass(d).removeAttr(d).prop(d, false) + $el.removeClass(d).removeAttr(d) } }, this), 0) } @@ -56,19 +56,15 @@ if ($parent.length) { var $input = this.$element.find('input') if ($input.prop('type') == 'radio') { - if ($input.prop('checked')) changed = false - $parent.find('.active').removeClass('active') - this.$element.addClass('active') - } else if ($input.prop('type') == 'checkbox') { - if (($input.prop('checked')) !== this.$element.hasClass('active')) changed = false - this.$element.toggleClass('active') + if ($input.prop('checked') && this.$element.hasClass('active')) changed = false + else $parent.find('.active').removeClass('active') } - $input.prop('checked', this.$element.hasClass('active')) - if (changed) $input.trigger('change') + if (changed) $input.prop('checked', !this.$element.hasClass('active')).trigger('change') } else { this.$element.attr('aria-pressed', !this.$element.hasClass('active')) - this.$element.toggleClass('active') } + + if (changed) this.$element.toggleClass('active') } @@ -108,15 +104,10 @@ $(document) .on('click.bs.button.data-api', '[data-toggle^="button"]', function (e) { - var $btn = $(e.target).closest('.btn') + var $btn = $(e.target) + if (!$btn.hasClass('btn')) $btn = $btn.closest('.btn') Plugin.call($btn, 'toggle') - if (!($(e.target).is('input[type="radio"], input[type="checkbox"]'))) { - // Prevent double click on radios, and the double selections (so cancellation) on checkboxes - e.preventDefault() - // The target component still receive the focus - if ($btn.is('input,button')) $btn.trigger('focus') - else $btn.find('input:visible,button:visible').first().trigger('focus') - } + e.preventDefault() }) .on('focus.bs.button.data-api blur.bs.button.data-api', '[data-toggle^="button"]', function (e) { $(e.target).closest('.btn').toggleClass('focus', /^focus(in)?$/.test(e.type)) diff --git a/jhipster/jhipster-microservice/gateway-app/src/main/webapp/bower_components/bootstrap/js/carousel.js b/apache-tapestry/src/main/webapp/mybootstrap/js/carousel.js similarity index 98% rename from jhipster/jhipster-microservice/gateway-app/src/main/webapp/bower_components/bootstrap/js/carousel.js rename to apache-tapestry/src/main/webapp/mybootstrap/js/carousel.js index 6ff954c9bd..a38ef14d0b 100644 --- a/jhipster/jhipster-microservice/gateway-app/src/main/webapp/bower_components/bootstrap/js/carousel.js +++ b/apache-tapestry/src/main/webapp/mybootstrap/js/carousel.js @@ -1,8 +1,8 @@ /* ======================================================================== - * Bootstrap: carousel.js v3.3.7 + * Bootstrap: carousel.js v3.3.4 * http://getbootstrap.com/javascript/#carousel * ======================================================================== - * Copyright 2011-2016 Twitter, Inc. + * Copyright 2011-2015 Twitter, Inc. * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE) * ======================================================================== */ @@ -30,7 +30,7 @@ .on('mouseleave.bs.carousel', $.proxy(this.cycle, this)) } - Carousel.VERSION = '3.3.7' + Carousel.VERSION = '3.3.4' Carousel.TRANSITION_DURATION = 600 diff --git a/jhipster/jhipster-microservice/gateway-app/src/main/webapp/bower_components/bootstrap/js/collapse.js b/apache-tapestry/src/main/webapp/mybootstrap/js/collapse.js similarity index 97% rename from jhipster/jhipster-microservice/gateway-app/src/main/webapp/bower_components/bootstrap/js/collapse.js rename to apache-tapestry/src/main/webapp/mybootstrap/js/collapse.js index 12038693d9..954513c5e1 100644 --- a/jhipster/jhipster-microservice/gateway-app/src/main/webapp/bower_components/bootstrap/js/collapse.js +++ b/apache-tapestry/src/main/webapp/mybootstrap/js/collapse.js @@ -1,12 +1,11 @@ /* ======================================================================== - * Bootstrap: collapse.js v3.3.7 + * Bootstrap: collapse.js v3.3.4 * http://getbootstrap.com/javascript/#collapse * ======================================================================== - * Copyright 2011-2016 Twitter, Inc. + * Copyright 2011-2015 Twitter, Inc. * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE) * ======================================================================== */ -/* jshint latedef: false */ +function ($) { 'use strict'; @@ -30,7 +29,7 @@ if (this.options.toggle) this.toggle() } - Collapse.VERSION = '3.3.7' + Collapse.VERSION = '3.3.4' Collapse.TRANSITION_DURATION = 350 diff --git a/jhipster/jhipster-microservice/gateway-app/src/main/webapp/bower_components/bootstrap/js/dropdown.js b/apache-tapestry/src/main/webapp/mybootstrap/js/dropdown.js similarity index 82% rename from jhipster/jhipster-microservice/gateway-app/src/main/webapp/bower_components/bootstrap/js/dropdown.js rename to apache-tapestry/src/main/webapp/mybootstrap/js/dropdown.js index 04e9c2de47..9874600f9d 100644 --- a/jhipster/jhipster-microservice/gateway-app/src/main/webapp/bower_components/bootstrap/js/dropdown.js +++ b/apache-tapestry/src/main/webapp/mybootstrap/js/dropdown.js @@ -1,8 +1,8 @@ /* ======================================================================== - * Bootstrap: dropdown.js v3.3.7 + * Bootstrap: dropdown.js v3.3.4 * http://getbootstrap.com/javascript/#dropdowns * ======================================================================== - * Copyright 2011-2016 Twitter, Inc. + * Copyright 2011-2015 Twitter, Inc. * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE) * ======================================================================== */ @@ -19,41 +19,7 @@ $(element).on('click.bs.dropdown', this.toggle) } - Dropdown.VERSION = '3.3.7' - - function getParent($this) { - var selector = $this.attr('data-target') - - if (!selector) { - selector = $this.attr('href') - selector = selector && /#[A-Za-z]/.test(selector) && selector.replace(/.*(?=#[^\s]*$)/, '') // strip for ie7 - } - - var $parent = selector && $(selector) - - return $parent && $parent.length ? $parent : $this.parent() - } - - function clearMenus(e) { - if (e && e.which === 3) return - $(backdrop).remove() - $(toggle).each(function () { - var $this = $(this) - var $parent = getParent($this) - var relatedTarget = { relatedTarget: this } - - if (!$parent.hasClass('open')) return - - if (e && e.type == 'click' && /input|textarea/i.test(e.target.tagName) && $.contains($parent[0], e.target)) return - - $parent.trigger(e = $.Event('hide.bs.dropdown', relatedTarget)) - - if (e.isDefaultPrevented()) return - - $this.attr('aria-expanded', 'false') - $parent.removeClass('open').trigger($.Event('hidden.bs.dropdown', relatedTarget)) - }) - } + Dropdown.VERSION = '3.3.4' Dropdown.prototype.toggle = function (e) { var $this = $(this) @@ -68,10 +34,7 @@ if (!isActive) { if ('ontouchstart' in document.documentElement && !$parent.closest('.navbar-nav').length) { // if mobile we use a backdrop because click events don't delegate - $(document.createElement('div')) - .addClass('dropdown-backdrop') - .insertAfter($(this)) - .on('click', clearMenus) + $('