List of usage examples for java.util Collections singleton
public static <T> Set<T> singleton(T o)
From source file:com.phoenixst.plexus.util.SingletonGraph.java
public Collection nodes(Predicate nodePredicate) { return (nodePredicate == null || nodePredicate.evaluate(singleNode)) ? Collections.singleton(singleNode) : Collections.EMPTY_SET; }
From source file:ddf.catalog.validation.impl.validator.EnumerationValidator.java
/** * {@inheritDoc}//from w w w .jav a 2 s . com * <p> * Validates each of {@code attribute}'s values against the set of acceptable values by calling * {@link String#valueOf(Object)} on each value and checking whether that string is in the set. * <p> * Note: comparisons are <strong>case-sensitive</strong>. */ @Override public Optional<AttributeValidationReport> validate(final Attribute attribute) { Preconditions.checkArgument(attribute != null, "The attribute cannot be null."); final String name = attribute.getName(); for (final Serializable value : attribute.getValues()) { final String stringValue = String.valueOf(value); if (!values.contains(stringValue)) { final AttributeValidationReportImpl report = new AttributeValidationReportImpl(); // TODO (jrnorth) - escape the value. report.addViolation(new ValidationViolationImpl(Collections.singleton(name), name + " has an invalid value: [" + stringValue + "]", Severity.ERROR)); values.forEach(report::addSuggestedValue); return Optional.of(report); } } return Optional.empty(); }
From source file:com.mirth.connect.server.controllers.AuthorizationController.java
public void auditAuthorizationRequest(Integer userId, Operation operation, Map<String, Object> parameterMap, ServerEvent.Outcome outcome, String address) { if (operation != null && operation.isAuditable()) { String displayName = operation.getDisplayName(); if (operation instanceof ExtensionOperation) { displayName += " invoked through " + ((ExtensionOperation) operation).getExtensionName(); }/*from w w w. j av a 2 s . c o m*/ ServerEvent serverEvent = new ServerEvent(serverId, displayName); serverEvent.setLevel(Level.INFORMATION); serverEvent.setUserId(userId); serverEvent.setOutcome(outcome); serverEvent.setIpAddress(address); if (MapUtils.isNotEmpty(parameterMap)) { for (Entry<String, Object> entry : parameterMap.entrySet()) { String key = entry.getKey(); Object value = entry.getValue(); // If channelId was one of the params, print out each channel as separate attributes and add the channel name if (key.contains("channelId")) { Set<String> collection = null; if (value instanceof Set) { collection = (Set<String>) value; } else if (value instanceof String) { collection = Collections.singleton((String) value); } if (collection != null) { String[] channelIds = collection.toArray(new String[collection.size()]); for (int i = 0; i < channelIds.length; i++) { String name = "channel"; if (channelIds.length > 1) { name += "[" + i + "]"; } value = channelController.getChannelById(channelIds[i]); addAttribute(serverEvent.getAttributes(), name, value); } } } else { addAttribute(serverEvent.getAttributes(), key, value); } } } eventController.dispatchEvent(serverEvent); } }
From source file:com.devicehive.handler.command.CommandSearchHandlerTest.java
@Test public void shouldHandleCommandInsertAndQueryByCommandNameAndDeviceGuid() throws Exception { DeviceCommand command = generateCommand(); CommandInsertRequest cir = new CommandInsertRequest(command); Response response = handlerInsert.handle(Request.newBuilder().withBody(cir).build()); assertNotNull(response);//from w ww. j av a 2s. c o m assertNotNull(response.getBody()); assertTrue(response.getBody() instanceof CommandInsertResponse); CommandInsertResponse body = (CommandInsertResponse) response.getBody(); assertEquals(command, body.getDeviceCommand()); CommandSearchRequest csr = new CommandSearchRequest(); csr.setGuid(command.getDeviceGuid()); csr.setNames(Collections.singleton(command.getCommand())); response = handlerSearch.handle(Request.newBuilder().withBody(csr).build()); assertNotNull(response); assertNotNull(response.getBody()); assertTrue(response.getBody() instanceof CommandSearchResponse); CommandSearchResponse responseBody = (CommandSearchResponse) response.getBody(); assertEquals(1, responseBody.getCommands().size()); assertEquals(command, responseBody.getCommands().get(0)); }
From source file:com.opengamma.financial.analytics.PositionTradeScalingFunction.java
@Override public Set<ValueSpecification> getResults(final FunctionCompilationContext context, final ComputationTarget target) { final ValueSpecification specification = new ValueSpecification(_requirementName, target.toSpecification(), ValueProperties.all());/*from w ww .ja v a 2s . c o m*/ return Collections.singleton(specification); }
From source file:com.haulmont.cuba.web.gui.components.WebAbstractOptionsField.java
@Override public void setDatasource(Datasource datasource, String property) { this.datasource = datasource; MetaClass metaClass = datasource.getMetaClass(); resolveMetaPropertyPath(metaClass, property); if (metaProperty.getRange().getCardinality() != null) { setMultiSelect(metaProperty.getRange().getCardinality().isMany()); }/* w w w . jav a2 s . c om*/ ItemWrapper wrapper = createDatasourceWrapper(datasource, Collections.singleton(metaPropertyPath)); Property itemProperty = wrapper.getItemProperty(metaPropertyPath); setRequired(metaProperty.isMandatory()); if (StringUtils.isEmpty(getRequiredMessage())) { MessageTools messageTools = AppBeans.get(MessageTools.NAME); setRequiredMessage(messageTools.getDefaultRequiredMessage(metaClass, property)); } if (metaProperty.getRange().isEnum()) { Enumeration enumeration = metaProperty.getRange().asEnumeration(); List options = Arrays.asList(enumeration.getJavaClass().getEnumConstants()); setComponentContainerDs(createEnumContainer(options)); setCaptionMode(CaptionMode.ITEM); } if (DynamicAttributesUtils.isDynamicAttribute(metaProperty)) { CategoryAttribute categoryAttribute = DynamicAttributesUtils.getCategoryAttribute(metaProperty); if (categoryAttribute != null && categoryAttribute.getDataType() == PropertyType.ENUMERATION) { setOptionsList(categoryAttribute.getEnumerationOptions()); } } component.setPropertyDataSource(itemProperty); if (metaProperty.isReadOnly()) { setEditable(false); } handleFilteredAttributes(this, this.datasource, metaPropertyPath); securitytemChangeListener = e -> handleFilteredAttributes(this, this.datasource, metaPropertyPath); //noinspection unchecked this.datasource.addItemChangeListener(new WeakItemChangeListener(datasource, securitytemChangeListener)); }
From source file:com.opengamma.engine.function.MarketDataSourcingFunction.java
@Override public Set<ValueSpecification> getResults(FunctionCompilationContext context, ComputationTarget target) { return Collections.singleton(getResult()); }
From source file:io.undertow.servlet.test.security.form.ServletFormAuthURLRewriteTestCase.java
@BeforeClass public static void setup() throws ServletException { final PathHandler path = new PathHandler(); final ServletContainer container = ServletContainer.Factory.newInstance(); ServletInfo s = new ServletInfo("servlet", SendUsernameServlet.class) .setServletSecurityInfo(new ServletSecurityInfo().addRoleAllowed("role1")).addMapping("/secured/*"); ServletInfo echo = new ServletInfo("echo", EchoServlet.class) .setServletSecurityInfo(new ServletSecurityInfo().addRoleAllowed("role1")) .addMapping("/secured/echo"); ServletInfo echoParam = new ServletInfo("echoParam", RequestParamEchoServlet.class) .setServletSecurityInfo(new ServletSecurityInfo().addRoleAllowed("role1")) .addMapping("/secured/echoParam"); ServletInfo s1 = new ServletInfo("loginPage", FormLoginServlet.class) .setServletSecurityInfo(new ServletSecurityInfo().addRoleAllowed("group1")) .addMapping("/FormLoginServlet"); ServletIdentityManager identityManager = new ServletIdentityManager(); identityManager.addUser("user1", "password1", "role1"); DeploymentInfo builder = new DeploymentInfo() .setServletSessionConfig(new ServletSessionConfig() .setSessionTrackingModes(Collections.singleton(SessionTrackingMode.URL))) .setClassLoader(SimpleServletTestCase.class.getClassLoader()).setContextPath("/servletContext") .setClassIntrospecter(TestClassIntrospector.INSTANCE).setDeploymentName("servletContext.war") .setAuthenticationMode(AuthenticationMode.CONSTRAINT_DRIVEN).setIdentityManager(identityManager) .setLoginConfig(new LoginConfig("FORM", "Test Realm", "/FormLoginServlet", "/error.html")) .addServlets(s, s1, echo, echoParam); DeploymentManager manager = container.addDeployment(builder); manager.deploy();//from w ww .jav a 2 s . c o m path.addPrefixPath(builder.getContextPath(), manager.start()); DefaultServer.setRootHandler(path); }
From source file:com.devicehive.resource.DeviceNotificationResourceTest.java
@Test public void should_get_response_with_status_200_and_notification_when_waitTimeout_is_0_and_polling_for_device() { DeviceClassEquipmentVO equipment = DeviceFixture.createEquipmentVO(); DeviceClassUpdate deviceClass = DeviceFixture.createDeviceClass(); deviceClass.setEquipment(Optional.of(Collections.singleton(equipment))); NetworkVO network = DeviceFixture.createNetwork(); String guid = UUID.randomUUID().toString(); DeviceUpdate deviceUpdate = DeviceFixture.createDevice(guid); deviceUpdate.setDeviceClass(Optional.of(deviceClass)); deviceUpdate.setNetwork(Optional.of(network)); DateTime timeStamp = new DateTime(DateTimeZone.UTC); // register device Response response = performRequest("/device/" + guid, "PUT", emptyMap(), singletonMap(HttpHeaders.AUTHORIZATION, tokenAuthHeader(ACCESS_KEY)), deviceUpdate, NO_CONTENT, null);//from w w w . ja v a 2s. co m assertNotNull(response); // Create notification DeviceNotification notification = DeviceFixture.createDeviceNotification(); notification = performRequest("/device/" + guid + "/notification", "POST", emptyMap(), singletonMap(HttpHeaders.AUTHORIZATION, tokenAuthHeader(ACCESS_KEY)), notification, CREATED, DeviceNotification.class); assertNotNull(notification.getId()); // poll notification Map<String, Object> params = new HashMap<>(); params.put("waitTimeout", 0); params.put("timestamp", timeStamp); ArrayList notifications = new ArrayList(); notifications = performRequest("/device/" + guid + "/notification/poll", "GET", params, singletonMap(HttpHeaders.AUTHORIZATION, tokenAuthHeader(ACCESS_KEY)), null, OK, notifications.getClass()); assertNotNull(notifications); assertEquals(1, notifications.size()); }
From source file:gobblin.converter.avro.AvroToJsonStringConverterBase.java
@Override public Iterable<T> convertRecord(String outputSchema, GenericRecord inputRecord, WorkUnitState workUnit) throws DataConversionException { try {/*from w ww . j a v a 2 s .c o m*/ byte[] utf8Bytes = this.serializer.get().serialize(inputRecord); return Collections.singleton(processUtf8Bytes(utf8Bytes)); } catch (IOException ioe) { throw new DataConversionException(ioe); } }