Example usage for com.google.common.collect ObjectArrays concat

List of usage examples for com.google.common.collect ObjectArrays concat

Introduction

In this page you can find the example usage for com.google.common.collect ObjectArrays concat.

Prototype

public static <T> T[] concat(T[] array, @Nullable T element) 

Source Link

Document

Returns a new array that appends element to array .

Usage

From source file:com.eucalyptus.component.ServiceTransitions.java

private static State[] pathToStarted(Component.State fromState) {
    State[] transition = new State[] { fromState };
    switch (fromState) {
    case NOTREADY:
        break;/* w ww  .  j a va 2s.c o  m*/
    case LOADED:
        transition = ObjectArrays.concat(transition, Component.State.NOTREADY);
        break;
    default:
        transition = ObjectArrays.concat(pathToLoaded(fromState), Component.State.NOTREADY);
    }
    return transition;
}

From source file:co.cask.cdap.internal.app.services.http.AppFabricTestBase.java

protected static HttpResponse doPost(String resource, String body, Header[] headers) throws Exception {
    DefaultHttpClient client = new DefaultHttpClient();
    HttpPost post = new HttpPost(AppFabricTestBase.getEndPoint(resource));

    if (body != null) {
        post.setEntity(new StringEntity(body));
    }//from  www  .ja v  a 2  s  .com

    if (headers != null) {
        post.setHeaders(ObjectArrays.concat(AUTH_HEADER, headers));
    } else {
        post.setHeader(AUTH_HEADER);
    }
    return client.execute(post);
}

From source file:com.eucalyptus.component.ServiceTransitions.java

private static final State[] pathToDisabled(final Component.State fromState) {
    State[] transition = new State[] { fromState };
    switch (fromState) {
    case ENABLED:
    case DISABLED:
    case NOTREADY:
        transition = ObjectArrays.concat(transition, Component.State.DISABLED);
        break;//from ww w .  j  a v  a2  s .co m
    default:
        transition = ObjectArrays.concat(pathToStarted(fromState), Component.State.DISABLED);
    }
    return transition;
}

From source file:com.google.caliper.runner.DefaultRunner.java

public static void main(Class<? extends Benchmark> suite, String... args) {
    main(ObjectArrays.concat(args, suite.getName()));
}

From source file:com.eucalyptus.component.ServiceTransitions.java

private static final State[] pathToEnabled(final Component.State fromState) {
    State[] transition = new State[] { fromState };
    switch (fromState) {
    case ENABLED:
        transition = ObjectArrays.concat(transition, Component.State.ENABLED);
        break;/*ww w.  j a  v  a2s  .  c  o m*/
    default:
        transition = ObjectArrays.concat(pathToDisabled(fromState), Component.State.ENABLED);
    }
    return transition;
}

From source file:org.easyrec.store.dao.core.types.impl.AssocTypeDAOMysqlImpl.java

@LongCacheable
public HashMap<String, Integer> getMapping(Integer tenantId, Boolean visible) {
    Preconditions.checkNotNull(tenantId, "missing constraints: missing 'tenantId'");

    ResultSetExtractor<HashMap<String, Integer>> rse = new ResultSetExtractor<HashMap<String, Integer>>() {
        public HashMap<String, Integer> extractData(ResultSet rs) {
            HashMap<String, Integer> mapping = new HashMap<String, Integer>();
            try {
                while (rs.next())
                    mapping.put(DaoUtils.getStringIfPresent(rs, DEFAULT_NAME_COLUMN_NAME),
                            DaoUtils.getInteger(rs, DEFAULT_ID_COLUMN_NAME));

                return mapping;
            } catch (SQLException e) {
                logger.error("error occurred", e);
                throw new RuntimeException(e);
            }/*w  w w  . j a  v a2 s .  c o m*/
        }
    };

    StringBuilder sqlQuery = new StringBuilder("SELECT ");
    sqlQuery.append(DEFAULT_NAME_COLUMN_NAME);
    sqlQuery.append(", ");
    sqlQuery.append(DEFAULT_ID_COLUMN_NAME);
    sqlQuery.append(" FROM ");
    sqlQuery.append(DEFAULT_TABLE_NAME);
    sqlQuery.append(" WHERE ");
    sqlQuery.append(DEFAULT_TENANT_COLUMN_NAME);
    sqlQuery.append("=?");

    Object[] args = { tenantId };
    int[] argTypes = { Types.INTEGER };

    if (visible != null) {
        sqlQuery.append(" AND ").append(DEFAULT_VISIBLE_COLUMN_NAME);
        sqlQuery.append("=?");

        args = ObjectArrays.concat(args, visible);
        argTypes = Ints.concat(argTypes, new int[] { Types.BIT });
    }

    return getJdbcTemplate().query(sqlQuery.toString(), args, argTypes, rse);
}

