|
18 | 18 | import java.util.ArrayList;
|
19 | 19 | import java.util.Arrays;
|
20 | 20 | import java.util.Collection;
|
| 21 | +import java.util.Collections; |
21 | 22 | import java.util.List;
|
22 | 23 | import java.util.concurrent.Future;
|
23 | 24 | import java.util.concurrent.TimeUnit;
|
@@ -529,24 +530,322 @@ public static <T> Observable<T> error(Throwable exception) {
|
529 | 530 | public static <T> Observable<T> from(Iterable<? extends T> iterable) {
|
530 | 531 | return create(OperationToObservableIterable.toObservableIterable(iterable));
|
531 | 532 | }
|
532 |
| - |
| 533 | + |
533 | 534 | /**
|
534 | 535 | * Converts an Array into an Observable.
|
535 | 536 | * <p>
|
536 | 537 | * <img width="640" src="https://github.com/Netflix/RxJava/wiki/images/rx-operators/from.png">
|
537 | 538 | *
|
| 539 | + * <p>Implementation note: the entire iterable sequence will be immediately emitted each time an {@link Observer} subscribes. Since this occurs before the {@link Subscription} is returned, |
| 540 | + * it in not possible to unsubscribe from the sequence before it completes. |
| 541 | + * |
| 542 | + * @param array |
| 543 | + * the source sequence |
| 544 | + * @param <T> |
| 545 | + * the type of items in the {@link Iterable} sequence and the type of items to be |
| 546 | + * emitted by the resulting Observable |
| 547 | + * @return an Observable that emits each item in the source {@link Iterable} sequence |
| 548 | + */ |
| 549 | + public static <T> Observable<T> from(T[] items) { |
| 550 | + return create(OperationToObservableIterable.toObservableIterable(Arrays.asList(items))); |
| 551 | + } |
| 552 | + |
| 553 | + /** |
| 554 | + * Converts a series of items into an Observable. |
| 555 | + * <p> |
| 556 | + * <img width="640" src="https://github.com/Netflix/RxJava/wiki/images/rx-operators/from.png"> |
| 557 | + * |
538 | 558 | * <p>Implementation note: the entire array will be immediately emitted each time an {@link Observer} subscribes. Since this occurs before the {@link Subscription} is returned,
|
539 | 559 | * it in not possible to unsubscribe from the sequence before it completes.
|
540 | 560 | *
|
541 |
| - * @param items |
542 |
| - * the source Array |
| 561 | + * @param t1 |
| 562 | + * item |
543 | 563 | * @param <T>
|
544 | 564 | * the type of items in the Array, and the type of items to be emitted by the
|
545 | 565 | * resulting Observable
|
546 | 566 | * @return an Observable that emits each item in the source Array
|
547 | 567 | */
|
548 |
| - public static <T> Observable<T> from(T... items) { |
549 |
| - return create(OperationToObservableIterable.toObservableIterable(Arrays.asList(items))); |
| 568 | + @SuppressWarnings("unchecked") |
| 569 | + // suppress unchecked because we are using varargs inside the method |
| 570 | + public static <T> Observable<T> from(T t1) { |
| 571 | + return from(Arrays.asList(t1)); |
| 572 | + } |
| 573 | + |
| 574 | + /** |
| 575 | + * Converts a series of items into an Observable. |
| 576 | + * <p> |
| 577 | + * <img width="640" src="https://github.com/Netflix/RxJava/wiki/images/rx-operators/from.png"> |
| 578 | + * |
| 579 | + * <p>Implementation note: the entire array will be immediately emitted each time an {@link Observer} subscribes. Since this occurs before the {@link Subscription} is returned, |
| 580 | + * it in not possible to unsubscribe from the sequence before it completes. |
| 581 | + * |
| 582 | + * @param t1 |
| 583 | + * item |
| 584 | + * @param t2 |
| 585 | + * item |
| 586 | + * @param <T> |
| 587 | + * the type of items in the Array, and the type of items to be emitted by the |
| 588 | + * resulting Observable |
| 589 | + * @return an Observable that emits each item in the source Array |
| 590 | + */ |
| 591 | + @SuppressWarnings("unchecked") |
| 592 | + // suppress unchecked because we are using varargs inside the method |
| 593 | + public static <T> Observable<T> from(T t1, T t2) { |
| 594 | + return from(Arrays.asList(t1, t2)); |
| 595 | + } |
| 596 | + |
| 597 | + /** |
| 598 | + * Converts a series of items into an Observable. |
| 599 | + * <p> |
| 600 | + * <img width="640" src="https://github.com/Netflix/RxJava/wiki/images/rx-operators/from.png"> |
| 601 | + * |
| 602 | + * <p>Implementation note: the entire array will be immediately emitted each time an {@link Observer} subscribes. Since this occurs before the {@link Subscription} is returned, |
| 603 | + * it in not possible to unsubscribe from the sequence before it completes. |
| 604 | + * |
| 605 | + * @param t1 |
| 606 | + * item |
| 607 | + * @param t2 |
| 608 | + * item |
| 609 | + * @param t3 |
| 610 | + * item |
| 611 | + * @param <T> |
| 612 | + * the type of items in the Array, and the type of items to be emitted by the |
| 613 | + * resulting Observable |
| 614 | + * @return an Observable that emits each item in the source Array |
| 615 | + */ |
| 616 | + @SuppressWarnings("unchecked") |
| 617 | + // suppress unchecked because we are using varargs inside the method |
| 618 | + public static <T> Observable<T> from(T t1, T t2, T t3) { |
| 619 | + return from(Arrays.asList(t1, t2, t3)); |
| 620 | + } |
| 621 | + |
| 622 | + /** |
| 623 | + * Converts a series of items into an Observable. |
| 624 | + * <p> |
| 625 | + * <img width="640" src="https://github.com/Netflix/RxJava/wiki/images/rx-operators/from.png"> |
| 626 | + * |
| 627 | + * <p>Implementation note: the entire array will be immediately emitted each time an {@link Observer} subscribes. Since this occurs before the {@link Subscription} is returned, |
| 628 | + * it in not possible to unsubscribe from the sequence before it completes. |
| 629 | + * |
| 630 | + * @param t1 |
| 631 | + * item |
| 632 | + * @param t2 |
| 633 | + * item |
| 634 | + * @param t3 |
| 635 | + * item |
| 636 | + * @param t4 |
| 637 | + * item |
| 638 | + * @param <T> |
| 639 | + * the type of items in the Array, and the type of items to be emitted by the |
| 640 | + * resulting Observable |
| 641 | + * @return an Observable that emits each item in the source Array |
| 642 | + */ |
| 643 | + @SuppressWarnings("unchecked") |
| 644 | + // suppress unchecked because we are using varargs inside the method |
| 645 | + public static <T> Observable<T> from(T t1, T t2, T t3, T t4) { |
| 646 | + return from(Arrays.asList(t1, t2, t3, t4)); |
| 647 | + } |
| 648 | + |
| 649 | + /** |
| 650 | + * Converts a series of items into an Observable. |
| 651 | + * <p> |
| 652 | + * <img width="640" src="https://github.com/Netflix/RxJava/wiki/images/rx-operators/from.png"> |
| 653 | + * |
| 654 | + * <p>Implementation note: the entire array will be immediately emitted each time an {@link Observer} subscribes. Since this occurs before the {@link Subscription} is returned, |
| 655 | + * it in not possible to unsubscribe from the sequence before it completes. |
| 656 | + * |
| 657 | + * @param t1 |
| 658 | + * item |
| 659 | + * @param t2 |
| 660 | + * item |
| 661 | + * @param t3 |
| 662 | + * item |
| 663 | + * @param t4 |
| 664 | + * item |
| 665 | + * @param t5 |
| 666 | + * item |
| 667 | + * @param <T> |
| 668 | + * the type of items in the Array, and the type of items to be emitted by the |
| 669 | + * resulting Observable |
| 670 | + * @return an Observable that emits each item in the source Array |
| 671 | + */ |
| 672 | + @SuppressWarnings("unchecked") |
| 673 | + // suppress unchecked because we are using varargs inside the method |
| 674 | + public static <T> Observable<T> from(T t1, T t2, T t3, T t4, T t5) { |
| 675 | + return from(Arrays.asList(t1, t2, t3, t4, t5)); |
| 676 | + } |
| 677 | + |
| 678 | + /** |
| 679 | + * Converts a series of items into an Observable. |
| 680 | + * <p> |
| 681 | + * <img width="640" src="https://github.com/Netflix/RxJava/wiki/images/rx-operators/from.png"> |
| 682 | + * |
| 683 | + * <p>Implementation note: the entire array will be immediately emitted each time an {@link Observer} subscribes. Since this occurs before the {@link Subscription} is returned, |
| 684 | + * it in not possible to unsubscribe from the sequence before it completes. |
| 685 | + * |
| 686 | + * @param t1 |
| 687 | + * item |
| 688 | + * @param t2 |
| 689 | + * item |
| 690 | + * @param t3 |
| 691 | + * item |
| 692 | + * @param t4 |
| 693 | + * item |
| 694 | + * @param t5 |
| 695 | + * item |
| 696 | + * @param t6 |
| 697 | + * item |
| 698 | + * @param <T> |
| 699 | + * the type of items in the Array, and the type of items to be emitted by the |
| 700 | + * resulting Observable |
| 701 | + * @return an Observable that emits each item in the source Array |
| 702 | + */ |
| 703 | + @SuppressWarnings("unchecked") |
| 704 | + // suppress unchecked because we are using varargs inside the method |
| 705 | + public static <T> Observable<T> from(T t1, T t2, T t3, T t4, T t5, T t6) { |
| 706 | + return from(Arrays.asList(t1, t2, t3, t4, t5, t6)); |
| 707 | + } |
| 708 | + |
| 709 | + /** |
| 710 | + * Converts a series of items into an Observable. |
| 711 | + * <p> |
| 712 | + * <img width="640" src="https://github.com/Netflix/RxJava/wiki/images/rx-operators/from.png"> |
| 713 | + * |
| 714 | + * <p>Implementation note: the entire array will be immediately emitted each time an {@link Observer} subscribes. Since this occurs before the {@link Subscription} is returned, |
| 715 | + * it in not possible to unsubscribe from the sequence before it completes. |
| 716 | + * |
| 717 | + * @param t1 |
| 718 | + * item |
| 719 | + * @param t2 |
| 720 | + * item |
| 721 | + * @param t3 |
| 722 | + * item |
| 723 | + * @param t4 |
| 724 | + * item |
| 725 | + * @param t5 |
| 726 | + * item |
| 727 | + * @param t6 |
| 728 | + * item |
| 729 | + * @param t7 |
| 730 | + * item |
| 731 | + * @param <T> |
| 732 | + * the type of items in the Array, and the type of items to be emitted by the |
| 733 | + * resulting Observable |
| 734 | + * @return an Observable that emits each item in the source Array |
| 735 | + */ |
| 736 | + @SuppressWarnings("unchecked") |
| 737 | + // suppress unchecked because we are using varargs inside the method |
| 738 | + public static <T> Observable<T> from(T t1, T t2, T t3, T t4, T t5, T t6, T t7) { |
| 739 | + return from(Arrays.asList(t1, t2, t3, t4, t5, t6, t7)); |
| 740 | + } |
| 741 | + |
| 742 | + /** |
| 743 | + * Converts a series of items into an Observable. |
| 744 | + * <p> |
| 745 | + * <img width="640" src="https://github.com/Netflix/RxJava/wiki/images/rx-operators/from.png"> |
| 746 | + * |
| 747 | + * <p>Implementation note: the entire array will be immediately emitted each time an {@link Observer} subscribes. Since this occurs before the {@link Subscription} is returned, |
| 748 | + * it in not possible to unsubscribe from the sequence before it completes. |
| 749 | + * |
| 750 | + * @param t1 |
| 751 | + * item |
| 752 | + * @param t2 |
| 753 | + * item |
| 754 | + * @param t3 |
| 755 | + * item |
| 756 | + * @param t4 |
| 757 | + * item |
| 758 | + * @param t5 |
| 759 | + * item |
| 760 | + * @param t6 |
| 761 | + * item |
| 762 | + * @param t7 |
| 763 | + * item |
| 764 | + * @param t8 |
| 765 | + * item |
| 766 | + * @param <T> |
| 767 | + * the type of items in the Array, and the type of items to be emitted by the |
| 768 | + * resulting Observable |
| 769 | + * @return an Observable that emits each item in the source Array |
| 770 | + */ |
| 771 | + @SuppressWarnings("unchecked") |
| 772 | + // suppress unchecked because we are using varargs inside the method |
| 773 | + public static <T> Observable<T> from(T t1, T t2, T t3, T t4, T t5, T t6, T t7, T t8) { |
| 774 | + return from(Arrays.asList(t1, t2, t3, t4, t5, t6, t7, t8)); |
| 775 | + } |
| 776 | + |
| 777 | + /** |
| 778 | + * Converts a series of items into an Observable. |
| 779 | + * <p> |
| 780 | + * <img width="640" src="https://github.com/Netflix/RxJava/wiki/images/rx-operators/from.png"> |
| 781 | + * |
| 782 | + * <p>Implementation note: the entire array will be immediately emitted each time an {@link Observer} subscribes. Since this occurs before the {@link Subscription} is returned, |
| 783 | + * it in not possible to unsubscribe from the sequence before it completes. |
| 784 | + * |
| 785 | + * @param t1 |
| 786 | + * item |
| 787 | + * @param t2 |
| 788 | + * item |
| 789 | + * @param t3 |
| 790 | + * item |
| 791 | + * @param t4 |
| 792 | + * item |
| 793 | + * @param t5 |
| 794 | + * item |
| 795 | + * @param t6 |
| 796 | + * item |
| 797 | + * @param t7 |
| 798 | + * item |
| 799 | + * @param t8 |
| 800 | + * item |
| 801 | + * @param t9 |
| 802 | + * item |
| 803 | + * @param <T> |
| 804 | + * the type of items in the Array, and the type of items to be emitted by the |
| 805 | + * resulting Observable |
| 806 | + * @return an Observable that emits each item in the source Array |
| 807 | + */ |
| 808 | + @SuppressWarnings("unchecked") |
| 809 | + // suppress unchecked because we are using varargs inside the method |
| 810 | + public static <T> Observable<T> from(T t1, T t2, T t3, T t4, T t5, T t6, T t7, T t8, T t9) { |
| 811 | + return from(Arrays.asList(t1, t2, t3, t4, t5, t6, t7, t8, t9)); |
| 812 | + } |
| 813 | + |
| 814 | + /** |
| 815 | + * Converts a series of items into an Observable. |
| 816 | + * <p> |
| 817 | + * <img width="640" src="https://github.com/Netflix/RxJava/wiki/images/rx-operators/from.png"> |
| 818 | + * |
| 819 | + * <p>Implementation note: the entire array will be immediately emitted each time an {@link Observer} subscribes. Since this occurs before the {@link Subscription} is returned, |
| 820 | + * it in not possible to unsubscribe from the sequence before it completes. |
| 821 | + * |
| 822 | + * @param t1 |
| 823 | + * item |
| 824 | + * @param t2 |
| 825 | + * item |
| 826 | + * @param t3 |
| 827 | + * item |
| 828 | + * @param t4 |
| 829 | + * item |
| 830 | + * @param t5 |
| 831 | + * item |
| 832 | + * @param t6 |
| 833 | + * item |
| 834 | + * @param t7 |
| 835 | + * item |
| 836 | + * @param t8 |
| 837 | + * item |
| 838 | + * @param t10 |
| 839 | + * item |
| 840 | + * @param <T> |
| 841 | + * the type of items in the Array, and the type of items to be emitted by the |
| 842 | + * resulting Observable |
| 843 | + * @return an Observable that emits each item in the source Array |
| 844 | + */ |
| 845 | + @SuppressWarnings("unchecked") |
| 846 | + // suppress unchecked because we are using varargs inside the method |
| 847 | + public static <T> Observable<T> from(T t1, T t2, T t3, T t4, T t5, T t6, T t7, T t8, T t9, T t10) { |
| 848 | + return from(Arrays.asList(t1, t2, t3, t4, t5, t6, t7, t8, t9, t10)); |
550 | 849 | }
|
551 | 850 |
|
552 | 851 | /**
|
|
0 commit comments