java.util.Collections#singleton ( )源码实例Demo

下面列出了java.util.Collections#singleton ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: FHIR   文件: DerbyMigrationTest.java
@Test
public void testMigrateFhirSchema() throws Exception {
    Set<String> resourceTypes = Collections.singleton("Observation");

    // 1. Create the new schema
    String dbPath = TARGET_DIR + "2020-1";
    try (DerbyMaster db_2020_1 = new DerbyMaster(TARGET_DIR + "2020-1")) {
        createOrUpgradeSchema(resourceTypes, db_2020_1);
        List<String> db_2020_1_ddl = inferDDL(dbPath);

        // 2. Create the old schema
        dbPath = TARGET_DIR + "2019";
        try (DerbyMaster db_2019 = createOldDerbyDatabase(dbPath, resourceTypes)) {

            // 3. Upgrade the old schema to the new one
            createOrUpgradeSchema(resourceTypes, db_2019);
            System.out.println("FHIR database migrated successfully.");

            // 4. Assert they match
            List<String> db_2019_migrated_ddl = inferDDL(dbPath);
            System.out.println("2019 migrated: " + db_2019_migrated_ddl);
            System.out.println("2020-1: " + db_2020_1_ddl);
            assertEquals(db_2020_1_ddl, db_2019_migrated_ddl);
        }
    }
}
 
源代码2 项目: SPDS   文件: HasNextStateMachine.java
@Override
public Set<WeightedForwardQuery<TransitionFunction>> generateSeed(SootMethod method, Unit unit) {
    Iterator<Edge> edIt = Scene.v().getCallGraph().edgesOutOf(unit);
    while (edIt.hasNext()) {
        SootMethod m = edIt.next().getTgt().method();
        if (retrieveIteratorConstructors().contains(m)) {
            Stmt stmt = ((Stmt) unit);
            InvokeExpr invokeExpr = stmt.getInvokeExpr();
            if (stmt instanceof AssignStmt) {
                AssignStmt assignStmt = (AssignStmt) stmt;
                InstanceInvokeExpr iie = (InstanceInvokeExpr) invokeExpr;
                return Collections
                        .singleton(new WeightedForwardQuery<>(
                                new Statement(stmt, method), new AllocVal(assignStmt.getLeftOp(), method,
                                        assignStmt.getLeftOp(), new Statement((Stmt) unit, m)),
                                initialTransition()));
            }
        }
    }
    return Collections.emptySet();
}
 
源代码3 项目: wallride   文件: WebGuestComponentScanRegistrar.java
private Set<String> getPackagesToScan(AnnotationMetadata metadata) {
	AnnotationAttributes attributes = AnnotationAttributes
			.fromMap(metadata.getAnnotationAttributes(WebGuestComponentScan.class.getName()));
	String[] value = attributes.getStringArray("value");
	String[] basePackages = attributes.getStringArray("basePackages");
	Class<?>[] basePackageClasses = attributes.getClassArray("basePackageClasses");
	if (!ObjectUtils.isEmpty(value)) {
		Assert.state(ObjectUtils.isEmpty(basePackages),
				"@WebGuestComponentScan basePackages and value attributes are mutually exclusive");
	}
	Set<String> packagesToScan = new LinkedHashSet<String>();
	packagesToScan.addAll(Arrays.asList(value));
	packagesToScan.addAll(Arrays.asList(basePackages));
	for (Class<?> basePackageClass : basePackageClasses) {
		packagesToScan.add(ClassUtils.getPackageName(basePackageClass));
	}
	if (packagesToScan.isEmpty()) {
		return Collections.singleton(ClassUtils.getPackageName(metadata.getClassName()));
	}
	return packagesToScan;
}
 
源代码4 项目: geode-examples   文件: TrainStopSerializer.java
@Override
public Collection<Document> toDocuments(LuceneIndex index, TrainStop value) {

  Document doc = new Document();
  // Index the name of the train stop
  doc.add(new TextField("name", value.getName(), Field.Store.NO));

  Field[] fields = SpatialHelper.getIndexableFields(value.getLongitude(), value.getLatitude());

  for (Field field : fields) {
    doc.add(field);
  }

  return Collections.singleton(doc);
}
 
