Java Code Examples for org.eclipse.jdt.annotation.Nullable

The following examples show how to use org.eclipse.jdt.annotation.Nullable. These examples are extracted from open source projects. 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 Project: arcusplatform   Source File: SQLite3StatementBindInvoker.java    License: Apache License 2.0 6 votes vote down vote up
@Nullable
public static Object bind(SQLiteStatement stmt, Class<?> type, int index) {
   try {
      if (type.equals(String.class)) {
         return stmt.columnString(index);
      } else if (type.equals(Integer.class) || type.equals(int.class) ) {
         return stmt.columnInt(index);
      } else if (type.equals(Long.class) || type.equals(long.class)) {
         return stmt.columnLong(index);
      } else if (type.equals(Byte.class) || type.equals(byte.class) ) {
         return (byte)stmt.columnInt(index);
      } else if ( type.equals(Boolean.class) || type.equals(boolean.class) ) {
         return stmt.columnInt(index) != 0;
      } else if (type.equals(Double.class) || type.equals(double.class)) {
         return stmt.columnDouble(index);
      } else if (type.equals(float.class) || type.equals(Float.class)) {
         return (float)stmt.columnDouble(index);
      } else if (type.equals(Serializable.class)) {
         return stmt.columnBlob(index);
      }
   } catch (SQLiteException e) {
      log.error("sql bind invoker could not invoke:" , e);
   }

   return null;
}
 
Example 2
Source Project: arcusplatform   Source File: ReflexDriver.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public @Nullable List<Action> match(ReflexDriverContext ctx, byte[] protocol) {
   if (notification) {
      parseIasZoneStatusChangeNotification(ctx, protocol);
      if (matchesIasZoneStatusChangeNotification(ctx)) {
         return actions;
      }
   }

   if (attr) {
      parseIasZoneAttributes(ctx, protocol);
      if (matchesIasZoneAttributes(ctx)) {
         return actions;
      }
   }

   return null;
}
 
Example 3
Source Project: arcusplatform   Source File: ProductLoaderForPairing.java    License: Apache License 2.0 6 votes vote down vote up
@Nullable
public static ProductCacheInfo saveOrClear(SubsystemContext<?> context, Optional<ProductCatalogEntry> product) {
	if(product !=null && product.isPresent()) {
		ProductCatalogEntry cur = product.get();
		ProductCacheInfo info = new ProductCacheInfo();
		info.pairingIdleTimeoutMs = cur.getPairingIdleTimeoutMs();
		info.pairingTimeoutMs = cur.getPairingTimeoutMs();	
		//Save it only if at least one value is not null to avoid saving ProductCacheInfo as Variable
		if(info.pairingIdleTimeoutMs != null || info.pairingTimeoutMs != null) {
			context.setVariable(VAR_PRODUCT_INFO, info);
			return info;
		}
	}
	context.setVariable(VAR_PRODUCT_INFO, null);
	return null;
}
 
Example 4
Source Project: arcusplatform   Source File: HubAttributeReporter.java    License: Apache License 2.0 6 votes vote down vote up
public HubAttributeReporter(Port port) {
   this.port = port;
   this.reporter = new PeriodicReporter();

   this.expectedSetAttributesLock = new ReentrantLock();
   this.expectedSetAttributes = new AtomicReference<>();
   this.aggregateReports = new HashMap<>();

   HubAttributesService.updates().subscribeOn(RxIris.io).retry().subscribe(new rx.Subscriber<HubAttributesService.UpdatedAttribute>() {
      @Override
      public void onNext(@Nullable UpdatedAttribute updated) {
         HubAttributesService.Attribute<?> attr = (updated != null) ? updated.getAttr() : null;
         if (attr != null) {
            hubAttributeUpdated(attr);
         }
      }

      @Override public void onError(@Nullable Throwable e) { }
      @Override public void onCompleted() { }
   });
}
 
Example 5
Source Project: arcusplatform   Source File: TestVideoAddedAppender.java    License: Apache License 2.0 5 votes vote down vote up
protected PlatformMessage videoAdded(@Nullable Address actor) {
	Map<String, Object> attributes =
			ModelFixtures
				.buildRecordingAttributes((UUID) videoAddress.getId())
				.put(RecordingCapability.ATTR_PLACEID, placeId.toString())
				.put(RecordingCapability.ATTR_CAMERAID, cameraId.toString())
				.create();
	MessageBody added = MessageBody.buildMessage(Capability.EVENT_ADDED, attributes);
	return 
			PlatformMessage
				.buildBroadcast(added, Address.fromString((String) attributes.get(Capability.ATTR_ADDRESS)))
				.withActor(actor)
				.withPlaceId(placeId)
				.create();
}
 
Example 6
Source Project: arcusplatform   Source File: BaseAlarmIncidentService.java    License: Apache License 2.0 5 votes vote down vote up
@Nullable
protected AlarmIncident onPlatformCompleted(UUID placeId, UUID incidentId, Address cancelledBy) {
	AlarmIncident incident = incidentDao.findById(placeId, incidentId);
	if(incident == null) {
		logger.warn("Incident cancellation succeeded, but incident could not be found [{}]", incidentId);
		return null;
	}
	else if(incident.getHubAlertState() == null || incident.getHubAlertState() == AlertState.COMPLETE) {
		// fully complete
		return onCompleted(incident, cancelledBy);
	}
	else {
		logger.debug("Incident [{}] is platform complete, waiting on hub to fully clear", incidentId);
		MonitoringState monitoringState = null;
		switch(incident.getMonitoringState()) {
		case PENDING:
		case DISPATCHING:
			// cancelled before dispatch
			monitoringState = MonitoringState.CANCELLED;
		default:
			monitoringState = incident.getMonitoringState();
		}
		AlarmIncident updated =
			AlarmIncident
				.builder(incident)
				.withPlatformAlertState(AlertState.COMPLETE)
				.withMonitoringState(monitoringState)
				.withCancelledBy(cancelledBy)
				.build();
		save(incident, updated);
		return updated;
	}
}
 
Example 7
Source Project: arcusplatform   Source File: AbstractKafkaConfig.java    License: Apache License 2.0 5 votes vote down vote up
private Boolean putIf(Properties props, String name, @Nullable String value) {
   if(value == null) {
      return false;
   }

   props.put(name, value);
   return true;
}
 
Example 8
Source Project: arcusplatform   Source File: DoorsNLocksSubsystem.java    License: Apache License 2.0 5 votes vote down vote up
private Map<String, String> notificationParams(Model m, @Nullable Map<String, String> additionalParams) {
   if(additionalParams == null) {
      additionalParams = ImmutableMap.of();
   }

   return ImmutableMap.<String, String>builder()
      .putAll(additionalParams)
      .put("deviceName", DeviceModel.getName(m, ""))
      .build();
}
 
Example 9
Source Project: arcusplatform   Source File: RxIris.java    License: Apache License 2.0 5 votes vote down vote up
public static Repeat repeat(long attempts, long delay, TimeUnit units, long duration, TimeUnit durationUnits, @Nullable AtomicBoolean alive) {
   return new RepeatBuilder()
      .attempts(attempts)
      .initial(delay, units)
      .delay(delay, units)
      .random((long)(0.10*TimeUnit.NANOSECONDS.convert(delay,units)), TimeUnit.NANOSECONDS)
      .factor(1.0)
      .duration(duration, durationUnits)
      .aliveOn(alive)
      .build();
}
 
Example 10
Source Project: arcusplatform   Source File: BaseRuleEnvironmentDaoImpl.java    License: Apache License 2.0 5 votes vote down vote up
@Nullable
public T findById(UUID placeId, Integer sequenceId) {
   Preconditions.checkNotNull(placeId);
   Preconditions.checkNotNull(sequenceId);

   try(Context c = metrics.startDaoReadTimer()) {
      BoundStatement bs = findById.bind(placeId, sequenceId);
      Row row = session.execute( bs ).one();
      if(row == null) {
         return null;
      }

      return buildEntity(row);
   }
}
 
Example 11
Source Project: arcusplatform   Source File: PairingState.java    License: Apache License 2.0 5 votes vote down vote up
@Nullable
private List<Map<String, Object>> getForm(ProductCatalogEntry product) {
	List<Map<String,Object>> inputs = new ArrayList<>();
	for(Step step: product.getPair()) {
		if(CollectionUtils.isEmpty(step.getInputs())) {
			continue;
		}
		
		for(Input input: step.getInputs()) {
			PairingInput pi = new PairingInput();
			pi.setLabel(input.getLabel());
			pi.setName(input.getName());
			switch(input.getType()) {
			case HIDDEN:
				pi.setType(PairingInput.TYPE_HIDDEN);
				break;
			case TEXT:
				pi.setType(PairingInput.TYPE_TEXT);
				break;
			default:
				throw new IllegalStateException("Invalid input type: " + input.getType());
			}
			pi.setValue(input.getValue());
			if(input.getMinlen() != null) {
				pi.setMinlen(input.getMinlen());
			}
			if(input.getMaxlen() != null) {
				pi.setMaxlen(input.getMaxlen());
			}
			pi.setRequired(Boolean.TRUE.equals(input.getRequired()));
			inputs.add(pi.toMap());
		}
	}
	
	return inputs;
}
 
Example 12
Source Project: arcusplatform   Source File: DefaultWatchHandle.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void onDirectoryDelete(@Nullable File directory) {
   if (directory == null) {
      return;
   }
   
   if (matches(directory)) {
      for (WatchListener listener : listeners) {
         listener.onDirectoryDelete(directory);
      }
   }
}
 
Example 13
Source Project: arcusplatform   Source File: Db.java    License: Apache License 2.0 5 votes vote down vote up
@Override
@Nullable
public Boolean execute(SQLiteConnection conn) throws Exception {
   SQLiteBackup backup = conn.initializeBackup(destination);
   try {
      backup.backupStep(-1);
   } finally {
      backup.dispose();
   }

   return backup.isFinished();
}
 
Example 14
Source Project: arcusplatform   Source File: PlatformBusClient.java    License: Apache License 2.0 5 votes vote down vote up
public PlatformBusClient(
      @NonNull PlatformMessageBus bus,
      @NonNull Executor executor,
      long defaultTimeoutMs,
      @Nullable Set<AddressMatcher> matchers
) {
   Preconditions.checkNotNull(bus);
   Preconditions.checkNotNull(executor);
   this.bus = bus;
   this.executor = executor;
   this.defaultTimeoutMs = defaultTimeoutMs;
   if(matchers != null) {
      bus.addMessageListener(matchers, this::queue);
   }
}
 
Example 15
Source Project: arcusplatform   Source File: SceneActionBuilder.java    License: Apache License 2.0 5 votes vote down vote up
@Nullable
public Action buildResilient() {
   Preconditions.checkNotNull(placeId, "Must specify placeId");
   Preconditions.checkNotNull(template, "Must specify a sceneTemplate");
   Preconditions.checkNotNull(name, "Must specify a name for the scene");
   Preconditions.checkNotNull(context, "Must specify the context");
   
   boolean isPremiumPlace = context.isPremium();
   ActionList.Builder builder = new ActionList.Builder();
   if(actions != null) {
      for(com.iris.messages.type.Action action: actions) {
         try {
            if(!Boolean.TRUE.equals(action.getPremium()) || isPremiumPlace) {
         	   addAction(action, template, builder);
            }else{
         	   context.logger().debug("Scene action [{}] for scene [{}] is skipped because place [{}] requires PREMIUM service level", action.getName(), template.getName(), context.getPlaceId());
            }
         }
         catch(Exception e) {
            context.logger().warn("Unable to create action for template [{}]", template, e);
         }
      }
   }
   if(notification) {
      addNotification(builder);
   }
   if(builder.isEmpty()) {
      return null;
   }
   return builder.build();
}
 
Example 16
protected void expectFindDeviceAndReturn(@Nullable String state) {
   if(state == null) {
      EasyMock.expect(deviceDao.findByProtocolAddress(device.getProtocolAddress())).andReturn(null);
   }
   else {
      device.setState(state);
      EasyMock.expect(deviceDao.findByProtocolAddress(device.getProtocolAddress())).andReturn(device);
   }
}
 
Example 17
Source Project: arcusplatform   Source File: ConversionService.java    License: Apache License 2.0 5 votes vote down vote up
@Nullable
@SuppressWarnings("unchecked")
public static <T> String from(@Nullable T value) {
   if (value == null) {
      return null;
   }

   Class<T> clazz = (Class<T>)value.getClass();
   return lookup(clazz).from(value);
}
 
Example 18
Source Project: arcusplatform   Source File: ComparableComparator.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public int compare(@Nullable T o1, @Nullable T o2) {
   if (o1 == o2) return 0;
   if (o1 == null) return -1;
   if (o2 == null) return 1;

   return o1.compareTo(o2);
}
 
Example 19
Source Project: arcusplatform   Source File: RtspInterleavedHandler.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void userEventTriggered(@Nullable ChannelHandlerContext ctx, @Nullable Object evt) throws Exception {
   if (evt instanceof IrisRtspSdp) {
      IrisRtspSdp sdp = (IrisRtspSdp)evt;
      log.trace("interleaved sdp: {}", sdp);
   }

   ctx.fireUserEventTriggered(evt);
}
 
Example 20
Source Project: arcusplatform   Source File: AlarmEvents.java    License: Apache License 2.0 5 votes vote down vote up
public static Event arm(Address addr, @Nullable Address actor, @NonNull MessageBody armRequest) {
   String armModeRaw = HubAlarmCapability.ArmRequest.getMode(armRequest);
   AlarmEvents.Mode armMode = "PARTIAL".equalsIgnoreCase(armModeRaw) ? AlarmEvents.Mode.PARTIAL : AlarmEvents.Mode.ON;

   Boolean bypassRaw = HubAlarmCapability.ArmRequest.getBypassed(armRequest);
   boolean bypass = bypassRaw == null ? false : bypassRaw.booleanValue();

   Integer entranceDelayRaw = HubAlarmCapability.ArmRequest.getEntranceDelaySecs(armRequest);
   int entranceDelay = entranceDelayRaw == null ? 30 : entranceDelayRaw.intValue();

   Integer exitDelayRaw = HubAlarmCapability.ArmRequest.getExitDelaySecs(armRequest);
   int exitDelay = exitDelayRaw == null ? 30 : exitDelayRaw.intValue();

   Integer alarmSensitivityRaw = HubAlarmCapability.ArmRequest.getAlarmSensitivityDeviceCount(armRequest);
   int alarmSensitivity = alarmSensitivityRaw == null ? 1 : alarmSensitivityRaw.intValue();

   Boolean silentRaw = HubAlarmCapability.ArmRequest.getSilent(armRequest);
   boolean silent = silentRaw == null ? false : silentRaw.booleanValue();

   Boolean soundsRaw = HubAlarmCapability.ArmRequest.getSoundsEnabled(armRequest);
   boolean sounds = soundsRaw == null ? false : soundsRaw.booleanValue();

   Collection<String> activeRaw = HubAlarmCapability.ArmRequest.getActiveDevices(armRequest);
   Set<String> active = activeRaw == null ? ImmutableSet.of() : ImmutableSet.copyOf(activeRaw);

   return new ArmEvent(addr, actor, armMode, bypass, entranceDelay, exitDelay, alarmSensitivity, silent, sounds, active);
}
 
Example 21
Source Project: arcusplatform   Source File: SessionController.java    License: Apache License 2.0 5 votes vote down vote up
@Nullable
private OculusSession getLastSession() {
   List<OculusSession> info = listRecentSessions();
   if(info == null || info.isEmpty()) {
      return null;
   }
   return info.get(0);
}
 
Example 22
Source Project: arcusplatform   Source File: HistoryTable.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public BoundStatement listByIdBefore(
      CompositeId<UUID, Integer> id,
      @Nullable UUID before
) {
   if(before == null) {
      return listById(id);
   }
   return listByIdBefore.bind(id.getPrimaryId(), id.getSecondaryId(), before);
}
 
Example 23
Source Project: arcusplatform   Source File: AbstractHubDriver.java    License: Apache License 2.0 5 votes vote down vote up
public @Nullable UUID verifyPinCode(byte[] ascii) {
   try {
      return verifyPinCode(new String(ascii, StandardCharsets.US_ASCII));
   } catch (Exception ex) {
      log.warn("could not decode pin code: ", ex);
      return null;
   }
}
 
Example 24
Source Project: arcusplatform   Source File: BackupService.java    License: Apache License 2.0 5 votes vote down vote up
private static List<Callable<Void>> getBackupTasks(final Db db) {
   List<Callable<Void>> tasks = new ArrayList<>(listeners.size());
   for (final BackupListener listener : listeners) {
      tasks.add(new Callable<Void>() {
         @Override
         @Nullable
         public Void call() {
            listener.hubBackup(db);
            return null;
         }
      });
   }

   return tasks;
}
 
Example 25
protected PlatformMessage createRemovedEvent(@Nullable String status) {
   MessageBody event =
         DeviceAdvancedCapability.RemovedDeviceEvent
            .builder()
            .withProtocol(device.getProtocol())
            .withProtocolId(device.getProtocolid())
            .withStatus(status)
            .build();
   PlatformMessage message =
         PlatformMessage
            .createBroadcast(event, Address.fromString(device.getProtocolAddress()));
   return message;
}
 
Example 26
Source Project: arcusplatform   Source File: IrisLayout.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public String doLayout(@Nullable ILoggingEvent event) {
   if (event == null) {
      return "";
   }

   for(Map.Entry<String, String> e: event.getMDCPropertyMap().entrySet()) {
      object.addProperty(e.getKey(), e.getValue());
   }

   object.addProperty("ts", event.getTimeStamp());
   object.addProperty("lvl", event.getLevel().toString());
   object.addProperty("thd", event.getThreadName());
   object.addProperty("log", event.getLoggerName());
   object.addProperty("msg", event.getFormattedMessage());
   object.addProperty("svc", "agent");

   String hubId = IrisHal.getHubIdOrNull();
   if (hubId != null) {
      object.addProperty("hst", hubId);
   }

   String hubVersion = IrisHal.getOperatingSystemVersionOrNull();
   if (hubVersion != null) {
      object.addProperty("svr", hubVersion);
   }

   IThrowableProxy thrw = event.getThrowableProxy();
   if (thrw != null) {
      String stackTrace = converter.convert(event);
      object.addProperty("exc", stackTrace);
   } else {
      object.remove("exc");
   }

   return IrisAgentSotConverter.SOT + GSON.toJson(object);
}
 
Example 27
Source Project: arcusplatform   Source File: RxIris.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void call(@Nullable T1 v1) {
   if (v1 == null) {
      throw new NullPointerException();
   }

   run(v1);
}
 
Example 28
Source Project: arcusplatform   Source File: RxIris.java    License: Apache License 2.0 5 votes vote down vote up
public static Retry retry(long attempts, long delay, TimeUnit units, long duration, TimeUnit durationUnits, @Nullable AtomicBoolean alive) {
   return new RetryBuilder()
      .attempts(attempts)
      .initial(delay, units)
      .delay(delay, units)
      .random((long)(0.10*TimeUnit.NANOSECONDS.convert(delay,units)), TimeUnit.NANOSECONDS)
      .factor(1.0)
      .duration(duration, durationUnits)
      .aliveOn(alive)
      .build();
}
 
Example 29
Source Project: arcusplatform   Source File: RxIris.java    License: Apache License 2.0 5 votes vote down vote up
private static <T> Observable.Operator<T,T> logger(final LogLevel level, final Logger log, final String format) {
   return new Operator<T,T>() {
      @Override
      public rx.Subscriber<? super T> run(final rx.Subscriber<? super T> s) {
         return new rx.Subscriber<T>(s) {
            @Override
            public void onNext(@Nullable T value) {
               if (!s.isUnsubscribed()) {
                  dolog(level, log, format, value);
                  s.onNext(value);
               }
            }

            @Override
            public void onCompleted() {
               if (!s.isUnsubscribed()) {
                  s.onCompleted();
               }
            }

            @Override
            public void onError(@Nullable Throwable e) {
               if (!s.isUnsubscribed()) {
                  s.onError(e);
               }
            }
         };
      }
   };
}
 
Example 30
Source Project: arcusplatform   Source File: RecordingSessionFactory.java    License: Apache License 2.0 5 votes vote down vote up
protected abstract T create(
   VideoSessionRegistry registry,
   @Nullable ChannelHandlerContext ctx,
   VideoRecordingManager dao,
   RecordingEventPublisher eventPublisher,
   VideoStorageSession storage,
   double precapture,
   boolean stream
);