forked from eclipse-leshan/leshan
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make LwM2mModel an interface. Concrete class is now StaticModel
- Loading branch information
1 parent
cad7db0
commit a8580a2
Showing
15 changed files
with
111 additions
and
70 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
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
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
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
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
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
73 changes: 73 additions & 0 deletions
73
leshan-core/src/main/java/org/eclipse/leshan/core/model/StaticModel.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,73 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2019 Sierra Wireless and others. | ||
* | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v1.0 | ||
* and Eclipse Distribution License v1.0 which accompany this distribution. | ||
* | ||
* The Eclipse Public License is available at | ||
* http://www.eclipse.org/legal/epl-v10.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.model; | ||
|
||
import java.util.Arrays; | ||
import java.util.Collection; | ||
import java.util.Collections; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
/** | ||
* A static implementation of {@link LwM2mModel}. | ||
*/ | ||
public class StaticModel implements LwM2mModel { | ||
|
||
private static final Logger LOG = LoggerFactory.getLogger(StaticModel.class); | ||
|
||
private final Map<Integer, ObjectModel> objects; // objects by ID | ||
|
||
public StaticModel(ObjectModel... objectModels) { | ||
this(Arrays.asList(objectModels)); | ||
} | ||
|
||
public StaticModel(Collection<ObjectModel> objectModels) { | ||
if (objectModels == null) { | ||
objects = new HashMap<>(); | ||
} else { | ||
Map<Integer, ObjectModel> map = new HashMap<>(); | ||
for (ObjectModel model : objectModels) { | ||
ObjectModel old = map.put(model.id, model); | ||
if (old != null) { | ||
LOG.debug("Model already exists for object {}. Overriding it.", model.id); | ||
} | ||
} | ||
objects = Collections.unmodifiableMap(map); | ||
} | ||
} | ||
|
||
@Override | ||
public ResourceModel getResourceModel(int objectId, int resourceId) { | ||
ObjectModel object = objects.get(objectId); | ||
if (object != null) { | ||
return object.resources.get(resourceId); | ||
} | ||
return null; | ||
} | ||
|
||
@Override | ||
public ObjectModel getObjectModel(int objectId) { | ||
return objects.get(objectId); | ||
} | ||
|
||
@Override | ||
public Collection<ObjectModel> getObjectModels() { | ||
return objects.values(); | ||
} | ||
} |
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
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
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
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
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
Oops, something went wrong.