Java Code Examples for java.util.Collections.singleton()

The following are Jave code examples for showing how to use singleton() of the java.util.Collections class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: monarch   File: RemotePutAllMessage.java   View Source Code Vote up 6 votes
public static PutAllResponse send(DistributedMember recipient, EntryEventImpl event,
    PutAllEntryData[] putAllData, int putAllDataCount, boolean useOriginRemote, int processorType,
    boolean possibleDuplicate) throws RemoteOperationException {
  // Assert.assertTrue(recipient != null, "RemotePutAllMessage NULL recipient"); recipient can be
  // null for event notifications
  Set recipients = Collections.singleton(recipient);
  PutAllResponse p = new PutAllResponse(event.getRegion().getSystem(), recipients);
  RemotePutAllMessage msg =
      new RemotePutAllMessage(event, recipients, p, putAllData, putAllDataCount, useOriginRemote,
          processorType, possibleDuplicate, !event.isGenerateCallbacks());
  msg.setTransactionDistributed(event.getRegion().getCache().getTxManager().isDistributed());
  Set failures = event.getRegion().getDistributionManager().putOutgoing(msg);
  if (failures != null && failures.size() > 0) {
    throw new RemoteOperationException(
        LocalizedStrings.RemotePutMessage_FAILED_SENDING_0.toLocalizedString(msg));
  }
  return p;
}
 
Example 2
Project: lams   File: LazySet.java   View Source Code Vote up 5 votes
/** {@inheritDoc} */
public boolean add(ElementType element) {
    if (delegate.isEmpty()) {
        delegate = Collections.singleton(element);
        return true;
    } else {
        delegate = createImplementation();
        return delegate.add(element);
    }
}
 
Example 3
Project: sushi-bar-BE   File: UserDetailsServiceImpl.java   View Source Code Vote up 5 votes
@Override
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
    User user = userRepository.findByUsername(username)
            .orElseThrow(() -> new UsernameNotFoundException("User not found"));
    String role = user.getRole();

    return new org.springframework.security.core.userdetails.User(user.getUsername(), user.getPassword(),
            user.isEnabled(), true, true, user.getConfirmed(), Collections.singleton(new SimpleGrantedAuthority(role)));
}
 
Example 4
Project: bullet-kafka   File: KafkaConfigTest.java   View Source Code Vote up 5 votes
@Test
public void testMakeKafkaProperties() {
    KafkaConfig config = new KafkaConfig("");
    Set<String> keys = new HashSet<>(Collections.singleton(KafkaConfig.REQUEST_TOPIC_NAME));
    Map<String, Object> kafkaProperties = config.getAllWithPrefix(Optional.of(keys), KafkaConfig.KAFKA_NAMESPACE, true);

    String strippedName = KafkaConfig.REQUEST_TOPIC_NAME.substring(KafkaConfig.KAFKA_NAMESPACE.length());
    Assert.assertEquals(kafkaProperties.size(), 1);
    Assert.assertTrue(kafkaProperties.containsKey(strippedName));
    Assert.assertEquals(kafkaProperties.get(strippedName), "bullet.queries");
}
 
Example 5
Project: kafka-0.11.0.0-src-with-comment   File: KGroupedTableImpl.java   View Source Code Vote up 5 votes
private <T> KTable<K, T> doAggregate(final ProcessorSupplier<K, Change<V>> aggregateSupplier,
                                     final String functionName,
                                     final StateStoreSupplier<KeyValueStore> storeSupplier) {
    String sinkName = topology.newName(KStreamImpl.SINK_NAME);
    String sourceName = topology.newName(KStreamImpl.SOURCE_NAME);
    String funcName = topology.newName(functionName);

    String topic = storeSupplier.name() + KStreamImpl.REPARTITION_TOPIC_SUFFIX;

    Serializer<? extends K> keySerializer = keySerde == null ? null : keySerde.serializer();
    Deserializer<? extends K> keyDeserializer = keySerde == null ? null : keySerde.deserializer();
    Serializer<? extends V> valueSerializer = valSerde == null ? null : valSerde.serializer();
    Deserializer<? extends V> valueDeserializer = valSerde == null ? null : valSerde.deserializer();

    ChangedSerializer<? extends V> changedValueSerializer = new ChangedSerializer<>(valueSerializer);
    ChangedDeserializer<? extends V> changedValueDeserializer = new ChangedDeserializer<>(valueDeserializer);

    // send the aggregate key-value pairs to the intermediate topic for partitioning
    topology.addInternalTopic(topic);
    topology.addSink(sinkName, topic, keySerializer, changedValueSerializer, this.name);

    // read the intermediate topic
    topology.addSource(sourceName, keyDeserializer, changedValueDeserializer, topic);

    // aggregate the values with the aggregator and local store
    topology.addProcessor(funcName, aggregateSupplier, sourceName);
    topology.addStateStore(storeSupplier, funcName);

    // return the KTable representation with the intermediate topic as the sources
    return new KTableImpl<>(topology, funcName, aggregateSupplier, Collections.singleton(sourceName), storeSupplier.name(), isQueryable);
}
 
