Skip to content

Commit 33f101f

Browse files
committed
more cleanup
1 parent 76d1443 commit 33f101f

File tree

5 files changed

+33
-306
lines changed

5 files changed

+33
-306
lines changed

src/generated/com/openize/drako/MetaClasses.java

Lines changed: 1 addition & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,6 @@ public Object newArray(int size)
1717
return ret;
1818
}
1919
@Override
20-
public CornerTable.VertexEdgePair[] unshadow(Object[] array)
21-
{
22-
CornerTable.VertexEdgePair[] ret = new CornerTable.VertexEdgePair[array.length];
23-
for (int i = 0; i < array.length; ++i)
24-
{
25-
ret[i] = Struct.byVal((CornerTable.VertexEdgePair)(array[i]));
26-
}
27-
28-
return ret;
29-
}
30-
@Override
3120
public Class<CornerTable.VertexEdgePair> classOf()
3221
{
3322
return CornerTable.VertexEdgePair.class;
@@ -55,18 +44,7 @@ public Object newArray(int size)
5544
}
5645

5746
return ret;
58-
}
59-
@Override
60-
public RAnsDecoder.ransSym[] unshadow(Object[] array)
61-
{
62-
RAnsDecoder.ransSym[] ret = new RAnsDecoder.ransSym[array.length];
63-
for (int i = 0; i < array.length; ++i)
64-
{
65-
ret[i] = Struct.byVal((RAnsDecoder.ransSym)(array[i]));
66-
}
67-
68-
return ret;
69-
}
47+
}
7048
@Override
7149
public Class<RAnsDecoder.ransSym> classOf()
7250
{
@@ -97,17 +75,6 @@ public Object newArray(int size)
9775
return ret;
9876
}
9977
@Override
100-
public RAnsBitCodec.RansSym[] unshadow(Object[] array)
101-
{
102-
RAnsBitCodec.RansSym[] ret = new RAnsBitCodec.RansSym[array.length];
103-
for (int i = 0; i < array.length; ++i)
104-
{
105-
ret[i] = Struct.byVal((RAnsBitCodec.RansSym)(array[i]));
106-
}
107-
108-
return ret;
109-
}
110-
@Override
11178
public Class<RAnsBitCodec.RansSym> classOf()
11279
{
11380
return RAnsBitCodec.RansSym.class;

src/helpers/com/openize/drako/AsposeUtils.java

Lines changed: 1 addition & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,6 @@
22

33

44
import java.io.*;
5-
import java.nio.ByteBuffer;
6-
import java.nio.CharBuffer;
7-
import java.nio.charset.Charset;
8-
import java.nio.charset.StandardCharsets;
9-
import java.nio.file.Files;
10-
import java.nio.file.Path;
115
import java.util.*;
126

137
/**
@@ -352,39 +346,7 @@ public static boolean equals(StringBuilder a, StringBuilder b) {
352346
return false;
353347
}
354348
return true;
355-
}
356-
/**
357-
* Equivalent to Files.readString, replacement when CsPorter can't read the module files
358-
* @param path
359-
* @return
360-
*/
361-
public static String readString(Path path) throws IOException {
362-
if(path == null || !Files.exists(path))
363-
throw new IllegalArgumentException("Invalid path");
364-
byte[] bytes = Files.readAllBytes(path);
365-
return StandardCharsets.UTF_8.decode(ByteBuffer.wrap(bytes)).toString();
366-
367-
}
368-
369-
/**
370-
* Equivalent to System.Text.Encoding.GetChars
371-
* @param charset
372-
* @param bytes
373-
* @param offset
374-
* @param numBytes
375-
* @param result
376-
* @param resultOffset
377-
* @return the number of characters decoded from bytes
378-
*/
379-
public static int charsFromBytes(Charset charset, byte[] bytes, int offset, int numBytes, char[] result, int resultOffset) {
380-
ByteBuffer input = ByteBuffer.wrap(bytes, offset, numBytes);
381-
CharBuffer chars = charset.decode(input);
382-
383-
int numChars = Math.min(chars.limit(), result.length - resultOffset);
384-
chars.get(result, resultOffset, numChars);
385-
return numChars;
386-
}
387-
349+
}
388350
/**
389351
* Parse command line into array
390352
* @param commandLine

src/helpers/com/openize/drako/Convert.java

Lines changed: 29 additions & 135 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
package com.openize.drako;
22

33

4-
import java.lang.reflect.Array;
5-
import java.text.DateFormat;
6-
import java.text.ParseException;
7-
import java.text.SimpleDateFormat;
84
import java.util.*;
95

106
/**
@@ -117,48 +113,6 @@ private static char[] encode (byte[] in, int iOff, int iLen) {
117113
}
118114
return out;
119115
}
120-
/**
121-
* Format date in ISO 8601 format
122-
* @param date
123-
* @return
124-
*/
125-
public static String formatISO8601(Date date) {
126-
127-
TimeZone tz = TimeZone.getTimeZone("UTC");
128-
DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm'Z'");
129-
df.setTimeZone(tz);
130-
return df.format(date);
131-
}
132-
public static String formatISO8601(Calendar date) {
133-
return formatISO8601(date.getTime());
134-
}
135-
136-
public static Calendar parseISO8601(String str) {
137-
long t = parseISO8601AsMilliseconds(str);
138-
if(t == -1)
139-
return null;
140-
Calendar ret = Calendar.getInstance();
141-
ret.setTimeInMillis(t);
142-
return ret;
143-
}
144-
private static SimpleDateFormat[] iso8601Formats = {
145-
new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ"),
146-
new SimpleDateFormat("yyyy-MM-dd'T'HH:mm'Z'")
147-
};
148-
private static long parseISO8601AsMilliseconds(String str)
149-
{
150-
for(int i = 0; i < iso8601Formats.length; i++) {
151-
synchronized (iso8601Formats[i]) {
152-
try {
153-
Date date = iso8601Formats[i].parse(str);
154-
return date.getTime();
155-
} catch (ParseException e) {
156-
157-
}
158-
}
159-
}
160-
return -1;
161-
}
162116

