Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Apache License 

import android.util.*;

public class Main {
    public static String replaceAll(String s, String as[], String as1[]) {
        // long millis = System.currentTimeMillis();
        StringBuilder sb = new StringBuilder();
        for (int k = 0; k < as.length; k++) {
            if (as[k].length() > 0) {
                int i = 0;
                sb.setLength(0);
                int j;
                while ((j = s.indexOf(as[k], i)) >= 0) {
                    sb.append(s, i, j);
                    sb.append(as1[k]);
                    // LOGGER.info("replaced " + as[k] + " = " + as1[k]);
                    i = j + as[k].length();
                }
                sb.append(s, i, s.length());
                s = sb.toString();
            }
        }
        // LOGGER.info("replaced result: " + s);
        return s;
    }

    public static StringBuilder replaceAll(String s, String s1, String s2) {
        StringBuilder sb = new StringBuilder(s.length());
        if (s1.length() > 0) {
            int i = 0;
            int j;
            while ((j = s.indexOf(s1, i)) >= 0) {
                sb.append(s, i, j);
                sb.append(s2);
                i = j + s1.length();
            }
            sb.append(s, i, s.length());
            return sb;
        } else {
            return new StringBuilder(s);
        }
    }

    public static StringBuilder replaceAll(String s, StringBuilder sb, String s1, String s2) {
        int s1Length = s1.length();
        if (s1Length > 0) {
            int i = 0;
            int j;
            while ((j = s.indexOf(s1, i)) >= 0) {
                sb.append(s, i, j);
                sb.append(s2);
                i = j + s1Length;
            }
            sb.append(s, i, s.length());
            return sb;
        } else {
            return sb.append(s);
        }
    }

    public static void replaceAll(CharSequence s, int start, int end, StringBuilder sb2, String[] s10,
            String[] s20) {
        replaceAll(s.toString(), start, end, sb2, s10, s20);
    }

    public static void replaceAll(String s, int start, int end, StringBuilder sb2, String[] s10, String[] s20) {
        s = s.substring(start, end);
        for (int k = 0; k < s10.length; k++) {
            String s1 = s10[k];
            String s2 = s20[k];
            int s1Length = s1.length();
            if (s1Length > 0) {
                int i = 0;
                int j;
                StringBuilder sb = new StringBuilder();
                end = s.length();
                while (((j = s.indexOf(s1, i)) >= 0) && j < end) {
                    sb.append(s, i, j);
                    sb.append(s2);
                    i = j + s1Length;
                }
                sb.append(s, i, end);
                s = sb.toString();
            }
        }
        sb2.append(s);
    }

    public static StringBuilder replaceAll(String s, int start, int end, StringBuilder sb, String s1, String s2) {
        int s1Length = s1.length();
        if (s1Length > 0) {
            int i = start;
            int j;
            while (((j = s.indexOf(s1, i)) >= 0) && j < end) {
                sb.append(s, i, j);
                sb.append(s2);
                i = j + s1Length;
            }
            sb.append(s, i, end);
            return sb;
        } else {
            return sb.append(s);
        }
    }

    public static StringBuilder replaceAll(StringBuilder s, int start, int end, StringBuilder sb, String s1,
            String s2) {
        int s1Length = s1.length();
        if (s1Length > 0) {
            int i = start;
            int j;
            while (((j = s.indexOf(s1, i)) >= 0) && j < end) {
                sb.append(s, i, j);
                sb.append(s2);
                i = j + s1Length;
            }
            sb.append(s, i, end);
            return sb;
        } else {
            return sb.append(s);
        }
    }

    public static StringBuilder replaceAll(String sourceCase, String sourceLower, int start, int end,
            StringBuilder sb, String pattern, String tagStart, String tagEnd) {
        Log.d("sourceCase, sourceLower, start, end", sourceCase.length() + ", " + sourceLower.length() + "," + start
                + "," + end + pattern + "," + tagStart + "," + tagEnd);
        int patternLength = pattern.length();
        if (patternLength > 0) {
            int i = start;
            int j;
            while (((j = sourceLower.indexOf(pattern, i)) >= 0) && ((j + patternLength) <= end)) {
                sb.append(sourceCase, i, j);
                sb.append(tagStart);
                i = j + patternLength;
                sb.append(sourceCase, j, i);
                sb.append(tagEnd);
            }
            Log.d("sourceCase, i, end", sourceCase.length() + ", " + i + ", " + end);
            sb.append(sourceCase, i, end);
            return sb;
        } else {
            return sb.append(sourceCase);
        }
    }

    public static StringBuilder replaceAll(StringBuilder sourceCase, StringBuilder sourceLower, int start, int end,
            StringBuilder sb, String pattern, String tagStart, String tagEnd) {
        Log.d("sourceCase, sourceLower, start, end", sourceCase.length() + ", " + sourceLower.length() + "," + start
                + "," + end + pattern + "," + tagStart + "," + tagEnd);
        int patternLength = pattern.length();
        if (patternLength > 0) {
            int i = start;
            int j;
            while (((j = sourceLower.indexOf(pattern, i)) >= 0) && ((j + patternLength) <= end)) {
                sb.append(sourceCase, i, j);
                sb.append(tagStart);
                i = j + patternLength;
                sb.append(sourceCase, j, i);
                sb.append(tagEnd);
            }
            Log.d("sourceCase, i, end", sourceCase.length() + ", " + i + ", " + end);
            sb.append(sourceCase, i, end);
            return sb;
        } else {
            return sb.append(sourceCase);
        }
    }
}