源代码5 项目: openjdk-jdk9   文件: SnippetTemplate.java
@Override
public Collection<LocationIdentity> getLocations() {
    if (locationIdentity == null) {
        return Collections.emptySet();
    } else {
        return Collections.singleton(locationIdentity);
    }
}
 
源代码6 项目: nexus-public   文件: PrivilegeApiResourceTest.java
@Test
public void testCreatePrivilege_applicationWithAllAction() {
  when(authorizationManager.getPrivilege("name")).thenThrow(new NoSuchPrivilegeException("name"));

  ApiPrivilegeApplicationRequest apiPrivilege = new ApiPrivilegeApplicationRequest("name", "description", "domain",
      Collections.singleton(PrivilegeAction.ALL));

  underTest.createPrivilege(apiPrivilege);

  ArgumentCaptor<Privilege> argument = ArgumentCaptor.forClass(Privilege.class);
  verify(authorizationManager).addPrivilege(argument.capture());
  assertPrivilege(argument.getValue(), "name", "description", DOMAIN_KEY, "domain", ACTIONS_KEY, "*");
}
 
源代码7 项目: datawave   文件: QueryFunctions.java
public static Collection<?> between(Object field, String left, boolean leftInclusive, String right, boolean rightInclusive) {
    // we only want to test against the normalized variant to be consistent with the DatawaveArithmetic
    String fieldValue = ValueTuple.getNormalizedStringValue(field);
    if (fieldValue != null) {
        int leftComparison = fieldValue.compareTo(left);
        if (leftComparison > 0 || (leftInclusive && leftComparison == 0)) {
            int rightComparison = fieldValue.compareTo(right);
            if (rightComparison < 0 || (rightInclusive && rightComparison == 0)) {
                return Collections.singleton(getHitTermString(field));
            }
        }
    }
    return Collections.emptySet();
}
 
源代码8 项目: Logisim   文件: ModelEditTextAction.java
@Override
public Collection<CanvasObject> getObjects() {
	return Collections.singleton((CanvasObject) text);
}
 
源代码9 项目: jeka   文件: JkLocalLibDependency.java
private JkLocalLibDependency(Runnable producer, Path file, Path ideProjectDir, JkDependencySet dependencies) {
    super(producer, ideProjectDir, Collections.singleton(file));
    this.dependencies = dependencies.withIdeProjectDir(ideProjectDir);
}
 
源代码10 项目: ignite   文件: ClusterNodeMetricsSelfTest.java
/**
 * Test JMX metrics.
 *
 * @throws Exception If failed.
 */
