public boolean run(String actionName, Profiler profiler, String[] args) { monitor.outcomeStarted(this, testClass.getName(), actionName); String[] arguments = ObjectArrays.concat(testClass.getName(), args); if (profile) { arguments = ObjectArrays.concat("--debug", arguments); } try { if (profiler != null) { profiler.start(); } new Runner().run(arguments); } catch (Exception ex) { ex.printStackTrace(); } finally { if (profiler != null) { profiler.stop(); } } monitor.outcomeFinished(Result.SUCCESS); return true; }
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 void prepareDataSourceContext(FlywayDataSourceContext dataSourceContext, Flyway flywayBean, FlywayTest annotation) throws Exception { if (isAppendable(flywayBean, annotation)) { dataSourceContext.reload(flywayBean); } else { String[] oldLocations = flywayBean.getLocations(); try { if (annotation.overrideLocations()) { flywayBean.setLocations(annotation.locationsForMigrate()); } else { flywayBean.setLocations(ObjectArrays.concat(oldLocations, annotation.locationsForMigrate(), String.class)); } dataSourceContext.reload(flywayBean); } finally { flywayBean.setLocations(oldLocations); } } }
public void findModDirMods(File modsDir, File[] supplementalModFileCandidates) { File[] modList = FileListHelper.sortFileList(modsDir, null); modList = FileListHelper.sortFileList(ObjectArrays.concat(modList, supplementalModFileCandidates, File.class)); for (File modFile : modList) { // skip loaded coremods if (CoreModManager.getIgnoredMods().contains(modFile.getName())) { FMLLog.finer("Skipping already parsed coremod or tweaker %s", modFile.getName()); } else if (modFile.isDirectory()) { FMLLog.fine("Found a candidate mod directory %s", modFile.getName()); addCandidate(new ModCandidate(modFile, modFile, ContainerType.DIR)); } else { Matcher matcher = zipJar.matcher(modFile.getName()); if (matcher.matches()) { FMLLog.fine("Found a candidate zip or jar file %s", matcher.group(0)); addCandidate(new ModCandidate(modFile, modFile, ContainerType.JAR)); } else { FMLLog.fine("Ignoring unknown file %s in mods directory", modFile.getName()); } } } }
@SuppressWarnings("MissingSuperCall") @Override protected Tool parseArguments(String[] args) { commandName = Iterables.getFirst(arguments(args), Command.help.name()); commandArgs = removeFirst(commandName, args); // Special behavior for help if (options(args).contains("--help")) { commandArgs = removeFirst("--help", ObjectArrays.concat(commandName, commandArgs)); commandName = Command.help.name(); args = removeFirst("--help", args); } // Display our version number and stop (note that commands can still override '--version') if (options(args).contains("--version") && (commandName.equals(Command.help.name()) || isBefore("--version", commandName, args))) { printVersion(); return doNothing(); } // Do not delegate to the super, allow the commands to do the parsing return this; }
/** * Add a new Module. * * @param module Module to add. */ public void addModule(Module module) throws DatabaseControllerException { try { //Notice: Changed order of values to avoid having to concat twice! databaseConnector.executeSql("insert into " + DatabaseContract.ElectronicModule.TABLE_NAME + " (" + DatabaseContract.ElectronicModule.COLUMN_GPIO_PIN + ", " + DatabaseContract.ElectronicModule.COLUMN_USB_PORT + ", " + DatabaseContract.ElectronicModule.COLUMN_WLAN_PORT + ", " + DatabaseContract.ElectronicModule.COLUMN_WLAN_USERNAME + ", " + DatabaseContract.ElectronicModule.COLUMN_WLAN_PASSWORD + ", " + DatabaseContract.ElectronicModule.COLUMN_WLAN_IP + ", " + DatabaseContract.ElectronicModule.COLUMN_MODULE_TYPE + ", " + DatabaseContract.ElectronicModule.COLUMN_CONNECTOR_TYPE + ", " + DatabaseContract.ElectronicModule.COLUMN_SLAVE_ID + ", " + DatabaseContract.ElectronicModule.COLUMN_NAME + ") values " + "(?, ?, ?, ?, ?, ?, ?, ?, (" + DatabaseContract.SqlQueries.SLAVE_ID_FROM_FINGERPRINT_SQL_QUERY + "), ?)", ObjectArrays.concat( createCombinedModulesAccessInformationFromSingle(module.getModuleAccessPoint()), new String[]{module.getModuleType().toString(), module.getModuleAccessPoint().getType(), module.getAtSlave().getIDString(), module.getName()}, String.class)); } catch (SQLiteConstraintException sqlce) { throw new DatabaseControllerException("The given Slave does not exist in the database" + " or the name is already used by another Module", sqlce); } }
public int getLatestRatingPageCount(int tenantId, int itemTypeId, Date since) { final StringBuilder query = new StringBuilder("SELECT CEIL(count(*) / ?)"); query.append("\n"); query.append("FROM ").append(DEFAULT_TABLE_NAME).append("\n"); query.append("WHERE "); query.append(DEFAULT_TENANT_COLUMN_NAME).append(" = ? AND "); query.append(DEFAULT_ITEM_TYPE_COLUMN_NAME).append(" = ?"); Object[] args = new Object[]{PAGE_SIZE, tenantId, itemTypeId}; int[] argt = new int[]{Types.INTEGER, Types.INTEGER, Types.INTEGER}; if (since != null) { query.append(" AND ").append(DEFAULT_ACTION_TIME_COLUMN_NAME).append(" > ?"); args = ObjectArrays.concat(args, since); argt = Ints.concat(argt, new int[]{Types.TIMESTAMP}); } int count = getJdbcTemplate().queryForInt(query.toString(), args, argt); return count; }
protected String getRecommendationIteratorQueryString(TimeConstraintVO timeConstraints, ArgsAndTypesHolder holder) { StringBuilder query = new StringBuilder("SELECT * FROM "); query.append(DEFAULT_TABLE_NAME); if (timeConstraints.getDateFrom() != null) { query.append(" WHERE "); query.append(DEFAULT_RECOMMENDATION_TIME_COLUMN_NAME); query.append(" >= ?"); holder.getArgs()[0] = timeConstraints.getDateFrom(); if (timeConstraints.getDateTo() != null) { query.append(" AND "); query.append(DEFAULT_RECOMMENDATION_TIME_COLUMN_NAME); query.append(" <= ?"); holder.setArgs(ObjectArrays.concat(holder.getArgs(), timeConstraints.getDateTo())); holder.setArgTypes(Ints.concat(holder.getArgTypes(), new int[] { Types.TIMESTAMP })); } } else { query.append(" WHERE "); query.append(DEFAULT_RECOMMENDATION_TIME_COLUMN_NAME); query.append(" <= ?"); holder.getArgs()[0] = timeConstraints.getDateTo(); } return query.toString(); }
/** * Removes the first occurrence of a given value from an array, if it is present in the array. * The array is assumed to be unordered. * * @param array * to remove the value from; may be {@code null} * @param value * to remove; must not be {@code null} * @return an array not containing the first occurrence of value, but containing all other elements of * the original array. If the original array does not contain the given value, the returned * array is == identical to the array passed in. */ public T[] remove(final T[] array, final T value) { if (array == null) { return null; } int i = find(array, value); if (i == 0 && array.length == 1) { return null; } if (i >= 0) { // Found it: remove value. i is guaranteed to be < array.length here. T[] newArray = ObjectArrays.newArray(componentType, array.length - 1); if (i > 0) { System.arraycopy(array, 0, newArray, 0, i); } if (i + 1 < array.length) { System.arraycopy(array, i + 1, newArray, i, array.length - i - 1); } return newArray; } return array; }
private static OreSpawnData getOreData(String category, String type, String size, String blockName, int meta, int rarity, String[] rocks, int min, int max, int v, int h) { oresConfig = TFC_ConfigFiles.getOresConfig(); String[] ALLOWED_TYPES = new String[] { "default", "veins" }; String[] ALLOWED_SIZES = new String[] { "small", "medium", "large" }; String[] ALLOWED_BASE_ROCKS = ObjectArrays.concat(Global.STONE_ALL, new String[] { "igneous intrusive", "igneous extrusive", "sedimentary", "metamorphic" }, String.class); return new OreSpawnData( oresConfig.get(category, "type", type).setValidValues(ALLOWED_TYPES).getString(), oresConfig.get(category, "size", size).setValidValues(ALLOWED_SIZES).getString(), oresConfig.get(category, "oreName", blockName).getString(), oresConfig.get(category, "oreMeta", meta).getInt(), oresConfig.get(category, "rarity", rarity).getInt(), oresConfig.get(category, "baseRocks", rocks).setValidValues(ALLOWED_BASE_ROCKS).getStringList(), oresConfig.get(category, "Minimum Height", min).getInt(), oresConfig.get(category, "Maximum Height", max).getInt(), oresConfig.get(category, "Vertical Density", v).getInt(), oresConfig.get(category, "Horizontal Density", h).getInt() ); }
/** * {@inheritDoc} */ @Override public void unlinkCommits(Repository domain, RepositoryPullRequestMapping request, Iterable<? extends RepositoryCommitMapping> commits) { Iterable<Integer> commitIds = Iterables.transform(commits, new Function<RepositoryCommitMapping, Integer>() { @Override public Integer apply(final RepositoryCommitMapping repositoryCommitMapping) { return repositoryCommitMapping.getID(); } }); final String baseWhereClause = ActiveObjectsUtils.renderListOperator(RepositoryPullRequestToCommitMapping.COMMIT, "IN", "OR", commitIds); Query query = Query.select().where(RepositoryPullRequestToCommitMapping.REQUEST_ID + " = ? AND " + baseWhereClause, ObjectArrays.concat(request.getID(), Iterables.toArray(commitIds, Object.class))); ActiveObjectsUtils.delete(activeObjects, RepositoryPullRequestToCommitMapping.class, query); }
@Override public List<RepositoryPullRequestMapping> getByIssueKeys(final Iterable<String> issueKeys) { Collection<Integer> prIds = findRelatedPullRequests(issueKeys); if (prIds.isEmpty()) { return Lists.newArrayList(); } final String whereClause = ActiveObjectsUtils.renderListOperator("pr.ID", "IN", "OR", prIds).toString(); final Object [] params = ObjectArrays.concat(new Object[]{Boolean.FALSE, Boolean.TRUE}, prIds.toArray(), Object.class); Query select = Query.select() .alias(RepositoryMapping.class, "repo") .alias(RepositoryPullRequestMapping.class, "pr") .join(RepositoryMapping.class, "repo.ID = pr." + RepositoryPullRequestMapping.TO_REPO_ID) .where("repo." + RepositoryMapping.DELETED + " = ? AND repo." + RepositoryMapping.LINKED + " = ? AND " + whereClause, params); return Arrays.asList(activeObjects.find(RepositoryPullRequestMapping.class, select)); }
@Override public List<RepositoryPullRequestMapping> getByIssueKeys(final Iterable<String> issueKeys, final String dvcsType) { Collection<Integer> prIds = findRelatedPullRequests(issueKeys); if (prIds.isEmpty()) { return Lists.newArrayList(); } final String whereClause = ActiveObjectsUtils.renderListOperator("pr.ID", "IN", "OR", prIds).toString(); final Object [] params = ObjectArrays.concat(new Object[] { dvcsType, Boolean.FALSE, Boolean.TRUE }, prIds.toArray(), Object.class); Query select = Query.select() .alias(RepositoryMapping.class, "repo") .alias(RepositoryPullRequestMapping.class, "pr") .alias(OrganizationMapping.class, "org") .join(RepositoryMapping.class, "repo.ID = pr." + RepositoryPullRequestMapping.TO_REPO_ID) .join(OrganizationMapping.class, "repo." + RepositoryMapping.ORGANIZATION_ID + " = org.ID") .where("org." + OrganizationMapping.DVCS_TYPE + " = ? AND repo." + RepositoryMapping.DELETED + " = ? AND repo." + RepositoryMapping.LINKED + " = ? AND " + whereClause, params); return Arrays.asList(activeObjects.find(RepositoryPullRequestMapping.class, select)); }
@Override public Optional<User> addOrgUser(UserRequest userRequest, UUID orgGuid, String currentUser) { Optional<UserIdNamePair> idNamePair = uaaClient.findUserIdByName(userRequest.getUsername()); if(!idNamePair.isPresent()) { inviteUserToOrg(userRequest.getUsername(), currentUser, orgGuid, ImmutableSet.<Role>builder() .addAll(userRequest.getRoles()) .add(Role.USERS) .build()); } return idNamePair.map(pair -> { UUID userGuid = pair.getGuid(); Role[] roles = ObjectArrays .concat(userRequest.getRoles().toArray(new Role[]{}), Role.USERS); assignOrgRolesToUser(userGuid, orgGuid, roles); return new User(userRequest.getUsername(), userGuid, userRequest.getRoles(), orgGuid); }); }
/** * Returns a String of all the UUIDs, comma separated, of the player's UUID given. * * @param pUUID * Player UUID * @param isRecursive * Is the search recursive? * @return the alt accounts of the player, or null if an error occurs. */ public BaseAccount[] getAltsOfPlayer(final UUID pUUID, final boolean isRecursive) { ResultSet rs; BaseAccount[] array = new BaseAccount[0]; try { rs = getResultSet("SELECT * FROM " + s.dbPrefix + "iplog WHERE uuid = \"" + pUUID.toString() + "\";"); while (rs.next()) { final ResultSet ipSet = getResultSet("SELECT * FROM " + s.dbPrefix + "iplog WHERE ip = \"" + rs.getString("ip") + "\";"); while (ipSet.next()) array = ObjectArrays.concat(array, new UUIDAlt(UUID.fromString(ipSet.getString("uuid")), ipSet.getString("ip"))); ipSet.close(); } rs.close(); if (isRecursive) return format(recursivePlayerSearch(array)); return format(array); } catch (final SQLException e) { error(e); return null; } }
public static IStatus addNatureToProjectDescription(IProjectDescription description, String natureId) { String[] natureIds = description.getNatureIds(); // calculate new nature IDs if (Arrays.asList(natureIds).contains(natureId)) { return Status.OK_STATUS; } natureIds = ObjectArrays.concat(description.getNatureIds(), natureId); // validate the natures IWorkspace workspace = ResourcesPlugin.getWorkspace(); IStatus validationResult = workspace.validateNatureSet(natureIds); if (validationResult.getCode() == IStatus.OK) { description.setNatureIds(natureIds); } return validationResult; }
@Override public UserSolution createUserSolution(Set<E> edges, Set<EdgeCycle<E>> cycles) { IloIntVar[] variables = ObjectArrays.concat(edgeVariables.getVars(), cycleVariables.getVars(), IloIntVar.class); double[] values = new double[edgeVariables.size() + cycleVariables.size()]; int ansPos = 0; for (IloIntVar edgeVar : edgeVariables.getVars()) { if (edges.contains(edgeVariables.getInverse(edgeVar))) { values[ansPos] = 1.0; } else { values[ansPos] = 0.0; } ansPos++; } for (IloIntVar cycleVar : cycleVariables.getVars()) { if (cycles.contains(cycleVariables.getInverse(cycleVar))) { values[ansPos] = 1.0; } else { values[ansPos] = 0.0; } ansPos++; } return new UserSolution(variables, values); }
public List<Integer> getItemTypeIds(Integer tenantId, Boolean visible) { Preconditions.checkNotNull(tenantId, "missing constraints: missing 'tenantId'"); Object[] args = new Object[]{tenantId}; int[] argTypes = new int[]{Types.INTEGER}; StringBuilder sqlString = new StringBuilder("SELECT "); sqlString.append(DEFAULT_ID_COLUMN_NAME); sqlString.append(" FROM "); sqlString.append(DEFAULT_TABLE_NAME); sqlString.append(" WHERE "); sqlString.append(DEFAULT_TENANT_COLUMN_NAME); sqlString.append(" =?"); if (visible != null) { sqlString.append(" AND ").append(DEFAULT_VISIBLE_COLUMN_NAME).append("=?"); args = ObjectArrays.concat(args, visible); argTypes = Ints.concat(argTypes, new int[]{Types.BIT}); } return getJdbcTemplate().queryForList(sqlString.toString(), args, argTypes, Integer.class); }
/** * Find the class for the specified name by using dynamic repository. */ @Override protected Class<?> findClass(String name) throws ClassNotFoundException { try { return Class.forName(name); } catch (ClassNotFoundException exc1) { URLClassLoader loader = newInstance(ObjectArrays.concat( this.getURLs(), this.urls.toArray(new URL[this.urls.size()]), URL.class), this.getParent()); Class<?> cls = loader.loadClass(name); try { loader.close(); } catch (IOException exc2) { LOG.error("Failed to close the URL class loader.", exc2); } return cls; } }
/** * Returns the fragment of text, which is matching the specified pattern, * otherwise {@code null}. */ @Override public String[] translate(String str) throws Exception { Matcher matcher = super.pattern.matcher(str); String[] fragments = new String[0]; while (matcher.find()) { fragments = ObjectArrays.concat(fragments, str.substring(matcher.start(), matcher.end())); } if (fragments.length > 0) { return fragments; } else { return null; } }
protected <T> T[] readSignal(Class<T> t, OffsetLength offsetLength) throws ReconException { if (offsetLength.getOffset() == 0 || offsetLength.getLength() == 0) { throw new ReconException("Cannot read signal as offset and length invalid " + offsetLength); } try { byte[] bytes = new byte[offsetLength.getLength()]; if (offsetLength.getLength() == resource.read(offsetLength.getOffset(), bytes)) { if (isCompressed()) { bytes = Compression.decompress(bytes); } BufferUnpacker unpacker = getMessagePack().createBufferUnpacker(bytes); int arrayLength = unpacker.readArrayBegin(); T[] out = ObjectArrays.newArray(t, arrayLength); for (int i = 0; i < arrayLength; i++) { out[i] = (T) readObject(unpacker); } unpacker.readArrayEnd(); unpacker.close(); return out; } throw new ReconException("Failed to read signal at location"); } catch (IOException ex) { throw new ReconException("Failed to read signal", ex); } }
public AndSpec<T> and(Spec<? super T>... specs) { if (specs.length == 0) { return this; } Spec<? super T>[] thisSpecs = getSpecsArray(); int thisLength = thisSpecs.length; if (thisLength == 0) { return new AndSpec<T>(specs); } Spec<? super T>[] combinedSpecs = uncheckedCast(ObjectArrays.newArray(Spec.class, thisLength + specs.length)); System.arraycopy(thisSpecs, 0, combinedSpecs, 0, thisLength); System.arraycopy(specs, 0, combinedSpecs, thisLength, specs.length); return new AndSpec<T>(combinedSpecs); }