下面列出了怎么用com.google.common.collect.ObjectArrays的API类实例代码及写法,或者点击链接到github查看源代码。
/**
* Create, compile, and run a unit test.
*
* @param testName An useful name for the unit test.
* @param pkg Qualified package name.
* @param cls Target class to be analyzed.
* @param expected Map of 'method signatures' to their 'expected list of NonNull parameters'.
* @param lines Source lines for the test code.
*/
private void testTemplate(
String testName,
String pkg, // in dot syntax
String cls,
Map<String, Set<Integer>> expected,
String... lines)
throws Exception {
boolean compileSucceeded =
compilerUtil
.addSourceLines(cls + ".java", ObjectArrays.concat("package " + pkg + ";\n", lines))
.run();
Assert.assertTrue(
testName + ": test compilation failed!\n" + compilerUtil.getOutput(), compileSucceeded);
DefinitelyDerefedParamsDriver driver = new DefinitelyDerefedParamsDriver();
Map<String, Set<Integer>> result =
driver.run(
temporaryFolder.getRoot().getAbsolutePath(), "L" + pkg.replaceAll("\\.", "/"), true);
Assert.assertTrue(
testName + ": test failed! \n" + result + " does not match " + expected,
verify(result, new HashMap<>(expected)));
}
protected static DataSource reloadDataSource(FlywayDataSourceContext dataSourceContext, Flyway flywayBean, FlywayTest annotation) throws Exception {
if (isAppendable(flywayBean, annotation)) {
return dataSourceContext.reload(flywayBean).get();
} else {
String[] oldLocations = getFlywayLocations(flywayBean);
try {
if (annotation.overrideLocations()) {
setFlywayLocations(flywayBean, annotation.locationsForMigrate());
} else {
setFlywayLocations(flywayBean, ObjectArrays.concat(oldLocations, annotation.locationsForMigrate(), String.class));
}
return dataSourceContext.reload(flywayBean).get();
} finally {
setFlywayLocations(flywayBean, oldLocations);
}
}
}
private static Exception throwCause(Exception e, boolean combineStackTraces) throws Exception {
Throwable cause = e.getCause();
if (cause == null) {
throw e;
}
if (combineStackTraces) {
StackTraceElement[] combined = ObjectArrays.concat(cause.getStackTrace(), e.getStackTrace(), StackTraceElement.class);
cause.setStackTrace(combined);
}
if (cause instanceof Exception) {
throw (Exception) cause;
}
if (cause instanceof Error) {
throw (Error) cause;
}
// The cause is a weird kind of Throwable, so throw the outer exception.
throw e;
}
private static Exception throwCause(Exception e, boolean combineStackTraces) throws Exception {
Throwable cause = e.getCause();
if (cause == null) {
throw e;
}
if (combineStackTraces) {
StackTraceElement[] combined = ObjectArrays.concat(cause.getStackTrace(), e.getStackTrace(), StackTraceElement.class);
cause.setStackTrace(combined);
}
if (cause instanceof Exception) {
throw (Exception) cause;
}
if (cause instanceof Error) {
throw (Error) cause;
}
// The cause is a weird kind of Throwable, so throw the outer exception.
throw e;
}
/**
* Waits and verifies that the texts of user status messages in the page are equal to the expected texts.
* The check is done multiple times with waiting times in between to account for
* timing issues due to page load, inconsistencies in Selenium API, etc.
*/
public void waitForTextsForAllStatusMessagesToUserEquals(String firstExpectedText, String... remainingExpectedTexts) {
List<String> expectedTexts = Arrays.asList(ObjectArrays.concat(firstExpectedText, remainingExpectedTexts));
try {
uiRetryManager.runUntilNoRecognizedException(new RetryableTask("Verify status to user") {
@Override
public void run() {
// Scroll to status message because it must be visible in order to get its text
new Actions(browser.driver).moveToElement(statusMessage).perform();
waitForElementVisibility(statusMessage);
assertEquals(expectedTexts, getTextsForAllStatusMessagesToUser());
}
}, WebDriverException.class, AssertionError.class);
} catch (MaximumRetriesExceededException e) {
assertEquals(expectedTexts, getTextsForAllStatusMessagesToUser());
}
}
private static Exception throwCause(Exception e, boolean combineStackTraces) throws Exception {
Throwable cause = e.getCause();
if (cause == null) {
throw e;
}
if (combineStackTraces) {
StackTraceElement[] combined = ObjectArrays.concat(cause.getStackTrace(), e.getStackTrace(), StackTraceElement.class);
cause.setStackTrace(combined);
}
if (cause instanceof Exception) {
throw (Exception) cause;
}
if (cause instanceof Error) {
throw (Error) cause;
}
// The cause is a weird kind of Throwable, so throw the outer exception.
throw e;
}
private static Exception throwCause(Exception e, boolean combineStackTraces) throws Exception {
Throwable cause = e.getCause();
if (cause == null) {
throw e;
}
if (combineStackTraces) {
StackTraceElement[] combined =
ObjectArrays.concat(cause.getStackTrace(), e.getStackTrace(), StackTraceElement.class);
cause.setStackTrace(combined);
}
if (cause instanceof Exception) {
throw (Exception) cause;
}
if (cause instanceof Error) {
throw (Error) cause;
}
// The cause is a weird kind of Throwable, so throw the outer exception.
throw e;
}
@Override
public Page<DTO> queryForCollection(
int pageIndex,
int pageSize,
String sortingRsql,
String query,
Predicate<DB>... predicates) {
Predicate<DB> rsqlPredicate = rsqlPredicateProducer.getCriteriaPredicate(type, query);
PageInfo pageInfo = pageInfoProducer.getPageInfo(pageIndex, pageSize);
SortInfo sortInfo = rsqlPredicateProducer.getSortInfo(type, sortingRsql);
List<DB> collection = repository
.queryWithPredicates(pageInfo, sortInfo, ObjectArrays.concat(rsqlPredicate, predicates));
int totalHits = repository.count(ObjectArrays.concat(rsqlPredicate, predicates));
int totalPages = (totalHits + pageSize - 1) / pageSize;
List<DTO> content = nullableStreamOf(collection).map(mapper::toDTO).collect(Collectors.toList());
return new Page<>(pageIndex, pageSize, totalPages, totalHits, content);
}
private void insertMenuEntry(MenuEntry newEntry, MenuEntry[] entries, boolean after)
{
MenuEntry[] newMenu = ObjectArrays.concat(entries, newEntry);
if (after)
{
int menuEntryCount = newMenu.length;
ArrayUtils.swap(newMenu, menuEntryCount - 1, menuEntryCount - 2);
}
client.setMenuEntries(newMenu);
}
static void logError(Throwable t, String format, Object... args)
{
if (isExpectedError(t)) {
log.error(format + ": %s", ObjectArrays.concat(args, t));
}
else {
log.error(t, format, args);
}
}
/**
* Returns a new TrustSource containing the same trusted CAs as this TrustSource, plus zero or more additional
* trusted X509Certificates. If trustedCertificates is null or empty, returns this same TrustSource.
*
* @param trustedCertificates X509Certificates of CAs to trust
* @return a new TrustSource containing this TrustSource's trusted CAs plus the specified CAs
*/
public TrustSource add(X509Certificate... trustedCertificates) {
if (trustedCertificates == null || trustedCertificates.length == 0) {
return this;
}
X509Certificate[] newTrustedCAs = ObjectArrays.concat(trustedCAs, trustedCertificates, X509Certificate.class);
return new TrustSource(newTrustedCAs);
}
public <V extends Comparable<? super V>> ConfigValue<V> defineInRange(List<String> path, Supplier<V> defaultSupplier, V min, V max, Class<V> clazz) {
Range<V> range = new Range<>(clazz, min, max);
context.setRange(range);
context.setComment(ObjectArrays.concat(context.getComment(), "Range: " + range.toString()));
if (min.compareTo(max) > 0) {
throw new IllegalArgumentException("Range min most be less then max.");
}
return define(path, defaultSupplier, range);
}
/**
* Returns a new TrustSource containing the same trusted CAs as this TrustSource, plus zero or more additional
* trusted X509Certificates. If trustedCertificates is null or empty, returns this same TrustSource.
*
* @param trustedCertificates X509Certificates of CAs to trust
* @return a new TrustSource containing this TrustSource's trusted CAs plus the specified CAs
*/
public TrustSource add(X509Certificate... trustedCertificates) {
if (trustedCertificates == null || trustedCertificates.length == 0) {
return this;
}
X509Certificate[] newTrustedCAs = ObjectArrays.concat(trustedCAs, trustedCertificates, X509Certificate.class);
return new TrustSource(newTrustedCAs);
}
public static XmlNode androidManifestForFeature(
String packageName, ManifestMutator... manifestMutators) {
return androidManifest(
packageName,
ObjectArrays.concat(
new ManifestMutator[] {withOnDemandAttribute(true), withFusingAttribute(true)},
manifestMutators,
ManifestMutator.class));
}
private static Block getAdjacentRegionBlock(Region region, Block origin) {
for(BlockFace face : ObjectArrays.concat(CARDINAL_DIRECTIONS, DIAGONAL_DIRECTIONS, BlockFace.class)) {
Block adjacent = origin.getRelative(face);
if(region.contains(BlockUtils.center(adjacent).toVector())) {
return adjacent;
}
}
return null;
}
public IAndroidTarget[] getTargets(boolean includeMissing) {
IAndroidTarget[] result = getTargets();
if (includeMissing) {
result = ObjectArrays.concat(result, getMissingTargets(), IAndroidTarget.class);
}
return result;
}
public GetIndexRequest addFeatures(Feature... features) {
if (this.features == DEFAULT_FEATURES) {
return features(features);
} else {
return features(ObjectArrays.concat(featuresAsEnums(), features, Feature.class));
}
}
/**
* Create a new string array with 'moreEntries' appended to the 'entries'
* array.
* @param entries initial entries in the array
* @param moreEntries variable-length additional entries.
* @return an array containing entries with all of moreEntries appended.
*/
protected String [] newStrArray(String [] entries, String... moreEntries) {
if (null == moreEntries) {
return entries;
}
if (null == entries) {
entries = new String[0];
}
return ObjectArrays.concat(entries, moreEntries, String.class);
}
private SendSequence beginSequence(Optional<SendInterceptor> sequenceInterceptor, int expectedResponses, Object... objects) {
if (requiresRset) {
if (ehloResponse.isSupported(Extension.PIPELINING)) {
return new SendSequence(sequenceInterceptor, expectedResponses + 1, ObjectArrays.concat(SmtpRequests.rset(), objects));
} else {
return new SendSequence(sequenceInterceptor, 1, SmtpRequests.rset()).thenSend(objects);
}
} else {
requiresRset = true;
return new SendSequence(sequenceInterceptor, expectedResponses, objects);
}
}
private void addDataBlocks() {
try(RollbackCloseable rollbackable = new RollbackCloseable()) {
// make sure can fit the next batch.
listener.addBatch();
{
FixedBlockVector newFixed = new FixedBlockVector(allocator, pivot.getBlockWidth());
rollbackable.add(newFixed);
newFixed.ensureAvailableBlocks(MAX_VALUES_PER_BATCH);
fixedBlocks = ObjectArrays.concat(fixedBlocks, newFixed);
tableFixedAddresses = Longs.concat(tableFixedAddresses, new long[]{newFixed.getMemoryAddress()});
}
{
VariableBlockVector newVariable = new VariableBlockVector(allocator, pivot.getVariableCount());
rollbackable.add(newVariable);
newVariable.ensureAvailableDataSpace(pivot.getVariableCount() == 0 ? 0 : MAX_VALUES_PER_BATCH * defaultVariableLengthSize);
variableBlocks = ObjectArrays.concat(variableBlocks, newVariable);
initVariableAddresses = Longs.concat(initVariableAddresses, new long[]{newVariable.getMemoryAddress()});
openVariableAddresses = Longs.concat(openVariableAddresses, new long[]{newVariable.getMemoryAddress()});
maxVariableAddresses = Longs.concat(maxVariableAddresses, new long[]{newVariable.getMaxMemoryAddress()});
}
rollbackable.commit();
} catch (Exception e) {
throw Throwables.propagate(e);
}
}
private void addDataBlocks(){
// make sure can fit the next batch.
listener.resized(currentOrdinal + MAX_VALUES_PER_BATCH);
try(RollbackCloseable rollbackable = new RollbackCloseable()) {
{
FixedBlockVector newFixed = new FixedBlockVector(allocator, pivot.getBlockWidth());
rollbackable.add(newFixed);
newFixed.ensureAvailableBlocks(MAX_VALUES_PER_BATCH);
fixedBlocks = ObjectArrays.concat(fixedBlocks, newFixed);
tableFixedAddresses = Longs.concat(tableFixedAddresses, new long[]{newFixed.getMemoryAddress()});
}
{
VariableBlockVector newVariable = new VariableBlockVector(allocator, pivot.getVariableCount());
rollbackable.add(newVariable);
newVariable.ensureAvailableDataSpace(pivot.getVariableCount() == 0 ? 0 : MAX_VALUES_PER_BATCH * defaultVariableLengthSize);
variableBlocks = ObjectArrays.concat(variableBlocks, newVariable);
initVariableAddresses = Longs.concat(initVariableAddresses, new long[]{newVariable.getMemoryAddress()});
openVariableAddresses = Longs.concat(openVariableAddresses, new long[]{newVariable.getMemoryAddress()});
maxVariableAddresses = Longs.concat(maxVariableAddresses, new long[]{newVariable.getMaxMemoryAddress()});
}
rollbackable.commit();
} catch (Exception e) {
throw Throwables.propagate(e);
}
}
@Override
public void onCreate() {
Context context = getApplicationContext();
String defaultPrefsName = getDefaultSharedPreferencesName(context);
String[] accountsPrefsNames = AccountsUtils.getSharedPreferencesNamesForAllAccounts(context);
SharedPreferencesBackupHelper helper =
new SharedPreferencesBackupHelper(
this, ObjectArrays.concat(defaultPrefsName, accountsPrefsNames));
addHelper(PREFS_BACKUP_KEY, helper);
}
private String[] getCommandArgsForShowOutputOrShowOutputs(
String showOutputCommand, String... args) {
if (useShowOutputs) {
return ObjectArrays.concat(
SHOW_OUTPUT_TO_SHOW_OUTPUTS.get(showOutputCommand), args, String.class);
}
return ObjectArrays.concat(showOutputCommand, args);
}
@Subscribe
public void onMenuEntryAdded(MenuEntryAdded event)
{
final int groupId = WidgetInfo.TO_GROUP(event.getActionParam1());
// Look for "Message" on friends list
if ((groupId == WidgetInfo.FRIENDS_LIST.getGroupId() && event.getOption().equals("Message")) ||
(groupId == WidgetInfo.IGNORE_LIST.getGroupId() && event.getOption().equals("Delete")))
{
// Friends have color tags
setHoveredFriend(Text.toJagexName(Text.removeTags(event.getTarget())));
// Build "Add Note" or "Edit Note" menu entry
final MenuEntry addNote = new MenuEntry();
addNote.setOption(hoveredFriend == null || hoveredFriend.getNote() == null ? ADD_NOTE : EDIT_NOTE);
addNote.setType(MenuAction.RUNELITE.getId());
addNote.setTarget(event.getTarget()); //Preserve color codes here
addNote.setParam0(event.getActionParam0());
addNote.setParam1(event.getActionParam1());
// Add menu entry
final MenuEntry[] menuEntries = ObjectArrays.concat(client.getMenuEntries(), addNote);
client.setMenuEntries(menuEntries);
}
else if (hoveredFriend != null)
{
hoveredFriend = null;
}
}
@Test
public void join_two_object_arrays_in_java_with_guava() {
String[] allStateCapitals = ObjectArrays.concat(firstHalfStateCapital,
secondHalfStateCapital, String.class);
assertTrue(allStateCapitals.length == 50);
}
private void insertMenuEntry(MenuEntry newEntry, MenuEntry[] entries, boolean after)
{
MenuEntry[] newMenu = ObjectArrays.concat(entries, newEntry);
if (after)
{
int menuEntryCount = newMenu.length;
ArrayUtils.swap(newMenu, menuEntryCount - 1, menuEntryCount - 2);
}
client.setMenuEntries(newMenu);
}
/**
* Returns a new TrustSource containing the same trusted CAs as this TrustSource, plus zero or more additional
* trusted X509Certificates. If trustedCertificates is null or empty, returns this same TrustSource.
*
* @param trustedCertificates X509Certificates of CAs to trust
* @return a new TrustSource containing this TrustSource's trusted CAs plus the specified CAs
*/
public TrustSource add(X509Certificate... trustedCertificates) {
if (trustedCertificates == null || trustedCertificates.length == 0) {
return this;
}
X509Certificate[] newTrustedCAs = ObjectArrays.concat(trustedCAs, trustedCertificates, X509Certificate.class);
return new TrustSource(newTrustedCAs);
}
public static Row append(Row row, String fieldName, DataType fieldType, boolean nullable, Object value) {
StructType appendedSchema = row.schema().add(fieldName, fieldType, nullable);
Object[] appendedValues = ObjectArrays.concat(valuesFor(row), value);
Row appendedRow = new RowWithSchema(appendedSchema, appendedValues);
return appendedRow;
}
static @Nullable String[] concat(@Nullable String[] first, @Nullable String[] second) {
if (first == null)
return second;
if (second == null)
return first;
return ObjectArrays.concat(first, second, String.class);
}
public static void addRequiredAttributes(SecurityState state, String[] requiredAttributes) {
if (state.requiredAttributes == null) {
state.requiredAttributes = requiredAttributes;
} else {
state.requiredAttributes =
ObjectArrays.concat(state.requiredAttributes, requiredAttributes, String.class);
}
}