@@ -54,7 +54,7 @@ public class StringObservable {
54
54
public static Observable <byte []> from (final InputStream i ) {
55
55
return from (i , 8 * 1024 );
56
56
}
57
-
57
+
58
58
/**
59
59
* Func0 that allows throwing an {@link IOException}s commonly thrown during IO operations.
60
60
* @see StringObservable#using(UnsafeFunc0, Func1)
@@ -534,50 +534,6 @@ public void onNext(String t) {
534
534
});
535
535
}
536
536
537
- public final static class Line {
538
- private final int number ;
539
- private final String text ;
540
-
541
- public Line (int number , String text ) {
542
- this .number = number ;
543
- this .text = text ;
544
- }
545
-
546
- public int getNumber () {
547
- return number ;
548
- }
549
-
550
- public String getText () {
551
- return text ;
552
- }
553
-
554
- @ Override
555
- public int hashCode () {
556
- int result = 31 + number ;
557
- result = 31 * result + (text == null ? 0 : text .hashCode ());
558
- return result ;
559
- }
560
-
561
- @ Override
562
- public boolean equals (Object obj ) {
563
- if (!(obj instanceof Line ))
564
- return false ;
565
- Line other = (Line ) obj ;
566
- if (number != other .number )
567
- return false ;
568
- if (other .text == text )
569
- return true ;
570
- if (text == null )
571
- return false ;
572
- return text .equals (other .text );
573
- }
574
-
575
- @ Override
576
- public String toString () {
577
- return number + ":" + text ;
578
- }
579
- }
580
-
581
537
/**
582
538
* Splits the {@link Observable} of Strings by lines and numbers them (zero based index)
583
539
* <p>
@@ -586,13 +542,42 @@ public String toString() {
586
542
* @param source
587
543
* @return the Observable conaining the split lines of the source
588
544
*/
589
- public static Observable <Line > byLine (Observable <String > source ) {
590
- return split (source , System .getProperty ("line.separator" )). map ( new Func1 < String , Line >() {
591
- int lineNumber = 0 ;
545
+ public static Observable <String > byLine (Observable <String > source ) {
546
+ return split (source , System .getProperty ("line.separator" ));
547
+ }
592
548
549
+ /**
550
+ * Converts an String into an Observable that emits the chars in the String.
551
+ * <p>
552
+ * <img width="640" height="315" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/from.png" alt="">
553
+ *
554
+ * @param str
555
+ * the source String
556
+ * @return an Observable that emits each char in the source String
557
+ * @see <a href="https://github.com/ReactiveX/RxJava/wiki/Creating-Observables#from">RxJava wiki: from</a>
558
+ */
559
+ public static Observable <String > byCharacter (Observable <String > source ) {
560
+ return source .lift (new Operator <String , String >() {
593
561
@ Override
594
- public Line call (String text ) {
595
- return new Line (lineNumber ++, text );
562
+ public Subscriber <? super String > call (final Subscriber <? super String > subscriber ) {
563
+ return new Subscriber <String >(subscriber ) {
564
+ @ Override
565
+ public void onCompleted () {
566
+ subscriber .onCompleted ();
567
+ }
568
+
569
+ @ Override
570
+ public void onError (Throwable e ) {
571
+ subscriber .onError (e );
572
+ }
573
+
574
+ @ Override
575
+ public void onNext (String str ) {
576
+ for (char c : str .toCharArray ()) {
577
+ subscriber .onNext (Character .toString (c ));
578
+ }
579
+ }
580
+ };
596
581
}
597
582
});
598
583
}
0 commit comments