Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
FRC-2013/src/com/team254/lib/util/Util.java /
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
44 lines (38 sloc)
1.14 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package com.team254.lib.util; | |
| import java.util.Vector; | |
| /** | |
| * Contains basic functions that are used often. | |
| * | |
| * @author richard@team254.com (Richard Lin) | |
| * @author brandon.gonzalez.451@gmail.com (Brandon Gonzalez) | |
| */ | |
| public class Util { | |
| // Prevent this class from being instantiated. | |
| private Util() { | |
| } | |
| /** | |
| * Limits the given input to the given magnitude. | |
| */ | |
| public static double limit(double v, double limit) { | |
| return (Math.abs(v) < limit) ? v : limit * (v < 0 ? -1 : 1); | |
| } | |
| /** | |
| * Returns the array of substrings obtained by dividing the given input string at each occurrence | |
| * of the given delimiter. | |
| */ | |
| public static String[] split(String input, String delimiter) { | |
| Vector node = new Vector(); | |
| int index = input.indexOf(delimiter); | |
| while (index >= 0) { | |
| node.addElement(input.substring(0, index)); | |
| input = input.substring(index + delimiter.length()); | |
| index = input.indexOf(delimiter); | |
| } | |
| node.addElement(input); | |
| String[] retString = new String[node.size()]; | |
| for (int i = 0; i < node.size(); ++i) { | |
| retString[i] = (String) node.elementAt(i); | |
| } | |
| return retString; | |
| } | |
| } |