Skip to content
Snippets Groups Projects
Commit 32117440 authored by Daniel Stonier's avatar Daniel Stonier
Browse files

Merge pull request #174 from rosjava/releases

First official hydro release going in
parents 1a3195f8 90673ee4
No related branches found
No related tags found
No related merge requests found
Showing
with 0 additions and 1266 deletions
/*
* Copyright (C) 2011 Google 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 org.ros.internal.message.field;
import com.google.common.base.Preconditions;
import org.jboss.netty.buffer.ChannelBuffer;
import java.util.Arrays;
/**
* @author damonkohler@google.com (Damon Kohler)
*/
public class ShortArrayField extends Field {
private final int size;
private short[] value;
public static ShortArrayField newVariable(FieldType type, String name, int size) {
return new ShortArrayField(type, name, size);
}
private ShortArrayField(FieldType type, String name, int size) {
super(type, name, false);
this.size = size;
setValue(new short[Math.max(0, size)]);
}
@SuppressWarnings("unchecked")
@Override
public short[] getValue() {
return value;
}
@Override
public void setValue(Object value) {
Preconditions.checkArgument(size < 0 || ((short[]) value).length == size);
this.value = (short[]) value;
}
@Override
public void serialize(ChannelBuffer buffer) {
if (size < 0) {
buffer.writeInt(value.length);
}
for (short v : value) {
type.serialize(v, buffer);
}
}
@Override
public void deserialize(ChannelBuffer buffer) {
int currentSize = size;
if (currentSize < 0) {
currentSize = buffer.readInt();
}
value = new short[currentSize];
for (int i = 0; i < currentSize; i++) {
value[i] = buffer.readShort();
}
}
@Override
public String getMd5String() {
return String.format("%s %s\n", type, name);
}
@Override
public String getJavaTypeName() {
return type.getJavaTypeName() + "[]";
}
@Override
public String toString() {
return "ShortArrayField<" + type + ", " + name + ">";
}
@Override
public int hashCode() {
final int prime = 31;
int result = super.hashCode();
result = prime * result + ((value == null) ? 0 : value.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (!super.equals(obj))
return false;
if (getClass() != obj.getClass())
return false;
ShortArrayField other = (ShortArrayField) obj;
if (value == null) {
if (other.value != null)
return false;
} else if (!Arrays.equals(value, other.value))
return false;
return true;
}
}
/*
* Copyright (C) 2011 Google 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 org.ros.internal.message.field;
import com.google.common.base.Preconditions;
import org.jboss.netty.buffer.ChannelBuffer;
/**
* @author damonkohler@google.com (Damon Kohler)
*/
class ValueField<T> extends Field {
private T value;
static <T> ValueField<T> newConstant(FieldType type, String name, T value) {
return new ValueField<T>(type, name, value, true);
}
static <T> ValueField<T> newVariable(FieldType type, String name) {
return new ValueField<T>(type, name, null, false);
}
private ValueField(FieldType type, String name, T value, boolean isConstant) {
super(type, name, isConstant);
this.value = value;
}
@SuppressWarnings("unchecked")
@Override
public T getValue() {
if (value == null) {
setValue(type.getDefaultValue());
}
return value;
}
@SuppressWarnings("unchecked")
@Override
public void setValue(Object value) {
Preconditions.checkNotNull(value);
Preconditions.checkState(!isConstant);
this.value = (T) value;
}
@Override
public void serialize(ChannelBuffer buffer) {
type.serialize(getValue(), buffer);
}
@Override
public void deserialize(ChannelBuffer buffer) {
Preconditions.checkState(!isConstant);
setValue(type.<T>deserialize(buffer));
}
@Override
public String getMd5String() {
return String.format("%s %s\n", type, name);
}
@Override
public String getJavaTypeName() {
return type.getJavaTypeName();
}
@Override
public String toString() {
return "ValueField<" + type + ", " + name + ">";
}
@Override
public int hashCode() {
final int prime = 31;
int result = super.hashCode();
result = prime * result + ((getValue() == null) ? 0 : getValue().hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (!super.equals(obj))
return false;
if (getClass() != obj.getClass())
return false;
Field other = (Field) obj;
if (getValue() == null) {
if (other.getValue() != null)
return false;
} else if (!getValue().equals(other.getValue()))
return false;
return true;
}
}
/*
* Copyright (C) 2012 Google 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.
*/
/**
* Provides internal classes for representing messages.
* <p>
* These classes should _not_ be used directly outside of the org.ros package.
*/
package org.ros.internal.message;
\ No newline at end of file
/*
* Copyright (C) 2011 Google 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 org.ros.internal.message.service;
import org.ros.internal.message.MessageInterfaceClassProvider;
import org.ros.internal.message.RawMessage;
/**
* @author damonkohler@google.com (Damon Kohler)
*/
public class ServiceRequestMessageInterfaceClassProvider implements MessageInterfaceClassProvider {
@SuppressWarnings("unchecked")
@Override
public <T> Class<T> get(String messageType) {
try {
String className = messageType.replace("/", ".") + "$Request";
return (Class<T>) getClass().getClassLoader().loadClass(className);
} catch (ClassNotFoundException e) {
return (Class<T>) RawMessage.class;
}
}
}
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment