org.eclipse.californium.core.coap.OptionSet.clearLocationPath()方法的使用及代码示例

x33g5p2x  于2022-01-26 转载在 其他  
字(2.6k)|赞(0)|评价(0)|浏览(71)

本文整理了Java中org.eclipse.californium.core.coap.OptionSet.clearLocationPath()方法的一些代码示例,展示了OptionSet.clearLocationPath()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。OptionSet.clearLocationPath()方法的具体详情如下:
包路径:org.eclipse.californium.core.coap.OptionSet
类名称:OptionSet
方法名:clearLocationPath

OptionSet.clearLocationPath介绍

[英]Removes all Location-Path options. Returns the current OptionSet object for a fluent API.
[中]删除所有位置路径选项。返回fluent API的当前OptionSet对象。

代码示例

代码示例来源:origin: eclipse/californium

/**
 * Sets the complete relative Location-Path.
 * Returns the current OptionSet object for a fluent API.
 * @param path the Location-Path to set
 * @return this OptionSet
 */
public OptionSet setLocationPath(String path) {
  final String slash = "/";
  
  // remove leading slash
  if (path.startsWith(slash)) {
    path = path.substring(slash.length());
  }
  
  clearLocationPath();
  
  for (String segment : path.split(slash)) {
    // empty path segments are allowed (e.g., /test vs /test/)
    addLocationPath(segment);
  }
  return this;
}

代码示例来源:origin: org.eclipse.californium/californium-core

/**
 * Sets the complete relative Location-Path.
 * Returns the current OptionSet object for a fluent API.
 * @param path the Location-Path to set
 * @return this OptionSet
 */
public OptionSet setLocationPath(String path) {
  final String slash = "/";
  
  // remove leading slash
  if (path.startsWith(slash)) {
    path = path.substring(slash.length());
  }
  
  clearLocationPath();
  
  for (String segment : path.split(slash)) {
    // empty path segments are allowed (e.g., /test vs /test/)
    addLocationPath(segment);
  }
  return this;
}

代码示例来源:origin: eclipse/californium

@Test
public void testLocationOptions() {
  OptionSet options = new OptionSet();
  
  options.setLocationPath("/foo/bar");
  Assert.assertEquals("Uri-Path", "foo/bar", options.getLocationPathString());
  options.setLocationPath("foo/bar");
  Assert.assertEquals("Uri-Path", "foo/bar", options.getLocationPathString());
  options.setLocationPath("//foo/bar");
  Assert.assertEquals("Uri-Path", "/foo/bar", options.getLocationPathString());
  options.setLocationPath("/foo//bar");
  Assert.assertEquals("Uri-Path", "foo//bar", options.getLocationPathString());
  
  options.clearLocationPath();
  options.addLocationPath("foo");
  options.addLocationPath("bar");
  Assert.assertEquals("Uri-Path", "foo/bar", options.getLocationPathString());
  options.clearLocationPath();
  options.addLocationPath("foo");
  options.addLocationPath("");
  options.addLocationPath("bar");
  Assert.assertEquals("Uri-Path", "foo//bar", options.getLocationPathString());
}

相关文章

微信公众号

最新文章

更多