Advertisement
Divinty2

AsciiCharSequence(2.0)

Jul 21st, 2019
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.89 KB | None | 0 0
  1. public class AsciiCharSequence implements java.lang.CharSequence{
  2.     // implementation
  3.    
  4.     private byte[] sequence;
  5.    
  6.     public AsciiCharSequence(byte[] byteArray) {
  7.     sequence = byteArray;
  8.     }
  9.    
  10.     public int length(){
  11.         return sequence.length;
  12.     }
  13.    
  14.     public char charAt(int index){
  15.         return (char)sequence[index];
  16.     }    
  17.    
  18.     public AsciiCharSequence subSequence(int start, int end) {
  19.         int len = end - start;
  20.         byte[] newSequence = new byte[len];
  21.         System.arraycopy(sequence, start, newSequence, 0,  len);
  22.         return new AsciiCharSequence(newSequence);
  23.     }
  24.    
  25.     public String toString() {
  26.         StringBuilder result = new StringBuilder();
  27.         int len = this.length();
  28.         for (int i = 0; i < len; i++) {
  29.             result.append(charAt(i));
  30.         }
  31.         return result.toString();
  32.     }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement