Example usage for java.lang Long TYPE

List of usage examples for java.lang Long TYPE

Introduction

In this page you can find the example usage for java.lang Long TYPE.

Prototype

Class TYPE

To view the source code for java.lang Long TYPE.

Click Source Link

Document

The Class instance representing the primitive type long .

Usage

From source file:com.phoenixnap.oss.ramlapisync.naming.SchemaHelper.java

/**
 * Maps primitives and other simple Java types into simple types supported by RAML
 * //from w w w  .java  2 s.  c o m
 * @param clazz The Class to map
 * @return The Simple RAML ParamType which maps to this class or null if one is not found
 */
public static ParamType mapSimpleType(Class<?> clazz) {
    Class<?> targetClazz = clazz;
    if (targetClazz.isArray() && clazz.getComponentType() != null) {
        targetClazz = clazz.getComponentType();
    }
    if (targetClazz.equals(Long.TYPE) || targetClazz.equals(Long.class) || targetClazz.equals(Integer.TYPE)
            || targetClazz.equals(Integer.class) || targetClazz.equals(Short.TYPE)
            || targetClazz.equals(Short.class) || targetClazz.equals(Byte.TYPE)
            || targetClazz.equals(Byte.class)) {
        return ParamType.INTEGER;
    } else if (targetClazz.equals(Float.TYPE) || targetClazz.equals(Float.class)
            || targetClazz.equals(Double.TYPE) || targetClazz.equals(Double.class)
            || targetClazz.equals(BigDecimal.class)) {
        return ParamType.NUMBER;
    } else if (targetClazz.equals(Boolean.class) || targetClazz.equals(Boolean.TYPE)) {
        return ParamType.BOOLEAN;
    } else if (targetClazz.equals(String.class)) {
        return ParamType.STRING;
    }
    return null; // default to string
}

From source file:nl.strohalm.cyclos.controls.loans.GrantLoanAction.java

/**
 * Resolve the GrantLoanDTO// ww  w . j a  v a2  s  .com
 */
private GrantLoanDTO resolveDTO(final ActionContext context) {
    final GrantLoanForm form = context.getForm();
    final long transferTypeId = CoercionHelper.coerce(Long.TYPE, form.getLoan("transferType"));
    if (transferTypeId <= 0L) {
        throw new ValidationException();
    }
    final TransferType transferType = transferTypeService.load(transferTypeId,
            RelationshipHelper.nested(TransferType.Relationships.TO, AccountType.Relationships.CURRENCY));
    final LoanParameters loanParameters = transferType.getLoan();
    if (loanParameters == null || loanParameters.getType() == null) {
        throw new ValidationException("transferType", "transfer.type", new InvalidError());
    }
    final GrantLoanDTO dto = getDataBinder(loanParameters.getType()).readFromString(form.getLoan());
    dto.setTransferType(transferType);
    if (dto.getLoanGroup() != null
            && !permissionService.hasPermission(AdminMemberPermission.LOAN_GROUPS_VIEW)) {
        throw new PermissionDeniedException();
    }
    return dto;
}

From source file:android.reflect.ClazzLoader.java

/**
 * ????//from   ww  w  .ja v a  2 s  . co  m
 */
public static <O, V> void setFieldValue(O o, Field field, V v) {
    if (field != null) {
        try {
            field.setAccessible(true);

            if (v == null) {
                field.set(o, null);
            } else {
                Class<?> vType = v.getClass();
                if (vType == Integer.TYPE) {
                    field.setInt(o, (Integer) v);
                } else if (vType == Long.TYPE) {
                    field.setLong(o, (Long) v);
                } else if (vType == Boolean.TYPE) {
                    field.setBoolean(o, (Boolean) v);
                } else if (vType == Float.TYPE) {
                    field.setFloat(o, (Float) v);
                } else if (vType == Short.TYPE) {
                    field.setShort(o, (Short) v);
                } else if (vType == Byte.TYPE) {
                    field.setByte(o, (Byte) v);
                } else if (vType == Double.TYPE) {
                    field.setDouble(o, (Double) v);
                } else if (vType == Character.TYPE) {
                    field.setChar(o, (Character) v);
                } else {
                    field.set(o, v);
                }
            }
        } catch (Throwable t) {
            Log.e(TAG, t);
        }
    }
}

From source file:com.ricemap.spateDB.core.RTree.java

/**
 * Builds the RTree given a serialized list of elements. It uses the given
 * stockObject to deserialize these elements and build the tree. Also writes
 * the created tree to the disk directly.
 * /*from  www .  j av  a2 s .  com*/
 * @param elements
 *            - serialization of elements to be written
 * @param offset
 *            - index of the first element to use in the elements array
 * @param len
 *            - number of bytes to user from the elements array
 * @param bytesAvailable
 *            - size available (in bytes) to store the tree structures
 * @param dataOut
 *            - an output to use for writing the tree to
 * @param fast_sort
 *            - setting this to <code>true</code> allows the method to run
 *            faster by materializing the offset of each element in the list
 *            which speeds up the comparison. However, this requires an
 *            additional 16 bytes per element. So, for each 1M elements, the
 *            method will require an additional 16 M bytes (approximately).
 */
public void bulkLoadWrite(final byte[] element_bytes, final int offset, final int len, final int degree,
        DataOutput dataOut, final boolean fast_sort, final boolean columnarStorage) {
    try {
        columnar = columnarStorage;
        //TODO: the order of fields should be stable under Oracle JVM, but not guaranteed
        Field[] fields = stockObject.getClass().getDeclaredFields();

        // Count number of elements in the given text
        int i_start = offset;
        final Text line = new Text();
        while (i_start < offset + len) {
            int i_end = skipToEOL(element_bytes, i_start);
            // Extract the line without end of line character
            line.set(element_bytes, i_start, i_end - i_start - 1);
            stockObject.fromText(line);

            elementCount++;
            i_start = i_end;
        }
        LOG.info("Bulk loading an RTree with " + elementCount + " elements");

        // It turns out the findBestDegree returns the best degree when the
        // whole
        // tree is loaded to memory when processed. However, as current
        // algorithms
        // process the tree while it's on disk, a higher degree should be
        // selected
        // such that a node fits one file block (assumed to be 4K).
        // final int degree = findBestDegree(bytesAvailable, elementCount);
        LOG.info("Writing an RTree with degree " + degree);

        int height = Math.max(1, (int) Math.ceil(Math.log(elementCount) / Math.log(degree)));
        int leafNodeCount = (int) Math.pow(degree, height - 1);
        if (elementCount < 2 * leafNodeCount && height > 1) {
            height--;
            leafNodeCount = (int) Math.pow(degree, height - 1);
        }
        int nodeCount = (int) ((Math.pow(degree, height) - 1) / (degree - 1));
        int nonLeafNodeCount = nodeCount - leafNodeCount;

        // Keep track of the offset of each element in the text
        final int[] offsets = new int[elementCount];
        final int[] ids = new int[elementCount];
        final double[] ts = fast_sort ? new double[elementCount] : null;
        final double[] xs = fast_sort ? new double[elementCount] : null;
        final double[] ys = fast_sort ? new double[elementCount] : null;

        //initialize columnar data output
        ByteArrayOutputStream index_bos = new ByteArrayOutputStream();
        DataOutputStream index_dos = new DataOutputStream(index_bos);
        ByteArrayOutputStream[] bos = new ByteArrayOutputStream[fields.length];
        DataOutputStream[] dos = new DataOutputStream[fields.length];
        for (int i = 0; i < bos.length; i++) {
            bos[i] = new ByteArrayOutputStream();
            dos[i] = new DataOutputStream(bos[i]);
        }

        i_start = offset;
        line.clear();
        for (int i = 0; i < elementCount; i++) {
            offsets[i] = i_start;
            ids[i] = i;
            int i_end = skipToEOL(element_bytes, i_start);
            if (xs != null) {
                // Extract the line with end of line character
                line.set(element_bytes, i_start, i_end - i_start - 1);
                stockObject.fromText(line);
                // Sample center of the shape
                ts[i] = (stockObject.getMBR().t1 + stockObject.getMBR().t2) / 2;
                xs[i] = (stockObject.getMBR().x1 + stockObject.getMBR().x2) / 2;
                ys[i] = (stockObject.getMBR().y1 + stockObject.getMBR().y2) / 2;

                //build columnar storage
                if (stockObject instanceof Point3d) {
                    index_dos.writeDouble(ts[i]);
                    index_dos.writeDouble(xs[i]);
                    index_dos.writeDouble(ys[i]);
                } else {
                    throw new RuntimeException("Indexing non-point shape with RTREE is not supported yet");
                }

                for (int j = 0; j < fields.length; j++) {
                    if (fields[j].getType().equals(Integer.TYPE)) {
                        dos[j].writeInt(fields[j].getInt(stockObject));
                    } else if (fields[j].getType().equals(Double.TYPE)) {
                        dos[j].writeDouble(fields[j].getDouble(stockObject));
                    } else if (fields[j].getType().equals(Long.TYPE)) {
                        dos[j].writeLong(fields[j].getLong(stockObject));
                    } else {
                        continue;
                        //throw new RuntimeException("Field type is not supported yet");
                    }
                }
            }
            i_start = i_end;
        }
        index_dos.close();
        for (int i = 0; i < dos.length; i++) {
            dos[i].close();
        }

        /** A struct to store information about a split */
        class SplitStruct extends Prism {
            /** Start and end index for this split */
            int index1, index2;
            /** Direction of this split */
            byte direction;
            /** Index of first element on disk */
            int offsetOfFirstElement;

            static final byte DIRECTION_T = 0;
            static final byte DIRECTION_X = 1;
            static final byte DIRECTION_Y = 2;

            SplitStruct(int index1, int index2, byte direction) {
                this.index1 = index1;
                this.index2 = index2;
                this.direction = direction;
            }

            @Override
            public void write(DataOutput out) throws IOException {
                //
                if (columnarStorage)
                    out.writeInt(index1);
                else
                    out.writeInt(offsetOfFirstElement);
                super.write(out);
            }

            void partition(Queue<SplitStruct> toBePartitioned) {
                IndexedSortable sortableT;
                IndexedSortable sortableX;
                IndexedSortable sortableY;

                if (fast_sort) {
                    // Use materialized xs[] and ys[] to do the comparisons
                    sortableT = new IndexedSortable() {
                        @Override
                        public void swap(int i, int j) {
                            // Swap ts
                            double tempt = ts[i];
                            ts[i] = ts[j];
                            ts[j] = tempt;
                            // Swap xs
                            double tempx = xs[i];
                            xs[i] = xs[j];
                            xs[j] = tempx;
                            // Swap ys
                            double tempY = ys[i];
                            ys[i] = ys[j];
                            ys[j] = tempY;
                            // Swap id
                            int tempid = offsets[i];
                            offsets[i] = offsets[j];
                            offsets[j] = tempid;

                            tempid = ids[i];
                            ids[i] = ids[j];
                            ids[j] = tempid;
                        }

                        @Override
                        public int compare(int i, int j) {
                            if (ts[i] < ts[j])
                                return -1;
                            if (ts[i] > ts[j])
                                return 1;
                            return 0;
                        }
                    };
                    sortableX = new IndexedSortable() {
                        @Override
                        public void swap(int i, int j) {
                            // Swap ts
                            double tempt = ts[i];
                            ts[i] = ts[j];
                            ts[j] = tempt;
                            // Swap xs
                            double tempx = xs[i];
                            xs[i] = xs[j];
                            xs[j] = tempx;
                            // Swap ys
                            double tempY = ys[i];
                            ys[i] = ys[j];
                            ys[j] = tempY;
                            // Swap id
                            int tempid = offsets[i];
                            offsets[i] = offsets[j];
                            offsets[j] = tempid;
                            tempid = ids[i];
                            ids[i] = ids[j];
                            ids[j] = tempid;
                        }

                        @Override
                        public int compare(int i, int j) {
                            if (ts[i] < ts[j])
                                return -1;
                            if (xs[i] < xs[j])
                                return -1;
                            if (xs[i] > xs[j])
                                return 1;
                            return 0;
                        }
                    };

                    sortableY = new IndexedSortable() {
                        @Override
                        public void swap(int i, int j) {
                            // Swap ts
                            double tempt = ts[i];
                            ts[i] = ts[j];
                            ts[j] = tempt;
                            // Swap xs
                            double tempx = xs[i];
                            xs[i] = xs[j];
                            xs[j] = tempx;
                            // Swap ys
                            double tempY = ys[i];
                            ys[i] = ys[j];
                            ys[j] = tempY;
                            // Swap id
                            int tempid = offsets[i];
                            offsets[i] = offsets[j];
                            offsets[j] = tempid;

                            tempid = ids[i];
                            ids[i] = ids[j];
                            ids[j] = tempid;
                        }

                        @Override
                        public int compare(int i, int j) {
                            if (ys[i] < ys[j])
                                return -1;
                            if (ys[i] > ys[j])
                                return 1;
                            return 0;
                        }
                    };
                } else {
                    // No materialized xs and ys. Always deserialize objects
                    // to compare
                    sortableT = new IndexedSortable() {
                        @Override
                        public void swap(int i, int j) {
                            // Swap id
                            int tempid = offsets[i];
                            offsets[i] = offsets[j];
                            offsets[j] = tempid;

                            tempid = ids[i];
                            ids[i] = ids[j];
                            ids[j] = tempid;
                        }

                        @Override
                        public int compare(int i, int j) {
                            // Get end of line
                            int eol = skipToEOL(element_bytes, offsets[i]);
                            line.set(element_bytes, offsets[i], eol - offsets[i] - 1);
                            stockObject.fromText(line);
                            double ti = (stockObject.getMBR().t1 + stockObject.getMBR().t2) / 2;

                            eol = skipToEOL(element_bytes, offsets[j]);
                            line.set(element_bytes, offsets[j], eol - offsets[j] - 1);
                            stockObject.fromText(line);
                            double tj = (stockObject.getMBR().t1 + stockObject.getMBR().t2) / 2;
                            if (ti < tj)
                                return -1;
                            if (ti > tj)
                                return 1;
                            return 0;
                        }
                    };
                    sortableX = new IndexedSortable() {
                        @Override
                        public void swap(int i, int j) {
                            // Swap id
                            int tempid = offsets[i];
                            offsets[i] = offsets[j];
                            offsets[j] = tempid;

                            tempid = ids[i];
                            ids[i] = ids[j];
                            ids[j] = tempid;
                        }

                        @Override
                        public int compare(int i, int j) {
                            // Get end of line
                            int eol = skipToEOL(element_bytes, offsets[i]);
                            line.set(element_bytes, offsets[i], eol - offsets[i] - 1);
                            stockObject.fromText(line);
                            double xi = (stockObject.getMBR().x1 + stockObject.getMBR().x2) / 2;

                            eol = skipToEOL(element_bytes, offsets[j]);
                            line.set(element_bytes, offsets[j], eol - offsets[j] - 1);
                            stockObject.fromText(line);
                            double xj = (stockObject.getMBR().x1 + stockObject.getMBR().x2) / 2;
                            if (xi < xj)
                                return -1;
                            if (xi > xj)
                                return 1;
                            return 0;
                        }
                    };

                    sortableY = new IndexedSortable() {
                        @Override
                        public void swap(int i, int j) {
                            // Swap id
                            int tempid = offsets[i];
                            offsets[i] = offsets[j];
                            offsets[j] = tempid;

                            tempid = ids[i];
                            ids[i] = ids[j];
                            ids[j] = tempid;
                        }

                        @Override
                        public int compare(int i, int j) {
                            int eol = skipToEOL(element_bytes, offsets[i]);
                            line.set(element_bytes, offsets[i], eol - offsets[i] - 1);
                            stockObject.fromText(line);
                            double yi = (stockObject.getMBR().y1 + stockObject.getMBR().y2) / 2;

                            eol = skipToEOL(element_bytes, offsets[j]);
                            line.set(element_bytes, offsets[j], eol - offsets[j] - 1);
                            stockObject.fromText(line);
                            double yj = (stockObject.getMBR().y1 + stockObject.getMBR().y2) / 2;
                            if (yi < yj)
                                return -1;
                            if (yi > yj)
                                return 1;
                            return 0;
                        }
                    };
                }

                final IndexedSorter sorter = new QuickSort();

                final IndexedSortable[] sortables = new IndexedSortable[3];
                sortables[SplitStruct.DIRECTION_T] = sortableT;
                sortables[SplitStruct.DIRECTION_X] = sortableX;
                sortables[SplitStruct.DIRECTION_Y] = sortableY;

                sorter.sort(sortables[direction], index1, index2);

                // Partition into maxEntries partitions (equally) and
                // create a SplitStruct for each partition
                int i1 = index1;
                for (int iSplit = 0; iSplit < degree; iSplit++) {
                    int i2 = index1 + (index2 - index1) * (iSplit + 1) / degree;
                    SplitStruct newSplit;
                    if (direction == 0) {
                        newSplit = new SplitStruct(i1, i2, (byte) 1);
                    } else if (direction == 1) {
                        newSplit = new SplitStruct(i1, i2, (byte) 2);
                    } else {
                        newSplit = new SplitStruct(i1, i2, (byte) 0);
                    }
                    toBePartitioned.add(newSplit);
                    i1 = i2;
                }
            }
        }

        // All nodes stored in level-order traversal
        Vector<SplitStruct> nodes = new Vector<SplitStruct>();
        final Queue<SplitStruct> toBePartitioned = new LinkedList<SplitStruct>();
        toBePartitioned.add(new SplitStruct(0, elementCount, SplitStruct.DIRECTION_X));

        while (!toBePartitioned.isEmpty()) {
            SplitStruct split = toBePartitioned.poll();
            if (nodes.size() < nonLeafNodeCount) {
                // This is a non-leaf
                split.partition(toBePartitioned);
            }
            nodes.add(split);
        }

        if (nodes.size() != nodeCount) {
            throw new RuntimeException(
                    "Expected node count: " + nodeCount + ". Real node count: " + nodes.size());
        }

        // Now we have our data sorted in the required order. Start building
        // the tree.
        // Store the offset of each leaf node in the tree
        FSDataOutputStream fakeOut = new FSDataOutputStream(new java.io.OutputStream() {
            // Null output stream
            @Override
            public void write(int b) throws IOException {
                // Do nothing
            }

            @Override
            public void write(byte[] b, int off, int len) throws IOException {
                // Do nothing
            }

            @Override
            public void write(byte[] b) throws IOException {
                // Do nothing
            }
        }, null, TreeHeaderSize + nodes.size() * NodeSize);
        for (int i_leaf = nonLeafNodeCount, i = 0; i_leaf < nodes.size(); i_leaf++) {
            nodes.elementAt(i_leaf).offsetOfFirstElement = (int) fakeOut.getPos();
            if (i != nodes.elementAt(i_leaf).index1)
                throw new RuntimeException();
            double t1, x1, y1, t2, x2, y2;

            // Initialize MBR to first object
            int eol = skipToEOL(element_bytes, offsets[i]);
            fakeOut.write(element_bytes, offsets[i], eol - offsets[i]);
            line.set(element_bytes, offsets[i], eol - offsets[i] - 1);
            stockObject.fromText(line);
            Prism mbr = stockObject.getMBR();
            t1 = mbr.t1;
            x1 = mbr.x1;
            y1 = mbr.y1;
            t2 = mbr.t2;
            x2 = mbr.x2;
            y2 = mbr.y2;
            i++;

            while (i < nodes.elementAt(i_leaf).index2) {
                eol = skipToEOL(element_bytes, offsets[i]);
                fakeOut.write(element_bytes, offsets[i], eol - offsets[i]);
                line.set(element_bytes, offsets[i], eol - offsets[i] - 1);
                stockObject.fromText(line);
                mbr = stockObject.getMBR();
                if (mbr.t1 < t1)
                    t1 = mbr.t1;
                if (mbr.x1 < x1)
                    x1 = mbr.x1;
                if (mbr.y1 < y1)
                    y1 = mbr.y1;
                if (mbr.t2 > t2)
                    t2 = mbr.t2;
                if (mbr.x2 > x2)
                    x2 = mbr.x2;
                if (mbr.y2 > y2)
                    y2 = mbr.y2;
                i++;
            }
            nodes.elementAt(i_leaf).set(t1, x1, y1, t2, x2, y2);
        }
        fakeOut.close();
        fakeOut = null;

        // Calculate MBR and offsetOfFirstElement for non-leaves
        for (int i_node = nonLeafNodeCount - 1; i_node >= 0; i_node--) {
            int i_first_child = i_node * degree + 1;
            nodes.elementAt(i_node).offsetOfFirstElement = nodes.elementAt(i_first_child).offsetOfFirstElement;
            int i_child = 0;
            Prism mbr;
            mbr = nodes.elementAt(i_first_child + i_child);
            double t1 = mbr.t1;
            double x1 = mbr.x1;
            double y1 = mbr.y1;
            double t2 = mbr.t2;
            double x2 = mbr.x2;
            double y2 = mbr.y2;
            i_child++;

            while (i_child < degree) {
                mbr = nodes.elementAt(i_first_child + i_child);
                if (mbr.t1 < t1)
                    t1 = mbr.t1;
                if (mbr.x1 < x1)
                    x1 = mbr.x1;
                if (mbr.y1 < y1)
                    y1 = mbr.y1;
                if (mbr.t2 > t2)
                    t2 = mbr.t2;
                if (mbr.x2 > x2)
                    x2 = mbr.x2;
                if (mbr.y2 > y2)
                    y2 = mbr.y2;
                i_child++;
            }
            nodes.elementAt(i_node).set(t1, x1, y1, t2, x2, y2);
        }

        // Start writing the tree
        // write tree header (including size)
        // Total tree size. (== Total bytes written - 8 bytes for the size
        // itself)
        dataOut.writeInt(TreeHeaderSize + NodeSize * nodeCount + len);
        // Tree height
        dataOut.writeInt(height);
        // Degree
        dataOut.writeInt(degree);
        dataOut.writeInt(elementCount);

        //isColumnar
        dataOut.writeInt(columnarStorage ? 1 : 0);

        // write nodes
        for (SplitStruct node : nodes) {
            node.write(dataOut);
        }
        // write elements
        if (columnarStorage) {
            byte[] index_bs = index_bos.toByteArray();
            byte[][] bss = new byte[bos.length][];
            for (int i = 0; i < bss.length; i++) {
                bss[i] = bos[i].toByteArray();
            }
            for (int element_i = 0; element_i < elementCount; element_i++) {
                //int eol = skipToEOL(element_bytes, offsets[element_i]);
                //dataOut.write(element_bytes, offsets[element_i], eol - offsets[element_i]);
                dataOut.write(index_bs, ids[element_i] * IndexUnitSize, IndexUnitSize);
            }

            for (int i = 0; i < fields.length; i++) {
                int fieldSize = 0;
                if (fields[i].getType().equals(Integer.TYPE)) {
                    fieldSize = 4;
                } else if (fields[i].getType().equals(Long.TYPE)) {
                    fieldSize = 8;
                } else if (fields[i].getType().equals(Double.TYPE)) {
                    fieldSize = 8;
                } else {
                    //throw new RuntimeException("Unsupported field type: " + fields[i].getType().getName());
                    continue;
                }
                for (int element_i = 0; element_i < elementCount; element_i++) {
                    //int eol = skipToEOL(element_bytes, offsets[element_i]);
                    //dataOut.write(element_bytes, offsets[element_i], eol - offsets[element_i]);
                    dataOut.write(bss[i], ids[element_i] * fieldSize, fieldSize);
                }
            }
        } else {
            for (int element_i = 0; element_i < elementCount; element_i++) {
                int eol = skipToEOL(element_bytes, offsets[element_i]);
                dataOut.write(element_bytes, offsets[element_i], eol - offsets[element_i]);
            }
        }

    } catch (IOException e) {
        e.printStackTrace();
    } catch (IllegalArgumentException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IllegalAccessException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

From source file:org.openlegacy.db.mvc.rest.DefaultDbRestController.java

private static Object toObject(Class<?> clazz, String value) {
    if (Boolean.class == clazz || Boolean.TYPE == clazz) {
        return Boolean.parseBoolean(value);
    }//  w w w  .j a va  2 s. c  o m
    if (Byte.class == clazz || Byte.TYPE == clazz) {
        return Byte.parseByte(value);
    }
    if (Short.class == clazz || Short.TYPE == clazz) {
        return Short.parseShort(value);
    }
    if (Integer.class == clazz || Integer.TYPE == clazz) {
        return Integer.parseInt(value);
    }
    if (Long.class == clazz || Long.TYPE == clazz) {
        return Long.parseLong(value);
    }
    if (Float.class == clazz || Float.TYPE == clazz) {
        return Float.parseFloat(value);
    }
    if (Double.class == clazz || Double.TYPE == clazz) {
        return Double.parseDouble(value);
    }
    return value;
}

From source file:com.examples.with.different.packagename.testcarver.AbstractConverter.java

/**
 * Change primitve Class types to the associated wrapper class.
 * @param type The class type to check.//  w  w  w  .ja  va  2s.co  m
 * @return The converted type.
 */
Class primitive(Class type) {
    if (type == null || !type.isPrimitive()) {
        return type;
    }

    if (type == Integer.TYPE) {
        return Integer.class;
    } else if (type == Double.TYPE) {
        return Double.class;
    } else if (type == Long.TYPE) {
        return Long.class;
    } else if (type == Boolean.TYPE) {
        return Boolean.class;
    } else if (type == Float.TYPE) {
        return Float.class;
    } else if (type == Short.TYPE) {
        return Short.class;
    } else if (type == Byte.TYPE) {
        return Byte.class;
    } else if (type == Character.TYPE) {
        return Character.class;
    } else {
        return type;
    }
}

From source file:Classes.java

/**
 * This method acts equivalently to invoking classLoader.loadClass(className)
 * but it also supports primitive types and array classes of object types or
 * primitive types./*from  w  w w .j  a v a 2  s .  co m*/
 * 
 * @param className
 *          the qualified name of the class or the name of primitive type or
 *          array in the same format as returned by the
 *          java.lang.Class.getName() method.
 * @param classLoader
 *          the ClassLoader used to load classes
 * @return the Class object for the requested className
 * 
 * @throws ClassNotFoundException
 *           when the <code>classLoader</code> can not find the requested
 *           class
 */
public static Class loadClass(String className, ClassLoader classLoader) throws ClassNotFoundException {
    // ClassLoader.loadClass() does not handle primitive types:
    //
    // B byte
    // C char
    // D double
    // F float
    // I int
    // J long
    // S short
    // Z boolean
    // V void
    //
    if (className.length() == 1) {
        char type = className.charAt(0);
        if (type == 'B')
            return Byte.TYPE;
        if (type == 'C')
            return Character.TYPE;
        if (type == 'D')
            return Double.TYPE;
        if (type == 'F')
            return Float.TYPE;
        if (type == 'I')
            return Integer.TYPE;
        if (type == 'J')
            return Long.TYPE;
        if (type == 'S')
            return Short.TYPE;
        if (type == 'Z')
            return Boolean.TYPE;
        if (type == 'V')
            return Void.TYPE;
        // else throw...
        throw new ClassNotFoundException(className);
    }

    // Check for a primative type
    if (isPrimitive(className) == true)
        return (Class) Classes.PRIMITIVE_NAME_TYPE_MAP.get(className);

    // Check for the internal vm format: Lclassname;
    if (className.charAt(0) == 'L' && className.charAt(className.length() - 1) == ';')
        return classLoader.loadClass(className.substring(1, className.length() - 1));

    // first try - be optimistic
    // this will succeed for all non-array classes and array classes that have
    // already been resolved
    //
    try {
        return classLoader.loadClass(className);
    } catch (ClassNotFoundException e) {
        // if it was non-array class then throw it
        if (className.charAt(0) != '[')
            throw e;
    }

    // we are now resolving array class for the first time

    // count opening braces
    int arrayDimension = 0;
    while (className.charAt(arrayDimension) == '[')
        arrayDimension++;

    // resolve component type - use recursion so that we can resolve primitive
    // types also
    Class componentType = loadClass(className.substring(arrayDimension), classLoader);

    // construct array class
    return Array.newInstance(componentType, new int[arrayDimension]).getClass();
}

From source file:at.treedb.backup.Import.java

private void adjustFields(DAOiface dao, Class<?> c, Iterator iter) throws Exception {
    ArrayList<Field> list = ClassDependency.getAllFields(c);
    ArrayList<Field> dbKeys = new ArrayList<Field>();
    ArrayList<Field> detached = new ArrayList<Field>();
    // System.out.println("adjust class:" + c.getSimpleName() + ":");
    for (Field f : list) {
        f.setAccessible(true);/* www  .  jav  a  2s.c om*/
        if (f.getAnnotation(Detach.class) != null) {
            detached.add(f);
        } else if (f.getAnnotation(DBkey.class) != null) {
            dbKeys.add(f);
        }
    }
    HashMap<Integer, Integer> detachMap = detachIdMap.get(c);
    HashMap<Integer, Integer> historicMap = historicIdMap.get(c);

    while (iter.hasNext()) {
        List<Object> l = iter.next();
        for (Object o : l) {
            Base b = (Base) o;
            for (Field f : dbKeys) {
                f.setAccessible(true);
                Class<?> clazz = f.getAnnotation(DBkey.class).value();
                HashMap<Integer, Integer> idMap;
                Class<?> sel = null;
                // ClassSelector necessary for ID re-mapping?
                if (clazz.equals(ClassSelector.class)) {
                    sel = ((ClassSelector) b).getClass(f);
                    if (sel == null) {
                        continue;
                    }
                    idMap = classIdMap.get(sel);
                } else {
                    idMap = classIdMap.get(clazz);
                }

                if (sel != null && f.getType().equals(Long.TYPE)) {
                    long oldKey = f.getLong(b);
                    if (oldKey > 0) {
                        int id = UIelement.extractHistIdFromComposedId(oldKey);
                        if (idMap.get(id) != null) {
                            long newKey = (oldKey & 0xffffffff00000000L) + idMap.get(id);
                            f.setLong(b, newKey);
                        }
                    }
                } else {
                    int oldKey = f.getInt(b);
                    if (oldKey > 0) {
                        if (c.getName().contains("CIimage")) {
                            System.out.println(f.getName() + ":" + idMap.get(oldKey));
                        }
                        f.setInt(b, idMap.get(oldKey));
                    }
                }
            }
            // re-attach detached binary data
            for (Field f : detached) {
                int index = f.getAnnotation(Detach.class).index();
                String path = Export.createBinaryPath(index, b.getCID(), detachMap.get(b.getDBid()));
                f.set(b, readData(path));

            }
            // set new historic ID

            b.setHistId(historicMap.get(b.getHistId()));

            if (c.equals(CIfile.class)) {
                ciFileHashSet.add(((CIfile) b).getDBfile());
            }

            dao.update(b);
            // re-import DBfile data
            if (c.equals(DBfile.class)) {
                DBfile file = (DBfile) b;
                if (ciFileHashSet.contains(file.getHistId())) {
                    // adapt CIfile virtual path:
                    // /files/ciId/uiElementId/fileName
                    String[] split = file.getPath().split("/");
                    split[2] = "" + classIdMap.get(CI.class).get(Integer.parseInt(split[2]));
                    long composed = Long.parseLong(split[3]);
                    int id = UIelement.extractHistIdFromComposedId(composed);
                    HashMap<Integer, Integer> idMap = classIdMap
                            .get(UIelement.getClassIdFromComposedId(composed));
                    split[3] = "" + ((composed & 0xffffffff00000000L) + idMap.get(id));
                    StringBuffer buf = new StringBuffer();
                    for (String s : split) {
                        if (s.equals("")) {
                            continue;
                        }
                        buf.append("/");
                        buf.append(s);
                    }
                    dBFilePathField.set(file, buf.toString());
                }
                writeFile(dao, file, Export.FILES_DIR + fileIdMap.get(file.getDBid()));
            }
            dao.flush();
            // try to free memory
            if (b instanceof CIblob) {
                // for EclipseLink a session clearing necessary! only
                // detaching isn't working really -
                // memory consumption is increasing in spite of detaching
                // objects!
                if (dao.isJPA() && dao.getJPAimpl() == DAO.JPA_IMPL.ECLIPSELINK) {
                    dao.clear();
                } else {
                    dao.detach(b);
                }
                // clear binary data
                ((CIblob) b).resetBlob();
                b = null;
            }
        }
    }
}

From source file:at.alladin.rmbt.shared.hstoreparser.HstoreParser.java

/**
 * /*www .ja va 2  s .c o  m*/
 * @param f
 * @param o
 * @return
 */
public static Object parseFieldValue(Field f, Object o) {
    if (o != JSONObject.NULL) {
        if (f.getType().equals(Integer.class) || f.getType().equals(Integer.TYPE)) {
            return Integer.parseInt(String.valueOf(o));
        } else if (f.getType().equals(String.class)) {
            return String.valueOf(o);
        } else if (f.getType().equals(Long.class) || f.getType().equals(Long.TYPE)) {
            return Long.parseLong(String.valueOf(o));
        } else if (f.getType().equals(Boolean.class) || f.getType().equals(Boolean.TYPE)) {
            return Boolean.parseBoolean(String.valueOf(o));
        } else if (f.getType().equals(Float.class) || f.getType().equals(Float.TYPE)) {
            return Float.parseFloat(String.valueOf(o));
        } else if (f.getType().equals(Double.class) || f.getType().equals(Double.TYPE)) {
            return Double.parseDouble(String.valueOf(o));
        } else if (f.getType().equals(Short.class) || f.getType().equals(Short.TYPE)) {
            return Short.parseShort(String.valueOf(o));
        } else {
            return o;
        }
    }

    return null;
}

From source file:com.mawujun.util.AnnotationUtils.java

/**
 * Helper method for generating a hash code for an array.
 *
 * @param componentType the component type of the array
 * @param o the array//from ww w .jav a 2  s .  c  om
 * @return a hash code for the specified array
 */
private static int arrayMemberHash(Class<?> componentType, Object o) {
    if (componentType.equals(Byte.TYPE)) {
        return Arrays.hashCode((byte[]) o);
    }
    if (componentType.equals(Short.TYPE)) {
        return Arrays.hashCode((short[]) o);
    }
    if (componentType.equals(Integer.TYPE)) {
        return Arrays.hashCode((int[]) o);
    }
    if (componentType.equals(Character.TYPE)) {
        return Arrays.hashCode((char[]) o);
    }
    if (componentType.equals(Long.TYPE)) {
        return Arrays.hashCode((long[]) o);
    }
    if (componentType.equals(Float.TYPE)) {
        return Arrays.hashCode((float[]) o);
    }
    if (componentType.equals(Double.TYPE)) {
        return Arrays.hashCode((double[]) o);
    }
    if (componentType.equals(Boolean.TYPE)) {
        return Arrays.hashCode((boolean[]) o);
    }
    return Arrays.hashCode((Object[]) o);
}