Java Code Examples for java.util.ArrayList.toArray()

The following are Jave code examples for showing how to use toArray() of the java.util.ArrayList class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: lams   File: StandardPipeline.java   Source Code and License Vote up 6 votes
/**
 * Return the set of Valves in the pipeline associated with this
 * Container, including the basic Valve (if any).  If there are no
 * such Valves, a zero-length array is returned.
 */
public Valve[] getValves() {

	ArrayList valveList = new ArrayList();
    Valve current = first;
    if (current == null) {
    	current = basic;
    }
    while (current != null) {
    	valveList.add(current);
    	current = current.getNext();
    }

    return ((Valve[]) valveList.toArray(new Valve[0]));

}
 
Example 2
Project: athena   File: DecodeConstraintCodecHelper.java   Source Code and License Vote up 6 votes
/**
 * Decodes a waypoint constraint.
 *
 * @return waypoint constraint object.
 */
private Constraint decodeWaypointConstraint() {
    JsonNode waypoints = nullIsIllegal(json.get(ConstraintCodec.WAYPOINTS),
            ConstraintCodec.WAYPOINTS + ConstraintCodec.MISSING_MEMBER_MESSAGE);
    if (waypoints.size() < 1) {
        throw new IllegalArgumentException(
                "obstacles array in obstacles constraint must have at least one value");
    }

    ArrayList<DeviceId> waypointEntries = new ArrayList<>(waypoints.size());
    IntStream.range(0, waypoints.size())
            .forEach(index ->
                    waypointEntries.add(DeviceId.deviceId(waypoints.get(index).asText())));

    return new WaypointConstraint(
            waypointEntries.toArray(new DeviceId[waypoints.size()]));
}
 
Example 3
Project: jerrydog   File: NamingResourcesMBean.java   Source Code and License Vote up 6 votes
/**
 * Return the MBean Names of all the defined resource link references for 
 * this application.
 */
public String[] getResourceLinks() {
    
    ContextResourceLink[] resourceLinks = 
                        ((NamingResources)this.resource).findResourceLinks();
    ArrayList results = new ArrayList();
    for (int i = 0; i < resourceLinks.length; i++) {
        try {
            ObjectName oname =
                MBeanUtils.createObjectName(managed.getDomain(), resourceLinks[i]);
            results.add(oname.toString());
        } catch (MalformedObjectNameException e) {
            throw new IllegalArgumentException
                ("Cannot create object name for resource " + resourceLinks[i]);
        }
    }
    return ((String[]) results.toArray(new String[results.size()]));

}
 
Example 4
Project: xxpay-master   File: PayDigestUtil.java   Source Code and License Vote up 6 votes
public static String getSign(Map<String,Object> map, String key){
	ArrayList<String> list = new ArrayList<String>();
	for(Map.Entry<String,Object> entry:map.entrySet()){
		if(!"".equals(entry.getValue())){
			list.add(entry.getKey() + "=" + entry.getValue() + "&");
		}
	}
	int size = list.size();
	String [] arrayToSort = list.toArray(new String[size]);
	Arrays.sort(arrayToSort, String.CASE_INSENSITIVE_ORDER);
	StringBuilder sb = new StringBuilder();
	for(int i = 0; i < size; i ++) {
		sb.append(arrayToSort[i]);
	}
	String result = sb.toString();
	result += "key=" + key;
	_log.debug("Sign Before MD5:" + result);
	result = md5(result, encodingCharset).toUpperCase();
	_log.debug("Sign Result:" + result);
	return result;
}
 
Example 5
Project: lams   File: XppDom.java   Source Code and License Vote up 6 votes
public XppDom[] getChildren(final String name) {
    if (null == childList) {
        return new XppDom[0];
    } else {
        final ArrayList<XppDom> children = new ArrayList<XppDom>();
        final int size = childList.size();

        for (int i = 0; i < size; i++) {
            final XppDom configuration = childList.get(i);
            if (name.equals(configuration.getName())) {
                children.add(configuration);
            }
        }

        return children.toArray(new XppDom[0]);
    }
}
 
Example 6
Project: openjdk-jdk10   File: UnicodeSpec.java   Source Code and License Vote up 5 votes
/**
* Read and parse a Unicode data file.
*
* @param file   a file specifying the Unicode data file to be read
* @return   an array of UnicodeSpec objects, one for each line of the
*           Unicode data file that could be successfully parsed as
*           specifying Unicode character attributes
*/