From source file:de.tuberlin.uebb.jdae.diff.total.TDOperations.java

private final void addCompOps(CompositionProduct[][][] ops) {
    ops[0] = new CompositionProduct[subOps.params + 1][];
    ops[0][0] = new CompositionProduct[] { new CompositionProduct(0, 1, new IntPair[0]) };

    for (int i = 1; i <= subOps.params; ++i) {
        ops[0][i] = new CompositionProduct[] {
                new CompositionProduct(1, 1, new IntPair[] { new IntPair(0, i) }) };
    }/*from  w ww  .  j  a  v a 2 s .c o  m*/

    if (order > 0) {
        final TDOperations smaller = getInstance(order - 1, subOps.params);

        final CompositionProduct[][][] subCompOps = smaller.compOps;
        final Product[][][] multOps = smaller.multOps;

        for (int i = 0; i < subCompOps.length; ++i) {
            ops[i + 1] = new CompositionProduct[subOps.params + 1][];

            for (int j = 0; j < subCompOps[i].length; ++j) {
                final Product[] sum = multOps[i][j];
                final List<CompositionProduct> newComp = Lists.newArrayList();
                for (Product product : sum) {
                    final CompositionProduct[] lhs = subCompOps[product.elements.lhs_row][product.elements.lhs_column];
                    final int a_i = product.elements.rhs_row + 1;
                    final int a_j = product.elements.rhs_column;

                    for (CompositionProduct p : lhs) {
                        newComp.add(new CompositionProduct(p.key.f_order + 1, p.f_factor * product.factor,
                                ObjectArrays.concat(new IntPair(a_i, a_j), p.key.keys)));
                    }
                }

                ops[i + 1][j] = newComp.toArray(new CompositionProduct[newComp.size()]);
            }
        }
    }
}

From source file:org.easyrec.plugin.pearson.store.dao.impl.LatestActionDAOMysqlImpl.java

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 });
    }//from  www  . java 2s.c  om

    int count = getJdbcTemplate().queryForInt(query.toString(), args, argt);

    return count;
}

From source file:com.eucalyptus.component.ServiceTransitions.java

private static final State[] pathToStopped(final Component.State fromState) {
    State[] transition = new State[] { fromState };
    switch (fromState) {
    case ENABLED:
        transition = ObjectArrays.concat(transition, Component.State.DISABLED);
        //$FALL-THROUGH$
    case DISABLED:
    case NOTREADY:
    case BROKEN://ww w. ja v  a  2s .c  om
        transition = ObjectArrays.concat(transition, Component.State.STOPPED);
        break;
    case STOPPED:
        break;
    default:
        transition = ObjectArrays.concat(pathToStarted(fromState), Component.State.STOPPED);
    }
    return transition;
}

From source file:org.eclipse.che.plugin.docker.machine.ComposeMachineProviderImpl.java

