Java Code Examples for com.google.common.collect.Lists#asList()

The following examples show how to use com.google.common.collect.Lists#asList() . 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: TableTest.java    From tablesaw with Apache License 2.0 6 votes vote down vote up
@Test
void testDoWithEachRow() throws Exception {
  Table t =
      Table.read()
          .csv(CsvReadOptions.builder("../data/bush.csv").minimizeColumnSizes())
          .first(10);
  Short[] ratingsArray = {53, 58};
  List<Short> ratings = Lists.asList((short) 52, ratingsArray);

  Consumer<Row> doable =
      row -> {
        if (row.getRowNumber() < 5) {
          assertTrue(ratings.contains(row.getShort("approval")));
        }
      };
  t.stream().forEach(doable);
}
 
Example 2
Source File: TestLogSegmentCache.java    From distributedlog with Apache License 2.0 5 votes vote down vote up
@Test(timeout = 60000)
public void testGapDetectionOnLogSegmentsWithoutLogSegmentSequenceNumber() throws Exception {
    LogSegmentCache cache = new LogSegmentCache("test-gap-detection");
    LogSegmentMetadata segment1 =
            DLMTestUtil.completedLogSegment("/segment-1", 1L, 1L, 100L, 100, 1L, 99L, 0L)
                    .mutator().setVersion(LogSegmentMetadata.LogSegmentMetadataVersion.VERSION_V1_ORIGINAL).build();
    cache.add(DLMTestUtil.completedLedgerZNodeNameWithLogSegmentSequenceNumber(1L), segment1);
    LogSegmentMetadata segment3 =
            DLMTestUtil.completedLogSegment("/segment-3", 3L, 3L, 300L, 100, 3L, 99L, 0L)
                    .mutator().setVersion(LogSegmentMetadata.LogSegmentMetadataVersion.VERSION_V2_LEDGER_SEQNO).build();
    cache.add(DLMTestUtil.completedLedgerZNodeNameWithLogSegmentSequenceNumber(3L), segment3);
    List<LogSegmentMetadata> expectedList = Lists.asList(segment1, new LogSegmentMetadata[] { segment3 });
    List<LogSegmentMetadata> resultList = cache.getLogSegments(LogSegmentMetadata.COMPARATOR);
    assertEquals(expectedList, resultList);
}
 
Example 3
Source File: HttpTestUtils.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
public static void assertContentContainsText(final String url, final String phrase, final String ...additionalPhrases) {
    try {
        String contents = getContent(url);
        Assert.assertTrue(contents != null && contents.length() > 0);
        for (String text: Lists.asList(phrase, additionalPhrases)) {
            if (!contents.contains(text)) {
                LOG.warn("CONTENTS OF URL "+url+" MISSING TEXT: "+text+"\n"+contents);
                Assert.fail("URL "+url+" does not contain text: "+text);
            }
        }
    } catch (Exception e) {
        throw Throwables.propagate(e);
    }
}
 
Example 4
Source File: NodeSourceParameterHelperTest.java    From scheduling with GNU Affero General Public License v3.0 5 votes vote down vote up
@Test
public void testNotDynamicParameterNotUpdated() {

    List<ConfigurableField> configurableFields = Lists.asList(this.notDynamicField, new ConfigurableField[] {});
    Object[] newParameters = { ATTEMPTED_CHANGE_VALUE };
    List<Serializable> oldParameters = Lists.asList(TO_BE_KEPT_VALUE, new Serializable[] {});

    List<Serializable> mergedParameters = this.nodeSourceParameterHelper.getParametersWithDynamicParametersUpdatedOnly(configurableFields,
                                                                                                                       newParameters,
                                                                                                                       oldParameters);
    assertThat(mergedParameters).hasSize(1);
    assertThat(mergedParameters.get(0)).isEqualTo(TO_BE_KEPT_VALUE);
}
 
Example 5
Source File: TestPerStreamLogSegmentCache.java    From distributedlog with Apache License 2.0 5 votes vote down vote up
@Test(timeout = 60000)
public void testGapDetectionOnLogSegmentsWithoutLogSegmentSequenceNumber() throws Exception {
    PerStreamLogSegmentCache cache = new PerStreamLogSegmentCache("test-gap-detection");
    LogSegmentMetadata segment1 =
            DLMTestUtil.completedLogSegment("/segment-1", 1L, 1L, 100L, 100, 1L, 99L, 0L)
                    .mutator().setVersion(LogSegmentMetadata.LogSegmentMetadataVersion.VERSION_V1_ORIGINAL).build();
    cache.add(DLMTestUtil.completedLedgerZNodeNameWithLogSegmentSequenceNumber(1L), segment1);
    LogSegmentMetadata segment3 =
            DLMTestUtil.completedLogSegment("/segment-3", 3L, 3L, 300L, 100, 3L, 99L, 0L)
            .mutator().setVersion(LogSegmentMetadata.LogSegmentMetadataVersion.VERSION_V2_LEDGER_SEQNO).build();
    cache.add(DLMTestUtil.completedLedgerZNodeNameWithLogSegmentSequenceNumber(3L), segment3);
    List<LogSegmentMetadata> expectedList = Lists.asList(segment1, new LogSegmentMetadata[] { segment3 });
    List<LogSegmentMetadata> resultList = cache.getLogSegments(LogSegmentMetadata.COMPARATOR);
    assertEquals(expectedList, resultList);
}
 