public static UnicodeSpec[] readSpecFile(File file, int plane) throws FileNotFoundException {
    ArrayList<UnicodeSpec> list = new ArrayList<>(3000);
    UnicodeSpec[] result = null;
    int count = 0;
    BufferedReader f = new BufferedReader(new FileReader(file));
    String line = null;
    loop:
    while(true) {
        try {
            line = f.readLine();
        }
        catch (IOException e) {
            break loop;
        }
        if (line == null) break loop;
        UnicodeSpec item = parse(line.trim());
        int specPlane = item.getCodePoint() >>> 16;
        if (specPlane < plane) continue;
        if (specPlane > plane) break;

        if (item != null) {
            list.add(item);
        }
    }
    result = new UnicodeSpec[list.size()];
    list.toArray(result);
    return result;
}
 
Example 7
Project: openjdk-jdk10   File: AbstractVerifier.java   Source Code and License Vote up 5 votes
@SuppressWarnings("unchecked")
protected static <T> T resolveAnnotationValue(Class<T> expectedType, AnnotationValue value) {
    if (value == null) {
        return null;
    }
    if (expectedType.isArray()) {
        ArrayList<Object> result = new ArrayList<>();
        List<AnnotationValue> l = (List<AnnotationValue>) value.getValue();
        for (AnnotationValue el : l) {
            result.add(resolveAnnotationValue(expectedType.getComponentType(), el));
        }
        return (T) result.toArray((Object[]) Array.newInstance(expectedType.getComponentType(), result.size()));
    }
    Object unboxedValue = value.getValue();
    if (unboxedValue != null) {
        if (expectedType == TypeMirror.class && unboxedValue instanceof String) {
            /*
             * Happens if type is invalid when using the ECJ compiler. The ECJ does not match
             * AP-API specification here.
             */
            return null;
        }
        if (!expectedType.isAssignableFrom(unboxedValue.getClass())) {
            throw new ClassCastException(unboxedValue.getClass().getName() + " not assignable from " + expectedType.getName());
        }
    }
    return (T) unboxedValue;
}
 
Example 8
Project: tomcat7   File: StandardContext.java   Source Code and License Vote up 5 votes
/**
 * Return the set of application listener class names configured
 * for this application.
 */
@Override
public String[] findApplicationListeners() {

    ArrayList<String> list =
            new ArrayList<String>(applicationListeners.length);
    for (ApplicationListener applicationListener: applicationListeners) {
        list.add(applicationListener.getClassName());
    }
    
    return list.toArray(new String[list.size()]);

}
 
Example 9
Project: elasticsearch_my   File: AbstractTermVectorsTestCase.java   Source Code and License Vote up 5 votes
protected TestConfig[] generateTestConfigs(int numberOfTests, TestDoc[] testDocs, TestFieldSetting[] fieldSettings) {
    ArrayList<TestConfig> configs = new ArrayList<>();
    for (int i = 0; i < numberOfTests; i++) {

        ArrayList<String> selectedFields = null;
        if (randomBoolean()) {
            // used field selection
            selectedFields = new ArrayList<>();
            if (randomBoolean()) {
                selectedFields.add("Doesnt_exist"); // this will be ignored.
            }
            for (TestFieldSetting field : fieldSettings)
                if (randomBoolean()) {
                    selectedFields.add(field.name);
                }

            if (selectedFields.size() == 0) {
                selectedFields = null; // 0 length set is not supported.
            }

        }
        TestConfig config = new TestConfig(testDocs[randomInt(testDocs.length - 1)], selectedFields == null ? null
                : selectedFields.toArray(new String[]{}), randomBoolean(), randomBoolean(), randomBoolean());

        configs.add(config);
    }
    // always adds a test that fails
    configs.add(new TestConfig(new TestDoc("doesnt_exist", new TestFieldSetting[]{}, new String[]{}).index("doesn't_exist").alias("doesn't_exist"),
            new String[]{"doesnt_exist"}, true, true, true).expectedException(org.elasticsearch.index.IndexNotFoundException.class));

    refresh();

    return configs.toArray(new TestConfig[configs.size()]);
}
 
Example 10
Project: boohee_v5.6   File: AndroidDnsServer.java   Source Code and License Vote up 5 votes
public static InetAddress[] getByCommand() {
    try {
        LineNumberReader lnr = new LineNumberReader(new InputStreamReader(Runtime.getRuntime
                ().exec("getprop").getInputStream()));
        ArrayList<InetAddress> servers = new ArrayList(5);
        while (true) {
            String line = lnr.readLine();
            if (line == null) {
                break;
            }
            int split = line.indexOf("]: [");
            if (split != -1) {
                String property = line.substring(1, split);
                String value = line.substring(split + 4, line.length() - 1);
                if (property.endsWith(".dns") || property.endsWith(".dns1") || property
                        .endsWith(".dns2") || property.endsWith(".dns3") || property.endsWith
                        (".dns4")) {
                    InetAddress ip = InetAddress.getByName(value);
                    if (ip != null) {
                        value = ip.getHostAddress();
                        if (!(value == null || value.length() == 0)) {
                            servers.add(ip);
                        }
                    }
                }
            }
        }
        if (servers.size() > 0) {
            return (InetAddress[]) servers.toArray(new InetAddress[servers.size()]);
        }
    } catch (IOException e) {
        Logger.getLogger("AndroidDnsServer").log(Level.WARNING, "Exception in findDNSByExec",
                e);
    }
    return null;
}
 
Example 11
Project: parabuild-ci   File: FormParameter.java   Source Code and License Vote up 5 votes
String[] getValues() {
    ArrayList valueList = new ArrayList();
    FormControl[] controls = getControls();
    for (int i = 0; i < controls.length; i++) {
        valueList.addAll( Arrays.asList( controls[i].getValues() ) );
    }
    return (String[]) valueList.toArray( new String[ valueList.size() ] );
}
 
Example 12
Project: s-store   File: MarkovTables.java   Source Code and License Vote up 5 votes
public static VoltTable initializeTableA() {
    ArrayList<VoltTable.ColumnInfo> columns = new ArrayList<VoltTable.ColumnInfo>();
    String prefix = "A";

    columns.add(new VoltTable.ColumnInfo(prefix + "_ID", VoltType.BIGINT));
    addStringColumns(columns, 20, prefix);
    addIntegerColumns(columns, 20, prefix);

    VoltTable.ColumnInfo cols[] = new VoltTable.ColumnInfo[columns.size()];
    return (new VoltTable(columns.toArray(cols)));
}
 
Example 13
Project: Moenagade   File: FilenameUtils.java   Source Code and License Vote up 5 votes
/**
 * Splits a string into a number of tokens.
 * The text is split by '?' and '*'.
 * Where multiple '*' occur consecutively they are collapsed into a single '*'.
 * 
 * @param text  the text to split
 * @return the array of tokens, never null
 */
static String[] splitOnTokens(String text) {
    // used by wildcardMatch
    // package level so a unit test may run on this
    
    if (text.indexOf('?') == -1 && text.indexOf('*') == -1) {
        return new String[] { text };
    }

    char[] array = text.toCharArray();
    ArrayList<String> list = new ArrayList<String>();
    StringBuilder buffer = new StringBuilder();
    for (int i = 0; i < array.length; i++) {
        if (array[i] == '?' || array[i] == '*') {
            if (buffer.length() != 0) {
                list.add(buffer.toString());
                buffer.setLength(0);
            }
            if (array[i] == '?') {
                list.add("?");
            } else if (list.size() == 0 ||
                    (i > 0 && list.get(list.size() - 1).equals("*") == false)) {
                list.add("*");
            }
        } else {
            buffer.append(array[i]);
        }
    }
    if (buffer.length() != 0) {
        list.add(buffer.toString());
    }

    return list.toArray( new String[ list.size() ] );
}
 
Example 14
Project: s-store   File: AnotherArgumentsParser.java   Source Code and License Vote up 5 votes
public void setOriginalParser(ArrayList<String> vargs) throws Exception
{
   
    String[] args = new String[vargs.size()];
    args = vargs.toArray(args);
    
    this.m_origianlParser = ArgumentsParser.load(args,
            ArgumentsParser.PARAM_CATALOG
            );
    
    catalog = this.m_origianlParser.catalog;
}
 
Example 15
Project: Logisim   File: ExpressionView.java   Source Code and License Vote up 5 votes
private void computeLineText(FontMetrics fm) {
	String text = exprData.text;
	int[] badness = exprData.badness;

	if (fm.stringWidth(text) <= width) {
		lineText = new String[] { text };
		return;
	}

	int startPos = 0;
	ArrayList<String> lines = new ArrayList<String>();
	while (startPos < text.length()) {
		int stopPos = startPos + 1;
		String bestLine = text.substring(startPos, stopPos);
		if (stopPos >= text.length()) {
			lines.add(bestLine);
			break;
		}
		int bestStopPos = stopPos;
		int lineWidth = fm.stringWidth(bestLine);
		int bestBadness = badness[stopPos] + (width - lineWidth) * BADNESS_PER_PIXEL;
		while (stopPos < text.length()) {
			++stopPos;
			String line = text.substring(startPos, stopPos);
			lineWidth = fm.stringWidth(line);
			if (lineWidth > width)
				break;

			int lineBadness = badness[stopPos] + (width - lineWidth) * BADNESS_PER_PIXEL;
			if (lineBadness < bestBadness) {
				bestBadness = lineBadness;
				bestStopPos = stopPos;
				bestLine = line;
			}
		}
		lines.add(bestLine);
		startPos = bestStopPos;
	}
	lineText = lines.toArray(new String[lines.size()]);
}
 
