Java Aspectj Usage combine(String[] one, String[] two)

Here you can find the source of combine(String[] one, String[] two)

Description

combine two string arrays, removing null and duplicates

License

Open Source License

Return

concatenation of both arrays, less null in either or dups in two

Declaration

public static String[] combine(String[] one, String[] two) 

Method Source Code

//package com.java2s;
/* *******************************************************************
 * Copyright (c) 1999-2000 Xerox Corporation. 
 * All rights reserved. // w w  w .ja v  a  2s .  c  o m
 * This program and the accompanying materials are made available 
 * under the terms of the Eclipse Public License v1.0 
 * which accompanies this distribution and is available at 
 * http://www.eclipse.org/legal/epl-v10.html 
 *  
 * Contributors: 
 *     Xerox/PARC     initial implementation 
 * ******************************************************************/

import java.util.ArrayList;

import java.util.Iterator;
import java.util.List;
import java.util.Properties;

public class Main {
    private static final String[] NONE = new String[0];

    /** combine two string arrays, removing null and duplicates 
     * @return concatenation of both arrays, less null in either or dups in two
     * @see Util#combine(Object[], Object[])
     */
    public static String[] combine(String[] one, String[] two) {
        ArrayList twoList = new ArrayList();
        twoList.addAll(org.aspectj.util.LangUtil.arrayAsList(two));
        ArrayList result = new ArrayList();
        if (null != one) {
            for (int i = 0; i < one.length; i++) {
                if (null != one[i]) {
                    twoList.remove(one[i]);
                    result.add(one[i]);
                }
            }
        }
        for (Iterator iterator = twoList.iterator(); iterator.hasNext();) {
            String element = (String) iterator.next();
            if (null != element) {
                result.add(element);
            }
        }
        return (String[]) result.toArray(NONE);
    }

    public static Properties combine(Properties dest, Properties add, boolean respectExisting) { // XXX
        if (null == add)
            return dest;
        if (null == dest)
            return add;
        for (Iterator iterator = add.keySet().iterator(); iterator.hasNext();) {
            String key = (String) iterator.next();
            if (null == key) {
                continue;
            }
            String value = add.getProperty(key);
            if (null == value) {
                continue;
            }
            if (!respectExisting || (null == dest.getProperty(key))) {
                dest.setProperty(key, value);
            }
        }
        return dest;
    }

    public static List arrayAsList(Object[] ra) {
        return org.aspectj.util.LangUtil.arrayAsList(ra);
    }
}

Related

  1. accessToString(int access_flags, boolean for_class)
  2. arrayAsList(Object[] ra)
  3. classOrInterface(int access_flags)
  4. collectArguments(JoinPoint jp)
  5. convertToFile(String path)
  6. copyInstruction(Instruction i)
  7. createConstant(InstructionFactory fact, int value)
  8. createInstanceof(InstructionFactory fact, ReferenceType t)