BAEL-3481 - Fixed Formatting.
This commit is contained in:
@@ -19,15 +19,11 @@ public class BalancedBracketsUsingDeque {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Deque<Character> deque = new LinkedList<>();
|
Deque<Character> deque = new LinkedList<>();
|
||||||
for (char ch: str.toCharArray()) {
|
for (char ch : str.toCharArray()) {
|
||||||
if (ch == '{' || ch == '[' || ch == '(') {
|
if (ch == '{' || ch == '[' || ch == '(') {
|
||||||
deque.addFirst(ch);
|
deque.addFirst(ch);
|
||||||
} else {
|
} else {
|
||||||
if ( !deque.isEmpty()
|
if (!deque.isEmpty() && ((deque.peekFirst() == '{' && ch == '}') || (deque.peekFirst() == '[' && ch == ']') || (deque.peekFirst() == '(' && ch == ')'))) {
|
||||||
&& ((deque.peekFirst() == '{' && ch == '}')
|
|
||||||
|| (deque.peekFirst() == '[' && ch == ']')
|
|
||||||
|| (deque.peekFirst() == '(' && ch == ')')
|
|
||||||
)) {
|
|
||||||
deque.removeFirst();
|
deque.removeFirst();
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -7,8 +7,8 @@ public class BalancedBracketsUsingString {
|
|||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
char[] ch = str.toCharArray();
|
char[] ch = str.toCharArray();
|
||||||
for(char c : ch) {
|
for (char c : ch) {
|
||||||
if(!(c == '{' || c == '[' || c == '(' || c == '}' || c == ']' || c == ')')) {
|
if (!(c == '{' || c == '[' || c == '(' || c == '}' || c == ']' || c == ')')) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -13,7 +13,6 @@ public class BalancedBracketsUsingDequeUnitTest {
|
|||||||
balancedBracketsUsingDeque = new BalancedBracketsUsingDeque();
|
balancedBracketsUsingDeque = new BalancedBracketsUsingDeque();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenNullInput_whenCheckingForBalance_shouldReturnFalse() {
|
public void givenNullInput_whenCheckingForBalance_shouldReturnFalse() {
|
||||||
boolean result = balancedBracketsUsingDeque.isBalanced(null);
|
boolean result = balancedBracketsUsingDeque.isBalanced(null);
|
||||||
@@ -50,7 +49,6 @@ public class BalancedBracketsUsingDequeUnitTest {
|
|||||||
assertThat(result).isFalse();
|
assertThat(result).isFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenEvenLengthBalancedString_whenCheckingForBalance_shouldReturnTrue() {
|
public void givenEvenLengthBalancedString_whenCheckingForBalance_shouldReturnTrue() {
|
||||||
boolean result = balancedBracketsUsingDeque.isBalanced("{[()]}");
|
boolean result = balancedBracketsUsingDeque.isBalanced("{[()]}");
|
||||||
@@ -63,14 +61,12 @@ public class BalancedBracketsUsingDequeUnitTest {
|
|||||||
assertThat(result).isTrue();
|
assertThat(result).isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenAnotherBalancedString_whenCheckingForBalance_shouldReturnTrue() {
|
public void givenAnotherBalancedString_whenCheckingForBalance_shouldReturnTrue() {
|
||||||
boolean result = balancedBracketsUsingDeque.isBalanced("{{([])}}");
|
boolean result = balancedBracketsUsingDeque.isBalanced("{{([])}}");
|
||||||
assertThat(result).isTrue();
|
assertThat(result).isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenUnBalancedString_whenCheckingForBalance_shouldReturnFalse() {
|
public void givenUnBalancedString_whenCheckingForBalance_shouldReturnFalse() {
|
||||||
boolean result = balancedBracketsUsingDeque.isBalanced("{{)[](}}");
|
boolean result = balancedBracketsUsingDeque.isBalanced("{{)[](}}");
|
||||||
|
|||||||
@@ -13,7 +13,6 @@ public class BalancedBracketsUsingStringUnitTest {
|
|||||||
balancedBracketsUsingString = new BalancedBracketsUsingString();
|
balancedBracketsUsingString = new BalancedBracketsUsingString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenNullInput_whenCheckingForBalance_shouldReturnFalse() {
|
public void givenNullInput_whenCheckingForBalance_shouldReturnFalse() {
|
||||||
boolean result = balancedBracketsUsingString.isBalanced(null);
|
boolean result = balancedBracketsUsingString.isBalanced(null);
|
||||||
@@ -50,7 +49,6 @@ public class BalancedBracketsUsingStringUnitTest {
|
|||||||
assertThat(result).isFalse();
|
assertThat(result).isFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenEvenLengthBalancedString_whenCheckingForBalance_shouldReturnTrue() {
|
public void givenEvenLengthBalancedString_whenCheckingForBalance_shouldReturnTrue() {
|
||||||
boolean result = balancedBracketsUsingString.isBalanced("{[()]}");
|
boolean result = balancedBracketsUsingString.isBalanced("{[()]}");
|
||||||
@@ -63,14 +61,12 @@ public class BalancedBracketsUsingStringUnitTest {
|
|||||||
assertThat(result).isTrue();
|
assertThat(result).isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenAnotherBalancedString_whenCheckingForBalance_shouldReturnTrue() {
|
public void givenAnotherBalancedString_whenCheckingForBalance_shouldReturnTrue() {
|
||||||
boolean result = balancedBracketsUsingString.isBalanced("{{([])}}");
|
boolean result = balancedBracketsUsingString.isBalanced("{{([])}}");
|
||||||
assertThat(result).isTrue();
|
assertThat(result).isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenUnBalancedString_whenCheckingForBalance_shouldReturnFalse() {
|
public void givenUnBalancedString_whenCheckingForBalance_shouldReturnFalse() {
|
||||||
boolean result = balancedBracketsUsingString.isBalanced("{{)[](}}");
|
boolean result = balancedBracketsUsingString.isBalanced("{{)[](}}");
|
||||||
|
|||||||
Reference in New Issue
Block a user