Example 16
Project: jdk8u-jdk   File: ProcessImpl.java   Source Code and License Vote up 5 votes
private static String[] getTokensFromCommand(String command) {
    ArrayList<String> matchList = new ArrayList<>(8);
    Matcher regexMatcher = LazyPattern.PATTERN.matcher(command);
    while (regexMatcher.find())
        matchList.add(regexMatcher.group());
    return matchList.toArray(new String[matchList.size()]);
}
 
Example 17
Project: minicraft-plus-revived   File: Level.java   Source Code and License Vote up 5 votes
public Entity[] getEntitiesOfClass(Class<? extends Entity> targetClass) {
	ArrayList<Entity> matches = new ArrayList<>();
	for(Entity e: getEntityArray()) {
		if(targetClass.isAssignableFrom(e.getClass()))
			matches.add(e);
	}
	
	return matches.toArray(new Entity[0]);
}
 
Example 18
Project: EasyAndroid   File: FileTool.java   Source Code and License Vote up 5 votes
/**
 * 返回file目录下所有符合names中任意名称的文件,不区分大小写
 *
 * @param file       文件
 * @param isAllFiles <br>{@code true} 包含所有目录文件<br>{@code false} 仅当前目录
 * @param names      名称列表
 * @return 文件数组
 */
public static File[] listFilesWithNamesNoCase(File file, boolean isAllFiles, String[] names)
{
    if(isAllFiles)
    {
        ArrayList<File> list = new ArrayList<>();
        listAllWithNamesNoCase(list, file, names);
        return list.toArray(new File[list.size()]);
    }
    else
    {
        return listFilesWithNamesNoCase(file, names);
    }
}
 
Example 19
Project: etomica   File: ClusterOperations.java   Source Code and License Vote up 5 votes
/**
 * Generates the set of diagrams obtained by adding the second set to the first set.
 * The returned array contains (copies of) all diagrams from the first set, with weights modified by adding
 * the weights of matching diagrams from the second set (if present), and all unmatched diagrams from
 * the second set. The returned array and all clusters in it are new instances.
 */
public static ClusterDiagram[] sum(ClusterDiagram[] set1, ClusterDiagram[] set2) {
    ArrayList<ClusterDiagram> list = new ArrayList<ClusterDiagram>();
    for(int i=0; i<set1.length; i++) {
        list.add(new ClusterDiagram(set1[i]));
    }
    for(int i=0; i<set2.length; i++) {
        list.add(new ClusterDiagram(set2[i]));
    }
    addEquivalents(list);
    return list.toArray(new ClusterDiagram[] {});
}
 
Example 20
Project: apache-tomcat-7.0.73-with-comment   File: JNDIRealm.java   Source Code and License Vote up 4 votes
/**
 * Return a User object containing information about the user
 * with the specified username, if found in the directory;
 * otherwise return <code>null</code>.
 *
 * If the <code>userPassword</code> configuration attribute is
 * specified, the value of that attribute is retrieved from the
 * user's directory entry. If the <code>userRoleName</code>
 * configuration attribute is specified, all values of that
 * attribute are retrieved from the directory entry.
 *
 * @param context The directory context
 * @param username Username to be looked up
 * @param credentials User credentials (optional)
 * @param curUserPattern Index into userPatternFormatArray
 *
 * @exception NamingException if a directory server error occurs
 */
protected User getUser(DirContext context, String username,
                       String credentials, int curUserPattern)
    throws NamingException {

    User user = null;

    // Get attributes to retrieve from user entry
    ArrayList<String> list = new ArrayList<String>();
    if (userPassword != null)
        list.add(userPassword);
    if (userRoleName != null)
        list.add(userRoleName);
    if (userRoleAttribute != null) {
        list.add(userRoleAttribute);
    }
    String[] attrIds = new String[list.size()];
    list.toArray(attrIds);

    // Use pattern or search for user entry
    if (userPatternFormatArray != null && curUserPattern >= 0) {
        user = getUserByPattern(context, username, credentials, attrIds, curUserPattern);
        if (containerLog.isDebugEnabled()) {
            containerLog.debug("Found user by pattern [" + user + "]");
        }
    } else {
        boolean thisUserSearchAsUser = isUserSearchAsUser();
        try {
            if (thisUserSearchAsUser) {
                userCredentialsAdd(context, username, credentials);
            }
            user = getUserBySearch(context, username, attrIds);
        } finally {
            if (thisUserSearchAsUser) {
                userCredentialsRemove(context);
            }
        }
        if (containerLog.isDebugEnabled()) {
            containerLog.debug("Found user by search [" + user + "]");
        }
    }

    if (userPassword == null && credentials != null && user != null) {
        // The password is available. Insert it since it may be required for
        // role searches.
        return new User(user.getUserName(), user.getDN(), credentials,
                user.getRoles(), user.getUserRoleId());
    }

    return user;
}