@Test
public void testJmxClusterMetrics() throws Exception {
    Ignite node = grid();

    Ignite node1 = startGrid(1);
    Ignite node2 = startClientGrid(2);

    waitForDiscovery(node2, node1, node);

    UUID nodeId0 = node.cluster().localNode().id();
    UUID nodeId1 = node1.cluster().localNode().id();
    UUID nodeId2 = node2.cluster().localNode().id();

    Set<UUID> srvNodes = new HashSet<>(Arrays.asList(nodeId0, nodeId1));
    Set<UUID> clientNodes = Collections.singleton(nodeId2);
    Set<UUID> allNodes = new HashSet<>(Arrays.asList(nodeId0, nodeId1, nodeId2));

    // ClusterMetricsMXBeanImpl test.
    JmxClusterMetricsHelper helperCluster = new JmxClusterMetricsHelper(node.configuration(),
        ClusterMetricsMXBeanImpl.class);

    assertEquals(node.cluster().topologyVersion(), helperCluster.attr("TopologyVersion"));

    assertEquals(2, helperCluster.attr("TotalServerNodes"));
    assertEquals(1, helperCluster.attr("TotalClientNodes"));

    assertEquals(allNodes, helperCluster.nodeIdsForAttribute(ATTR_BUILD_VER, VER_STR, true, true));
    assertEquals(srvNodes, helperCluster.nodeIdsForAttribute(ATTR_BUILD_VER, VER_STR, true, false));
    assertEquals(clientNodes, helperCluster.nodeIdsForAttribute(ATTR_BUILD_VER, VER_STR, false, true));
    assertEquals(Collections.emptySet(), helperCluster.nodeIdsForAttribute(ATTR_BUILD_VER, VER_STR, false, false));

    assertEquals(srvNodes, helperCluster.nodeIdsForAttribute(ATTR_CLIENT_MODE, "false", true, true));
    assertEquals(Collections.emptySet(), helperCluster.nodeIdsForAttribute(ATTR_CLIENT_MODE, "false", false,
        false));
    assertEquals(clientNodes, helperCluster.nodeIdsForAttribute(ATTR_CLIENT_MODE, "true", true, true));

    assertTrue(helperCluster.attributeNames().containsAll(node.cluster().localNode().attributes().keySet()));
    assertTrue(helperCluster.attributeNames().containsAll(node1.cluster().localNode().attributes().keySet()));
    assertTrue(helperCluster.attributeNames().containsAll(node2.cluster().localNode().attributes().keySet()));

    assertEquals(new HashSet<>(Arrays.asList("true", "false")), helperCluster.attributeValues(ATTR_CLIENT_MODE));
    assertEquals(Collections.emptySet(), helperCluster.attributeValues("NO_SUCH_ATTRIBUTE"));

    // ClusterLocalNodeMetricsMXBeanImpl test.
    JmxClusterMetricsHelper helperNode0 = new JmxClusterMetricsHelper(node.configuration(),
        ClusterLocalNodeMetricsMXBeanImpl.class);
    JmxClusterMetricsHelper helperNode2 = new JmxClusterMetricsHelper(node2.configuration(),
        ClusterLocalNodeMetricsMXBeanImpl.class);

    // For server node.
    assertEquals(1, helperNode0.attr("TotalServerNodes"));
    assertEquals(0, helperNode0.attr("TotalClientNodes"));

    assertEquals(node.cluster().topologyVersion(), helperNode0.attr("TopologyVersion"));

    assertEquals(node.cluster().localNode().attributes().keySet(), helperNode0.attributeNames());

    assertEquals(Collections.singleton("false"), helperNode0.attributeValues(ATTR_CLIENT_MODE));
    assertEquals(Collections.emptySet(), helperNode0.attributeValues("NO_SUCH_ATTRIBUTE"));

    assertEquals(Collections.singleton(nodeId0), helperNode0.nodeIdsForAttribute(ATTR_BUILD_VER, VER_STR, true,
        true));
    assertEquals(Collections.singleton(nodeId0), helperNode0.nodeIdsForAttribute(ATTR_BUILD_VER, VER_STR, true,
        false));
    assertEquals(Collections.emptySet(), helperNode0.nodeIdsForAttribute(ATTR_BUILD_VER, VER_STR, false, true));
    assertEquals(Collections.emptySet(), helperNode0.nodeIdsForAttribute(ATTR_BUILD_VER, VER_STR, false, false));

    // For client node.
    assertEquals(0, helperNode2.attr("TotalServerNodes"));
    assertEquals(1, helperNode2.attr("TotalClientNodes"));

    assertEquals(node.cluster().topologyVersion(), helperNode2.attr("TopologyVersion"));

    assertEquals(node2.cluster().localNode().attributes().keySet(), helperNode2.attributeNames());

    assertEquals(Collections.singleton("true"), helperNode2.attributeValues(ATTR_CLIENT_MODE));
    assertEquals(Collections.emptySet(), helperNode2.attributeValues("NO_SUCH_ATTRIBUTE"));

    assertEquals(Collections.singleton(nodeId2), helperNode2.nodeIdsForAttribute(ATTR_BUILD_VER, VER_STR, true,
        true));
    assertEquals(Collections.emptySet(), helperNode2.nodeIdsForAttribute(ATTR_BUILD_VER, VER_STR, true, false));
    assertEquals(Collections.singleton(nodeId2), helperNode2.nodeIdsForAttribute(ATTR_BUILD_VER, VER_STR, false,
        true));
    assertEquals(Collections.emptySet(), helperNode2.nodeIdsForAttribute(ATTR_BUILD_VER, VER_STR, false, false));
}
 
