Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,20 @@

public class BubbleSort {

public void bubbleSort(Integer[] arr) {
void bubbleSort(Integer[] arr) {
int n = arr.length;
IntStream.range(0, n - 1)
.forEach(i -> {
IntStream.range(i + 1, n - i)
.forEach(j -> {
if (arr[j - 1] > arr[j]) {
int temp = arr[j];
arr[j] = arr[j - 1];
arr[j - 1] = temp;
}
});
});
.flatMap(i -> IntStream.range(i + 1, n - i))
.forEach(j -> {
if (arr[j - 1] > arr[j]) {
int temp = arr[j];
arr[j] = arr[j - 1];
arr[j - 1] = temp;
}
});
}

public void optimizedBubbleSort(Integer[] arr) {
void optimizedBubbleSort(Integer[] arr) {
int i = 0, n = arr.length;
boolean swapNeeded = true;
while (i < n - 1 && swapNeeded) {
Expand All @@ -37,5 +35,4 @@ public void optimizedBubbleSort(Integer[] arr) {
i++;
}
}

}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.baelding.rxjava;
package com.baeldung.rxjava;

import rx.Observable;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.baelding.rxjava;
package com.baeldung.rxjava;

import rx.Observable;
import rx.observables.ConnectableObservable;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.baelding.rxjava;
package com.baeldung.rxjava;

import rx.Observable;
import rx.observables.BlockingObservable;
Expand All @@ -8,13 +8,13 @@

public class ObservableImpl {

static Integer[] numbers = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
private static Integer[] numbers = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};

static String[] letters = {"a", "b", "c", "d", "e", "f", "g", "h", "i"};
static String[] titles = {"title"};
public static List<String> titleList = Arrays.asList(titles);
private static String[] letters = {"a", "b", "c", "d", "e", "f", "g", "h", "i"};
private static String[] titles = {"title"};
private static List<String> titleList = Arrays.asList(titles);

public static Observable<String> getTitle() {
static Observable<String> getTitle() {
return Observable.from(titleList);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.baelding.rxjava;
package com.baeldung.rxjava;

import rx.Observable;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.baelding.rxjava;
package com.baeldung.rxjava;

import rx.Observable;
import rx.Single;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package com.baelding.rxjava;
package com.baeldung.rxjava;

import rx.Observer;
import rx.subjects.PublishSubject;

public class SubjectImpl {

public static Integer subscriber1 = 0;
public static Integer subscriber2 = 0;
static Integer subscriber1 = 0;
static Integer subscriber2 = 0;

public static Integer subjectMethod() {
private static Integer subjectMethod() {
PublishSubject<Integer> subject = PublishSubject.create();

subject.subscribe(getFirstObserver());
Expand All @@ -25,7 +25,7 @@ public static Integer subjectMethod() {
}


public static Observer<Integer> getFirstObserver() {
static Observer<Integer> getFirstObserver() {
return new Observer<Integer>() {

@Override
Expand All @@ -46,7 +46,7 @@ public void onCompleted() {
};
}

public static Observer<Integer> getSecondObserver() {
static Observer<Integer> getSecondObserver() {
return new Observer<Integer>() {

@Override
Expand Down
6 changes: 3 additions & 3 deletions rxjava/src/main/java/com/baeldung/rxjava/jdbc/Connector.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@

class Connector {

static final String DB_CONNECTION = "jdbc:h2:mem:test;DB_CLOSE_DELAY=-1";
static final String DB_USER = "";
static final String DB_PASSWORD = "";
private static final String DB_CONNECTION = "jdbc:h2:mem:test;DB_CLOSE_DELAY=-1";
private static final String DB_USER = "";
private static final String DB_PASSWORD = "";

static final ConnectionProvider connectionProvider = new ConnectionProviderFromUrl(DB_CONNECTION, DB_USER, DB_PASSWORD);
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.baelding.rxjava.operator;
package com.baeldung.rxjava.operator;

import rx.Observable.Operator;
import rx.Subscriber;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.baelding.rxjava.operator;
package com.baeldung.rxjava.operator;

import rx.Observable;
import rx.Observable.Transformer;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import org.junit.Test;
import rx.Observable;

import static com.baelding.rxjava.ObservableImpl.getTitle;
import static com.baeldung.rxjava.ObservableImpl.getTitle;
import static junit.framework.Assert.assertTrue;

public class ObservableTest {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
import java.util.Arrays;
import java.util.List;

import static com.baelding.rxjava.operator.ToCleanString.toCleanString;
import static com.baelding.rxjava.operator.ToLength.toLength;
import static com.baeldung.rxjava.operator.ToCleanString.toCleanString;
import static com.baeldung.rxjava.operator.ToLength.toLength;
import static org.hamcrest.Matchers.hasItems;
import static org.hamcrest.Matchers.hasSize;
import static org.hamcrest.Matchers.notNullValue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;

public class SchedulersTest {
public class SchedulersLiveTest {
private String result = "";
private String result1 = "";
private String result2 = "";
Expand Down
1 change: 0 additions & 1 deletion rxjava/src/test/java/com/baeldung/rxjava/SubjectTest.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.baeldung.rxjava;

import com.baelding.rxjava.SubjectImpl;
import org.junit.Test;
import rx.subjects.PublishSubject;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,25 @@ public class BasicQueryTypesIntegrationTest {
private ConnectionProvider connectionProvider = Connector.connectionProvider;
private Database db = Database.from(connectionProvider);

private Observable<Integer> create, insert1, insert2, insert3, update, delete = null;
private Observable<Integer> create;

@Test
public void whenCreateTableAndInsertRecords_thenCorrect() {
create = db.update("CREATE TABLE IF NOT EXISTS EMPLOYEE(id int primary key, name varchar(255))")
.count();
insert1 = db.update("INSERT INTO EMPLOYEE(id, name) VALUES(1, 'John')")
Observable<Integer> insert1 = db.update("INSERT INTO EMPLOYEE(id, name) VALUES(1, 'John')")
.dependsOn(create)
.count();
update = db.update("UPDATE EMPLOYEE SET name = 'Alan' WHERE id = 1")
Observable<Integer> update = db.update("UPDATE EMPLOYEE SET name = 'Alan' WHERE id = 1")
.dependsOn(create)
.count();
insert2 = db.update("INSERT INTO EMPLOYEE(id, name) VALUES(2, 'Sarah')")
Observable<Integer> insert2 = db.update("INSERT INTO EMPLOYEE(id, name) VALUES(2, 'Sarah')")
.dependsOn(create)
.count();
insert3 = db.update("INSERT INTO EMPLOYEE(id, name) VALUES(3, 'Mike')")
Observable<Integer> insert3 = db.update("INSERT INTO EMPLOYEE(id, name) VALUES(3, 'Mike')")
.dependsOn(create)
.count();
delete = db.update("DELETE FROM EMPLOYEE WHERE id = 2")
Observable<Integer> delete = db.update("DELETE FROM EMPLOYEE WHERE id = 2")
.dependsOn(create)
.count();
List<String> names = db.select("select name from EMPLOYEE where id < ?")
Expand Down