Example 6
Source File: Configuration.java    From jimfs with Apache License 2.0 5 votes vote down vote up
/**
 * Sets the roots for the file system.
 *
 * @throws InvalidPathException if any of the given roots is not a valid path for this builder's
 *     path type
 * @throws IllegalArgumentException if any of the given roots is a valid path for this builder's
 *     path type but is not a root path with no name elements
 */
public Builder setRoots(String first, String... more) {
  List<String> roots = Lists.asList(first, more);
  for (String root : roots) {
    PathType.ParseResult parseResult = pathType.parsePath(root);
    checkArgument(parseResult.isRoot(), "invalid root: %s", root);
  }
  this.roots = ImmutableSet.copyOf(roots);
  return this;
}
 
Example 7
Source File: HttpTestUtils.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
public static void assertErrorContentContainsText(final String url, final String phrase, final String ...additionalPhrases) {
    try {
        String contents = getErrorContent(url);
        Assert.assertTrue(contents != null && contents.length() > 0);
        for (String text: Lists.asList(phrase, additionalPhrases)) {
            if (!contents.contains(text)) {
                LOG.warn("CONTENTS OF URL "+url+" MISSING TEXT: "+text+"\n"+contents);
                Assert.fail("URL "+url+" does not contain text: "+text);
            }
        }
    } catch (Exception e) {
        throw Throwables.propagate(e);
    }
}
 
Example 8
Source File: CFDv2.java    From factura-electronica with Apache License 2.0 5 votes vote down vote up
private static JAXBContext getContext(String[] contexts) throws Exception {
    List<String> ctx = Lists.asList(BASE_CONTEXT, contexts);
    if(!contextMap.containsKey(ctx)) {
        JAXBContext context = JAXBContext.newInstance(JOINER.join(ctx));
        contextMap.put(ctx, context);
    }
    return contextMap.get(ctx);
}
 
Example 9
Source File: DaggerServletContextListener.java    From dagger-servlet with Apache License 2.0 4 votes vote down vote up
/**
 * @param urlPattern Any Servlet-style pattern. examples: /*, /html/*, *.html, etc.
 */
protected final ServletDefinitionBuilder serve(String urlPattern, String... morePatterns) {
    return new ServletDefinitionBuilderImpl(Lists.asList(urlPattern, morePatterns), UriPatternType.SERVLET);
}
 
Example 10
Source File: DaggerServletContextListener.java    From dagger-servlet with Apache License 2.0 4 votes vote down vote up
/**
 * @param regex Any Java-style regular expression.
 */
protected final ServletDefinitionBuilder serveRegex(String regex, String... moreRegexes) {
    return new ServletDefinitionBuilderImpl(Lists.asList(regex, moreRegexes), UriPatternType.REGEX);
}
 
Example 11
Source File: TokenTest.java    From helios with Apache License 2.0 4 votes vote down vote up
private List<String> buildArgs(final String token, String... args) {
  return token == null ? Arrays.asList(args) : Lists.asList(token, args);
}
 
