-
Notifications
You must be signed in to change notification settings - Fork 56
Class Unbox
Ori Roth edited this page Apr 2, 2017
·
3 revisions
public enum Unbox {
/*
* Utilities (16)
*/
static boolean[] unbox(Boolean[] bs);
static byte[] unbox(Byte[] bs);
static char[] unbox(Character[] cs);
static double[] unbox(Double[] ds);
static float[] unbox(Float[] fs);
static int[] unbox(Integer[] is);
static long[] unbox(Long[] ls);
static short[] unbox(Short[] ss);
static boolean[] unbox(Collection<Boolean> bs);
static byte[] unbox(Collection<Byte> bs);
static char[] unbox(Collection<Character> bs);
static double[] unbox(Collection<Double> ds);
static float[] unbox(Collection<Float> fs);
static int[] unbox(Collection<Integer> is);
static long[] unbox(Collection<Long> ls);
static short[] unbox(Collection<Short> ss);
}
Input types: Collection<Boolean>
, Collection<Byte>
, Collection<Character>
, Collection<Double>
, Collection<Float>
, Collection<Integer>
, Collection<Long>
, Collection<Short>
.
// SSDLPedia
package il.ac.technion.cs.ssdl.utils;
import il.ac.technion.cs.ssdl.stereotypes.Utility;
import java.util.Collection;
/**
* A utility class, offering a collection of function to unbox arrays and
* collection of the boxed versions of the primitive types. The input of each
* unboxing function is a Collection or an array of one the following
* eight reference types
*
* 1. Boolean
* 2. Byte
* 3. Character
* 4. Double
* 5. Float
* 6. Integer
* 7. Long
* 8. Short
*
* The returned value is an array of the equivalent primitive type.
*
* Note that unboxing of a single value of a reference type is easy using a
* function such as Long#longValue()
*
* Author: Yossi Gil, the Technion.
* See: 21/06/2008
* See: Box
*/
@Utility public enum Unbox {
// A namespace: no values to this enum
/**
* Unbox an array of Booleans into an array of
* booleans.
*
* bs an array of Booleans
* Return: an equivalent array of booleans.
*/
;
public static boolean[] unbox(final Boolean[] bs) {
final boolean[] $ = new boolean[bs.length];
for (int i = 0; i < bs.length; i++)
$[i] = bs[i].booleanValue();
return $;
}
/**
* Unbox an array of Bytes into an array of byte
* s.
*
* bs an array of Bytes
* Return: an equivalent array of bytes.
*/
public static byte[] unbox(final Byte[] bs) {
final byte[] $ = new byte[bs.length];
for (int i = 0; i < bs.length; i++)
$[i] = bs[i].byteValue();
return $;
}
/**
* Unbox an array of Characters into an array of
* chars.
*
* cs an array of Characters
* Return: an equivalent array of chars.
*/
public static char[] unbox(final Character[] cs) {
final char[] $ = new char[cs.length];
for (int i = 0; i < cs.length; i++)
$[i] = cs[i].charValue();
return $;
}
/**
* Unbox an array of Doubles into an array of
* doubles.
*
* ds an array of Doubles
* Return: an equivalent array of doubles.
*/
public static double[] unbox(final Double[] ds) {
final double[] $ = new double[ds.length];
for (int i = 0; i < ds.length; i++)
$[i] = ds[i].floatValue();
return $;
}
/**
* Unbox an array of Floats into an array of
* floats.
*
* fs an array of Floats
* Return: an equivalent array of floats.
*/
public static float[] unbox(final Float[] fs) {
final float[] $ = new float[fs.length];
for (int i = 0; i < fs.length; i++)
$[i] = fs[i].floatValue();
return $;
}
/**
* Unbox an array of Integers into an array of
* ints.
*
* is an array of Integers
* Return: an equivalent array of ints.
*/
public static int[] unbox(final Integer[] is) {
final int[] $ = new int[is.length];
for (int i = 0; i < is.length; i++)
$[i] = is[i].intValue();
return $;
}
/**
* Unbox an array of Longs into an array of long
* s.
*
* ls an array of Longs
* Return: an equivalent array of longs.
*/
public static long[] unbox(final Long[] ls) {
final long[] $ = new long[ls.length];
for (int i = 0; i < ls.length; i++)
$[i] = ls[i].longValue();
return $;
}
/**
* Unbox an array of Shorts into an array of
* shorts.
*
* ss an array of Integers
* Return: an equivalent array of shorts.
*/
public static short[] unbox(final Short[] ss) {
final short[] $ = new short[ss.length];
for (int i = 0; i < ss.length; i++)
$[i] = ss[i].shortValue();
return $;
}
/**
* Unbox a Collection of Booleans into an array of
* booleans.
*
* bs a Collection of Booleans
* Return: an equivalent array of booleans.
*/
public static boolean[] unbox(final Collection<Boolean> bs) {
final boolean[] $ = new boolean[bs.size()];
int i = 0;
for (final Boolean v : bs)
$[i++] = v.booleanValue();
return $;
}
/**
* Unbox a Collection of Bytes into an array of
* byte s.
*
* bs a Collection of Bytes
* Return: an equivalent array of bytes.
*/
public static byte[] unbox(final Collection<Byte> bs) {
final byte[] $ = new byte[bs.size()];
int i = 0;
for (final Byte v : bs)
$[i++] = v.byteValue();
return $;
}
/**
* Unbox a Collection of Characters into an array of
* chars.
*
* bs a Collection of Characters
* Return: an equivalent array of chars.
*/
public static char[] unbox(final Collection<Character> bs) {
final char[] $ = new char[bs.size()];
int i = 0;
for (final Character v : bs)
$[i++] = v.charValue();
return $;
}
/**
* Unbox a Collection of Doubles into an array of
* doubles.
*
* ds a Collection of Doubles
* Return: an equivalent array of doubles.
*/
public static double[] unbox(final Collection<Double> ds) {
final double[] $ = new double[ds.size()];
int i = 0;
for (final Double v : ds)
$[i++] = v.doubleValue();
return $;
}
/**
* Unbox a Collection of Floats into an array of
* floats.
*
* fs a Collection of Floats
* Return: an equivalent array of floats.
*/
public static float[] unbox(final Collection<Float> fs) {
final float[] $ = new float[fs.size()];
int i = 0;
for (final Float v : fs)
$[i++] = v.floatValue();
return $;
}
/**
* Unbox a Collection of Integers into an array of
* ints.
*
* is a Collection of Integers
* Return: an equivalent array of ints.
*/
public static int[] unbox(final Collection<Integer> is) {
final int[] $ = new int[is.size()];
int i = 0;
for (final Integer v : is)
$[i++] = v.intValue();
return $;
}
/**
* Unbox a Collection of Longs into an array of
* long s.
*
* ls a Collection of Longs
* Return: an equivalent array of longs.
*/
public static long[] unbox(final Collection<Long> ls) {
final long[] $ = new long[ls.size()];
int i = 0;
for (final Long v : ls)
$[i++] = v.longValue();
return $;
}
/**
* Unbox a Collection of Shorts into an array of
* shorts.
*
* ss a Collection of Integers
* Return: an equivalent array of shorts.
*/
public static short[] unbox(final Collection<Short> ss) {
final short[] $ = new short[ss.size()];
int i = 0;
for (final Short v : ss)
$[i++] = v.shortValue();
return $;
}
}
Metric | Value | Acronym | Explanation |
---|---|---|---|
LOC | 267 | Lines Of Code | Total number of lines in the code |
SCC | 76 | SemiColons Count | Total number of semicolon tokens found in the code. |
NOT | 1018 | Number Of Tokens | Comments, whitespace and text which cannot be made into a token not included. |
VCC | 5818 | Visible Characters Count | The total number of non-white (i.e., not space, tab, newline, carriage return, form feed) characters. |
CCC | 2358 | Code Characters Count | Total number of non-white characters in tokens. White space characters in string and character literals are not counted. |
UIC | 40 | Unique Identifiers Count | The number of different identifiers found in the code |
WHC | 4 | Weighted Horizontal Complexity | A heuritistic on horizontal complexity |
Statistic | Value |
---|---|
Average token length | 2.3 |
Tokens/line | 3.8 |
Visible characters/line | 22 |
Code characters/line | 8.8 |
Semicolons/tokens | 7% |
Comment text percentage | 59% |
Token Kind | Occurrences |
---|---|
KEYWORD | 189 |
OPERATOR | 88 |
LITERAL | 16 |
ID | 282 |
PUNCTUATION | 443 |
COMMENT | 19 |
OTHER | 487 |