Example 6
Project: athena   File: ProxyArpManagerTest.java   View Source Code Vote up 5 votes
/**
 * Test ARP request from external network to an internal host.
 */
@Test
public void testReplyToRequestForUs() {
    Ip4Address theirIp = Ip4Address.valueOf("10.0.1.254");
    Ip4Address ourFirstIp = Ip4Address.valueOf("10.0.1.1");
    Ip4Address ourSecondIp = Ip4Address.valueOf("10.0.2.1");
    MacAddress firstMac = MacAddress.valueOf(1L);
    MacAddress secondMac = MacAddress.valueOf(2L);

    Host requestor = new DefaultHost(PID, HID1, MAC1, VLAN1, LOC1,
            Collections.singleton(theirIp));

    expect(hostService.getHost(HID1)).andReturn(requestor);
    replay(hostService);
    replay(interfaceService);

    Ethernet arpRequest = buildArp(ARP.OP_REQUEST, VLAN1, MAC1, null, theirIp, ourFirstIp);

    proxyArp.reply(arpRequest, LOC1);

    assertEquals(1, packetService.packets.size());
    Ethernet arpReply = buildArp(ARP.OP_REPLY, VLAN1, firstMac, MAC1, ourFirstIp, theirIp);
    verifyPacketOut(arpReply, LOC1, packetService.packets.get(0));

    // Test a request for the second address on that port
    packetService.packets.clear();
    arpRequest = buildArp(ARP.OP_REQUEST, VLAN1, MAC1, null, theirIp, ourSecondIp);

    proxyArp.reply(arpRequest, LOC1);

    assertEquals(1, packetService.packets.size());
    arpReply = buildArp(ARP.OP_REPLY, VLAN1, secondMac, MAC1, ourSecondIp, theirIp);
    verifyPacketOut(arpReply, LOC1, packetService.packets.get(0));
}
 
Example 7
Project: openjdk-jdk10   File: Locations.java   View Source Code Vote up 4 votes
@Override
Iterable<Set<Location>> listLocationsForModules() throws IOException {
    return Collections.singleton(moduleTable.locations());
}
 
Example 8
Project: Reer   File: CacheableTaskOutputCompositeFilePropertyElementSpec.java   View Source Code Vote up 4 votes
public CacheableTaskOutputCompositeFilePropertyElementSpec(CompositeTaskOutputPropertySpec parentProperty, String propertySuffix, File file) {
    this.parentProperty = parentProperty;
    this.propertySuffix = propertySuffix;
    this.files = new SimpleFileCollection(Collections.singleton(file));
    this.file = file;
}
 
Example 9
Project: Nird2   File: BlogPostValidator.java   View Source Code Vote up 4 votes
private BdfMessageContext validateComment(Message m, Group g, BdfList body)
		throws InvalidMessageException, FormatException {

	// comment, parent_original_id, parent_id, signature
	checkSize(body, 4);

	// Comment
	String comment = body.getOptionalString(0);
	checkLength(comment, 1, MAX_BLOG_COMMENT_LENGTH);

	// parent_original_id
	// The ID of a post or comment in this group or another group
	byte[] pOriginalIdBytes = body.getRaw(1);
	checkLength(pOriginalIdBytes, MessageId.LENGTH);
	MessageId pOriginalId = new MessageId(pOriginalIdBytes);

	// parent_id
	// The ID of a post, comment, wrapped post or wrapped comment in this
	// group, which had the ID parent_original_id in the group
	// where it was originally posted
	byte[] currentIdBytes = body.getRaw(2);
	checkLength(currentIdBytes, MessageId.LENGTH);
	MessageId currentId = new MessageId(currentIdBytes);

	// Signature
	byte[] sig = body.getRaw(3);
	checkLength(sig, 0, MAX_SIGNATURE_LENGTH);
	BdfList signed =
			BdfList.of(g.getId(), m.getTimestamp(), comment, pOriginalId,
					currentId);
	Blog b = blogFactory.parseBlog(g);
	Author a = b.getAuthor();
	try {
		clientHelper.verifySignature(SIGNING_LABEL_COMMENT, sig,
				a.getPublicKey(), signed);
	} catch (GeneralSecurityException e) {
		throw new InvalidMessageException(e);
	}

	// Return the metadata and dependencies
	BdfDictionary meta = new BdfDictionary();
	if (comment != null) meta.put(KEY_COMMENT, comment);
	meta.put(KEY_ORIGINAL_MSG_ID, m.getId());
	meta.put(KEY_ORIGINAL_PARENT_MSG_ID, pOriginalId);
	meta.put(KEY_PARENT_MSG_ID, currentId);
	meta.put(KEY_AUTHOR, authorToBdfDictionary(a));
	Collection<MessageId> dependencies = Collections.singleton(currentId);
	return new BdfMessageContext(meta, dependencies);
}
 
Example 10
Project: cas-5.1.0   File: SamlUniqueTicketIdGeneratorConfiguration.java   View Source Code Vote up 4 votes
@Override
public Collection<Pair<String, UniqueTicketIdGenerator>> buildUniqueTicketIdGenerators() {
    return Collections.singleton(Pair.of(SamlService.class.getCanonicalName(), samlServiceTicketUniqueIdGenerator()));
}
 