protected Set<String> getObject() {
    return Collections.singleton("string");
}
 
源代码12 项目: ozark   文件: RequestDispatcherApplication.java
@Override
public Set<Class<?>> getClasses() {
    return Collections.singleton(RequestDispatcherController.class);
}
 
源代码13 项目: ProjectAres   文件: BlitzModule.java
@Override
public Set<MapDoc.Gamemode> getGamemodes(MapModuleContext context) {
    return isEnabled() ? Collections.singleton(MapDoc.Gamemode.blitz) : Collections.emptySet();
}
 
源代码14 项目: synthea   文件: TransitionMetricsTest.java
@Test public void testExampleModule() throws Exception {
  Person person = new Person(0L);
  person.attributes.put(Person.RACE, "black");
  person.attributes.put(Person.ETHNICITY, "nonhispanic");
  person.attributes.put(Person.GENDER, "F");
  long time = System.currentTimeMillis();
  LifecycleModule.birth(person, time);
  
  Module example = TestHelper.getFixture("example_module.json");
  // some notes about this example module:
  // 1. gender != M --> transition immediately to terminal
  // 2. Age_Guard waits until age 40 and transitions 90% to terminal
  //    so we need a fixed seed to ensure we hit things
  
  time = run(person, example, time);
  
  TransitionMetrics metrics = new TransitionMetrics();
  
  Collection<Module> modules = Collections.singleton(example);
  
  metrics.recordStats(person, time, modules);
  metrics.printStats(1, modules); // print it to ensure no exceptions. don't parse the output

  Metric m = metrics.getMetric(example.name, "Initial");
  assertEquals(1, m.entered.get()); // 1 person entered the state
  assertEquals(0, m.current.get()); // none currently in this state
  
  Map<String,AtomicInteger> dests = m.destinations;
  assertEquals(null, dests.get("Age_Guard")); // the 1 person did not go here
  assertEquals(1, dests.get("Terminal").get()); // they went here
  
  m = metrics.getMetric(example.name, "Pre_Examplitis");
  assertEquals(0, m.entered.get()); // nobody hit this
  
  m = metrics.getMetric(example.name, "Terminal");
  assertEquals(1, m.entered.get()); // 1 person hit this
  assertEquals(1, m.current.get()); // and is still there
  
  metrics = new TransitionMetrics();
  for (long seed : new long[] {31255L, 0L, 12345L}) {
    // seeds chosen by experimentation, to ensure we hit "Pre_Examplitis" at least once
    person = new Person(seed); 
    person.attributes.put(Person.GENDER, "M");
    person.setProvider(EncounterType.WELLNESS, Mockito.mock(Provider.class));
    time = System.currentTimeMillis();
    person.attributes.put(Person.BIRTHDATE, time);

    time = run(person, example, time);
    metrics.recordStats(person, time, modules);
  }

  metrics.printStats(3, modules); // print it to ensure no exceptions

  m = metrics.getMetric(example.name, "Initial");
  assertEquals(3, m.entered.get()); // 3 people entered the state
  assertEquals(0, m.current.get()); // none currently in this state
  
  dests = m.destinations;
  assertEquals(null, dests.get("Terminal")); // the 3 people did not go here
  assertEquals(3, dests.get("Age_Guard").get()); // they went here
  
  m = metrics.getMetric(example.name, "Pre_Examplitis");
  assertEquals(1, m.entered.get());
  
  m = metrics.getMetric(example.name, "Terminal");
  assertEquals(3, m.entered.get());
  assertEquals(3, m.current.get());
}
 
源代码15 项目: xtext-core   文件: SlotEntry.java
protected Set<String> getNsUris() {
	if (nsURI != null)
		return Collections.singleton(nsURI);
	return Sets.newHashSet(EPackage.Registry.INSTANCE.keySet());
}
 
