Java Code Examples for com.google.common.base.Functions#constant()

The following examples show how to use com.google.common.base.Functions#constant() . 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: TestSetAndRestore.java    From arcusplatform with Apache License 2.0 6 votes vote down vote up
protected SetAndRestore createAction(int duration, TimeUnit unit, String conditionStr) {
 
 Predicate<Model> conditionQuery = (Predicate<Model>) (StringUtils.isNotBlank(conditionStr)?ExpressionCompiler.compile(conditionStr):com.google.common.base.Predicates.alwaysTrue());
 SetAndRestore curAction = 
    new SetAndRestore(
        new MockFunction(Functions.constant(motionDevice.getAddress())),
        new MockFunction(Functions.constant(MotionCapability.ATTR_MOTION)),
        new MockFunction(Functions.constant(MotionCapability.MOTION_DETECTED)),			        
        duration,
        conditionQuery			        
       );	  
context.setVariable("motion", motionDevice.getAddress().getRepresentation());
context.setVariable("switch", switchDevice.getAddress().getRepresentation());
context.setVariable("state", MotionCapability.MOTION_DETECTED);
return curAction;
}
 
Example 2
Source File: ShadeResolver.java    From arcusplatform with Apache License 2.0 6 votes vote down vote up
private Action genSomfy(ActionContext context, Address target, Map<String, Object> variables) {
	String value = (String) variables.get(SOMFY_SELECTOR_NAME);

	if (StringUtils.isNoneBlank(value)) {
		String requestType;
		switch (value) {
		case Somfyv1Capability.CURRENTSTATE_OPEN:
			requestType = Somfyv1Capability.GoToOpenRequest.NAME;
			break;
		case Somfyv1Capability.CURRENTSTATE_CLOSED:
			requestType = Somfyv1Capability.GoToClosedRequest.NAME;
			break;

		default:
			throw new ErrorEventException(Errors.invalidParam(SOMFY_SELECTOR_NAME));
		}
		return new SendAction(requestType, Functions.constant(target), ImmutableMap.of());
	} else {
		throw new ErrorEventException(Errors.invalidParam(SOMFY_SELECTOR_NAME));
	}
}
 
Example 3
Source File: ShadeResolver.java    From arcusplatform with Apache License 2.0 6 votes vote down vote up
private Action genShade(ActionContext context, Address target, Map<String, Object> variables) {
	String value = (String) variables.get(SHADE_SELECTOR_NAME);

	if (StringUtils.isNoneBlank(value)) {
		String requestType;
		switch (value) {
		case SHADE_OPEN:
			requestType = ShadeCapability.GoToOpenRequest.NAME;
			break;
		case SHADE_CLOSED:
			requestType = ShadeCapability.GoToClosedRequest.NAME;
			break;

		default:
			throw new ErrorEventException(Errors.invalidParam(SHADE_SELECTOR_NAME));
		}
		return new SendAction(requestType, Functions.constant(target), ImmutableMap.of());
	} else {
		throw new ErrorEventException(Errors.invalidParam(SHADE_SELECTOR_NAME));
	}
}
 
Example 4
Source File: CameraResolver.java    From arcusplatform with Apache License 2.0 6 votes vote down vote up
@Override
public Action generate(ActionContext context, Address target, Map<String, Object> variables) {
   Object duration = (Object) variables.get("duration");
   Preconditions.checkNotNull(duration, "duration is required");
   int durationSec = AttributeTypes.coerceInt(duration);
   Preconditions.checkArgument(durationSec >= MIN_DURATION && durationSec <= MAX_DURATION, "Invalid duration");
   
   MessageBody payload =
      VideoService.StartRecordingRequest
         .builder()
         .withAccountId(getAccountId(context))
         .withCameraAddress(target.getRepresentation())
         .withDuration(durationSec)
         .withPlaceId(context.getPlaceId().toString())
         .withStream(false)
         .build();
      
   return new SendAction(payload.getMessageType(), Functions.constant(videoServiceAddress), payload.getAttributes());
}
 
Example 5
Source File: SceneActionBuilder.java    From arcusplatform with Apache License 2.0 5 votes vote down vote up
private void addNotification(ActionList.Builder builder) {
   SendAction action = new SendAction(
         NotificationCapability.NotifyRequest.NAME,
         Functions.constant(Address.platformService(NotificationCapability.NAMESPACE)),
         ImmutableMap.<String, Object>of(
               NotifyRequest.ATTR_PRIORITY, NotifyRequest.PRIORITY_MEDIUM,
               NotifyRequest.ATTR_PLACEID, placeId.toString(),
               NotifyRequest.ATTR_PERSONID, accountOwner,
               NotifyRequest.ATTR_MSGKEY, "scene." + template.getId() + ".run",
               NotifyRequest.ATTR_MSGPARAMS, ImmutableMap.of("_scene", name)
         )
   );
   builder.addAction(action);
}
 
Example 6
Source File: RelOptTableImpl.java    From Quicksql with MIT License 5 votes vote down vote up
public static RelOptTableImpl create(RelOptSchema schema, RelDataType rowType,
                                     Table table, List<String> names,
                                     Expression expression) {
  final Function<Class, Expression> expressionFunction =
      (Function) Functions.constant(expression);
  return new RelOptTableImpl(schema, rowType, names, table,
      expressionFunction, table.getStatistic().getRowCount());
}
 
Example 7
Source File: SecurityAlarmResolver.java    From arcusplatform with Apache License 2.0 5 votes vote down vote up
@Override
public Action generate(ActionContext context, Address target, Map<String, Object> variables) {
   String value = (String) variables.get("alarm-state");
   String type;
   String mode=null;;
   switch(value) {
   case SecuritySubsystemCapability.ALARMMODE_ON:
      type = SecuritySubsystemCapability.ArmBypassedRequest.NAME;
      mode=SecuritySubsystemCapability.ALARMMODE_ON;
      break;
   case SecuritySubsystemCapability.ALARMMODE_PARTIAL:
      type = SecuritySubsystemCapability.ArmBypassedRequest.NAME;
      mode=SecuritySubsystemCapability.ALARMMODE_PARTIAL;
      break;
   case SecuritySubsystemCapability.ALARMMODE_OFF:
      type = SecuritySubsystemCapability.DisarmRequest.NAME;
      break;
      
   default:
      throw new ErrorEventException(Errors.invalidParam("alarm-state"));
   }
   Map<String,Object>args=ImmutableMap.of();
   if(mode!=null){
      args=ImmutableMap.of(SecuritySubsystemCapability.ArmBypassedRequest.ATTR_MODE,mode);
   }
   return new SendAction(type, Functions.constant(target),args);
}
 
Example 8
Source File: PlatformDispatcherFactory.java    From arcusplatform with Apache License 2.0 5 votes vote down vote up
@Override
public Function<Object, Void> getResolverForReturnType(Method method) {
   if(Void.TYPE.equals(method.getReturnType())) {
      return Functions.constant(null);
   }
   throw new IllegalArgumentException("Unsupported return type of " + method.getReturnType() + ". Expected void.");
}
 
Example 9
Source File: SolrIndex.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
protected Function<? super String, ? extends SpatialContext> createSpatialContextMapper(
		Map<String, String> parameters) {
	// this should really be based on the schema
	ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
	SpatialContext geoContext = SpatialContextFactory.makeSpatialContext(parameters, classLoader);
	return Functions.constant(geoContext);
}
 
Example 10
Source File: ElasticsearchIndex.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
protected Function<? super String, ? extends SpatialContext> createSpatialContextMapper(
		Map<String, String> parameters) {
	// this should really be based on the schema
	ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
	SpatialContext geoContext = SpatialContextFactory.makeSpatialContext(parameters, classLoader);
	return Functions.constant(geoContext);
}
 
Example 11
Source File: RendererHints.java    From brooklyn-server with Apache License 2.0 4 votes vote down vote up
/**
 * Forces the given sensor or config key's value to be censored. It will be
 * presented as <code>********</code>.
 */
@Beta
public static <T> DisplayValue<T> censoredValue() {
    return new DisplayValue<T>(Functions.constant("********"));
}
 
Example 12
Source File: EnrichersYamlTest.java    From brooklyn-server with Apache License 2.0 4 votes vote down vote up
public static <E> Function<Object, E> constantOfSingletonMapValue(Map<?, E> singletonMap) {
    return Functions.constant(Iterables.getOnlyElement(singletonMap.values()));
}
 
Example 13
Source File: KnifeConvergeTaskFactory.java    From brooklyn-library with Apache License 2.0 4 votes vote down vote up
public KnifeConvergeTaskFactory<RET> knifeRunList(String runList) {
    this.runList = Functions.constant(runList);
    return self();
}
 
Example 14
Source File: SymbolToFieldExtractor.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
private static <T> Function<T, Object> constant(Object value) {
    //noinspection unchecked
    return (Function<T, Object>) Functions.constant(value);
}
 
Example 15
Source File: ThermostatResolver.java    From arcusplatform with Apache License 2.0 4 votes vote down vote up
private Action generateSetAttributes(ActionContext context, Address target, ThermostatAction action) {
   Map<String, Object> attributes = new HashMap<String, Object>(5);
   attributes.put(ThermostatCapability.ATTR_HVACMODE, action.getMode());
   switch(action.getMode()) {
   case ThermostatCapability.HVACMODE_AUTO:
      Preconditions.checkNotNull(action.getHeatSetPoint());
      Preconditions.checkNotNull(action.getCoolSetPoint());
      Model model = context.getModelByAddress(target);
      Preconditions.checkNotNull(model);
      //The minimum setpoint for the thermostat, inclusive.  The heatsetpoint can't be set below this and the coolsetpoint can't be set below minsetpoint + setpointseparation.
      double minSetPoint = ThermostatModel.getMinsetpoint(model).doubleValue();
      //The maximum setpoint for the thermostat, inclusive.  The coolsetpoint can't be set above this and the heatsetpoint can't be set above maxsetpoint - setpointseparation.
      double maxSetPoint = ThermostatModel.getMaxsetpoint(model).doubleValue();
      double seperation = ThermostatModel.getSetpointseparation(model).doubleValue();
      Preconditions.checkArgument(Precision.compareTo(action.getHeatSetPoint(), minSetPoint, PRECISION) >= 0 , "The heatsetpoint can't be set below minSetPoint");
      Preconditions.checkArgument(Precision.compareTo(action.getCoolSetPoint(), minSetPoint + seperation, PRECISION) >= 0 , "The coolsetpoint can't be set below minSetPoint + setpointseparation");
      Preconditions.checkArgument(Precision.compareTo(action.getCoolSetPoint(), maxSetPoint, PRECISION) <= 0 , "The coolsetpoint can't be set above maxSetPoint");
      Preconditions.checkArgument(Precision.compareTo(action.getHeatSetPoint(), maxSetPoint - seperation, PRECISION) <= 0 , "The heatsetpoint can't be set above maxsetpoint - setpointseparation");

      attributes.put(ThermostatCapability.ATTR_HEATSETPOINT, action.getHeatSetPoint());
      attributes.put(ThermostatCapability.ATTR_COOLSETPOINT, action.getCoolSetPoint());
      break;
   case ThermostatCapability.HVACMODE_HEAT:
      Preconditions.checkNotNull(action.getHeatSetPoint());
      attributes.put(ThermostatCapability.ATTR_HEATSETPOINT, action.getHeatSetPoint());
      attributes.put(ThermostatCapability.ATTR_COOLSETPOINT, action.getHeatSetPoint() + 2);
      break;
   case ThermostatCapability.HVACMODE_COOL:
      Preconditions.checkNotNull(action.getCoolSetPoint());
      attributes.put(ThermostatCapability.ATTR_COOLSETPOINT, action.getCoolSetPoint());
      attributes.put(ThermostatCapability.ATTR_HEATSETPOINT, action.getCoolSetPoint() - 2);
      break;

   }

   if (action.getFanmode() != null)
   {
      attributes.put(ThermostatCapability.ATTR_FANMODE, action.getFanmode());
   }
   return new SendAction(Capability.CMD_SET_ATTRIBUTES, Functions.constant(target), attributes);
}
 
Example 16
Source File: ThermostatResolver.java    From arcusplatform with Apache License 2.0 4 votes vote down vote up
private Action generateScheduleEnabled(ActionContext context, Address thermostat, boolean enable) {
   Address address = Address.platformService(context.getPlaceId(), ClimateSubsystemCapability.NAMESPACE);
   String command = enable ? ClimateSubsystemCapability.EnableSchedulerRequest.NAME : ClimateSubsystemCapability.DisableSchedulerRequest.NAME;
   Map<String, Object> attributes = ImmutableMap.of(EnableSchedulerRequest.ATTR_THERMOSTAT, thermostat.getRepresentation()); 
   return new SendAction(command, Functions.constant(address), attributes);
}
 
Example 17
Source File: CatalogActionTemplateResolver.java    From arcusplatform with Apache License 2.0 4 votes vote down vote up
private Action generateSetAttributesAction(Address target, Map<String, Object> attributes){
      return new SendAction(Capability.CMD_SET_ATTRIBUTES, Functions.constant(target), attributes);
}