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 java.util.HashSet;

public class Main {
    static final HashSet<String> sSet = new HashSet<>();

    /**
     * merge the refer variable by target mainRefer and otherRefer, refer variable is something like: 'user,handler''
     * @param mainRefer the main refer variable
     * @param otherRefer the other refer variable
     * @return the new he refer variable
     */
    public static String mergeReferVariable(String mainRefer, String otherRefer) {
        if (mainRefer == null)
            return otherRefer;
        if (otherRefer == null)
            return mainRefer;
        if (mainRefer.equals(otherRefer))
            return mainRefer;

        final String[] mainStrs = mainRefer.split(",");
        final String[] otherStrs = otherRefer.split(",");

        for (int i = 0, size = mainStrs.length; i < size; i++) {
            sSet.add(mainStrs[i]);
        }
        for (int i = 0, size = otherStrs.length; i < size; i++) {
            sSet.add(otherStrs[i]);
        }
        StringBuilder sb = new StringBuilder();
        for (String str : sSet) {
            sb.append(str).append(",");
        }
        //delete last
        sb.deleteCharAt(sb.length() - 1);
        sSet.clear();
        return sb.toString();
    }
}