源代码16 项目: herddb   文件: SimpleSubqueryTest.java
@Test
public void subQueryOnWhereTest() throws Exception {
    String nodeId = "localhost";
    try (DBManager manager = new DBManager("localhost", new MemoryMetadataStorageManager(), new MemoryDataStorageManager(), new MemoryCommitLogManager(), null, null)) {
        manager.start();
        CreateTableSpaceStatement st1 = new CreateTableSpaceStatement("tblspace1", Collections.singleton(nodeId), nodeId, 1, 0, 0);
        manager.executeStatement(st1, StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION);
        manager.waitForTablespace("tblspace1", 10000);

        execute(manager, "CREATE TABLE tblspace1.table1 (k1 string primary key,n1 int)", Collections.emptyList());
        execute(manager, "CREATE TABLE tblspace1.table2 (k2 string primary key,fk string)", Collections.emptyList());

        assertEquals(1, executeUpdate(manager, "INSERT INTO tblspace1.table1(k1,n1) values(?,?)", Arrays.asList("mykey", Integer.valueOf(1234))).getUpdateCount());
        assertEquals(1, executeUpdate(manager, "INSERT INTO tblspace1.table1(k1,n1) values(?,?)", Arrays.asList("mykey2", Integer.valueOf(1234))).getUpdateCount());
        assertEquals(1, executeUpdate(manager, "INSERT INTO tblspace1.table1(k1,n1) values(?,?)", Arrays.asList("mykey3", Integer.valueOf(1234))).getUpdateCount());
        assertEquals(1, executeUpdate(manager, "INSERT INTO tblspace1.table1(k1,n1) values(?,?)", Arrays.asList("mykey4", Integer.valueOf(1234))).getUpdateCount());

        assertEquals(1, executeUpdate(manager, "INSERT INTO tblspace1.table2(k2,fk) values(?,?)", Arrays.asList("subkey1", "mykey2")).getUpdateCount());
        assertEquals(1, executeUpdate(manager, "INSERT INTO tblspace1.table2(k2,fk) values(?,?)", Arrays.asList("subkey2", "mykey2")).getUpdateCount());
        assertEquals(1, executeUpdate(manager, "INSERT INTO tblspace1.table2(k2,fk) values(?,?)", Arrays.asList("subkey3", "mykey3")).getUpdateCount());
        assertEquals(1, executeUpdate(manager, "INSERT INTO tblspace1.table2(k2,fk) values(?,?)", Arrays.asList("subkey4", "mykey4")).getUpdateCount());

        assertEquals(2, scan(manager, "SELECT * "
                + "FROM tblspace1.table1 t1 "
                + "WHERE t1.k1 in ('mykey','mykey3')"
                + "", Collections.emptyList()).consumeAndClose().size());

        assertEquals(1, scan(manager, "SELECT * "
                + "FROM tblspace1.table1 t1 "
                + "WHERE t1.k1 in (SELECT fk FROM tblspace1.table2 WHERE k2='subkey4')"
                + "", Collections.emptyList()).consumeAndClose().size());

        assertEquals(1, scan(manager, "SELECT * "
                + "FROM tblspace1.table1 t1 "
                + "WHERE t1.n1 = ? and t1.k1 in (SELECT fk FROM tblspace1.table2 WHERE k2=?)"
                + "", Arrays.asList(1234, "subkey4")).consumeAndClose().size());

        assertEquals(0, scan(manager, "SELECT * "
                + "FROM tblspace1.table1 t1 "
                + "WHERE t1.n1 = ? and t1.k1 in (SELECT fk FROM tblspace1.table2 WHERE k2=?)"
                + "", Arrays.asList(1234, "subkey5")).consumeAndClose().size());

    }
}
 
源代码17 项目: scava   文件: SimpleNBody.java
/**
 * Divide the simulation space into the given number of cubes. The number of
 * cubes must be a power of 2. This should be called once per simulation, at the beginning.
 * 
 * @return
 * @throws InvalidNumberOfCubesException
 */