Example 11
Project: incubator-netbeans   File: HTTPElementFactoryProvider.java   View Source Code Vote up 4 votes
public Set<QName> getElementQNames() {
    return Collections.singleton(HTTPQName.OPERATION.getQName());
}
 
Example 12
Project: Equella   File: HierarchyDialog.java   View Source Code Vote up 4 votes
public HierarchyDialog(Frame frame, final ClientService clientService)
{
	super(frame);

	final RemoteHierarchyService hierarchyService = clientService.getService(RemoteHierarchyService.class);

	tree = new AbstractTreeEditor<HierarchyTreeNode>()
	{
		private static final long serialVersionUID = 1L;

		protected EntityCache cache;

		@Override
		protected AbstractTreeNodeEditor createEditor(HierarchyTreeNode node)
		{
			if( !tree.canEdit(node) )
			{
				return new BasicMessageEditor(getString("notopic.noteditable"));
			}

			HierarchyPack pack = hierarchyService.getHierarchyPack(node.getId());
			if( cache == null )
			{
				cache = new EntityCache(clientService);
			}
			return new TopicEditor(clientService, cache, node, pack);
		}

		@Override
		protected AbstractTreeEditorTree<HierarchyTreeNode> createTree()
		{
			Collection<String> privs = Collections.singleton("EDIT_HIERARCHY_TOPIC");
			final boolean canAddRootTopics = !clientService.getService(RemoteTLEAclManager.class)
				.filterNonGrantedPrivileges(null, privs).isEmpty();

			return new TreeEditor(hierarchyService, canAddRootTopics);
		}
	};

	JPanel all = new JPanel(new MigLayout("fill, wrap 1", "[grow]", "[fill, grow][][]"));
	all.add(tree, "grow, push");
	all.add(new JSeparator(), "growx");
	all.add(new JButton(closeAction), "alignx right");

	setTitle(getString("hierarchydialog.title"));
	setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
	getContentPane().add(all);
	setModal(true);

	addWindowListener(new WindowAdapter()
	{
		@Override
		public void windowClosing(WindowEvent e)
		{
			closeAction.actionPerformed(null);
		}
	});

	ComponentHelper.percentageOfScreen(this, 0.9f, 0.9f);
	ComponentHelper.centreOnScreen(this);
}
 
Example 13
Project: elasticsearch_my   File: MinThreadsSnapshotRestoreIT.java   View Source Code Vote up 4 votes
@Override
protected Collection<Class<? extends Plugin>> nodePlugins() {
    return Collections.singleton(MockRepository.Plugin.class);
}
 
Example 14
Project: elasticsearch_my   File: CardinalityIT.java   View Source Code Vote up 4 votes
@Override
protected Collection<Class<? extends Plugin>> nodePlugins() {
    return Collections.singleton(CustomScriptPlugin.class);
}
 
Example 15
Project: incubator-netbeans   File: RepositoryUpdater2Test.java   View Source Code Vote up 4 votes
public @Override Set<String> getMimeTypes() {
    return Collections.singleton("text/plain");
}
 
Example 16
Project: Pogamut3   File: DependencyProjectStub.java   View Source Code Vote up 4 votes
public Set getReportArtifacts()
{
    return Collections.singleton( "" );
}
 
Example 17
Project: incubator-netbeans   File: LayerBuilderTest.java   View Source Code Vote up 4 votes
public @Override Set<String> getSupportedAnnotationTypes() {
    return Collections.singleton(A.class.getCanonicalName());
}
 
Example 18
Project: Logisim   File: ModelAddAction.java   View Source Code Vote up 4 votes
public ModelAddAction(CanvasModel model, CanvasObject added) {
	this(model, Collections.singleton(added));
}
 
Example 19
Project: JRediClients   File: JedisCluster.java   View Source Code Vote up 4 votes
public JedisCluster(HostAndPort node, final GenericObjectPoolConfig poolConfig) {
	this(Collections.singleton(node), DEFAULT_TIMEOUT, DEFAULT_MAX_REDIRECTIONS, poolConfig);
}
 
Example 20
Project: kafka-0.11.0.0-src-with-comment   File: KStreamImpl.java   View Source Code Vote up 3 votes
/**
 * Repartition a stream. This is required on join operations occurring after
 * an operation that changes the key, i.e, selectKey, map(..), flatMap(..).
 * @param keySerde      Serdes for serializing the keys
 * @param valSerde      Serdes for serilaizing the values
 * @param topicNamePrefix  prefix of topic name created for repartitioning, can be null,
 *                         in which case the prefix will be auto-generated internally.
 * @return a new {@link KStreamImpl}
 */
private KStreamImpl<K, V> repartitionForJoin(Serde<K> keySerde,
                                             Serde<V> valSerde,
                                             final String topicNamePrefix) {

    String repartitionedSourceName = createReparitionedSource(this, keySerde, valSerde, topicNamePrefix);
    return new KStreamImpl<>(topology, repartitionedSourceName, Collections
        .singleton(repartitionedSourceName), false);
}