Java Code Examples for com.google.common.collect.ObjectArrays#concat()

The following examples show how to use com.google.common.collect.ObjectArrays#concat() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SimpleTimeLimiter.java    From codebuff with BSD 2-Clause "Simplified" License 6 votes vote down vote up
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;
}
 
Example 2
Source File: SimpleTimeLimiter.java    From codebuff with BSD 2-Clause "Simplified" License 6 votes vote down vote up
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;
}
 
Example 3
Source File: LaneMatchModule.java    From ProjectAres with GNU Affero General Public License v3.0 5 votes vote down vote up
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;
}
 
Example 4
Source File: SimpleBackupAgent.java    From science-journal with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example 5
Source File: LBlockHashTableNoSpill.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
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);
    }
  }
 
Example 6
Source File: TrustSource.java    From AndroidHttpCapture with MIT License 5 votes vote down vote up
/**
 * 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);
}
 
Example 7
Source File: Proto.java    From immutables with Apache License 2.0 5 votes vote down vote up
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);
}
 
Example 8
Source File: GrammarElementsInterner.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
EObject[] prependedGrammarElements() {
	if(grammarElements instanceof EObject) {
		return new EObject[] {grammarElement, (EObject) grammarElements};
	} else {
		return ObjectArrays.concat(grammarElement, (EObject[]) grammarElements);
	}
}
 
Example 9
Source File: TrustSource.java    From CapturePacket with MIT License 5 votes vote down vote up
/**
 * 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);
}
 
Example 10
Source File: TrustSource.java    From browserup-proxy with Apache License 2.0 5 votes vote down vote up
/**
 * 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);
}
 
Example 11
Source File: RedirectInjector.java    From Mixin with MIT License 5 votes vote down vote up
RedirectedInvokeData(Target target, MethodInsnNode node) {
    super(target);
    this.node = node;
    this.returnType = Type.getReturnType(node.desc);
    this.targetArgs = Type.getArgumentTypes(node.desc);
    this.handlerArgs = node.getOpcode() == Opcodes.INVOKESTATIC
            ? this.targetArgs
            : ObjectArrays.concat(Type.getObjectType(node.owner), this.targetArgs);
}
 
Example 12
Source File: ArrayUtil.java    From vjtools with Apache License 2.0 4 votes vote down vote up
/**
 * 添加元素到数组末尾.
 */
public static <T> T[] concat(T[] array, @Nullable T element) {
	return ObjectArrays.concat(array, element);
}
 
Example 13
Source File: IntersectionInt.java    From opennars with MIT License 4 votes vote down vote up
/**
 * Try to make a new compound from two term. Called by the inference rules.
 * @param term1 The first component
 * @param term2 The second component
 * @return A compound generated or a term it reduced to
 */
public static Term make(final Term term1, final Term term2) {
    
    if ((term1 instanceof SetExt) && (term2 instanceof SetExt)) {
        // set union
        final Term[] both = ObjectArrays.concat(
                ((CompoundTerm) term1).term, 
                ((CompoundTerm) term2).term, Term.class);
        return SetExt.make(both);
    }
    if ((term1 instanceof SetInt) && (term2 instanceof SetInt)) {
        // set intersection
        final NavigableSet<Term> set = Term.toSortedSet(((CompoundTerm) term1).term);
        
        set.retainAll(((CompoundTerm) term2).asTermList());     
        
        //technically this can be used directly if it can be converted to array
        //but wait until we can verify that NavigableSet.toarray does it or write a helper function like existed previously
        return SetInt.make(set.toArray(new Term[0]));
    }
    
    final List<Term> se = new ArrayList();
    if (term1 instanceof IntersectionInt) {
        ((CompoundTerm) term1).addTermsTo(se);
        if (term2 instanceof IntersectionInt) {
            // (&,(&,P,Q),(&,R,S)) = (&,P,Q,R,S)                
            ((CompoundTerm) term2).addTermsTo(se);
        }               
        else {
            // (&,(&,P,Q),R) = (&,P,Q,R)
            se.add(term2);
        }               
    } else if (term2 instanceof IntersectionInt) {
        // (&,R,(&,P,Q)) = (&,P,Q,R)
        ((CompoundTerm) term2).addTermsTo(se);
        se.add(term1);
    } else {
        se.add(term1);
        se.add(term2);
    }
    return make(se.toArray(new Term[0]));
}
 
Example 14
Source File: XtextEditor.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
@Override
protected String[] collectContextMenuPreferencePages() {
	String[] commonPages = super.collectContextMenuPreferencePages();
	String[] langSpecificPages = collectLanguageContextMenuPreferencePages();
	return ObjectArrays.concat(langSpecificPages, commonPages, String.class);
}
 
Example 15
Source File: ArrayUtil.java    From vjtools with Apache License 2.0 4 votes vote down vote up
/**
 * 添加元素到数组头.
 */
public static <T> T[] concat(@Nullable T element, T[] array) {
	return ObjectArrays.concat(element, array);
}
 
Example 16
Source File: RepositoryPaginatorContext.java    From business with Mozilla Public License 2.0 4 votes vote down vote up
private Repository.Option[] applyOffset(Repository.Option[] options, long offset) {
    return ObjectArrays.concat(options, new OffsetOption(offset));
}
 
Example 17
Source File: Global.java    From NationStatesPlusPlus with MIT License 4 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public <T extends EssentialFilter> Class<T>[] filters() {
	return (Class[]) ObjectArrays.concat(GzipFilter.class, super.filters());
}
 
Example 18
Source File: RepositoryPaginatorContext.java    From business with Mozilla Public License 2.0 4 votes vote down vote up
private Repository.Option[] applyLimit(Repository.Option[] options, long limit) {
    return ObjectArrays.concat(options, new LimitOption(limit));
}
 
Example 19
Source File: ArrayUtil.java    From j360-dubbo-app-all with Apache License 2.0 4 votes vote down vote up
/**
 * 添加元素到数组末尾,没有银弹,复制扩容.
 */
public static <T> T[] concat(T[] array, @Nullable T element) {
	return ObjectArrays.concat(array, element);
}
 
Example 20
Source File: LocalSeleniumGrid.java    From Selenium-Foundation with Apache License 2.0 2 votes vote down vote up
/**
 * Combine driver dependency contexts with the specified core Selenium Grid contexts.
 *
 * @param dependencyContexts core Selenium Grid dependency contexts
 * @param driverPlugin driver plug-in from which to acquire dependencies
 * @return combined contexts for Selenium Grid dependencies
 */
public static String[] combineDependencyContexts(String[] dependencyContexts, DriverPlugin driverPlugin) {
    return ObjectArrays.concat(dependencyContexts, driverPlugin.getDependencyContexts(), String.class);
}