Example 12
Source File: ExecutePlanActionTest.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
@Test
  public void testExecute() throws Exception {
    CloudSolrClient solrClient = cluster.getSolrClient();
    String collectionName = "testExecute";
    CollectionAdminRequest.Create create = CollectionAdminRequest.createCollection(collectionName,
        "conf", 1, 2);
    create.setMaxShardsPerNode(1);
    create.process(solrClient);
    
    cluster.waitForActiveCollection(collectionName, 1, 2);

    waitForState("Timed out waiting for replicas of new collection to be active",
        collectionName, clusterShape(1, 2));

    JettySolrRunner sourceNode = cluster.getRandomJetty(random());
    String sourceNodeName = sourceNode.getNodeName();
    ClusterState clusterState = solrClient.getZkStateReader().getClusterState();
    DocCollection docCollection = clusterState.getCollection(collectionName);
    List<Replica> replicas = docCollection.getReplicas(sourceNodeName);
    assertNotNull(replicas);
    assertFalse(replicas.isEmpty());

    List<JettySolrRunner> otherJetties = cluster.getJettySolrRunners().stream()
        .filter(jettySolrRunner -> jettySolrRunner != sourceNode).collect(Collectors.toList());
    assertFalse(otherJetties.isEmpty());
    JettySolrRunner survivor = otherJetties.get(0);

    try (ExecutePlanAction action = new ExecutePlanAction()) {
      action.configure(loader, cloudManager, Collections.singletonMap("name", "execute_plan"));

      // used to signal if we found that ExecutePlanAction did in fact create the right znode before executing the operation
      AtomicBoolean znodeCreated = new AtomicBoolean(false);

      CollectionAdminRequest.AsyncCollectionAdminRequest moveReplica = new CollectionAdminRequest.MoveReplica(collectionName, replicas.get(0).getName(), survivor.getNodeName());
      CollectionAdminRequest.AsyncCollectionAdminRequest mockRequest = new CollectionAdminRequest.AsyncCollectionAdminRequest(CollectionParams.CollectionAction.OVERSEERSTATUS) {
        @Override
        public void setAsyncId(String asyncId) {
          super.setAsyncId(asyncId);
          String parentPath = ZkStateReader.SOLR_AUTOSCALING_TRIGGER_STATE_PATH + "/xyz/execute_plan";
          try {
            if (zkClient().exists(parentPath, true)) {
              java.util.List<String> children = zkClient().getChildren(parentPath, null, true);
              if (!children.isEmpty()) {
                String child = children.get(0);
                byte[] data = zkClient().getData(parentPath + "/" + child, null, null, true);
                @SuppressWarnings({"rawtypes"})
                Map m = (Map) Utils.fromJSON(data);
                if (m.containsKey("requestid")) {
                  znodeCreated.set(m.get("requestid").equals(asyncId));
                }
              }
            }
          } catch (Exception e) {
            throw new RuntimeException(e);
          }

        }
      };
      List<CollectionAdminRequest.AsyncCollectionAdminRequest> operations = Lists.asList(moveReplica, new CollectionAdminRequest.AsyncCollectionAdminRequest[]{mockRequest});
      NodeLostTrigger.NodeLostEvent nodeLostEvent = new NodeLostTrigger.NodeLostEvent
        (TriggerEventType.NODELOST, "mock_trigger_name",
         Collections.singletonList(cloudManager.getTimeSource().getTimeNs()),
         Collections.singletonList(sourceNodeName),
         CollectionParams.CollectionAction.MOVEREPLICA.toLower());
      ActionContext actionContext = new ActionContext(survivor.getCoreContainer().getZkController().getSolrCloudManager(), null,
          new HashMap<>(Collections.singletonMap("operations", operations)));
      action.process(nodeLostEvent, actionContext);

//      assertTrue("ExecutePlanAction should have stored the requestid in ZK before executing the request", znodeCreated.get());
      @SuppressWarnings({"unchecked"})
      List<NamedList<Object>> responses = (List<NamedList<Object>>) actionContext.getProperty("responses");
      assertNotNull(responses);
      assertEquals(2, responses.size());
      NamedList<Object> response = responses.get(0);
      assertNull(response.get("failure"));
      assertNotNull(response.get("success"));
    }

    waitForState("Timed out waiting for replicas of new collection to be active",
        collectionName, clusterShape(1, 2));
  }
 
Example 13
Source File: DaggerServletContextListener.java    From dagger-servlet with Apache License 2.0 4 votes vote down vote up
/**
 * @param urlPattern Any Servlet-style pattern. examples: /*, /html/*, *.html, etc.
 */
protected final FilterDefinitionBuilder filter(String urlPattern, String... morePatterns) {
    return new FilterDefinitionBuilderImpl(Lists.asList(urlPattern, morePatterns), UriPatternType.SERVLET);
}
 
Example 14
Source File: RelOptRule.java    From Bats with Apache License 2.0 3 votes vote down vote up
/**
 * Creates a list of child operands that matches child relational
 * expressions in any order.
 *
 * <p>This is useful when matching a relational expression which
 * can have a variable number of children. For example, the rule to
 * eliminate empty children of a Union would have operands</p>
 *
 * <blockquote>Operand(Union, true, Operand(Empty))</blockquote>
 *
 * <p>and given the relational expressions</p>
 *
 * <blockquote>Union(LogicalFilter, Empty, LogicalProject)</blockquote>
 *
 * <p>would fire the rule with arguments</p>
 *
 * <blockquote>{Union, Empty}</blockquote>
 *
 * <p>It is up to the rule to deduce the other children, or indeed the
 * position of the matched child.</p>
 *
 * @param first First child operand
 * @param rest  Remaining child operands (may be empty)
 * @return List of child operands that matches child relational
 *   expressions in any order
 */