private void setupCubes() throws InvalidNumberOfCubesException {
	if (!((numCubes > 0) && ((numCubes & (numCubes - 1)) == 0))) {
		throw new InvalidNumberOfCubesException();
	}
	if (numCubes == 1) {
		cuboides = Collections.singleton(new AxisAlignedCuboid());
	}
	else {
		// axis 0 = x, 1 = y, 2 = z;
		int xPoints = 0;
		int yPoints = 0;
		int zPoints = 0;
		int axis = 0;
		int numcubes = numCubes;
		while (numcubes > 1) {
			switch (axis) {
			case 0:
				xPoints += 2;
				break;
			case 1:
				yPoints += 2;
				break;
			case 2:
				zPoints += 2;
			default:
				axis = 0;
			}
			numcubes /= 2;
			axis++;
		}
		cuboides = new HashSet<>();
		double[] xCoords = axisSlices(xPoints);
		double[] yCoords = axisSlices((yPoints == 0) ? 1 : yPoints);
		double[] zCoords = axisSlices((zPoints == 0) ? 1 : zPoints);
		for (int i = 0; i < xCoords.length-1; i++) {
			for (int j = 0; j < yCoords.length-1; j++) {
				for (int k = 0; k < zCoords.length-1; k++) {
					cuboides.add(new AxisAlignedCuboid(new StockCuboidCoordinates(xCoords[i], yCoords[j], zCoords[k], xCoords[i+1], yCoords[j+1], zCoords[k+1])));
				}
			}
		}
	}
}
 
源代码18 项目: herddb   文件: RestartPendingTransactionBase.java
@Test
public void recoverDelete() throws Exception {

    Path dataPath = folder.newFolder("data").toPath();
    Path logsPath = folder.newFolder("logs").toPath();
    Path metadataPath = folder.newFolder("metadata").toPath();
    Path tmoDir = folder.newFolder("tmoDir").toPath();
    Bytes key1 = Bytes.from_string("k1");
    Bytes key2 = Bytes.from_string("k2");
    Bytes key3 = Bytes.from_string("k3");
    String nodeId = "localhost";
    try (DBManager manager = buildDBManager(nodeId,
            metadataPath,
            dataPath,
            logsPath,
            tmoDir)) {
        manager.start();

        CreateTableSpaceStatement st1 = new CreateTableSpaceStatement("tblspace1", Collections.singleton(nodeId),
                nodeId, 1, 0, 0);
        manager.executeStatement(st1, StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(),
                TransactionContext.NO_TRANSACTION);
        manager.waitForTablespace("tblspace1", 10000);

        Table table = Table
                .builder()
                .tablespace("tblspace1")
                .name("t1")
                .column("id", ColumnTypes.STRING)
                .column("name", ColumnTypes.STRING)
                .primaryKey("id")
                .build();
        manager.executeStatement(new CreateTableStatement(table), StatementEvaluationContext.
                DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION);
        manager.executeStatement(new InsertStatement("tblspace1", table.name, new Record(key1, key1)),
                StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION);
        manager.executeStatement(new InsertStatement("tblspace1", table.name, new Record(key2, key2)),
                StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION);
        manager.executeStatement(new InsertStatement("tblspace1", table.name, new Record(key3, key3)),
                StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION);
        manager.checkpoint();

        manager.executeStatement(new DeleteStatement("tblspace1", table.name, key2, null),
                StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION);

    }

    try (DBManager manager = buildDBManager(nodeId,
            metadataPath,
            dataPath,
            logsPath,
            tmoDir)) {
        manager.start();

        manager.waitForTablespace("tblspace1", 10000);

        GetResult result = manager.get(new GetStatement("tblspace1", "t1", key1, null, false),
                StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION);
        assertTrue(result.found());
    }

}
 
源代码19 项目: jaxrs-analyzer   文件: TestClass12.java
public static Set<HttpResponse> getResult() {
    final HttpResponse result = new HttpResponse();

    result.getStatuses().addAll(Arrays.asList(200, 201));

    return Collections.singleton(result);
}
 
源代码20 项目: jaxrs-analyzer   文件: TestClass8.java
public static Set<TypeRepresentation> expectedTypeRepresentations() {
    final Map<String, TypeIdentifier> properties = new HashMap<>();

    properties.put("third", TypeUtils.STRING_IDENTIFIER);

    return Collections.singleton(TypeRepresentation.ofConcrete(expectedIdentifier(), properties));
}