163117
public static void blockCopy(Object src, int srcOffset, Object dst, int dstOffset, int count) {
164118
if(dst == null || src == null)
@@ -393,22 +347,7 @@ public static Object changeType(Object value, Class<?> clazz) {
393347
public static Class<?> getUnderlyingType(Object value) {
394348
throw new RuntimeException("Not implemented");
395349
}
396-
public static boolean parseDateTime(String input, String pattern, @Out Calendar[] ret)
397-
{
398-
try {
399-
400-
String newPattern = normalizeDateFormat(pattern);
401-
SimpleDateFormat sdf = new SimpleDateFormat(newPattern);
402-
Date d = sdf.parse(trim(input));
403-
ret[0] = Calendar.getInstance();
404-
ret[0].setTimeInMillis(d.getTime());
405-
return true;
406-
} catch (Exception e) {
407-
ret[0] = null;
408-
return false;
409-
410-
}
411-
}
350+
412351

413352
/**
414353
* Convert .net style date format into java's style
@@ -479,104 +418,59 @@ public static List<?> asList(Object array)
479418
}
480419
public static List<Character> asList(char[] array)
481420
{
482-
return new ListUtils.NativeArrayList<Character>(array);
421+
ArrayList<Character> ret = new ArrayList<>(array.length);
422+
for(char c : array)
423+
ret.add(c);
424+
return ret;
483425
}
484426
public static List<Boolean> asList(boolean[] array)
485427
{
486-
return new ListUtils.NativeArrayList<Boolean>(array);
428+
ArrayList<Boolean> ret = new ArrayList<>(array.length);
429+
for(boolean b : array)
430+
ret.add(b);
431+
return ret;
487432
}
488433
public static List<Byte> asList(byte[] array)
489434
{
490-
return new ListUtils.NativeArrayList<Byte>(array);
435+
ArrayList<Byte> ret = new ArrayList<>(array.length);
436+
for(byte b : array)
437+
ret.add(b);
438+
return ret;
491439
}
492440
public static List<Short> asList(short[] array)
493441
{
494-
return new ListUtils.NativeArrayList<Short>(array);
442+
ArrayList<Short> ret = new ArrayList<>(array.length);
443+
for(short s : array)
444+
ret.add(s);
445+
return ret;
495446
}
496447
public static List<Integer> asList(int[] array)
497448
{
498449
return new ListUtils.IntList(array);
499450
}
500451
public static List<Long> asList(long[] array)
501452
{
502-
return new ListUtils.NativeArrayList<Long>(array);
453+
ArrayList<Long> ret = new ArrayList<>(array.length);
454+
for(long l : array)
455+
ret.add(l);
456+
return ret;
503457
}
504458
public static List<Float> asList(float[] array)
505459
{
506-
return new ListUtils.NativeArrayList<Float>(array);
460+
ArrayList<Float> ret = new ArrayList<>(array.length);
461+
for(float f : array)
462+
ret.add(f);
463+
return ret;
507464
}
508465
public static List<Double> asList(double[] array)
509466
{
510-
return new ListUtils.NativeArrayList<Double>(array);
467+
ArrayList<Double> ret = new ArrayList<>(array.length);
468+
for(double d : array)
469+
ret.add(d);
470+
return ret;
511471
}
512472

513473

514-
/**
515-
* Unbox the boxed array to primitive array
516-
* e.g. Convert Object[] to int[]
517-
* Call unbox(array, int.class)
518-
* @param array array of boxed type
519-
* @return array of primitive type
520-
*/
521-
public static Object unbox(Object[] array, Class<?> elementType)
522-
{
523-
if(array == null)
524-
throw new IllegalArgumentException("array cannot be null");
525-
if(elementType == null)
526-
throw new IllegalArgumentException("elementType cannot be null");
527-
528-
Object ret = Array.newInstance(elementType, array.length);
529-
if(array.length > 0) {
530-
if(elementType == int.class) {
531-
int[] ints = (int[]) ret;
532-
for (int i = 0; i < array.length; i++) {
533-
ints[i] = ((Number) array[i]).intValue();
534-
}
535-
} else if(elementType == short.class) {
536-
short[] vals = (short[]) ret;
537-
for (int i = 0; i < array.length; i++) {
538-
vals[i] = ((Number) array[i]).shortValue();
539-
}
540-
} else if(elementType == byte.class) {
541-
byte[] vals = (byte[]) ret;
542-
for (int i = 0; i < array.length; i++) {
543-
vals[i] = ((Number) array[i]).byteValue();
544-
}
545-
} else if(elementType == long.class) {
546-
long[] vals = (long[]) ret;
547-
for (int i = 0; i < array.length; i++) {
548-
vals[i] = ((Number) array[i]).longValue();
549-
}
550-
} else if(elementType == double.class) {
551-
double[] vals = (double[]) ret;
552-
for (int i = 0; i < array.length; i++) {
553-
vals[i] = ((Number) array[i]).doubleValue();
554-
}
555-
} else if(elementType == float.class) {
556-
float[] vals = (float[]) ret;
557-
for (int i = 0; i < array.length; i++) {
558-
vals[i] = ((Number) array[i]).floatValue();
559-
}
560-
} else if(elementType == boolean.class) {
561-
boolean[] vals = (boolean[]) ret;
562-
for (int i = 0; i < array.length; i++) {
563-
vals[i] = (Boolean) array[i];
564-
}
565-
} else if(elementType == char.class) {
566-
char[] vals = (char[]) ret;
567-
for (int i = 0; i < array.length; i++) {
568-
vals[i] = (Character) array[i];
569-
}
570-
} else {
571-
//generic version, slow but for all types
572-
for (int i = 0; i < array.length; i++) {
573-
Array.set(ret, i, array[i]);
574-
}
575-
}
576-
}
577-
return ret;
578-
579-
}
580474
/**
581475
* Unbox the boxed array to primitive array
582476
* @param array array of boxed type

0 commit comments

Comments
 (0)