public static RelOptRuleOperandChildren unordered(
    RelOptRuleOperand first,
    RelOptRuleOperand... rest) {
  return new RelOptRuleOperandChildren(
      RelOptRuleOperandChildPolicy.UNORDERED,
      Lists.asList(first, rest));
}
 
Example 15
Source File: RelOptRule.java    From Bats with Apache License 2.0 3 votes vote down vote up
/**
 * Creates a list of child operands that matches child relational
 * expressions in the order they appear.
 *
 * @param first First child operand
 * @param rest  Remaining child operands (may be empty)
 * @return List of child operands that matches child relational
 *   expressions in the order
 */
public static RelOptRuleOperandChildren some(
    RelOptRuleOperand first,
    RelOptRuleOperand... rest) {
  return new RelOptRuleOperandChildren(RelOptRuleOperandChildPolicy.SOME,
      Lists.asList(first, rest));
}
 
Example 16
Source File: ProofMapIndexProxy.java    From exonum-java-binding with Apache License 2.0 3 votes vote down vote up
/**
 * Returns a proof that there are values mapped to the specified keys or that there are no such
 * mappings.
 *
 * @param key a proof map key which might be mapped to some value
 * @param otherKeys other proof map keys which might be mapped to some values
 * @throws IllegalStateException if this map is not valid
 * @throws IllegalArgumentException if the size of any of the keys is not 32 bytes (in case of a
 *     <a href="ProofMapIndexProxy.html#key-hashing">proof map that uses non-hashed keys</a>)
 * @see <a href="../../blockchain/Blockchain.html#proofs">Blockchain Proofs</a>
 */
@SafeVarargs
public final MapProof getProof(K key, K... otherKeys) {
  if (otherKeys.length == 0) {
    return getSingleKeyProof(key);
  } else {
    List<K> keys = Lists.asList(key, otherKeys);
    return getMultiKeyProof(keys);
  }
}
 
Example 17
Source File: ArrayUtil.java    From j360-dubbo-app-all with Apache License 2.0 2 votes vote down vote up
/**
 * 一个独立元素+一个数组组成新的list,只是一个View,不复制数组内容,而且独立元素在最前.
 *
 *
 * 注意转换后的List不能写入, 否则抛出UnsupportedOperationException
 *
 * @see com.google.common.collect.Lists#asList(Object, Object[])
 */
public static <E> List<E> asList(E first, E[] rest) {
	return Lists.asList(first, rest);
}
 
Example 18
Source File: PubUtil.java    From dartboard with Eclipse Public License 2.0 2 votes vote down vote up
/**
 * Constructs a process builder with the given {@code args}.
 * 
 * If pub is invoked from a tool there should be a PUB_ENVIRONMENT variable
 * present describing the tool. This methods returns a {@link ProcessBuilder}
 * that has it and the correct value in it.
 * 
 * @param args - the arguments passed to the ProcessBuilder
 * @return the {@link ProcessBuilder} with the correct environment variables and
 *         args
 */
public static ProcessBuilder getPubProcessBuilder(String... args) {
	ProcessBuilder builder = new ProcessBuilder(Lists.asList(DartUtil.getTool("pub"), args)); //$NON-NLS-1$
	builder.environment().put(Constants.PUB_ENVIRONMENT_VARIABLE, getUpdatePubEnviroment(builder));
	return builder;
}
 
Example 19
Source File: ExternalLibraryPreferenceModel.java    From n4js with Eclipse Public License 1.0 2 votes vote down vote up
/**
 * Creates a new model instance with the given location arguments.
 *
 * @param firstLocation
 *            the external library folder location.
 * @param restLocations
 *            other external library folder locations.
 */
public ExternalLibraryPreferenceModel(final FileURI firstLocation,
		final FileURI... restLocations) {
	this(Lists.asList(firstLocation, restLocations));
}
 
Example 20
Source File: MasterSlaveDataSourceFactory.java    From sharding-jdbc-1.5.1 with Apache License 2.0 2 votes vote down vote up
/**
 * 创建读写分离数据源.
 * 
 * @param name 读写分离数据源名称
 * @param masterDataSource 主节点数据源
 * @param slaveDataSource 从节点数据源
 * @param otherSlaveDataSources 其他从节点数据源
 * @return 读写分离数据源
 */
public static DataSource createDataSource(final String name, final DataSource masterDataSource, final DataSource slaveDataSource, final DataSource... otherSlaveDataSources) {
    return new MasterSlaveDataSource(name, masterDataSource, Lists.asList(slaveDataSource, otherSlaveDataSources));
}