下面列出了怎么用java.lang.IllegalArgumentException的API类实例代码及写法,或者点击链接到github查看源代码。
public static MainFragmentArgs fromBundle(Bundle bundle) {
MainFragmentArgs result = new MainFragmentArgs();
if (bundle.containsKey("main")) {
result.main = bundle.getString("main");
} else {
throw new IllegalArgumentException("Required argument \"main\" is missing and does not have an android:defaultValue");
}
if (bundle.containsKey("optional")) {
result.optional = bundle.getInt("optional");
}
if (bundle.containsKey("reference")) {
result.reference = bundle.getInt("reference");
}
if (bundle.containsKey("floatArg")) {
result.floatArg = bundle.getFloat("floatArg");
}
if (bundle.containsKey("boolArg")) {
result.boolArg = bundle.getBoolean("boolArg");
}
return result;
}
/**
* Return a sub-FrameSet object starting at startFrame with max chunkSize members
* @param startFrameIndex Index of frame to start at; not the frame itself
* @param chunkSize Max number of frames per chunk
* @return String representation of the chunk, e.g. 1-1001x3
*/
public String getChunk(int startFrameIndex, int chunkSize) {
if (frameList.size() <= startFrameIndex || startFrameIndex < 0) {
String sf = String.valueOf(startFrameIndex);
String sz = String.valueOf(frameList.size() - 1);
throw new IllegalArgumentException("startFrameIndex " + sf + " is not in range 0-" + sz);
}
if (chunkSize == 1) {
// Chunksize of 1 so the FrameSet is just the startFrame
return String.valueOf(frameList.get(startFrameIndex));
}
int finalFrameIndex = frameList.size() - 1;
int endFrameIndex = startFrameIndex + chunkSize - 1;
if (endFrameIndex > finalFrameIndex) {
// We don't have enough frames, so return the remaining frames.
endFrameIndex = finalFrameIndex;
}
return framesToFrameRanges(frameList.subList(startFrameIndex, endFrameIndex+1));
}
public LocationProvider getInstance (Integer locationProvider) {
LocationProvider provider;
switch (locationProvider) {
case Config.DISTANCE_FILTER_PROVIDER:
provider = new DistanceFilterLocationProvider(mContext);
break;
case Config.ACTIVITY_PROVIDER:
provider = new ActivityRecognitionLocationProvider(mContext);
break;
case Config.RAW_PROVIDER:
provider = new RawLocationProvider(mContext);
break;
default:
throw new IllegalArgumentException("Provider not found");
}
return provider;
}
/**
* Convert a tag string into a tag map.
*
* @param tagString a space-delimited string of key-value pairs. For example, {@code "key1=value1 key_n=value_n"}
* @return a tag {@link Map}
* @throws IllegalArgumentException if the tag string is corrupted.
*/
public static Map<String, String> parseTags(final String tagString) throws IllegalArgumentException {
// delimit by whitespace or '='
Scanner scanner = new Scanner(tagString).useDelimiter("\\s+|=");
Map<String, String> tagMap = new HashMap<String, String>();
try {
while (scanner.hasNext()) {
String tagName = scanner.next();
String tagValue = scanner.next();
tagMap.put(tagName, tagValue);
}
} catch (NoSuchElementException e) {
// The tag string is corrupted.
throw new IllegalArgumentException("Invalid tag string '" + tagString + "'");
} finally {
scanner.close();
}
return tagMap;
}
@Override
public final Property getProperty(String columnName) {
columnName = QueryBuilder.quoteIfNeeded(columnName);
switch ((columnName)) {
case "`wId`": {
return wId;
}
case "`id`": {
return id;
}
case "`icon`": {
return icon;
}
case "`description`": {
return description;
}
case "`main`": {
return main;
}
default: {
throw new IllegalArgumentException("Invalid column name passed. Ensure you are calling the correct table's column");
}
}
}
@Override
public final Property getProperty(String columnName) {
columnName = QueryBuilder.quoteIfNeeded(columnName);
switch ((columnName)) {
case "`id`": {
return id;
}
case "`message`": {
return message;
}
case "`cnt`": {
return cnt;
}
case "`cod`": {
return cod;
}
case "`dt`": {
return dt;
}
default: {
throw new IllegalArgumentException("Invalid column name passed. Ensure you are calling the correct table's column");
}
}
}
@Override
public final Property getProperty(String columnName) {
columnName = QueryBuilder.quoteIfNeeded(columnName);
switch ((columnName)) {
case "`id`": {
return id;
}
case "`dt`": {
return dt;
}
case "`rainCount`": {
return rainCount;
}
default: {
throw new IllegalArgumentException("Invalid column name passed. Ensure you are calling the correct table's column");
}
}
}
@Override
public final Property getProperty(String columnName) {
columnName = QueryBuilder.quoteIfNeeded(columnName);
switch ((columnName)) {
case "`id`": {
return id;
}
case "`dt`": {
return dt;
}
case "`dt_txt`": {
return dt_txt;
}
default: {
throw new IllegalArgumentException("Invalid column name passed. Ensure you are calling the correct table's column");
}
}
}
@Override
public final Property getProperty(String columnName) {
columnName = QueryBuilder.quoteIfNeeded(columnName);
switch ((columnName)) {
case "`id`": {
return id;
}
case "`speed`": {
return speed;
}
case "`deg`": {
return deg;
}
default: {
throw new IllegalArgumentException("Invalid column name passed. Ensure you are calling the correct table's column");
}
}
}
public Task.Status fromProto(TaskPb.Task.Status from) {
Task.Status to;
switch (from) {
case IN_PROGRESS: to = Task.Status.IN_PROGRESS; break;
case CANCELED: to = Task.Status.CANCELED; break;
case FAILED: to = Task.Status.FAILED; break;
case FAILED_WITH_TERMINAL_ERROR: to = Task.Status.FAILED_WITH_TERMINAL_ERROR; break;
case COMPLETED: to = Task.Status.COMPLETED; break;
case COMPLETED_WITH_ERRORS: to = Task.Status.COMPLETED_WITH_ERRORS; break;
case SCHEDULED: to = Task.Status.SCHEDULED; break;
case TIMED_OUT: to = Task.Status.TIMED_OUT; break;
case SKIPPED: to = Task.Status.SKIPPED; break;
default: throw new IllegalArgumentException("Unexpected enum constant: " + from);
}
return to;
}
public void checkValid() {
if (this.javaExec == null || this.javaExec.equals("")) {
throw new IllegalArgumentException("Repairnator Process building failed: java executable location is null");
}
if (this.jarLocation == null || this.jarLocation.equals("")) {
throw new IllegalArgumentException("Repairnator Process building failed: repairnator JAR location is null");
}
if (this.gitUrl == null || this.gitUrl.equals("")) {
throw new IllegalArgumentException("Repairnator Process building failed: no git url provided");
}
if (this.gitBranch == null || this.gitBranch.equals("")) {
throw new IllegalArgumentException("Repairnator Process building failed: no git branch provided");
}
if (this.repairTools == null || this.repairTools.equals("")) {
throw new IllegalArgumentException("Repairnator Process building failed: no repair tools specified");
}
}
public IncomingTextMessage decrypt(Context context, IncomingTextMessage message)
throws LegacyMessageException, InvalidMessageException, DuplicateMessageException,
NoSessionException, UntrustedIdentityException
{
try {
byte[] decoded = transportDetails.getDecodedMessage(message.getMessageBody().getBytes());
SignalMessage signalMessage = new SignalMessage(decoded);
SessionCipher sessionCipher = new SessionCipher(signalProtocolStore, new SignalProtocolAddress(message.getSender(), 1));
byte[] padded = sessionCipher.decrypt(signalMessage);
byte[] plaintext = transportDetails.getStrippedPaddingMessageBody(padded);
if (message.isEndSession() && "TERMINATE".equals(new String(plaintext))) {
signalProtocolStore.deleteSession(new SignalProtocolAddress(message.getSender(), 1));
}
return message.withMessageBody(new String(plaintext));
} catch (IOException | IllegalArgumentException | NullPointerException e) {
throw new InvalidMessageException(e);
}
}
/**
* @param queryVecStore Vector store to use for query generation.
* @param searchVecStore The vector store to search.
* @param luceneUtils LuceneUtils object to use for query weighting. (May be null.)
* @param queryTerms Terms that will be parsed into a query
* expression. If the string "?" appears, terms best fitting into this position will be returned
*/
public VectorSearcherPerm(VectorStore queryVecStore,
VectorStore searchVecStore,
LuceneUtils luceneUtils,
FlagConfig flagConfig,
String[] queryTerms)
throws IllegalArgumentException, ZeroVectorException {
super(queryVecStore, searchVecStore, luceneUtils, flagConfig);
try {
theAvg = pitt.search.semanticvectors.CompoundVectorBuilder.
getPermutedQueryVector(queryVecStore, luceneUtils, flagConfig, queryTerms);
} catch (IllegalArgumentException e) {
logger.info("Couldn't create permutation VectorSearcher ...");
throw e;
}
if (theAvg.isZeroVector()) {
throw new ZeroVectorException("Permutation query vector is zero ... no results.");
}
}
/**
* @param queryVecStore Vector store to use for query generation (this is also reversed).
* @param searchVecStore The vector store to search (this is also reversed).
* @param luceneUtils LuceneUtils object to use for query weighting. (May be null.)
* @param queryTerms Terms that will be parsed into a query
* expression. If the string "?" appears, terms best fitting into this position will be returned
*/
public BalancedVectorSearcherPerm(
VectorStore queryVecStore, VectorStore searchVecStore, LuceneUtils luceneUtils,
FlagConfig flagConfig, String[] queryTerms)
throws IllegalArgumentException, ZeroVectorException {
super(queryVecStore, searchVecStore, luceneUtils, flagConfig);
specialFlagConfig = flagConfig;
specialLuceneUtils = luceneUtils;
try {
oneDirection = pitt.search.semanticvectors.CompoundVectorBuilder.
getPermutedQueryVector(queryVecStore, luceneUtils, flagConfig, queryTerms);
otherDirection = pitt.search.semanticvectors.CompoundVectorBuilder.
getPermutedQueryVector(searchVecStore, luceneUtils, flagConfig, queryTerms);
} catch (IllegalArgumentException e) {
logger.info("Couldn't create balanced permutation VectorSearcher ...");
throw e;
}
if (oneDirection.isZeroVector()) {
throw new ZeroVectorException("Permutation query vector is zero ... no results.");
}
}
/**
* Lucene search, no semantic vectors required
* @param luceneUtils LuceneUtils object to use for query weighting. (May not be null.)
* @param queryTerms Terms that will be parsed into a query expression
*/
public VectorSearcherLucene(LuceneUtils luceneUtils,
FlagConfig flagConfig, String[] queryTerms)
throws IllegalArgumentException, ZeroVectorException {
super(null, null, luceneUtils, flagConfig);
this.specialLuceneUtils = luceneUtils;
this.specialFlagConfig = flagConfig;
Directory dir;
try {
dir = FSDirectory.open(FileSystems.getDefault().getPath(flagConfig.luceneindexpath()));
this.iSearcher = new IndexSearcher(DirectoryReader.open(dir));
if (!flagConfig.elementalvectorfile().equals("elementalvectors"))
{this.acceptableTerms = new VectorStoreRAM(flagConfig);
acceptableTerms.initFromFile(flagConfig.elementalvectorfile());
}
} catch (IOException e) {
logger.info("Lucene index initialization failed: "+e.getMessage());
}
this.queryTerms = queryTerms;
}
/**
* Sort the integers in the buffer
* @param order (as of version 2.9)
* it can be either ASCENDING or DESCENDING
*/
public void sort(int order) {
switch (order) {
case ASCENDING:
if (size > 0)
quickSort_ascending(0, size - 1);
break;
case DESCENDING:
if (size > 0)
quickSort_descending(0, size - 1);
break;
default:
throw new IllegalArgumentException("Sort type undefined");
}
}
/**
* Checks if the specified array is neither null nor empty.
*
* @param array the array to check
* @throws IllegalArgumentException if {@code array} is either {@code null} or empty
*/
private static void validateArray(final Object array) {
if (array == null) {
throw new IllegalArgumentException("The Array must not be null");
} else if (Array.getLength(array) == 0) {
throw new IllegalArgumentException("Array cannot be empty.");
}
}
/** Create the {@link Algorithm} to be used for signing and parsing tokens. */
private static Algorithm createAlgorithm(String secret) {
try {
return Algorithm.HMAC256(secret);
} catch (IllegalArgumentException e) {
throw new RuntimeException(e); // TODO: Better error handling
}
}
/**
* ContextBuffer constructor comment.
* inc is the # of int to be pushed/pop to/from the underlying storage
* @param i int
*/
public ContextBuffer(int i) {
super();
pageSize =1024;
n = 10; //1<<10 == 1024
r = pageSize - 1;
incSize = i;
if (incSize<0)
throw new IllegalArgumentException();
bufferArrayList = new arrayList();
}
public void windowActivated(WindowEvent e) {
logger.entering(getClass().getName(), "windowActivated");
WeakReference<RootPaneContainer> ww = getWeak((RootPaneContainer)e.getWindow());
if (ww != null) {
// place as last item in zOrder list
zOrder.remove(ww);
zOrder.add(ww);
} else {
throw new IllegalArgumentException("Window not attached: " + e.getWindow()); //NOI18N
}
}
@Override
public final IllegalArgumentException paramCannotBeNull(final String param) {
final IllegalArgumentException result = new IllegalArgumentException(String.format(getLoggingLocale(), paramCannotBeNull1$str(), param));
final StackTraceElement[] st = result.getStackTrace();
result.setStackTrace(Arrays.copyOfRange(st, 1, st.length));
return result;
}
@Override
public final IllegalArgumentException paramCannotBeNull(final String param, final String componentType, final String name) {
final IllegalArgumentException result = new IllegalArgumentException(String.format(getLoggingLocale(), paramCannotBeNull3$str(), param, componentType, name));
final StackTraceElement[] st = result.getStackTrace();
result.setStackTrace(Arrays.copyOfRange(st, 1, st.length));
return result;
}
@Override
public final IllegalArgumentException twoServletsWithSameMapping(final String path) {
final IllegalArgumentException result = new IllegalArgumentException(String.format(getLoggingLocale(), twoServletsWithSameMapping$str(), path));
final StackTraceElement[] st = result.getStackTrace();
result.setStackTrace(Arrays.copyOfRange(st, 1, st.length));
return result;
}
@Override
public final IllegalArgumentException headerCannotBeConvertedToDate(final String header) {
final IllegalArgumentException result = new IllegalArgumentException(String.format(getLoggingLocale(), headerCannotBeConvertedToDate$str(), header));
final StackTraceElement[] st = result.getStackTrace();
result.setStackTrace(Arrays.copyOfRange(st, 1, st.length));
return result;
}
@Override
public final IllegalArgumentException servletMustImplementServlet(final String name, final Class<? extends javax.servlet.Servlet> servletClass) {
final IllegalArgumentException result = new IllegalArgumentException(String.format(getLoggingLocale(), servletMustImplementServlet$str(), name, servletClass));
final StackTraceElement[] st = result.getStackTrace();
result.setStackTrace(Arrays.copyOfRange(st, 1, st.length));
return result;
}
@Override
public final IllegalArgumentException componentMustHaveDefaultConstructor(final String componentType, final Class<?> componentClass) {
final IllegalArgumentException result = new IllegalArgumentException(String.format(getLoggingLocale(), componentMustHaveDefaultConstructor$str(), componentType, componentClass));
final StackTraceElement[] st = result.getStackTrace();
result.setStackTrace(Arrays.copyOfRange(st, 1, st.length));
return result;
}
/**
* ContextBuffer constructor comment.
* incSize is the # of int to be pushed/pop to/from the underlying storage
* Creation date: (11/16/03 8:02:21 PM)
* @param p int (pageSize equals (1<<p)
* @param i int
*/
public ContextBuffer(int p, int i) {
if (p<0)throw new IllegalArgumentException("invalid Buffer size");
pageSize = (1<<p);
r = pageSize - 1;
n = p;
incSize = i;
if (incSize < 0)
throw new IllegalArgumentException("context buffer's incremental size must be greater than zero");
bufferArrayList = new ArrayList();
}
@Override
public final IllegalArgumentException listenerMustImplementListenerClass(final Class<?> listenerClass) {
final IllegalArgumentException result = new IllegalArgumentException(String.format(getLoggingLocale(), listenerMustImplementListenerClass$str(), listenerClass));
final StackTraceElement[] st = result.getStackTrace();
result.setStackTrace(Arrays.copyOfRange(st, 1, st.length));
return result;
}
@Test(expected = IllegalArgumentException.class)
public void testName() throws Exception {
String baseUrl = System.getProperty("cache.base.url");
HttpGet get = new HttpGet(baseUrl);
CloseableHttpClient httpClient = HttpClients.createDefault();
try (CloseableHttpResponse response = httpClient.execute(get)) {
HttpEntity entity = response.getEntity();
EntityUtils.consume(entity);
}
}
@Override
public final IllegalArgumentException responseWasNotOriginalOrWrapper(final ServletResponse response) {
final IllegalArgumentException result = new IllegalArgumentException(String.format(getLoggingLocale(), responseWasNotOriginalOrWrapper$str(), response));
final StackTraceElement[] st = result.getStackTrace();
result.setStackTrace(Arrays.copyOfRange(st, 1, st.length));
return result;
}