Merge branches/froyo_12.03 to head.
This commit is contained in:
parent
530ed1d4c5
commit
c6a9f17179
@ -5,7 +5,7 @@
|
|||||||
android:versionName="1.0" >
|
android:versionName="1.0" >
|
||||||
|
|
||||||
<uses-sdk
|
<uses-sdk
|
||||||
android:minSdkVersion="9"
|
android:minSdkVersion="8"
|
||||||
android:targetSdkVersion="15" />
|
android:targetSdkVersion="15" />
|
||||||
|
|
||||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
|
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
|
||||||
|
@ -18,14 +18,14 @@ import net.sf.openrocket.motor.ThrustCurveMotorPlaceholder;
|
|||||||
|
|
||||||
public abstract class ThrustCurveAPI {
|
public abstract class ThrustCurveAPI {
|
||||||
|
|
||||||
private static String url_base = "http://www.thrustcurve.org/servlets/";
|
//private static String url_base = "http://www.thrustcurve.org/servlets/";
|
||||||
|
|
||||||
public static SearchResponse doSearch( SearchRequest request ) throws MalformedURLException, IOException {
|
public static SearchResponse doSearch( SearchRequest request ) throws MalformedURLException, IOException {
|
||||||
|
|
||||||
String requestString = request.toString();
|
String requestString = request.toString();
|
||||||
|
|
||||||
AndroidLogWrapper.d(ThrustCurveAPI.class, "doSearch: " + requestString);
|
AndroidLogWrapper.d(ThrustCurveAPI.class, "doSearch: " + requestString);
|
||||||
URL url = new URL(url_base + "search");
|
URL url = new URL("http", "www.thurustcurve.org", "servlets/search");
|
||||||
|
|
||||||
OutputStream stream;
|
OutputStream stream;
|
||||||
|
|
||||||
@ -58,7 +58,7 @@ public abstract class ThrustCurveAPI {
|
|||||||
String requestString = dr.toString();
|
String requestString = dr.toString();
|
||||||
|
|
||||||
AndroidLogWrapper.d(ThrustCurveAPI.class, "downloadData: " + requestString);
|
AndroidLogWrapper.d(ThrustCurveAPI.class, "downloadData: " + requestString);
|
||||||
URL url = new URL(url_base + "download");
|
URL url = new URL("http", "www.thurustcurve.org", "servlets/download");
|
||||||
|
|
||||||
OutputStream stream;
|
OutputStream stream;
|
||||||
|
|
||||||
|
@ -12,6 +12,7 @@ import java.util.zip.ZipInputStream;
|
|||||||
import net.sf.openrocket.document.OpenRocketDocument;
|
import net.sf.openrocket.document.OpenRocketDocument;
|
||||||
import net.sf.openrocket.file.openrocket.importt.OpenRocketLoader;
|
import net.sf.openrocket.file.openrocket.importt.OpenRocketLoader;
|
||||||
import net.sf.openrocket.file.rocksim.importt.RocksimLoader;
|
import net.sf.openrocket.file.rocksim.importt.RocksimLoader;
|
||||||
|
import net.sf.openrocket.util.TextUtil;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -26,9 +27,9 @@ public class GeneralRocketLoader extends AbstractRocketLoader {
|
|||||||
private static final int READ_BYTES = 300;
|
private static final int READ_BYTES = 300;
|
||||||
|
|
||||||
private static final byte[] GZIP_SIGNATURE = { 31, -117 }; // 0x1f, 0x8b
|
private static final byte[] GZIP_SIGNATURE = { 31, -117 }; // 0x1f, 0x8b
|
||||||
private static final byte[] ZIP_SIGNATURE = "PK".getBytes(Charset.forName("US-ASCII"));
|
private static final byte[] ZIP_SIGNATURE = TextUtil.convertStringToBytes("PK",Charset.forName("US-ASCII"));
|
||||||
private static final byte[] OPENROCKET_SIGNATURE = "<openrocket".getBytes(Charset.forName("US-ASCII"));
|
private static final byte[] OPENROCKET_SIGNATURE = TextUtil.convertStringToBytes("<openrocket",Charset.forName("US-ASCII"));
|
||||||
private static final byte[] ROCKSIM_SIGNATURE = "<RockSimDoc".getBytes(Charset.forName("US-ASCII"));
|
private static final byte[] ROCKSIM_SIGNATURE = TextUtil.convertStringToBytes("<RockSimDoc",Charset.forName("US-ASCII"));
|
||||||
|
|
||||||
private final OpenRocketLoader openRocketLoader = new OpenRocketLoader();
|
private final OpenRocketLoader openRocketLoader = new OpenRocketLoader();
|
||||||
|
|
||||||
|
@ -6,11 +6,11 @@ import java.io.InputStreamReader;
|
|||||||
import java.io.Reader;
|
import java.io.Reader;
|
||||||
import java.nio.charset.Charset;
|
import java.nio.charset.Charset;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import net.sf.openrocket.motor.Motor;
|
import net.sf.openrocket.motor.Motor;
|
||||||
|
import net.sf.openrocket.util.ArrayUtils;
|
||||||
import net.sf.openrocket.util.MathUtil;
|
import net.sf.openrocket.util.MathUtil;
|
||||||
|
|
||||||
public abstract class AbstractMotorLoader implements MotorLoader {
|
public abstract class AbstractMotorLoader implements MotorLoader {
|
||||||
@ -136,7 +136,7 @@ public abstract class AbstractMotorLoader implements MotorLoader {
|
|||||||
String[] pieces = str.split(delim);
|
String[] pieces = str.split(delim);
|
||||||
if (pieces.length == 0 || !pieces[0].equals(""))
|
if (pieces.length == 0 || !pieces[0].equals(""))
|
||||||
return pieces;
|
return pieces;
|
||||||
return Arrays.copyOfRange(pieces, 1, pieces.length);
|
return ArrayUtils.copyOfRange(pieces, 1, pieces.length);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,11 +1,10 @@
|
|||||||
package net.sf.openrocket.file.simplesax;
|
package net.sf.openrocket.file.simplesax;
|
||||||
|
|
||||||
import java.util.ArrayDeque;
|
|
||||||
import java.util.Deque;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
|
||||||
import net.sf.openrocket.aerodynamics.Warning;
|
import net.sf.openrocket.aerodynamics.Warning;
|
||||||
import net.sf.openrocket.aerodynamics.WarningSet;
|
import net.sf.openrocket.aerodynamics.WarningSet;
|
||||||
|
import net.sf.openrocket.util.SimpleStack;
|
||||||
|
|
||||||
import org.xml.sax.Attributes;
|
import org.xml.sax.Attributes;
|
||||||
import org.xml.sax.SAXException;
|
import org.xml.sax.SAXException;
|
||||||
@ -18,9 +17,9 @@ import org.xml.sax.helpers.DefaultHandler;
|
|||||||
class DelegatorHandler extends DefaultHandler {
|
class DelegatorHandler extends DefaultHandler {
|
||||||
private final WarningSet warnings;
|
private final WarningSet warnings;
|
||||||
|
|
||||||
private final Deque<ElementHandler> handlerStack = new ArrayDeque<ElementHandler>();
|
private final SimpleStack<ElementHandler> handlerStack = new SimpleStack<ElementHandler>();
|
||||||
private final Deque<StringBuilder> elementData = new ArrayDeque<StringBuilder>();
|
private final SimpleStack<StringBuilder> elementData = new SimpleStack<StringBuilder>();
|
||||||
private final Deque<HashMap<String, String>> elementAttributes = new ArrayDeque<HashMap<String, String>>();
|
private final SimpleStack<HashMap<String, String>> elementAttributes = new SimpleStack<HashMap<String, String>>();
|
||||||
|
|
||||||
|
|
||||||
// Ignore all elements as long as ignore > 0
|
// Ignore all elements as long as ignore > 0
|
||||||
|
@ -1,8 +1,6 @@
|
|||||||
package net.sf.openrocket.rocketcomponent;
|
package net.sf.openrocket.rocketcomponent;
|
||||||
|
|
||||||
import java.util.ArrayDeque;
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Deque;
|
|
||||||
import java.util.EventListener;
|
import java.util.EventListener;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -21,6 +19,7 @@ import net.sf.openrocket.util.Invalidator;
|
|||||||
import net.sf.openrocket.util.LineStyle;
|
import net.sf.openrocket.util.LineStyle;
|
||||||
import net.sf.openrocket.util.MathUtil;
|
import net.sf.openrocket.util.MathUtil;
|
||||||
import net.sf.openrocket.util.SafetyMutex;
|
import net.sf.openrocket.util.SafetyMutex;
|
||||||
|
import net.sf.openrocket.util.SimpleStack;
|
||||||
import net.sf.openrocket.util.UniqueID;
|
import net.sf.openrocket.util.UniqueID;
|
||||||
|
|
||||||
|
|
||||||
@ -1853,7 +1852,7 @@ public abstract class RocketComponent implements ChangeSource, Cloneable, Iterab
|
|||||||
*/
|
*/
|
||||||
private static class RocketComponentIterator implements Iterator<RocketComponent> {
|
private static class RocketComponentIterator implements Iterator<RocketComponent> {
|
||||||
// Stack holds iterators which still have some components left.
|
// Stack holds iterators which still have some components left.
|
||||||
private final Deque<Iterator<RocketComponent>> iteratorStack = new ArrayDeque<Iterator<RocketComponent>>();
|
private final SimpleStack<Iterator<RocketComponent>> iteratorStack = new SimpleStack<Iterator<RocketComponent>>();
|
||||||
|
|
||||||
private final Rocket root;
|
private final Rocket root;
|
||||||
private final int treeModID;
|
private final int treeModID;
|
||||||
|
46
core/src/net/sf/openrocket/util/ArrayUtils.java
Normal file
46
core/src/net/sf/openrocket/util/ArrayUtils.java
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
package net.sf.openrocket.util;
|
||||||
|
|
||||||
|
import java.lang.reflect.Array;
|
||||||
|
|
||||||
|
public class ArrayUtils {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Implementation of java.util.Arrays.copyOfRange
|
||||||
|
*
|
||||||
|
* Since Froyo does not include this function it must be implemented here.
|
||||||
|
*
|
||||||
|
* @param original
|
||||||
|
* @param start
|
||||||
|
* @param end
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static <T> T[] copyOfRange( T[] original, int start, int end ) {
|
||||||
|
|
||||||
|
if ( original == null ) {
|
||||||
|
throw new NullPointerException();
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( start < 0 || start > original.length ) {
|
||||||
|
throw new ArrayIndexOutOfBoundsException();
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( start > end ) {
|
||||||
|
throw new IllegalArgumentException();
|
||||||
|
}
|
||||||
|
|
||||||
|
T[] result = (T[]) Array.newInstance( original.getClass().getComponentType(), end-start );
|
||||||
|
|
||||||
|
int index = 0;
|
||||||
|
int stop = original.length < end ? original.length : end;
|
||||||
|
for ( int i = start; i < stop; i ++ ) {
|
||||||
|
if ( i < original.length ) {
|
||||||
|
result[index] = original[i];
|
||||||
|
}
|
||||||
|
index++;
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
29
core/src/net/sf/openrocket/util/SimpleStack.java
Normal file
29
core/src/net/sf/openrocket/util/SimpleStack.java
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
package net.sf.openrocket.util;
|
||||||
|
|
||||||
|
import java.util.NoSuchElementException;
|
||||||
|
/**
|
||||||
|
* SimpleStack implementation backed by an ArrayList.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class SimpleStack<T> extends ArrayList<T> {
|
||||||
|
|
||||||
|
public void push( T value ) {
|
||||||
|
this.add(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public T peek() {
|
||||||
|
if ( size() <= 0 ) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return this.get( size() -1 );
|
||||||
|
}
|
||||||
|
|
||||||
|
public T pop() {
|
||||||
|
if ( size() <= 0 ) {
|
||||||
|
throw new NoSuchElementException();
|
||||||
|
}
|
||||||
|
T value = this.remove( size() -1 );
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -1,12 +1,32 @@
|
|||||||
package net.sf.openrocket.util;
|
package net.sf.openrocket.util;
|
||||||
|
|
||||||
|
import java.nio.ByteBuffer;
|
||||||
|
import java.nio.charset.Charset;
|
||||||
|
|
||||||
|
|
||||||
public class TextUtil {
|
public class TextUtil {
|
||||||
|
|
||||||
|
|
||||||
private static final char[] HEX = {
|
private static final char[] HEX = {
|
||||||
'0', '1', '2', '3', '4', '5', '6', '7',
|
'0', '1', '2', '3', '4', '5', '6', '7',
|
||||||
'8', '9', 'a', 'b', 'c', 'd', 'e', 'f'
|
'8', '9', 'a', 'b', 'c', 'd', 'e', 'f'
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the byte array for the string in the given charset.
|
||||||
|
*
|
||||||
|
* This function is implemented because Froyo (Android API 8) does not support
|
||||||
|
* String.getBytes(Charset)
|
||||||
|
*
|
||||||
|
* @param string
|
||||||
|
* @param charSet
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static byte[] convertStringToBytes( String string, Charset charSet ) {
|
||||||
|
ByteBuffer encoded = charSet.encode(string);
|
||||||
|
return encoded.array();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the bytes formatted as a hexadecimal string. The length of the
|
* Return the bytes formatted as a hexadecimal string. The length of the
|
||||||
|
84
core/test/net/sf/openrocket/util/ArrayUtilsTest.java
Normal file
84
core/test/net/sf/openrocket/util/ArrayUtilsTest.java
Normal file
@ -0,0 +1,84 @@
|
|||||||
|
package net.sf.openrocket.util;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertNull;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
public class ArrayUtilsTest {
|
||||||
|
|
||||||
|
@Test(expected=NullPointerException.class)
|
||||||
|
public void testCopyOfRange_NullArg() {
|
||||||
|
ArrayUtils.copyOfRange( (Byte[]) null, 0 , 14);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected=ArrayIndexOutOfBoundsException.class)
|
||||||
|
public void testCopyOfRange_StartTooBig() {
|
||||||
|
Integer[] original = new Integer[5];
|
||||||
|
ArrayUtils.copyOfRange( original, 8 , 14);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected=ArrayIndexOutOfBoundsException.class)
|
||||||
|
public void testCopyOfRange_StartTooSmall() {
|
||||||
|
Integer[] original = new Integer[5];
|
||||||
|
ArrayUtils.copyOfRange( original, -1 , 14);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected=IllegalArgumentException.class)
|
||||||
|
public void testCopyOfRange_IllegalRange() {
|
||||||
|
Integer[] original = new Integer[5];
|
||||||
|
ArrayUtils.copyOfRange( original, 5, 0 );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testCopyOfRange() {
|
||||||
|
Integer[] original = new Integer[5];
|
||||||
|
for ( int i =0; i < 5; i++ ) {
|
||||||
|
original[i] = i;
|
||||||
|
}
|
||||||
|
Integer[] copy = ArrayUtils.copyOfRange( original, 0, 0 );
|
||||||
|
assertEquals( 0, copy.length );
|
||||||
|
|
||||||
|
copy = ArrayUtils.copyOfRange( original, 2, 2 );
|
||||||
|
assertEquals( 0, copy.length );
|
||||||
|
|
||||||
|
copy = ArrayUtils.copyOfRange( original, 0, 2 );
|
||||||
|
assertEquals( 2, copy.length );
|
||||||
|
for( int i =0; i< 2; i++ ) {
|
||||||
|
assertEquals( original[i], copy[i] );
|
||||||
|
}
|
||||||
|
|
||||||
|
copy = ArrayUtils.copyOfRange( original, 2, 5 );
|
||||||
|
assertEquals( 3, copy.length );
|
||||||
|
for( int i =0; i< 3; i++ ) {
|
||||||
|
assertEquals( original[i+2], copy[i] );
|
||||||
|
}
|
||||||
|
|
||||||
|
copy = ArrayUtils.copyOfRange( original, 2, 15 );
|
||||||
|
assertEquals( 13, copy.length );
|
||||||
|
for( int i =0; i< 3; i++ ) {
|
||||||
|
assertEquals( original[i+2], copy[i] );
|
||||||
|
}
|
||||||
|
for ( int i=3; i< 13; i++ ) {
|
||||||
|
assertNull(copy[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testCopyOfRange_ZeroSize() {
|
||||||
|
Integer[] original = new Integer[0];
|
||||||
|
|
||||||
|
Integer[] copy = ArrayUtils.copyOfRange( original, 0, 0 );
|
||||||
|
assertEquals( 0, copy.length );
|
||||||
|
|
||||||
|
copy = ArrayUtils.copyOfRange( original, 0, 2 );
|
||||||
|
assertEquals( 2, copy.length );
|
||||||
|
for( int i =0; i< 2; i++ ) {
|
||||||
|
assertEquals( null, copy[i] );
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
43
core/test/net/sf/openrocket/util/SimpleStackTest.java
Normal file
43
core/test/net/sf/openrocket/util/SimpleStackTest.java
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
package net.sf.openrocket.util;
|
||||||
|
|
||||||
|
import java.util.NoSuchElementException;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertNull;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
public class SimpleStackTest {
|
||||||
|
|
||||||
|
@Test(expected=NoSuchElementException.class)
|
||||||
|
public void testEmptyStack() {
|
||||||
|
SimpleStack<Integer> s = new SimpleStack<Integer>();
|
||||||
|
|
||||||
|
assertNull(s.peek());
|
||||||
|
|
||||||
|
s.pop();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testPushAndPop() {
|
||||||
|
|
||||||
|
SimpleStack<Integer> s = new SimpleStack<Integer>();
|
||||||
|
|
||||||
|
for( int i = 0; i< 10; i++ ) {
|
||||||
|
s.push(i);
|
||||||
|
assertEquals(i+1, s.size());
|
||||||
|
}
|
||||||
|
|
||||||
|
for( int i=9; i>= 0; i-- ) {
|
||||||
|
assertEquals( i, s.peek().intValue() );
|
||||||
|
Integer val = s.pop();
|
||||||
|
assertEquals( i, val.intValue() );
|
||||||
|
assertEquals( i, s.size() );
|
||||||
|
}
|
||||||
|
|
||||||
|
assertNull( s.peek() );
|
||||||
|
assertEquals( 0, s.size() );
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -2,13 +2,36 @@ package net.sf.openrocket.util;
|
|||||||
|
|
||||||
import static java.lang.Math.PI;
|
import static java.lang.Math.PI;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertArrayEquals;
|
||||||
|
|
||||||
|
import java.nio.charset.Charset;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
public class TextUtilTest {
|
public class TextUtilTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testConvertStringToBytes() {
|
||||||
|
|
||||||
|
Charset us_ascii = Charset.forName("US-ASCII");
|
||||||
|
|
||||||
|
byte[] ZIP_SIGNATURE_CORRECT = "PK".getBytes(us_ascii);
|
||||||
|
byte[] ZIP_SIGNATURE_TEST = TextUtil.convertStringToBytes( "PK", us_ascii);
|
||||||
|
|
||||||
|
assertArrayEquals( ZIP_SIGNATURE_CORRECT, ZIP_SIGNATURE_TEST );
|
||||||
|
|
||||||
|
byte[] OPENROCKET_SIGNATURE_CORRECT = "<openrocket".getBytes(us_ascii);
|
||||||
|
byte[] OPENROCKET_SIGNATURE_TEST = TextUtil.convertStringToBytes( "<openrocket", us_ascii);
|
||||||
|
|
||||||
|
assertArrayEquals( OPENROCKET_SIGNATURE_CORRECT, OPENROCKET_SIGNATURE_TEST);
|
||||||
|
|
||||||
|
byte[] ROCKSIM_SIGNATURE_CORRECT = "<RockSimDoc".getBytes(us_ascii);
|
||||||
|
byte[] ROCKSIM_SIGNATURE_TEST = TextUtil.convertStringToBytes( "<RockSimDoc", us_ascii);
|
||||||
|
|
||||||
|
assertArrayEquals( ROCKSIM_SIGNATURE_CORRECT, ROCKSIM_SIGNATURE_TEST );
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testHexString() {
|
public void testHexString() {
|
||||||
assertEquals("", TextUtil.hexString(new byte[0]));
|
assertEquals("", TextUtil.hexString(new byte[0]));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user