parent
e5400faad8
commit
f753a86e84
@ -4,22 +4,20 @@ import java.util.stream.IntStream;
|
|||||||
|
|
||||||
public class BubbleSort {
|
public class BubbleSort {
|
||||||
|
|
||||||
public void bubbleSort(Integer[] arr) {
|
void bubbleSort(Integer[] arr) {
|
||||||
int n = arr.length;
|
int n = arr.length;
|
||||||
IntStream.range(0, n - 1)
|
IntStream.range(0, n - 1)
|
||||||
.forEach(i -> {
|
.flatMap(i -> IntStream.range(i + 1, n - i))
|
||||||
IntStream.range(i + 1, n - i)
|
.forEach(j -> {
|
||||||
.forEach(j -> {
|
if (arr[j - 1] > arr[j]) {
|
||||||
if (arr[j - 1] > arr[j]) {
|
int temp = arr[j];
|
||||||
int temp = arr[j];
|
arr[j] = arr[j - 1];
|
||||||
arr[j] = arr[j - 1];
|
arr[j - 1] = temp;
|
||||||
arr[j - 1] = temp;
|
}
|
||||||
}
|
});
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void optimizedBubbleSort(Integer[] arr) {
|
void optimizedBubbleSort(Integer[] arr) {
|
||||||
int i = 0, n = arr.length;
|
int i = 0, n = arr.length;
|
||||||
boolean swapNeeded = true;
|
boolean swapNeeded = true;
|
||||||
while (i < n - 1 && swapNeeded) {
|
while (i < n - 1 && swapNeeded) {
|
||||||
@ -37,5 +35,4 @@ public class BubbleSort {
|
|||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
package com.baelding.rxjava;
|
package com.baeldung.rxjava;
|
||||||
|
|
||||||
import rx.Observable;
|
import rx.Observable;
|
||||||
|
|
@ -1,4 +1,4 @@
|
|||||||
package com.baelding.rxjava;
|
package com.baeldung.rxjava;
|
||||||
|
|
||||||
import rx.Observable;
|
import rx.Observable;
|
||||||
import rx.observables.ConnectableObservable;
|
import rx.observables.ConnectableObservable;
|
@ -1,4 +1,4 @@
|
|||||||
package com.baelding.rxjava;
|
package com.baeldung.rxjava;
|
||||||
|
|
||||||
import rx.Observable;
|
import rx.Observable;
|
||||||
import rx.observables.BlockingObservable;
|
import rx.observables.BlockingObservable;
|
||||||
@ -8,13 +8,13 @@ import java.util.List;
|
|||||||
|
|
||||||
public class ObservableImpl {
|
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"};
|
private static String[] letters = {"a", "b", "c", "d", "e", "f", "g", "h", "i"};
|
||||||
static String[] titles = {"title"};
|
private static String[] titles = {"title"};
|
||||||
public static List<String> titleList = Arrays.asList(titles);
|
private static List<String> titleList = Arrays.asList(titles);
|
||||||
|
|
||||||
public static Observable<String> getTitle() {
|
static Observable<String> getTitle() {
|
||||||
return Observable.from(titleList);
|
return Observable.from(titleList);
|
||||||
}
|
}
|
||||||
|
|
@ -1,4 +1,4 @@
|
|||||||
package com.baelding.rxjava;
|
package com.baeldung.rxjava;
|
||||||
|
|
||||||
import rx.Observable;
|
import rx.Observable;
|
||||||
|
|
@ -1,4 +1,4 @@
|
|||||||
package com.baelding.rxjava;
|
package com.baeldung.rxjava;
|
||||||
|
|
||||||
import rx.Observable;
|
import rx.Observable;
|
||||||
import rx.Single;
|
import rx.Single;
|
@ -1,14 +1,14 @@
|
|||||||
package com.baelding.rxjava;
|
package com.baeldung.rxjava;
|
||||||
|
|
||||||
import rx.Observer;
|
import rx.Observer;
|
||||||
import rx.subjects.PublishSubject;
|
import rx.subjects.PublishSubject;
|
||||||
|
|
||||||
public class SubjectImpl {
|
public class SubjectImpl {
|
||||||
|
|
||||||
public static Integer subscriber1 = 0;
|
static Integer subscriber1 = 0;
|
||||||
public static Integer subscriber2 = 0;
|
static Integer subscriber2 = 0;
|
||||||
|
|
||||||
public static Integer subjectMethod() {
|
private static Integer subjectMethod() {
|
||||||
PublishSubject<Integer> subject = PublishSubject.create();
|
PublishSubject<Integer> subject = PublishSubject.create();
|
||||||
|
|
||||||
subject.subscribe(getFirstObserver());
|
subject.subscribe(getFirstObserver());
|
||||||
@ -25,7 +25,7 @@ public class SubjectImpl {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static Observer<Integer> getFirstObserver() {
|
static Observer<Integer> getFirstObserver() {
|
||||||
return new Observer<Integer>() {
|
return new Observer<Integer>() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -46,7 +46,7 @@ public class SubjectImpl {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Observer<Integer> getSecondObserver() {
|
static Observer<Integer> getSecondObserver() {
|
||||||
return new Observer<Integer>() {
|
return new Observer<Integer>() {
|
||||||
|
|
||||||
@Override
|
@Override
|
@ -5,9 +5,9 @@ import com.github.davidmoten.rx.jdbc.ConnectionProviderFromUrl;
|
|||||||
|
|
||||||
class Connector {
|
class Connector {
|
||||||
|
|
||||||
static final String DB_CONNECTION = "jdbc:h2:mem:test;DB_CLOSE_DELAY=-1";
|
private static final String DB_CONNECTION = "jdbc:h2:mem:test;DB_CLOSE_DELAY=-1";
|
||||||
static final String DB_USER = "";
|
private static final String DB_USER = "";
|
||||||
static final String DB_PASSWORD = "";
|
private static final String DB_PASSWORD = "";
|
||||||
|
|
||||||
static final ConnectionProvider connectionProvider = new ConnectionProviderFromUrl(DB_CONNECTION, DB_USER, 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.Observable.Operator;
|
||||||
import rx.Subscriber;
|
import rx.Subscriber;
|
@ -1,4 +1,4 @@
|
|||||||
package com.baelding.rxjava.operator;
|
package com.baeldung.rxjava.operator;
|
||||||
|
|
||||||
import rx.Observable;
|
import rx.Observable;
|
||||||
import rx.Observable.Transformer;
|
import rx.Observable.Transformer;
|
@ -3,7 +3,7 @@ package com.baeldung.rxjava;
|
|||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import rx.Observable;
|
import rx.Observable;
|
||||||
|
|
||||||
import static com.baelding.rxjava.ObservableImpl.getTitle;
|
import static com.baeldung.rxjava.ObservableImpl.getTitle;
|
||||||
import static junit.framework.Assert.assertTrue;
|
import static junit.framework.Assert.assertTrue;
|
||||||
|
|
||||||
public class ObservableTest {
|
public class ObservableTest {
|
||||||
|
@ -10,8 +10,8 @@ import java.util.ArrayList;
|
|||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static com.baelding.rxjava.operator.ToCleanString.toCleanString;
|
import static com.baeldung.rxjava.operator.ToCleanString.toCleanString;
|
||||||
import static com.baelding.rxjava.operator.ToLength.toLength;
|
import static com.baeldung.rxjava.operator.ToLength.toLength;
|
||||||
import static org.hamcrest.Matchers.hasItems;
|
import static org.hamcrest.Matchers.hasItems;
|
||||||
import static org.hamcrest.Matchers.hasSize;
|
import static org.hamcrest.Matchers.hasSize;
|
||||||
import static org.hamcrest.Matchers.notNullValue;
|
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.assertThat;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
public class SchedulersTest {
|
public class SchedulersLiveTest {
|
||||||
private String result = "";
|
private String result = "";
|
||||||
private String result1 = "";
|
private String result1 = "";
|
||||||
private String result2 = "";
|
private String result2 = "";
|
@ -1,6 +1,5 @@
|
|||||||
package com.baeldung.rxjava;
|
package com.baeldung.rxjava;
|
||||||
|
|
||||||
import com.baelding.rxjava.SubjectImpl;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import rx.subjects.PublishSubject;
|
import rx.subjects.PublishSubject;
|
||||||
|
|
||||||
|
@ -18,25 +18,25 @@ public class BasicQueryTypesIntegrationTest {
|
|||||||
private ConnectionProvider connectionProvider = Connector.connectionProvider;
|
private ConnectionProvider connectionProvider = Connector.connectionProvider;
|
||||||
private Database db = Database.from(connectionProvider);
|
private Database db = Database.from(connectionProvider);
|
||||||
|
|
||||||
private Observable<Integer> create, insert1, insert2, insert3, update, delete = null;
|
private Observable<Integer> create;
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenCreateTableAndInsertRecords_thenCorrect() {
|
public void whenCreateTableAndInsertRecords_thenCorrect() {
|
||||||
create = db.update("CREATE TABLE IF NOT EXISTS EMPLOYEE(id int primary key, name varchar(255))")
|
create = db.update("CREATE TABLE IF NOT EXISTS EMPLOYEE(id int primary key, name varchar(255))")
|
||||||
.count();
|
.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)
|
.dependsOn(create)
|
||||||
.count();
|
.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)
|
.dependsOn(create)
|
||||||
.count();
|
.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)
|
.dependsOn(create)
|
||||||
.count();
|
.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)
|
.dependsOn(create)
|
||||||
.count();
|
.count();
|
||||||
delete = db.update("DELETE FROM EMPLOYEE WHERE id = 2")
|
Observable<Integer> delete = db.update("DELETE FROM EMPLOYEE WHERE id = 2")
|
||||||
.dependsOn(create)
|
.dependsOn(create)
|
||||||
.count();
|
.count();
|
||||||
List<String> names = db.select("select name from EMPLOYEE where id < ?")
|
List<String> names = db.select("select name from EMPLOYEE where id < ?")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user