-
Notifications
You must be signed in to change notification settings - Fork 406
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Share CIDConverter code between demos.
- Loading branch information
1 parent
d4f7259
commit eeb8907
Showing
5 changed files
with
59 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
leshan-core-demo/src/main/java/org/eclipse/leshan/core/demo/cli/converters/CIDConverter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2021 Sierra Wireless and others. | ||
* | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v2.0 | ||
* and Eclipse Distribution License v1.0 which accompany this distribution. | ||
* | ||
* The Eclipse Public License is available at | ||
* http://www.eclipse.org/legal/epl-v20.html | ||
* and the Eclipse Distribution License is available at | ||
* http://www.eclipse.org/org/documents/edl-v10.html. | ||
* | ||
* Contributors: | ||
* Sierra Wireless - initial API and implementation | ||
*******************************************************************************/ | ||
package org.eclipse.leshan.core.demo.cli.converters; | ||
|
||
import picocli.CommandLine.ITypeConverter; | ||
|
||
public class CIDConverter implements ITypeConverter<Integer> { | ||
|
||
private Integer onValue; | ||
|
||
public CIDConverter(Integer onValue) { | ||
this.onValue = onValue; | ||
} | ||
|
||
@Override | ||
public Integer convert(String cid) { | ||
if ("off".equals(cid)) { | ||
return null; | ||
} else if ("on".equals(cid)) { | ||
return onValue; | ||
} else { | ||
Integer res = Integer.parseInt(cid); | ||
return res < 0 ? null : res; | ||
} | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
.../src/main/java/org/eclipse/leshan/server/core/demo/cli/converters/ServerCIDConverter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package org.eclipse.leshan.server.core.demo.cli.converters; | ||
|
||
import org.eclipse.leshan.core.demo.cli.converters.CIDConverter; | ||
|
||
public class ServerCIDConverter extends CIDConverter { | ||
public ServerCIDConverter() { | ||
super(6); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters