parent
e5400faad8
commit
f753a86e84
|
@ -4,22 +4,20 @@ import java.util.stream.IntStream;
|
|||
|
||||
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) {
|
||||
|
@ -37,5 +35,4 @@ public class BubbleSort {
|
|||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package com.baelding.rxjava;
|
||||
package com.baeldung.rxjava;
|
||||
|
||||
import rx.Observable;
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package com.baelding.rxjava;
|
||||
package com.baeldung.rxjava;
|
||||
|
||||
import rx.Observable;
|
||||
import rx.observables.ConnectableObservable;
|
|
@ -1,4 +1,4 @@
|
|||
package com.baelding.rxjava;
|
||||
package com.baeldung.rxjava;
|
||||
|
||||
import rx.Observable;
|
||||
import rx.observables.BlockingObservable;
|
||||
|
@ -8,13 +8,13 @@ import java.util.List;
|
|||
|
||||
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);
|
||||
}
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package com.baelding.rxjava;
|
||||
package com.baeldung.rxjava;
|
||||
|
||||
import rx.Observable;
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package com.baelding.rxjava;
|
||||
package com.baeldung.rxjava;
|
||||
|
||||
import rx.Observable;
|
||||
import rx.Single;
|
|
@ -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());
|
||||
|
@ -25,7 +25,7 @@ public class SubjectImpl {
|
|||
}
|
||||
|
||||
|
||||
public static Observer<Integer> getFirstObserver() {
|
||||
static Observer<Integer> getFirstObserver() {
|
||||
return new Observer<Integer>() {
|
||||
|
||||
@Override
|
||||
|
@ -46,7 +46,7 @@ public class SubjectImpl {
|
|||
};
|
||||
}
|
||||
|
||||
public static Observer<Integer> getSecondObserver() {
|
||||
static Observer<Integer> getSecondObserver() {
|
||||
return new Observer<Integer>() {
|
||||
|
||||
@Override
|
|
@ -5,9 +5,9 @@ import com.github.davidmoten.rx.jdbc.ConnectionProviderFromUrl;
|
|||
|
||||
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);
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package com.baelding.rxjava.operator;
|
||||
package com.baeldung.rxjava.operator;
|
||||
|
||||
import rx.Observable.Operator;
|
||||
import rx.Subscriber;
|
|
@ -1,4 +1,4 @@
|
|||
package com.baelding.rxjava.operator;
|
||||
package com.baeldung.rxjava.operator;
|
||||
|
||||
import rx.Observable;
|
||||
import rx.Observable.Transformer;
|
|
@ -3,7 +3,7 @@ package com.baeldung.rxjava;
|
|||
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 {
|
||||
|
|
|
@ -10,8 +10,8 @@ import java.util.ArrayList;
|
|||
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;
|
||||
|
|
|
@ -21,7 +21,7 @@ import static org.hamcrest.Matchers.hasItems;
|
|||
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 = "";
|
|
@ -1,6 +1,5 @@
|
|||
package com.baeldung.rxjava;
|
||||
|
||||
import com.baelding.rxjava.SubjectImpl;
|
||||
import org.junit.Test;
|
||||
import rx.subjects.PublishSubject;
|
||||
|
||||
|
|
|
@ -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 < ?")
|
||||
|
|
Loading…
Reference in New Issue