Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.company;
- import java.io.ObjectStreamClass;
- import java.io.ObjectStreamField;
- import java.io.UnsupportedEncodingException;
- import java.nio.charset.Charset;
- import java.util.ArrayList;
- import java.util.Arrays;
- public class Main {
- public static class MyString {
- int count;
- ArrayList<Object> value;
- public MyString() {
- this.count = 0;
- this.value = new ArrayList<Object>(0);
- }
- public MyString(ArrayList<Object> value) {
- int size = value.size();
- this.count = size;
- this.value = value;
- }
- MyString(int count, ArrayList<Object> value) {//проверить на положительные числа
- this.value = value;
- this.count = count;
- }
- public Object at(int place) { //проверить не выйдет ли из массива
- return value.get(place);
- }
- public int length() {
- return count;
- }
- public void add(Object a) {
- value.add(a);
- this.count++;
- }
- public void insert(int i,Object a) {//добавить проверку на размер
- this.value.add(i, a);
- this.count++;
- }
- public MyString substring(int beginIndex, int endIndex) {//проверить
- if (beginIndex < 0) {
- throw new StringIndexOutOfBoundsException(beginIndex);
- }
- if (endIndex > count) {
- throw new StringIndexOutOfBoundsException(endIndex);
- }
- if (beginIndex > endIndex) {
- throw new StringIndexOutOfBoundsException(endIndex - beginIndex);
- }
- return ((beginIndex == 0) && (endIndex == count)) ? this :
- new MyString( endIndex - beginIndex, new ArrayList<Object>(this.value.subList(beginIndex, endIndex+1)));
- }
- public MyString substring(int endIndex) {//проверить
- if (endIndex < 0) {
- throw new StringIndexOutOfBoundsException(endIndex);
- }
- if (endIndex > count) {
- throw new StringIndexOutOfBoundsException(endIndex);
- }
- return (endIndex == count) ? this :
- new MyString( endIndex, new ArrayList<Object>(this.value.subList(0, endIndex)));
- }
- public MyString(ArrayList<Object> value, int count) {
- if (count < 0) {
- throw new StringIndexOutOfBoundsException(count);
- }
- this.count = count;
- this.value = new ArrayList<Object>(this.value.subList(0, count));
- }
- public MyString concat(MyString s) {//конкатенация строк
- MyString j = new MyString();
- j.count = this.count + s.count;
- for(int i = 0; i< this.count;i++){
- j.value.add(this.value.get(i));
- }
- for(int i = 0; i< s.count;i++){
- j.value.add(s.value.get(i));
- }
- return j;
- }
- public void beginsWith(MyString s){
- for(int i = 0; i< s.count;i++){
- this.value.add(0,s.value.get(i));
- this.count++;
- }
- }
- public void endsWith(MyString s){
- for(int i = 0; i< s.count;i++){
- this.value.add(this.count,s.value.get(i));
- this.count++;
- }
- }
- public boolean equals(MyString o) {
- if(this.count == o.count){
- for(int i = 0; i< o.count;i++)
- {
- if (o.value.get(i) != this.value.get(i)){
- return false;
- }
- }
- return true;
- }
- else
- return false;
- }
- }
- public static void main(String[] args) {
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement