method2testcases
stringlengths
118
6.63k
### Question: TimeDuration { public static Duration ofMinutes(double min) { return Duration.ofNanos((long) (min * 60 * NANOSEC_IN_SEC)); } private TimeDuration(); static Duration createDuration(long sec, int nanoSec); static Duration ofDays(double day); static Duration ofHours(double hour); static Duration ofMinutes(d...
### Question: TimeDuration { public static Duration ofHours(double hour) { return Duration.ofNanos((long) (hour * 60 * 60 * NANOSEC_IN_SEC)); } private TimeDuration(); static Duration createDuration(long sec, int nanoSec); static Duration ofDays(double day); static Duration ofHours(double hour); static Duration ofMinu...
### Question: TimeDuration { public static Duration ofHertz(double hz) { if (hz <= 0.0) { throw new IllegalArgumentException("Frequency has to be greater than 0.0"); } return Duration.ofNanos((long) (1000000000.0 / hz)); } private TimeDuration(); static Duration createDuration(long sec, int nanoSec); static Duration o...
### Question: Services implements IServices { @Override @Transactional public Node updateConfiguration(Node configToUpdate, List<ConfigPv> configPvs) { logger.info("Updating configuration unique id: {}", configToUpdate.getUniqueId()); return nodeDAO.updateConfiguration(configToUpdate, configPvs); } @Override Node getP...
### Question: Services implements IServices { @Override public List<SnapshotItem> getSnapshotItems(String snapshotUniqueId) { logger.info("Getting snapshot items for snapshot id {}", snapshotUniqueId); return nodeDAO.getSnapshotItems(snapshotUniqueId); } @Override Node getParentNode(String uniqueNodeId); @Override Lis...
### Question: TimeDuration { public static String toSecondString(Duration duration){ return duration.getSeconds() + "." + format.format(duration.getNano()); } private TimeDuration(); static Duration createDuration(long sec, int nanoSec); static Duration ofDays(double day); static Duration ofHours(double hour); static ...
### Question: Services implements IServices { @Override public Node getParentNode(String uniqueNodeId) { return nodeDAO.getParentNode(uniqueNodeId); } @Override Node getParentNode(String uniqueNodeId); @Override List<Node> getSnapshots(String configUniqueId); @Override Node getSnapshot(String snapshotUniqueId); @Overr...
### Question: TimeInterval { public static TimeInterval between(Instant start, Instant end) { return new TimeInterval(start, end); } private TimeInterval(Instant start, Instant end); boolean contains(Instant instant); static TimeInterval between(Instant start, Instant end); TimeInterval minus(Duration duration); stati...
### Question: Services implements IServices { @Override public List<Node> getChildNodes(String nodeUniqueId) { logger.info("Getting child nodes for node unique id={}", nodeUniqueId); return nodeDAO.getChildNodes(nodeUniqueId); } @Override Node getParentNode(String uniqueNodeId); @Override List<Node> getSnapshots(Strin...
### Question: TimeParser { @Deprecated public static Instant getInstant(String time) { if (time.equalsIgnoreCase(NOW)) { return Instant.now(); } else { Matcher nUnitsAgoMatcher = timeQuantityUnitsPattern.matcher(time); while (nUnitsAgoMatcher.find()) { return Instant.now().minus(parseDuration(nUnitsAgoMatcher.group(1))...
### Question: TimeParser { @Deprecated public static Duration parseDuration(String string) { int quantity = 0; String unit = ""; Matcher timeQunatityUnitsMatcher = durationTimeQunatityUnitsPattern.matcher(string); Map<ChronoUnit, Integer> timeQuantities = new HashMap<>(); while (timeQunatityUnitsMatcher.find()) { quant...
### Question: Services implements IServices { @Override public Node getRootNode() { return nodeDAO.getRootNode(); } @Override Node getParentNode(String uniqueNodeId); @Override List<Node> getSnapshots(String configUniqueId); @Override Node getSnapshot(String snapshotUniqueId); @Override Node createNode(String parentsU...
### Question: TimeParser { public static String format(final TemporalAmount amount) { final StringBuilder buf = new StringBuilder(); if (amount instanceof Period) { final Period period = (Period) amount; if (period.isZero()) return NOW; if (period.getYears() == 1) buf.append("1 year "); else if (period.getYears() > 1) ...
### Question: CommandExecutor implements Callable<Integer> { public static List<String> splitCmd(final String cmd) { final List<String> items = new ArrayList<>(); final int len = cmd.length(); int i = 0; final StringBuilder line = new StringBuilder(); while (i < len) { char c = cmd.charAt(i); if (c == ' ' || c == '\t')...
### Question: CommandExecutor implements Callable<Integer> { @Override public Integer call() throws Exception { String cmd = process_builder.command().get(0); final int sep = cmd.lastIndexOf('/'); if (sep >= 0) cmd = cmd.substring(sep+1); process = process_builder.start(); final Thread stdout = new LogWriter(process.ge...
### Question: ResourceParser { public static URI createResourceURI(final String resource) throws Exception { try { final URI uri = URI.create(resource); if (uri.getScheme() != null) return uri; else { final Path fileResource = Paths.get(resource); return fileResource.toUri(); } } catch (Throwable ex) { try { return new...
### Question: SimProposal extends Proposal { public SimProposal(final String name, final String... arguments) { super(name); this.arguments = arguments; } SimProposal(final String name, final String... arguments); @Override String getDescription(); @Override List<MatchSegment> getMatch(final String text); }### Answer:...
### Question: SimProposal extends Proposal { @Override public List<MatchSegment> getMatch(final String text) { final List<String> split = splitNameAndParameters(text); if (split.isEmpty()) return List.of(); final List<MatchSegment> segs = new ArrayList<>(split.size()); final String noparm_text = split.get(0); final int...
### Question: History implements ProposalProvider { public History() { this(10); } History(); History(final int max_size); @Override String getName(); synchronized void add(final Proposal proposal); @Override synchronized List<Proposal> lookup(String text); }### Answer: @Test public void testHistory() { final History...
### Question: FormulaFunctionProposal extends Proposal { @Override public List<MatchSegment> getMatch(final String text) { final int match = text.indexOf(function.getName()); if (match < 0) return List.of(MatchSegment.normal(getDescription())); final List<MatchSegment> segs = new ArrayList<>(); if (match > 0) segs.add(...
### Question: Services implements IServices { @Override public List<ConfigPv> getConfigPvs(String configUniqueId) { logger.info("Getting config pvs config id id {}", configUniqueId); return nodeDAO.getConfigPvs(configUniqueId); } @Override Node getParentNode(String uniqueNodeId); @Override List<Node> getSnapshots(Stri...
### Question: ScanCommandImplTool { @SuppressWarnings("unchecked") public static <C extends ScanCommand> ScanCommandImpl<C> implement(final C command, final JythonSupport jython) throws Exception { for (ScanCommandImplFactory factory : factories) { ScanCommandImpl<?> impl = factory.createImplementation(command, jython)...
### Question: Proposal { public String apply(final String text) { final StringBuilder result = new StringBuilder(); final List<MatchSegment> match = getMatch(text); for (MatchSegment seg : match) if (seg.getType() != MatchSegment.Type.COMMENT) result.append(seg.getText()); return result.toString(); } Proposal(final Str...
### Question: Proposal { public List<MatchSegment> getMatch(final String text) { final int match = value.indexOf(text); if (match < 0) return List.of(MatchSegment.normal(value)); else { final List<MatchSegment> segs = new ArrayList<>(); if (match > 0) segs.add(MatchSegment.normal(value.substring(0, match))); if (! text...
### Question: LocProposal extends Proposal { static List<String> splitNameTypeAndInitialValues(final String text) { final List<String> result = new ArrayList<>(); int sep = text.indexOf('<'); if (sep >= 0) { result.add(text.substring(0, sep).trim()); int pos = text.indexOf('>', sep+1); if (pos < 0) result.add(text.subs...
### Question: LocProposal extends Proposal { public LocProposal(final String name, final String type, final String... initial_values) { super(name); this.type = type; this.initial_values = initial_values; } LocProposal(final String name, final String type, final String... initial_values); @Override String getDescriptio...
### Question: LocProposal extends Proposal { @Override public List<MatchSegment> getMatch(final String text) { if (! text.startsWith("loc")) return List.of(MatchSegment.normal(getDescription())); final List<String> split = splitNameTypeAndInitialValues(text); if (split.size() < 1) return List.of(); final List<MatchSegm...
### Question: PreferencesReader { static String replaceProperties(final String value) { if (value == null) return value; String result = value; Matcher matcher = PROP_PATTERN.matcher(value); while (matcher.find()) { final String prop_spec = matcher.group(); final String prop_name = prop_spec.substring(2, prop_spec.leng...
### Question: UpdateThrottle { public UpdateThrottle(final long dormant_time, final TimeUnit unit, final Runnable update) { this(dormant_time, unit, update, TIMER); } UpdateThrottle(final long dormant_time, final TimeUnit unit, final Runnable update); UpdateThrottle(final long dormant_time, final TimeUnit unit, final ...
### Question: Services implements IServices { @Override public Node saveSnapshot(String configUniqueId, List<SnapshotItem> snapshotItems, String snapshotName, String userName, String comment) { logger.info("Saving snapshot for config id {}", configUniqueId); logger.info("Snapshot name: {}, values:", snapshotName); for ...
### Question: Services implements IServices { @Override public List<Node> getFromPath(String path){ return nodeDAO.getFromPath(path); } @Override Node getParentNode(String uniqueNodeId); @Override List<Node> getSnapshots(String configUniqueId); @Override Node getSnapshot(String snapshotUniqueId); @Override Node create...
### Question: ArrayScalarDivisionFunction extends BaseArrayFunction { @Override public VType compute(VType... args) { if(VTypeHelper.isNumericArray(args[0]) && args[1] instanceof VNumber){ VNumberArray array1 = (VNumberArray)args[0]; VNumber factor = (VNumber) args[1]; return VNumberArray.of( ListMath.rescale(array1.ge...
### Question: ArrayMinFunction extends BaseArrayFunction { @Override public VType compute(VType... args) { if (VTypeHelper.isNumericArray(args[0])) { return VDouble.of(Arrays.stream(VTypeHelper.toDoubles(args[0])).summaryStatistics().getMin(), Alarm.none(), Time.now(), Display.none()); } else { return DEFAULT_NAN_DOUBL...
### Question: ElementAtNumberFunction extends BaseArrayFunction { @Override public VType compute(VType... args) throws Exception { boolean isStringArray = args[0] instanceof VStringArray; if(VTypeHelper.isNumericArray(args[0]) && args[1] instanceof VNumber){ VNumberArray numberArray = (VNumberArray)args[0]; int index =...
### Question: ArrayOfFunction extends BaseArrayFunction { @Override public VType compute(VType... args) { if(args[0] instanceof VString){ List<String> data = new ArrayList<>(); for (Object arg : args) { if(arg == null){ data.add(null); } else { data.add(((VString)arg).getValue()); } } return VStringArray.of(data, Alarm...
### Question: ArrayDivisionFunction extends BaseArrayFunction { @Override public VType compute(VType... args) throws Exception { if(VTypeHelper.isNumericArray(args[0]) && VTypeHelper.isNumericArray(args[1])){ VNumberArray array1 = (VNumberArray)args[0]; VNumberArray array2 = (VNumberArray)args[1]; if(array1.getData().s...
### Question: Services implements IServices { @Override public String getFullPath(String uniqueNodeId){ return nodeDAO.getFullPath(uniqueNodeId); } @Override Node getParentNode(String uniqueNodeId); @Override List<Node> getSnapshots(String configUniqueId); @Override Node getSnapshot(String snapshotUniqueId); @Override...
### Question: ArrayMaxFunction extends BaseArrayFunction { @Override public VType compute(VType... args) { if (VTypeHelper.isNumericArray(args[0])) { return VDouble.of(Arrays.stream(VTypeHelper.toDoubles(args[0])).summaryStatistics().getMax(), Alarm.none(), Time.now(), Display.none()); } else { return DEFAULT_NAN_DOUBL...
### Question: ArrayMultiplicationFunction extends BaseArrayFunction { @Override public VType compute(VType... args) throws Exception { if(args[0] instanceof VNumberArray && args[1] instanceof VNumberArray){ VNumberArray array1 = (VNumberArray)args[0]; VNumberArray array2 = (VNumberArray)args[1]; if(array1.getData().siz...
### Question: ArrayRangeOfFunction extends BaseArrayFunction { @Override public VType compute(VType... args) { if(args[0] instanceof VNumberArray){ VNumberArray array = (VNumberArray)args[0]; Range range = array.getDisplay().getDisplayRange(); double min = range.getMinimum(); double max = range.getMaximum(); return VNu...
### Question: ScaleArrayFormulaFunction extends BaseArrayFunction { @Override public VType compute(VType... args) throws Exception{ if(args.length != 2 && args.length != 3){ throw new Exception(String.format("Function %s takes 2 or 3 aruments, got %d", getName(), args.length)); } if(VTypeHelper.isNumericArray(args[0]))...
### Question: ArrayStatsFunction extends BaseArrayFunction { @Override public VType compute(VType... args) { if (VTypeHelper.isNumericArray(args[0])) { DoubleSummaryStatistics stats = Arrays.stream(VTypeHelper.toDoubles(args[0])).summaryStatistics(); return VStatistics.of(stats.getAverage(), Double.NaN, stats.getMin(),...
### Question: ArraySumFunction extends BaseArrayFunction { @Override public VType compute(VType... args) { if(VTypeHelper.isNumericArray(args[0]) && args[1] instanceof VNumber){ VNumberArray array = (VNumberArray)args[0]; VNumber offset = (VNumber)args[1]; return VNumberArray.of( ListMath.rescale(array.getData(), 1, of...
### Question: ArrayInverseScalarDivisionFunction extends BaseArrayFunction { @Override public VType compute(VType... args) { if(args[0] instanceof VNumber && VTypeHelper.isNumericArray(args[1])){ VNumberArray array = (VNumberArray)args[1]; VNumber factor = (VNumber) args[0]; return VNumberArray.of( ListMath.inverseResc...
### Question: ArrayPowFunction extends BaseArrayFunction { @Override public VType compute(VType... args) { if(VTypeHelper.isNumericArray(args[0]) && args[1] instanceof VNumber){ VNumberArray array = (VNumberArray)args[0]; VNumber exponent = (VNumber)args[1]; return VNumberArray.of( ListMath.pow(array.getData(), exponen...
### Question: HistogramOfFunction extends BaseArrayFunction { @Override public VType compute(VType... args) { if (VTypeHelper.isNumericArray(args[0])) { VNumberArray numberArray = (VNumberArray) args[0]; if (numberArray == null) { return null; } VNumberArray previousValue = null; VNumberArray previousResult = null; Ran...
### Question: SubArrayFunction extends BaseArrayFunction { @Override public VType compute(VType... args) throws Exception { VNumber fromIndex = (VNumber) args[1]; VNumber toIndex = (VNumber) args[2]; if(VTypeHelper.isNumericArray(args[0])){ VNumberArray array = (VNumberArray)args[0]; if(fromIndex.getValue().intValue() ...
### Question: FieldRequest { public void encode(final ByteBuffer buffer) throws Exception { desc.encode(buffer); } FieldRequest(final String request); FieldRequest(final int pipeline, final String request); void encodeType(final ByteBuffer buffer); void encode(final ByteBuffer buffer); @Override String toString(); }#...
### Question: SnapshotDataConverter { public static SnapshotPv fromVType(VType vType) { SnapshotPvDataType dataType = getDataType(vType); if(vType instanceof VNumber) { VNumber vNumber = (VNumber)vType; Alarm alarm = vNumber.getAlarm(); Instant instant = vNumber.getTime().getTimestamp(); return SnapshotPv.builder() .al...
### Question: VTypeHelper { public static double[] toDoubles(final VType value) { final double[] array; if (value instanceof VNumberArray) { final ListNumber list = ((VNumberArray) value).getData(); array = new double[list.size()]; for (int i = 0; i < array.length; ++i) { array[i] = list.getDouble(i); } } else array = ...
### Question: VTypeHelper { public static String toString(final VType value) { if (value == null) { return "null"; } if (isDisconnected(value)) { return null; } if (value instanceof VNumber) { return ((VNumber) value).getValue().toString(); } if (value instanceof VEnum) { return ((VEnum) value).getValue(); } if (value ...
### Question: VTypeHelper { public static boolean isNumericArray(final VType value) { return value instanceof VNumberArray || value instanceof VEnumArray; } final static double toDouble(final VType value); static double[] toDoubles(final VType value); static String toString(final VType value); static double toDouble(f...
### Question: VTypeHelper { public static int getArraySize(final VType value) { final ListInteger sizes; if (value instanceof VNumberArray) { sizes = ((VNumberArray) value).getSizes(); } else if (value instanceof VEnumArray) { sizes = ((VEnumArray) value).getSizes(); } else if (value instanceof VStringArray) { sizes = ...
### Question: VTypeHelper { public static Time lastestTimeOf(final VType a, final VType b) { final Time ta = Time.timeOf(a); final Time tb = Time.timeOf(b); if (ta.getTimestamp().isAfter(tb.getTimestamp())) { return ta; } return tb; } final static double toDouble(final VType value); static double[] toDoubles(final VTy...
### Question: VTypeHelper { final public static Instant getTimestamp(final VType value) { final Time time = Time.timeOf(value); if (time != null && time.isValid()) { return time.getTimestamp(); } return Instant.now(); } final static double toDouble(final VType value); static double[] toDoubles(final VType value); stat...
### Question: VTypeHelper { public static VType transformTimestamp(final VType value, final Instant time) { if (value instanceof VDouble) { final VDouble number = (VDouble) value; return VDouble.of(number.getValue().doubleValue(), number.getAlarm(), Time.of(time), number.getDisplay()); } if (value instanceof VNumber) {...
### Question: SnapshotDataConverter { protected static String getScalarValueString(Object value) { ObjectMapper objectMapper = new ObjectMapper(); Object[] valueArray = {value}; try { return objectMapper.writeValueAsString(valueArray); } catch (JsonProcessingException e) { throw new PVConversionException(String.format(...
### Question: VTypeHelper { public static Alarm highestAlarmOf(final VType a, VType b) { return Alarm.highestAlarmOf(java.util.List.of(a, b), false); } final static double toDouble(final VType value); static double[] toDoubles(final VType value); static String toString(final VType value); static double toDouble(final ...
### Question: SnapshotDataConverter { protected static String getNumberArrayValueString(VNumberArray vNumberArray) { List<Object> valueList = new ArrayList<>(); if(vNumberArray instanceof VByteArray || vNumberArray instanceof VUByteArray || vNumberArray instanceof VShortArray || vNumberArray instanceof VUShortArray || ...
### Question: SnapshotDataConverter { protected static String getDimensionString(VNumberArray vNumberArray) { ListInteger sizes = vNumberArray.getSizes(); List<Integer> sizesAsIntList = new ArrayList<>(); for(int i = 0; i < sizes.size(); i++) { sizesAsIntList.add(sizes.getInt(i)); } ObjectMapper objectMapper = new Obje...
### Question: SnapshotDataConverter { protected static ListInteger toSizes(SnapshotPv snapshotPv) { ObjectMapper objectMapper = new ObjectMapper(); try { int[] sizes = objectMapper.readValue(snapshotPv.getSizes(), int[].class); return CollectionNumbers.toListInt(sizes); } catch (Exception e) { throw new PVConversionExc...
### Question: Services implements IServices { @Override public Node createNode(String parentsUniqueId, Node node) { Node parentFolder = nodeDAO.getNode(parentsUniqueId); if (parentFolder == null || !parentFolder.getNodeType().equals(NodeType.FOLDER)) { String message = String.format("Cannot create new folder as parent ...
### Question: SnapshotDataConverter { public static SnapshotItem fromSnapshotPv(SnapshotPv snapshotPv, SnapshotPv readback) { if(snapshotPv == null) { return null; } SnapshotItem snapshotItem = SnapshotItem.builder() .configPv(snapshotPv.getConfigPv()) .snapshotId(snapshotPv.getSnapshotId()) .build(); if(snapshotPv.get...
### Question: NodeRowMapper implements RowMapper<Node> { @Override public Node mapRow(ResultSet resultSet, int rowIndex) throws SQLException { return Node.builder() .id(resultSet.getInt("id")) .nodeType(NodeType.valueOf(resultSet.getString("type"))) .created(resultSet.getTimestamp("created")) .lastModified(resultSet.ge...
### Question: SnapshotPvRowMapper implements RowMapper<SnapshotPv> { @Override public SnapshotPv mapRow(ResultSet resultSet, int rowIndex) throws SQLException { ConfigPv configPv = new ConfigPvRowMapper().mapRow(resultSet, rowIndex); return SnapshotPv.builder() .configPv(configPv) .snapshotId(resultSet.getInt("snapshot...
### Question: SnapshotController extends BaseController { @GetMapping("/snapshot/{uniqueNodeId}") public Node getSnapshot(@PathVariable String uniqueNodeId) { return services.getSnapshot(uniqueNodeId); } @GetMapping("/snapshot/{uniqueNodeId}") Node getSnapshot(@PathVariable String uniqueNodeId); @GetMapping("/snapshot...
### Question: SnapshotController extends BaseController { @GetMapping("/snapshot/{uniqueNodeId}/items") public List<SnapshotItem> getSnapshotItems(@PathVariable String uniqueNodeId) { return services.getSnapshotItems(uniqueNodeId); } @GetMapping("/snapshot/{uniqueNodeId}") Node getSnapshot(@PathVariable String uniqueN...
### Question: SnapshotController extends BaseController { @PutMapping("/snapshot/{configUniqueId}") public Node saveSnapshot(@PathVariable String configUniqueId, @RequestParam(required = true) String snapshotName, @RequestParam(required = true) String userName, @RequestParam(required = true) String comment, @RequestBod...
### Question: Services implements IServices { @Override public Node getNode(String nodeId) { logger.info("Getting node {}", nodeId); return nodeDAO.getNode(nodeId); } @Override Node getParentNode(String uniqueNodeId); @Override List<Node> getSnapshots(String configUniqueId); @Override Node getSnapshot(String snapshotU...
### Question: ConfigurationController extends BaseController { @GetMapping("/root") public Node getRootNode() { return services.getRootNode(); } @PutMapping("/node/{parentsUniqueId}") Node createNode(@PathVariable String parentsUniqueId, @RequestBody final Node node); @GetMapping("/node/{uniqueNodeId}") Node getNode(@...
### Question: ConfigurationController extends BaseController { @PutMapping("/node/{parentsUniqueId}") public Node createNode(@PathVariable String parentsUniqueId, @RequestBody final Node node) { if(node.getUserName() == null || node.getUserName().isEmpty()) { throw new IllegalArgumentException("User name must be non-nu...
### Question: ConfigurationController extends BaseController { @GetMapping("/node/{uniqueNodeId}/children") public List<Node> getChildNodes(@PathVariable final String uniqueNodeId) { return services.getChildNodes(uniqueNodeId); } @PutMapping("/node/{parentsUniqueId}") Node createNode(@PathVariable String parentsUnique...
### Question: ConfigurationController extends BaseController { @GetMapping("/node/{uniqueNodeId}") public Node getNode(@PathVariable final String uniqueNodeId) { return services.getNode(uniqueNodeId); } @PutMapping("/node/{parentsUniqueId}") Node createNode(@PathVariable String parentsUniqueId, @RequestBody final Node...
### Question: ConfigurationController extends BaseController { @GetMapping("/config/{uniqueNodeId}/snapshots") public List<Node> getSnapshots(@PathVariable String uniqueNodeId) { return services.getSnapshots(uniqueNodeId); } @PutMapping("/node/{parentsUniqueId}") Node createNode(@PathVariable String parentsUniqueId, @...
### Question: ConfigurationController extends BaseController { @DeleteMapping("/node/{uniqueNodeId}") public void deleteNode(@PathVariable final String uniqueNodeId) { services.deleteNode(uniqueNodeId); } @PutMapping("/node/{parentsUniqueId}") Node createNode(@PathVariable String parentsUniqueId, @RequestBody final No...
### Question: Services implements IServices { @Override public List<Node> getSnapshots(String configUniqueId) { logger.info("Obtaining snapshot for config id={}", configUniqueId); return nodeDAO.getSnapshots(configUniqueId); } @Override Node getParentNode(String uniqueNodeId); @Override List<Node> getSnapshots(String ...
### Question: ConfigurationController extends BaseController { @PostMapping("/node/{uniqueNodeId}") public Node moveNode(@PathVariable String uniqueNodeId, @RequestParam(value = "to", required = true) String to, @RequestParam(value = "username", required = true) String userName) { return services.moveNode(uniqueNodeId,...
### Question: ConfigurationController extends BaseController { @PostMapping("/node/{uniqueNodeId}/update") public Node updateNode(@PathVariable String uniqueNodeId, @RequestParam(value = "customTimeForMigration", required = true) String customTimeForMigration, @RequestBody Node nodeToUpdate) { return services.updateNod...
### Question: ConfigurationController extends BaseController { @GetMapping("/config/{uniqueNodeId}/items") public List<ConfigPv> getConfigPvs(@PathVariable String uniqueNodeId) { return services.getConfigPvs(uniqueNodeId); } @PutMapping("/node/{parentsUniqueId}") Node createNode(@PathVariable String parentsUniqueId, @...
### Question: Services implements IServices { @Override public Node getSnapshot(String snapshotUniqueId) { Node snapshot = nodeDAO.getSnapshot(snapshotUniqueId); if (snapshot == null) { String message = String.format("Snapshot with id=%s not found", snapshotUniqueId); logger.error(message); throw new SnapshotNotFoundEx...
### Question: ConfigurationController extends BaseController { @GetMapping("/path") public List<Node> getFromPath(@RequestParam(value = "path") String path){ List<Node> nodes = services.getFromPath(path); if(nodes == null){ throw new ResponseStatusException(HttpStatus.NOT_FOUND); } return nodes; } @PutMapping("/node/{...
### Question: ConfigurationController extends BaseController { @GetMapping("/path/{uniqueNodeId}") public String getFullPath(@PathVariable String uniqueNodeId){ String fullPath = services.getFullPath(uniqueNodeId); if(fullPath == null){ throw new ResponseStatusException(HttpStatus.NOT_FOUND); } return fullPath; } @Put...
### Question: SeverityLevelHelper { final public static SeverityLevel decodeSeverity(final VType value) { final Alarm alarm = Alarm.alarmOf(value); if (alarm == null) return SeverityLevel.OK; switch (alarm.getSeverity()) { case NONE: return SeverityLevel.OK; case MINOR: return SeverityLevel.MINOR; case MAJOR: return Se...
### Question: SeverityLevelHelper { final public static String getStatusMessage(final VType value) { final Alarm alarm = Alarm.alarmOf(value); if (alarm != null) return alarm.getName(); return SeverityLevel.OK.toString(); } final static SeverityLevel decodeSeverity(final VType value); final static String getStatusMess...
### Question: PlotSample implements PlotDataItem<Instant> { @Override public double getValue() { return org.phoebus.core.vtypes.VTypeHelper.toDouble(value, waveform_index.get()); } PlotSample(final AtomicInteger waveform_index, final String source, final VType value, final String info); PlotSample(final AtomicIntege...
### Question: TimestampHelper { public static Instant roundUp(final Instant time, final Duration duration) { return roundUp(time, duration.getSeconds()); } static Instant roundUp(final Instant time, final Duration duration); static Instant roundUp(final Instant time, final long seconds); static Timestamp toSQLTimestam...
### Question: EdmConverter { public DisplayModel getDisplayModel() { return model; } EdmConverter(final File input, final AssetLocator asset_locator); DisplayModel getDisplayModel(); void write(final File output); int nextGroup(); void downloadAsset(final String asset); Collection<String> getIncludedDisplays(); Collect...
### Question: Cache { public Cache(final Duration timeout) { this.timeout = timeout; } Cache(final Duration timeout); T getCachedOrNew(final String key, final CreateEntry<String, T> creator); Collection<String> getKeys(); void clear(); }### Answer: @Test public void testCache() throws Exception { final Cache<String> c...
### Question: Version implements Comparable<Version> { public static Version parse(final String version) { Matcher matcher = VERSION_PATTERN.matcher(version); if (matcher.matches()) return new Version(Integer.parseInt(matcher.group(1)), Integer.parseInt(matcher.group(2)), Integer.parseInt(matcher.group(3))); matcher = ...
### Question: Converter { public Converter(final File input, final File output) throws Exception { logger.log(Level.INFO, "Convert " + input + " -> " + output); final ADLWidget root = ParserADL.getNextElement(input); colorMap = getColorMap(root); logger.log(Level.FINE, "Color map: " + Arrays.toString(colorMap)); initia...
### Question: JFXUtil extends org.phoebus.ui.javafx.JFXUtil { public static String webRGB(final WidgetColor color) { return webRGBCache.computeIfAbsent(color, col -> { if (col.getAlpha() < 255) return "rgba(" + col.getRed() + ',' + col.getGreen() + ',' + col.getBlue() + ',' + col.getAlpha()/255f + ')'; else return Stri...
### Question: SVGHelper { public static Image loadSVG(String imageFileName, double width, double height){ String cachedSVGFileName = imageFileName + "_" + width + "_" + height; return ImageCache.cache(cachedSVGFileName, () -> { try(InputStream inputStream = ModelResourceUtil.openResourceStream(imageFileName)){ return l...
### Question: ResettableTimeout { public void reset() { final ScheduledFuture<?> previous = timeout.getAndSet(timer.schedule(signal_no_more_messages, timeout_secs, TimeUnit.SECONDS)); if (previous != null) previous.cancel(false); } ResettableTimeout(final long timeout_secs); void reset(); boolean awaitTimeout(final lon...
### Question: AlarmContext { static String encodedURLPath(String path) { return String.valueOf(path).replace(": } static synchronized void registerPV(AlarmPV alarmPV); static synchronized void releasePV(AlarmPV alarmPV); static synchronized void acknowledgePV(AlarmPV alarmPV, boolean ack); static synchronized void ena...
### Question: AlarmContext { static String decodedURLPath(String path) { return String.valueOf(path).replace(encodecDelimiter, ": } static synchronized void registerPV(AlarmPV alarmPV); static synchronized void releasePV(AlarmPV alarmPV); static synchronized void acknowledgePV(AlarmPV alarmPV, boolean ack); static syn...
### Question: AlarmContext { static String decodedKafaPath(String path) { return path.replace("\\/","/"); } static synchronized void registerPV(AlarmPV alarmPV); static synchronized void releasePV(AlarmPV alarmPV); static synchronized void acknowledgePV(AlarmPV alarmPV, boolean ack); static synchronized void enablePV(...
### Question: FormulaTreeRootNode extends TreeItem<FormulaTreeByCategoryNode> { public void addChild(FormulaFunction child) { for (FormulaTreeCategoryNode category : categories) { if (category.getValue().getSignature().equals(child.getCategory())) { category.addChild(child); return; } } FormulaTreeCategoryNode newCateg...
### Question: Node implements Comparable<Node> { @Override public int compareTo(Node other) { if(nodeType.equals(NodeType.FOLDER) && other.getNodeType().equals(NodeType.CONFIGURATION)){ return -1; } else if(getNodeType().equals(NodeType.CONFIGURATION) && other.getNodeType().equals(NodeType.FOLDER)){ return 1; } else{ r...
### Question: Node implements Comparable<Node> { @Override public int hashCode() { return Objects.hash(nodeType, uniqueId); } void putProperty(String key, String value); void removeProperty(String key); String getProperty(String key); void addTag(Tag tag); void removeTag(Tag tag); @Override boolean equals(Object other...
### Question: Node implements Comparable<Node> { @Override public boolean equals(Object other) { if(other == null) { return false; } if(other instanceof Node) { Node otherNode = (Node)other; return nodeType.equals(otherNode.getNodeType()) && uniqueId.equals(otherNode.getUniqueId()); } return false; } void putProperty(...