Java Code Examples for java.util.Collections#singleton()
The following examples show how to use
java.util.Collections#singleton() .
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: WebGuestComponentScanRegistrar.java From wallride with Apache License 2.0 | 6 votes |
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; }
Example 2
Source File: HasNextStateMachine.java From SPDS with Eclipse Public License 2.0 | 6 votes |
@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(); }
Example 3
Source File: DerbyMigrationTest.java From FHIR with Apache License 2.0 | 6 votes |
@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); } } }
Example 4
Source File: TrainStopSerializer.java From geode-examples with Apache License 2.0 | 5 votes |
@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); }
Example 5
Source File: QueryFunctions.java From datawave with Apache License 2.0 | 5 votes |
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(); }
Example 6
Source File: PrivilegeApiResourceTest.java From nexus-public with Eclipse Public License 1.0 | 5 votes |
@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, "*"); }
Example 7
Source File: SnippetTemplate.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
@Override public Collection<LocationIdentity> getLocations() { if (locationIdentity == null) { return Collections.emptySet(); } else { return Collections.singleton(locationIdentity); } }
Example 8
Source File: RestartPendingTransactionBase.java From herddb with Apache License 2.0 | 4 votes |
@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()); } }
Example 9
Source File: ModelEditTextAction.java From Logisim with GNU General Public License v3.0 | 4 votes |
@Override public Collection<CanvasObject> getObjects() { return Collections.singleton((CanvasObject) text); }
Example 10
Source File: SimpleNBody.java From scava with Eclipse Public License 2.0 | 4 votes |
/** * 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]))); } } } } }
Example 11
Source File: SimpleSubqueryTest.java From herddb with Apache License 2.0 | 4 votes |
@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()); } }
Example 12
Source File: SlotEntry.java From xtext-core with Eclipse Public License 2.0 | 4 votes |
protected Set<String> getNsUris() { if (nsURI != null) return Collections.singleton(nsURI); return Sets.newHashSet(EPackage.Registry.INSTANCE.keySet()); }
Example 13
Source File: TransitionMetricsTest.java From synthea with Apache License 2.0 | 4 votes |
@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()); }
Example 14
Source File: BlitzModule.java From ProjectAres with GNU Affero General Public License v3.0 | 4 votes |
@Override public Set<MapDoc.Gamemode> getGamemodes(MapModuleContext context) { return isEnabled() ? Collections.singleton(MapDoc.Gamemode.blitz) : Collections.emptySet(); }
Example 15
Source File: RequestDispatcherApplication.java From ozark with Apache License 2.0 | 4 votes |
@Override public Set<Class<?>> getClasses() { return Collections.singleton(RequestDispatcherController.class); }
Example 16
Source File: java_util_Collections_SingletonSet.java From openjdk-8 with GNU General Public License v2.0 | 4 votes |
protected Set<String> getObject() { return Collections.singleton("string"); }
Example 17
Source File: ClusterNodeMetricsSelfTest.java From ignite with Apache License 2.0 | 4 votes |
/** * 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)); }
Example 18
Source File: JkLocalLibDependency.java From jeka with Apache License 2.0 | 4 votes |
private JkLocalLibDependency(Runnable producer, Path file, Path ideProjectDir, JkDependencySet dependencies) { super(producer, ideProjectDir, Collections.singleton(file)); this.dependencies = dependencies.withIdeProjectDir(ideProjectDir); }
Example 19
Source File: TestClass8.java From jaxrs-analyzer with Apache License 2.0 | 3 votes |
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)); }
Example 20
Source File: TestClass12.java From jaxrs-analyzer with Apache License 2.0 | 3 votes |
public static Set<HttpResponse> getResult() { final HttpResponse result = new HttpResponse(); result.getStatuses().addAll(Arrays.asList(200, 201)); return Collections.singleton(result); }