@Inject
public ComposeMachineProviderImpl(DockerConnector docker,
        DockerConnectorConfiguration dockerConnectorConfiguration,
        UserSpecificDockerRegistryCredentialsProvider dockerCredentials,
        DockerMachineFactory dockerMachineFactory, DockerInstanceStopDetector dockerInstanceStopDetector,
        DockerContainerNameGenerator containerNameGenerator,
        @Named("machine.docker.dev_machine.machine_servers") Set<ServerConf> devMachineServers,
        @Named("machine.docker.machine_servers") Set<ServerConf> allMachinesServers,
        @Named("machine.docker.dev_machine.machine_volumes") Set<String> devMachineSystemVolumes,
        @Named("machine.docker.machine_volumes") Set<String> allMachinesSystemVolumes,
        @Nullable @Named("machine.docker.machine_extra_hosts") String allMachinesExtraHosts,
        WorkspaceFolderPathProvider workspaceFolderPathProvider,
        @Named("che.machine.projects.internal.storage") String projectFolderPath,
        @Named("machine.docker.pull_image") boolean doForcePullOnBuild,
        @Named("machine.docker.privilege_mode") boolean privilegeMode,
        @Named("machine.docker.dev_machine.machine_env") Set<String> devMachineEnvVariables,
        @Named("machine.docker.machine_env") Set<String> allMachinesEnvVariables,
        @Named("machine.docker.snapshot_use_registry") boolean snapshotUseRegistry,
        @Named("machine.docker.memory_swap_multiplier") double memorySwapMultiplier,
        @Named("machine.docker.networks") Set<Set<String>> additionalNetworks) throws IOException {
    this.docker = docker;
    this.dockerCredentials = dockerCredentials;
    this.dockerMachineFactory = dockerMachineFactory;
    this.dockerInstanceStopDetector = dockerInstanceStopDetector;
    this.containerNameGenerator = containerNameGenerator;
    this.workspaceFolderPathProvider = workspaceFolderPathProvider;
    this.doForcePullOnBuild = doForcePullOnBuild;
    this.privilegeMode = privilegeMode;
    this.projectFolderPath = projectFolderPath;
    this.snapshotUseRegistry = snapshotUseRegistry;
    // use-cases:
    //  -1  enable unlimited swap
    //  0   disable swap
    //  0.5 enable swap with size equal to half of current memory size
    //  1   enable swap with size equal to current memory size
    ////from  w ww .j  av  a 2  s  .  c  o m
    //  according to docker docs field  memorySwap should be equal to memory+swap
    //  we calculate this field as memorySwap=memory * (1+ multiplier) so we just add +1 to multiplier
    this.memorySwapMultiplier = memorySwapMultiplier == -1 ? -1 : memorySwapMultiplier + 1;

    allMachinesSystemVolumes = removeEmptyAndNullValues(allMachinesSystemVolumes);
    devMachineSystemVolumes = removeEmptyAndNullValues(devMachineSystemVolumes);

    allMachinesSystemVolumes = allMachinesSystemVolumes.stream().map(line -> line.split(";"))
            .flatMap(Arrays::stream).distinct().collect(Collectors.toSet());

    devMachineSystemVolumes = devMachineSystemVolumes.stream().map(line -> line.split(";"))
            .flatMap(Arrays::stream).distinct().collect(Collectors.toSet());

    if (SystemInfo.isWindows()) {
        allMachinesSystemVolumes = escapePaths(allMachinesSystemVolumes);
        devMachineSystemVolumes = escapePaths(devMachineSystemVolumes);
    }
    this.commonMachineSystemVolumes = new ArrayList<>(allMachinesSystemVolumes);
    List<String> devMachineVolumes = new ArrayList<>(
            allMachinesSystemVolumes.size() + devMachineSystemVolumes.size());
    devMachineVolumes.addAll(allMachinesSystemVolumes);
    devMachineVolumes.addAll(devMachineSystemVolumes);
    this.devMachineSystemVolumes = devMachineVolumes;

    this.devMachinePortsToExpose = new ArrayList<>(allMachinesServers.size() + devMachineServers.size());
    this.commonMachinePortsToExpose = new ArrayList<>(allMachinesServers.size());
    for (ServerConf serverConf : devMachineServers) {
        devMachinePortsToExpose.add(serverConf.getPort());
    }
    for (ServerConf serverConf : allMachinesServers) {
        commonMachinePortsToExpose.add(serverConf.getPort());
        devMachinePortsToExpose.add(serverConf.getPort());
    }

    allMachinesEnvVariables = removeEmptyAndNullValues(allMachinesEnvVariables);
    devMachineEnvVariables = removeEmptyAndNullValues(devMachineEnvVariables);
    this.commonMachineEnvVariables = new HashMap<>();
    this.devMachineEnvVariables = new HashMap<>();
    allMachinesEnvVariables.forEach(envVar -> {
        String[] split = envVar.split("=", 2);
        this.commonMachineEnvVariables.put(split[0], split[1]);
        this.devMachineEnvVariables.put(split[0], split[1]);
    });
    devMachineEnvVariables.forEach(envVar -> {
        String[] split = envVar.split("=", 2);
        this.devMachineEnvVariables.put(split[0], split[1]);
    });

    // always add Che server to hosts list
    String cheHost = dockerConnectorConfiguration.getDockerHostIp();
    String cheHostAlias = DockerInstanceRuntimeInfo.CHE_HOST.concat(":").concat(cheHost);
    if (isNullOrEmpty(allMachinesExtraHosts)) {
        this.allMachinesExtraHosts = new String[] { cheHostAlias };
    } else {
        this.allMachinesExtraHosts = ObjectArrays.concat(allMachinesExtraHosts.split(","), cheHostAlias);
    }

    this.additionalNetworks = additionalNetworks.stream().flatMap(Set::stream).collect(Collectors.toSet());

    // TODO single point of failure in case of highly loaded system
    executor = Executors.newCachedThreadPool(
            new ThreadFactoryBuilder().setNameFormat("MachineLogsStreamer-%d").setDaemon(true).build());
}