Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
// Copyright 2015-2019 SWIM.AI inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package swim.runtime.lane;
import java.util.Iterator;
import java.util.Map;
import swim.api.Link;
import swim.api.data.SpatialData;
import swim.collections.FingerTrieSeq;
import swim.math.Z2Form;
import swim.runtime.LaneContext;
import swim.runtime.LinkBinding;
import swim.spatial.SpatialMap;
import swim.structure.Form;
import swim.structure.Record;
import swim.structure.Value;
import swim.warp.CommandMessage;
public class SpatialLaneModel extends LaneModel, SpatialLaneUplink> {
protected int flags;
protected SpatialData data;
protected final Z2Form shapeForm;
SpatialLaneModel(Z2Form shapeForm, int flags) {
this.shapeForm = shapeForm;
this.flags = flags;
}
public SpatialLaneModel(Z2Form shapeForm) {
this(shapeForm, 0);
}
@Override
protected SpatialLaneUplink createUplink(LinkBinding link) {
return new SpatialLaneUplink(this, link);
}
@Override
public void setLaneContext(LaneContext laneContext) {
super.setLaneContext(laneContext);
openStore();
}
protected void openStore() {
this.data = this.laneContext.data().spatialData(laneUri().toString(), shapeForm)
.isResident(isResident())
.isTransient(isTransient());
}
@Override
public void onCommand(CommandMessage message) {
final Value payload = message.body();
final String tag = payload.tag();
if ("update".equals(tag)) {
final Value header = payload.header("update");
final Value key = header.get("key");
final Value shape = header.get("shape");
final S shapeObject = shapeForm.cast(shape);
final Value value = payload.body();
new SpatialLaneRelayUpdate(this, null, message, key, shapeObject, value).run();
} else if ("move".equals(tag)) {
final Value header = payload.header("move");
final Value key = header.get("key");
final Value oldShape = header.get("from");
final Value newShape = header.get("to");
final S oldShapeObject = shapeForm.cast(oldShape);
final S newShapeObject = shapeForm.cast(newShape);
final Value value = payload.body();
new SpatialLaneRelayMove(this, null, message, key, oldShapeObject, newShapeObject, value).run();
} else if ("remove".equals(tag)) {
final Value header = payload.header("remove");
final Value key = header.get("key");
final Value shape = header.get("shape");
final S shapeObject = shapeForm.cast(shape);
new SpatialLaneRelayRemove(this, null, message, key, shapeObject).run();
} else if ("clear".equals(tag)) {
new SpatialLaneRelayClear(this, null, message).run();
}
}
protected void cueDownKey(Value key) {
FingerTrieSeq> uplinks;
do {
uplinks = this.uplinks;
for (int i = 0, n = uplinks.size(); i < n; i += 1) {
uplinks.get(i).cueDownKey(key);
}
} while (uplinks != this.uplinks);
}
@Override
protected void didOpenLaneView(SpatialLaneView, S, ?> view) {
view.setLaneBinding(this);
}
public final boolean isResident() {
return (this.flags & RESIDENT) != 0;
}
public SpatialLaneModel isResident(boolean isResident) {
if (this.data != null) {
this.data.isResident(isResident);
}
if (isResident) {
this.flags |= RESIDENT;
} else {
this.flags &= ~RESIDENT;
}
final Object views = this.views;
if (views instanceof SpatialLaneView, ?, ?>) {
((SpatialLaneView, ?, ?>) views).didSetResident(isResident);
} else if (views instanceof LaneView[]) {
final LaneView[] viewArray = (LaneView[]) views;
for (int i = 0, n = viewArray.length; i < n; i += 1) {
((SpatialLaneView, ?, ?>) viewArray[i]).didSetResident(isResident);
}
}
return this;
}
public final boolean isTransient() {
return (this.flags & TRANSIENT) != 0;
}
public SpatialLaneModel isTransient(boolean isTransient) {
if (this.data != null) {
this.data.isTransient(isTransient);
}
if (isTransient) {
this.flags |= TRANSIENT;
} else {
this.flags &= ~TRANSIENT;
}
final Object views = this.views;
if (views instanceof SpatialLaneView, ?, ?>) {
((SpatialLaneView, ?, ?>) views).didSetTransient(isTransient);
} else if (views instanceof LaneView[]) {
final LaneView[] viewArray = (LaneView[]) views;
for (int i = 0, n = viewArray.length; i < n; i += 1) {
((SpatialLaneView, ?, ?>) viewArray[i]).didSetTransient(isTransient);
}
}
return this;
}
public final boolean isSigned() {
return (this.flags & SIGNED) != 0;
}
public SpatialLaneModel isSigned(boolean isSigned) {
if (isSigned) {
this.flags |= SIGNED;
} else {
this.flags &= ~SIGNED;
}
final Object views = this.views;
if (views instanceof SpatialLaneView, ?, ?>) {
((SpatialLaneView, ?, ?>) views).didSetSigned(isSigned);
} else if (views instanceof LaneView[]) {
final LaneView[] viewArray = (LaneView[]) views;
for (int i = 0, n = viewArray.length; i < n; i += 1) {
((SpatialLaneView, ?, ?>) viewArray[i]).didSetSigned(isSigned);
}
}
return this;
}
public Value get(Value key) {
if (key != null) {
return this.data.get(key);
} else {
return Value.absent();
}
}
@SuppressWarnings("unchecked")
public V put(SpatialLaneView view, K keyObject, S shapeObject, V newObject) {
final Form keyForm = view.keyForm;
final Form valueForm = view.valueForm;
final Value key = keyForm.mold(keyObject).toValue();
final Value newValue = valueForm.mold(newObject).toValue();
final SpatialLaneRelayUpdate relay = new SpatialLaneRelayUpdate(this, null, key, shapeObject, newValue);
relay.keyForm = (Form