Example usage for java.lang Byte Byte

List of usage examples for java.lang Byte Byte

Introduction

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

Prototype

@Deprecated(since = "9")
public Byte(String s) throws NumberFormatException 

Source Link

Document

Constructs a newly allocated Byte object that represents the byte value indicated by the String parameter.

Usage

From source file:org.apache.tinkerpop.gremlin.structure.io.Model.java

private Model() {
    final Configuration conf = new BaseConfiguration();
    conf.setProperty(TinkerGraph.GREMLIN_TINKERGRAPH_DEFAULT_VERTEX_PROPERTY_CARDINALITY,
            VertexProperty.Cardinality.list.name());
    final TinkerGraph graph = TinkerGraph.open(conf);
    TinkerFactory.generateTheCrew(graph);
    final GraphTraversalSource g = graph.traversal();

    final Compatibility[] noTypeGraphSONPlusGryo3_2_3 = Compatibilities.with(GryoCompatibility.class)
            .beforeRelease("3.2.4").join(Compatibilities.UNTYPED_GRAPHSON).matchToArray();
    final Compatibility[] noTypeGraphSONPlusGryo3_3_0 = Compatibilities.with(GryoCompatibility.class)
            .beforeRelease("3.3.0").join(Compatibilities.UNTYPED_GRAPHSON).matchToArray();
    final Compatibility[] noGraphSONBeforeV3 = Compatibilities.with(GraphSONCompatibility.class)
            .configuredAs(".*v2d0-partial|v1d0|v2d0-no-types").join(Compatibilities.GRYO_ONLY).matchToArray();

    // IMPORTANT - the "title" or name of the Entry needs to be unique

    // Serialization of Class in Gryo 1.0 had a bug that prevented proper operation in versions prior to 3.2.4.
    addCoreEntry(File.class, "Class", "", noTypeGraphSONPlusGryo3_2_3);
    addCoreEntry(new Date(1481750076295L), "Date");
    addCoreEntry(100.00d, "Double");
    addCoreEntry(100.00f, "Float", "", Compatibilities.UNTYPED_GRAPHSON.matchToArray());
    addCoreEntry(100, "Integer");
    addCoreEntry(Arrays.asList(1, "person", true), "List",
            "List is used to distinguish between different collection types as JSON is not explicit enough for all of Gremlin's requirements.",
            noGraphSONBeforeV3);//from   w  w w  .  j a  va 2 s .c  o m
    addCoreEntry(100L, "Long", "", Compatibilities.UNTYPED_GRAPHSON.matchToArray());
    final Map<Object, Object> map = new HashMap<>();
    map.put("test", 123);
    map.put(new Date(1481750076295L), "red");
    map.put(Arrays.asList(1, 2, 3), new Date(1481750076295L));
    addCoreEntry(map, "Map",
            "Map is redefined so that to provide the ability to allow for non-String keys, which is not possible in JSON.",
            noGraphSONBeforeV3);
    addCoreEntry(new HashSet<>(Arrays.asList(1, "person", true)), "Set",
            "Allows a JSON collection to behave as a Set.", noGraphSONBeforeV3);
    // Timestamp was added to Gryo 1.0 as of 3.2.4. It was not supported in 3.2.3.
    addCoreEntry(new java.sql.Timestamp(1481750076295L), "Timestamp", "", noTypeGraphSONPlusGryo3_2_3);
    addCoreEntry(UUID.fromString("41d2e28a-20a4-4ab0-b379-d810dede3786"), "UUID");

    addGraphStructureEntry(graph.edges().next(), "Edge", "");
    addGraphStructureEntry(g.V().out().out().path().next(), "Path", "");
    addGraphStructureEntry(graph.edges().next().properties().next(), "Property", "");
    // TODO: missing a stargraph deserializer in graphson v1/v2
    addEntry("Graph Structure", StarGraph.of(graph.vertices().next()), "StarGraph", "",
            Compatibilities.GRYO_ONLY.match());
    addGraphStructureEntry(graph, "TinkerGraph",
            "`TinkerGraph` has a custom serializer that is registered as part of the `TinkerIoRegistry`.");
    // TODO: tree has bugs for graphson
    addEntry("Graph Structure", g.V(1).out().out().tree().next(), "Tree", "",
            Compatibilities.GRYO_ONLY.match());
    addGraphStructureEntry(graph.vertices().next(), "Vertex", "");
    addGraphStructureEntry(graph.vertices().next().properties().next(), "VertexProperty", "");

    addGraphProcessEntry(SackFunctions.Barrier.normSack, "Barrier", "",
            Compatibilities.UNTYPED_GRAPHSON.matchToArray());
    addGraphProcessEntry(new Bytecode.Binding("x", 1), "Binding",
            "A \"Binding\" refers to a `Bytecode.Binding`.", Compatibilities.UNTYPED_GRAPHSON.matchToArray());
    addGraphProcessEntry(g.V().hasLabel("person").out().in().tree().asAdmin().getBytecode(), "Bytecode",
            "The following `Bytecode` example represents the traversal of `g.V().hasLabel('person').out().in().tree()`. Obviously the serialized `Bytecode` woudl be quite different for the endless variations of commands that could be used together in the Gremlin language.",
            Compatibilities.UNTYPED_GRAPHSON.matchToArray());
    addGraphProcessEntry(VertexProperty.Cardinality.list, "Cardinality", "",
            Compatibilities.UNTYPED_GRAPHSON.matchToArray());
    addGraphProcessEntry(Column.keys, "Column", "", Compatibilities.UNTYPED_GRAPHSON.matchToArray());
    addGraphProcessEntry(Direction.OUT, "Direction", "", Compatibilities.UNTYPED_GRAPHSON.matchToArray());
    addGraphProcessEntry(Operator.sum, "Operator", "", Compatibilities.UNTYPED_GRAPHSON.matchToArray());
    addGraphProcessEntry(Order.incr, "Order", "", Compatibilities.UNTYPED_GRAPHSON.matchToArray());
    addGraphProcessEntry(TraversalOptionParent.Pick.any, "Pick", "",
            Compatibilities.UNTYPED_GRAPHSON.matchToArray());
    addGraphProcessEntry(Pop.all, "Pop", "", Compatibilities.UNTYPED_GRAPHSON.matchToArray());
    addGraphProcessEntry(org.apache.tinkerpop.gremlin.util.function.Lambda.function("{ it.get() }"), "Lambda",
            "", Compatibilities.UNTYPED_GRAPHSON.matchToArray());
    final TraversalMetrics tm = createStaticTraversalMetrics();
    final MutableMetrics metrics = new MutableMetrics(tm.getMetrics("7.0.0()"));
    metrics.addNested(new MutableMetrics(tm.getMetrics("3.0.0()")));
    addGraphProcessEntry(metrics, "Metrics", "", noTypeGraphSONPlusGryo3_3_0);
    addGraphProcessEntry(P.gt(0), "P", "", Compatibilities.UNTYPED_GRAPHSON.matchToArray());
    addGraphProcessEntry(P.within(1), "P within", "", Compatibilities.UNTYPED_GRAPHSON.matchToArray());
    addGraphProcessEntry(P.without(1, 2), "P without", "", Compatibilities.UNTYPED_GRAPHSON.matchToArray());
    // A bug in the the Gryo serialization of ConjunctiveP prevented its proper serialization in versions prior to 3.3.0 and 3.2.4.
    addGraphProcessEntry(P.gt(0).and(P.lt(10)), "P and", "", noTypeGraphSONPlusGryo3_2_3);
    // A bug in the the Gryo serialization of ConjunctiveP prevented its proper serialization in versions prior to 3.3.0 and 3.2.4.
    addGraphProcessEntry(P.gt(0).or(P.within(-1, -10, -100)), "P or", "", noTypeGraphSONPlusGryo3_2_3);
    addGraphProcessEntry(Scope.local, "Scope", "", Compatibilities.UNTYPED_GRAPHSON.matchToArray());
    addGraphProcessEntry(T.label, "T", "", Compatibilities.UNTYPED_GRAPHSON.matchToArray());
    addGraphProcessEntry(createStaticTraversalMetrics(), "TraversalMetrics", "", noTypeGraphSONPlusGryo3_3_0);
    addGraphProcessEntry(g.V().hasLabel("person").asAdmin().nextTraverser(), "Traverser", "",
            Compatibilities.UNTYPED_GRAPHSON.matchToArray());

    final Map<String, Object> requestBindings = new HashMap<>();
    requestBindings.put("x", 1);

    final Map<String, Object> requestAliases = new HashMap<>();
    requestAliases.put("g", "social");

    // RequestMessage is not testable prior to Gryo 3.0 as serialization was handled by an intermediate component
    // (MessageSerializer) that doesn't fit the test model.
    RequestMessage requestMessage;
    requestMessage = RequestMessage.build("authentication")
            .overrideRequestId(UUID.fromString("cb682578-9d92-4499-9ebc-5c6aa73c5397"))
            .add("saslMechanism", "PLAIN", "sasl", "AHN0ZXBocGhlbgBwYXNzd29yZA==").create();
    addRequestMessageEntry(requestMessage, "Authentication Response",
            "The following `RequestMessage` is an example of the response that should be made to a SASL-based authentication challenge.");
    requestMessage = RequestMessage.build("eval").processor("session")
            .overrideRequestId(UUID.fromString("cb682578-9d92-4499-9ebc-5c6aa73c5397"))
            .add("gremlin", "g.V(x)", "bindings", requestBindings, "language", "gremlin-groovy", "session",
                    UUID.fromString("41d2e28a-20a4-4ab0-b379-d810dede3786"))
            .create();
    addRequestMessageEntry(requestMessage, "Session Eval",
            "The following `RequestMessage` is an example of a simple session request for a script evaluation with parameters.");
    requestMessage = RequestMessage.build("eval").processor("session")
            .overrideRequestId(UUID.fromString("cb682578-9d92-4499-9ebc-5c6aa73c5397"))
            .add("gremlin", "social.V(x)", "bindings", requestBindings, "language", "gremlin-groovy", "aliases",
                    requestAliases, "session", UUID.fromString("41d2e28a-20a4-4ab0-b379-d810dede3786"))
            .create();
    addRequestMessageEntry(requestMessage, "Session Eval Aliased",
            "The following `RequestMessage` is an example of a session request for a script evaluation with an alias that binds the `TraversalSource` of \"g\" to \"social\".");
    requestMessage = RequestMessage.build("close").processor("session")
            .overrideRequestId(UUID.fromString("cb682578-9d92-4499-9ebc-5c6aa73c5397"))
            .add("session", UUID.fromString("41d2e28a-20a4-4ab0-b379-d810dede3786")).create();
    addRequestMessageEntry(requestMessage, "Session Close",
            "The following `RequestMessage` is an example of a request to close a session.");
    requestMessage = RequestMessage.build("eval")
            .overrideRequestId(UUID.fromString("cb682578-9d92-4499-9ebc-5c6aa73c5397"))
            .add("gremlin", "g.V(x)", "bindings", requestBindings, "language", "gremlin-groovy").create();
    addRequestMessageEntry(requestMessage, "Sessionless Eval",
            "The following `RequestMessage` is an example of a simple sessionless request for a script evaluation with parameters.");
    requestMessage = RequestMessage.build("eval")
            .overrideRequestId(UUID.fromString("cb682578-9d92-4499-9ebc-5c6aa73c5397"))
            .add("gremlin", "social.V(x)", "bindings", requestBindings, "language", "gremlin-groovy", "aliases",
                    requestAliases)
            .create();
    addRequestMessageEntry(requestMessage, "Sessionless Eval Aliased",
            "The following `RequestMessage` is an example of a sessionless request for a script evaluation with an alias that binds the `TraversalSource` of \"g\" to \"social\".");

    // ResponseMessage is not testable prior to Gryo 3.0 as serialization was handled by an intermediate component
    // (MessageSerializer) that doesn't fit the test model
    ResponseMessage responseMessage = ResponseMessage
            .build(UUID.fromString("41d2e28a-20a4-4ab0-b379-d810dede3786"))
            .code(org.apache.tinkerpop.gremlin.driver.message.ResponseStatusCode.AUTHENTICATE).create();
    addResponseMessageEntry(responseMessage, "Authentication Challenge",
            "When authentication is enabled, an initial request to the server will result in an authentication challenge. The typical response message will appear as follows, but handling it could be different depending on the SASL implementation (e.g. multiple challenges maybe requested in some cases, but not in the default provided by Gremlin Server).");
    responseMessage = ResponseMessage.build(UUID.fromString("41d2e28a-20a4-4ab0-b379-d810dede3786"))
            .code(org.apache.tinkerpop.gremlin.driver.message.ResponseStatusCode.SUCCESS)
            .result(Collections.singletonList(graph.vertices().next())).create();
    addResponseMessageEntry(responseMessage, "Standard Result",
            "The following `ResponseMessage` is a typical example of the typical successful response Gremlin Server will return when returning results from a script.");

    addExtendedEntry(new BigDecimal(new java.math.BigInteger("123456789987654321123456789987654321")),
            "BigDecimal", "", Compatibilities.UNTYPED_GRAPHSON.matchToArray());
    addExtendedEntry(new BigInteger("123456789987654321123456789987654321"), "BigInteger", "",
            Compatibilities.UNTYPED_GRAPHSON.matchToArray());
    addExtendedEntry(new Byte("1"), "Byte", "", Compatibilities.UNTYPED_GRAPHSON.matchToArray());
    // ByteBuffer was added to Gryo 1.0 as of 3.2.4. It was not supported in earlier versions.
    addEntry("Extended", () -> java.nio.ByteBuffer.wrap("some bytes for you".getBytes()), "ByteBuffer", "",
            noTypeGraphSONPlusGryo3_2_3);
    addExtendedEntry("x".charAt(0), "Char", "", Compatibilities.UNTYPED_GRAPHSON.matchToArray());
    addExtendedEntry(Duration.ofDays(5), "Duration", "The following example is a `Duration` of five days.",
            Compatibilities.UNTYPED_GRAPHSON.matchToArray());
    try {
        // InetAddress was added to Gryo 1.0 as of 3.2.4. It was not supported in earlier versions.
        addEntry("Extended", InetAddress.getByName("localhost"), "InetAddress", "",
                noTypeGraphSONPlusGryo3_2_3);
    } catch (Exception ex) {
        throw new RuntimeException(ex);
    }
    addExtendedEntry(Instant.parse("2016-12-14T16:39:19.349Z"), "Instant", "",
            Compatibilities.UNTYPED_GRAPHSON.matchToArray());
    addExtendedEntry(LocalDate.of(2016, 1, 1), "LocalDate", "",
            Compatibilities.UNTYPED_GRAPHSON.matchToArray());
    addExtendedEntry(LocalDateTime.of(2016, 1, 1, 12, 30), "LocalDateTime", "",
            Compatibilities.UNTYPED_GRAPHSON.matchToArray());
    addExtendedEntry(LocalTime.of(12, 30, 45), "LocalTime", "",
            Compatibilities.UNTYPED_GRAPHSON.matchToArray());
    addExtendedEntry(MonthDay.of(1, 1), "MonthDay", "", Compatibilities.UNTYPED_GRAPHSON.matchToArray());
    addExtendedEntry(OffsetDateTime.parse("2007-12-03T10:15:30+01:00"), "OffsetDateTime", "",
            Compatibilities.UNTYPED_GRAPHSON.matchToArray());
    addExtendedEntry(OffsetTime.parse("10:15:30+01:00"), "OffsetTime", "",
            Compatibilities.UNTYPED_GRAPHSON.matchToArray());
    addExtendedEntry(Period.of(1, 6, 15), "Period",
            "The following example is a `Period` of one year, six months and fifteen days.",
            Compatibilities.UNTYPED_GRAPHSON.matchToArray());
    addExtendedEntry(new Short("100"), "Short", "", Compatibilities.UNTYPED_GRAPHSON.matchToArray());
    addExtendedEntry(Year.of(2016), "Year", "The following example is of the `Year` \"2016\".",
            Compatibilities.UNTYPED_GRAPHSON.matchToArray());
    addExtendedEntry(YearMonth.of(2016, 6), "YearMonth",
            "The following example is a `YearMonth` of \"June 2016\"",
            Compatibilities.UNTYPED_GRAPHSON.matchToArray());
    addExtendedEntry(ZonedDateTime.of(2016, 12, 23, 12, 12, 24, 36, ZoneId.of("GMT+2")), "ZonedDateTime", "",
            Compatibilities.UNTYPED_GRAPHSON.matchToArray());
    addExtendedEntry(ZoneOffset.ofHoursMinutesSeconds(3, 6, 9), "ZoneOffset",
            "The following example is a `ZoneOffset` of three hours, six minutes, and nine seconds.",
            Compatibilities.UNTYPED_GRAPHSON.matchToArray());
}

From source file:org.jboss.dashboard.commons.misc.ReflectionUtils.java

public static <T> T newInstanceForClass(Class<T> type) {
    Object object = null;//from  w w  w.  j  a  v a 2s  . co  m
    if (type.isArray()) {
        Class componentClass = type.getComponentType();
        if (componentClass.isPrimitive()) {
            if (componentClass.equals(int.class))
                object = new int[0];
            else if (componentClass.equals(boolean.class))
                object = new boolean[0];
            else if (componentClass.equals(long.class))
                object = new long[0];
            else if (componentClass.equals(char.class))
                object = new char[0];
            else if (componentClass.equals(double.class))
                object = new double[0];
            else if (componentClass.equals(float.class))
                object = new float[0];
            else if (componentClass.equals(byte.class))
                object = new byte[0];
            else if (componentClass.equals(short.class))
                object = new short[0];
        } else if (String.class.equals(componentClass))
            object = new String[0];
        else if (componentClass.equals(Integer.class))
            object = new Integer[0];
        else if (componentClass.equals(Boolean.class))
            object = new Boolean[0];
        else if (componentClass.equals(Long.class))
            object = new Long[0];
        else if (componentClass.equals(Character.class))
            object = new Character[0];
        else if (componentClass.equals(Double.class))
            object = new Double[0];
        else if (componentClass.equals(Float.class))
            object = new Float[0];
        else if (componentClass.equals(Byte.class))
            object = new Byte[0];
        else if (componentClass.equals(Short.class))
            object = new Short[0];
        else
            object = Array.newInstance(componentClass, 0);
    } else {
        if (String.class.equals(type))
            object = "";
        else if (type.equals(int.class))
            object = new Integer(0);
        else if (type.equals(boolean.class))
            object = Boolean.FALSE;
        else if (type.equals(long.class))
            object = new Long(0);
        else if (type.equals(char.class))
            object = new Character((char) 0);
        else if (type.equals(double.class))
            object = new Double(0);
        else if (type.equals(float.class))
            object = new Float(0);
        else if (type.equals(byte.class))
            object = new Byte((byte) 0);
        else if (type.equals(short.class))
            object = new Short((short) 0);
        else if (type.equals(Integer.class))
            object = new Integer(0);
        else if (type.equals(Boolean.class))
            object = Boolean.FALSE;
        else if (type.equals(Long.class))
            object = new Long(0);
        else if (type.equals(Character.class))
            object = new Character((char) 0);
        else if (type.equals(Double.class))
            object = new Double(0);
        else if (type.equals(Float.class))
            object = new Float(0);
        else if (type.equals(Byte.class))
            object = new Byte((byte) 0);
        else if (type.equals(Short.class))
            object = new Short((short) 0);
        else
            object = null;
    }
    return type.cast(object);
}

From source file:org.voltdb.TestParameterSet.java

public void testRoundtrip() throws IOException {
    Byte byteparam = new Byte((byte) 2);
    Short shortparam = new Short(Short.MAX_VALUE);
    Integer intparam = new Integer(Integer.MIN_VALUE);
    Long longparam = new Long(Long.MAX_VALUE - 1);
    Double doubleparam = new Double(Double.MAX_VALUE - 1);
    String stringparam = new String("ABCDE");
    TimestampType dateparam = new TimestampType(); // current time
    BigDecimal bigdecimalparam = new BigDecimal(7654321).setScale(VoltDecimalHelper.kDefaultScale);
    VoltTable volttableparam = new VoltTable(new VoltTable.ColumnInfo("foo", VoltType.INTEGER));
    volttableparam.addRow(Integer.MAX_VALUE);

    byte[] bytearray = new byte[] { (byte) 'f', (byte) 'o', (byte) 'o' };
    short[] shortarray = new short[] { Short.MAX_VALUE, Short.MIN_VALUE, (short) 5 };
    int[] intarray = new int[] { Integer.MAX_VALUE, Integer.MIN_VALUE, 5 };
    double[] doublearray = new double[] { Double.MAX_VALUE, Double.MIN_VALUE, 5.5 };
    String[] stringarray = new String[] { "ABC", "DEF", "HIJ" };
    TimestampType[] datearray = new TimestampType[] { new TimestampType(), new TimestampType(),
            new TimestampType() };

    BigDecimal bdtmp1 = new BigDecimal(7654321).setScale(VoltDecimalHelper.kDefaultScale);
    BigDecimal bdtmp2 = new BigDecimal(654321).setScale(VoltDecimalHelper.kDefaultScale);
    BigDecimal bdtmp3 = new BigDecimal(54321).setScale(VoltDecimalHelper.kDefaultScale);
    BigDecimal[] bigdecimalarray = new BigDecimal[] { bdtmp1, bdtmp2, bdtmp3 };

    VoltTable vttmp1 = new VoltTable(new VoltTable.ColumnInfo("foo", VoltType.INTEGER),
            new VoltTable.ColumnInfo("bar", VoltType.STRING));
    vttmp1.addRow(Integer.MAX_VALUE, "ry@nlikestheyankees");
    VoltTable vttmp2 = new VoltTable(new VoltTable.ColumnInfo("bar", VoltType.INTEGER),
            new VoltTable.ColumnInfo("bar", VoltType.STRING));
    vttmp2.addRow(Integer.MIN_VALUE, null);
    VoltTable vttmp3 = new VoltTable(new VoltTable.ColumnInfo("far", VoltType.INTEGER),
            new VoltTable.ColumnInfo("bar", VoltType.STRING));
    vttmp3.addRow(new Integer(5), "");
    VoltTable[] volttablearray = new VoltTable[] { vttmp1, vttmp2, vttmp3 };

    assertTrue(bigdecimalparam.scale() == VoltDecimalHelper.kDefaultScale);
    assertTrue(bdtmp1.scale() == VoltDecimalHelper.kDefaultScale);
    assertTrue(bdtmp2.scale() == VoltDecimalHelper.kDefaultScale);
    assertTrue(bdtmp3.scale() == VoltDecimalHelper.kDefaultScale);

    ParameterSet pset = ParameterSet.fromArrayNoCopy(byteparam, shortparam, intparam, longparam, doubleparam,
            stringparam, dateparam, bigdecimalparam, volttableparam, bytearray, shortarray, intarray,
            doublearray, stringarray, datearray, bigdecimalarray, volttablearray);

    ByteBuffer buf = ByteBuffer.allocate(pset.getSerializedSize());
    pset.flattenToBuffer(buf);/* ww  w. ja  va2 s.co m*/
    buf.flip();
    ParameterSet pset2 = ParameterSet.fromByteBuffer(buf);

    Object[] pset1array = pset.toArray();
    Object[] pset2array = pset2.toArray();

    assertTrue(Arrays.deepEquals(pset1array, pset2array));
}

From source file:fr.in2p3.cc.storage.treqs.control.activator.Activator.java

/**
 * Get the allocation information from configuration database. Puts data
 * into Allocations list./*  w ww  .ja  va  2  s . c  om*/
 *
 * @throws TReqSException
 *             If there is a problem retrieving the allocations.
 */
void refreshAllocations() throws TReqSException {
    LOGGER.trace("> refreshAllocations");

    // Get the drives allocations from data source.
    this.allocations.clear();
    this.allocations.addAll(ResourcesController.getInstance().getMediaAllocations());

    // Now get the shares from the data source.
    final MultiMap shares = ResourcesController.getInstance().getResourceAllocation();

    // Browse the resources
    final Iterator<Resource> resources = this.allocations.iterator();
    while (resources.hasNext()) {
        final Resource resource = resources.next();
        // Find all shares for the current media type.
        final byte id = resource.getMediaType().getId();
        @SuppressWarnings("unchecked")
        final Collection<PersistenceHelperResourceAllocation> shareRange = (Collection<PersistenceHelperResourceAllocation>) shares
                .get(new Byte(id));
        if (shareRange != null) {
            // Browse the shares for this media type and set the resources
            final Iterator<PersistenceHelperResourceAllocation> iterShares = shareRange.iterator();
            while (iterShares.hasNext()) {
                final PersistenceHelperResourceAllocation resAlloc = iterShares.next();

                resource.setUserAllocation(UsersController.getInstance().add(resAlloc.getUsername()),
                        resAlloc.getAllocation());
                resource.setTimestamp(new GregorianCalendar());
                LOGGER.info("Setting share on media: {} ; user: {}; share: {}", new Object[] {
                        resource.getMediaType().getName(), resAlloc.getUsername(), resAlloc.getAllocation() });
            }
        } else {
            LOGGER.info("This media type has not defined users: id {}", id);
        }
    }

    LOGGER.trace("< refreshAllocations");
}

From source file:com.jaspersoft.jasperserver.api.engine.scheduling.domain.ReportJob.java

/**
 * Removes an output format from the job.
 * //from  w w  w .j a  va  2  s .c o m
 * @param outputFormat the key of the output format to remoce
 * @return <code>true</code> if the output format was present in the job
 */
public boolean removeOutputFormat(byte outputFormat) {
    return outputFormats.remove(new Byte(outputFormat));
}

From source file:org.xenei.jdbc4sparql.iface.TypeConverter.java

private static <T> T fromNumber(final Object columnObject, final Class<T> resultingClass) throws SQLException {
    final Number n = Number.class.cast(columnObject);
    if (resultingClass == BigDecimal.class) {
        return resultingClass.cast(new BigDecimal(n.toString()));
    }/*from  w w w.  j  a  v a  2s .c o m*/
    if (resultingClass == BigInteger.class) {
        return resultingClass.cast(new BigInteger(n.toString()));
    }
    if (resultingClass == Byte.class) {
        return resultingClass.cast(new Byte(n.byteValue()));
    }
    if (resultingClass == Double.class) {
        return resultingClass.cast(new Double(n.doubleValue()));
    }
    if (resultingClass == Float.class) {
        return resultingClass.cast(new Float(n.floatValue()));
    }
    if (resultingClass == Integer.class) {
        return resultingClass.cast(new Integer(n.intValue()));
    }
    if (resultingClass == Long.class) {
        return resultingClass.cast(new Long(n.longValue()));
    }
    if (resultingClass == Short.class) {
        return resultingClass.cast(new Short(n.shortValue()));
    }
    if (resultingClass == String.class) {
        return resultingClass.cast(n.toString());
    }
    if (resultingClass == Boolean.class) {
        if (n.byteValue() == 0) {
            return resultingClass.cast(Boolean.FALSE);
        }
        if (n.byteValue() == 1) {
            return resultingClass.cast(Boolean.TRUE);
        }
    }
    if (resultingClass == byte[].class) {
        return resultingClass.cast(n.toString().getBytes());
    }
    if (resultingClass == Blob.class) {
        return resultingClass.cast(new SerialBlob(n.toString().getBytes()));
    }
    if (resultingClass == Clob.class) {
        return resultingClass.cast(new SerialClob(n.toString().toCharArray()));
    }
    return null;
}

From source file:org.jasper.collectionspace.smk.datasource.JsonCSDataSource.java

protected Object convertNumber(Number number, Class<?> valueClass) throws JRException {
    Number value = null;//w w w  .java2s  . c  o  m
    if (valueClass.equals(Byte.class)) {
        value = new Byte(number.byteValue());
    } else if (valueClass.equals(Short.class)) {
        value = new Short(number.shortValue());
    } else if (valueClass.equals(Integer.class)) {
        value = Integer.valueOf(number.intValue());
    } else if (valueClass.equals(Long.class)) {
        value = new Long(number.longValue());
    } else if (valueClass.equals(Float.class)) {
        value = new Float(number.floatValue());
    } else if (valueClass.equals(Double.class)) {
        value = new Double(number.doubleValue());
    } else if (valueClass.equals(BigInteger.class)) {
        value = BigInteger.valueOf(number.longValue());
    } else if (valueClass.equals(BigDecimal.class)) {
        value = new BigDecimal(Double.toString(number.doubleValue()));
    } else {
        throw new JRException("Unknown number class " + valueClass.getName());
    }
    return value;
}

From source file:org.pentaho.di.trans.steps.accessoutput.AccessOutputMeta.java

public static Object[] createObjectsForRow(RowMetaInterface rowMeta, Object[] rowData)
        throws KettleValueException {
    Object[] values = new Object[rowMeta.size()];
    for (int i = 0; i < rowMeta.size(); i++) {
        ValueMetaInterface valueMeta = rowMeta.getValueMeta(i);
        Object valueData = rowData[i];

        // Prevent a NullPointerException below
        if (valueData == null || valueMeta == null) {
            values[i] = null;// w ww . j a va  2  s. c  om
            continue;
        }

        int length = valueMeta.getLength();

        switch (valueMeta.getType()) {
        case ValueMetaInterface.TYPE_INTEGER:
            if (length < 3) {
                values[i] = new Byte(valueMeta.getInteger(valueData).byteValue());
            } else {
                if (length < 5) {
                    values[i] = new Short(valueMeta.getInteger(valueData).shortValue());
                } else {
                    values[i] = valueMeta.getInteger(valueData);
                }
            }
            break;
        case ValueMetaInterface.TYPE_NUMBER:
            values[i] = valueMeta.getNumber(valueData);
            break;
        case ValueMetaInterface.TYPE_DATE:
            values[i] = valueMeta.getDate(valueData);
            break;
        case ValueMetaInterface.TYPE_STRING:
            values[i] = valueMeta.getString(valueData);
            break;
        case ValueMetaInterface.TYPE_BINARY:
            values[i] = valueMeta.getBinary(valueData);
            break;
        case ValueMetaInterface.TYPE_BOOLEAN:
            values[i] = valueMeta.getBoolean(valueData);
            break;
        case ValueMetaInterface.TYPE_BIGNUMBER:
            values[i] = valueMeta.getNumber(valueData);
            break;
        default:
            break;
        }
    }
    return values;
}

From source file:com.twinsoft.convertigo.engine.util.XMLUtils.java

public static Object readObjectFromXml(Element node) throws Exception {
    String nodeName = node.getNodeName();
    String nodeValue = ((Element) node).getAttribute("value");

    if (nodeName.equals("java.lang.Boolean")) {
        return new Boolean(nodeValue);
    } else if (nodeName.equals("java.lang.Byte")) {
        return new Byte(nodeValue);
    } else if (nodeName.equals("java.lang.Character")) {
        return new Character(nodeValue.charAt(0));
    } else if (nodeName.equals("java.lang.Integer")) {
        return new Integer(nodeValue);
    } else if (nodeName.equals("java.lang.Double")) {
        return new Double(nodeValue);
    } else if (nodeName.equals("java.lang.Float")) {
        return new Float(nodeValue);
    } else if (nodeName.equals("java.lang.Long")) {
        return new Long(nodeValue);
    } else if (nodeName.equals("java.lang.Short")) {
        return new Short(nodeValue);
    } else if (nodeName.equals("java.lang.String")) {
        return nodeValue;
    } else if (nodeName.equals("array")) {
        String className = node.getAttribute("classname");
        String length = node.getAttribute("length");
        int len = (new Integer(length)).intValue();

        Object array;/*from w w  w. j  a  v  a  2  s.c o  m*/
        if (className.equals("byte")) {
            array = new byte[len];
        } else if (className.equals("boolean")) {
            array = new boolean[len];
        } else if (className.equals("char")) {
            array = new char[len];
        } else if (className.equals("double")) {
            array = new double[len];
        } else if (className.equals("float")) {
            array = new float[len];
        } else if (className.equals("int")) {
            array = new int[len];
        } else if (className.equals("long")) {
            array = new long[len];
        } else if (className.equals("short")) {
            array = new short[len];
        } else {
            array = Array.newInstance(Class.forName(className), len);
        }

        Node xmlNode = null;
        NodeList nl = node.getChildNodes();
        int len_nl = nl.getLength();
        int i = 0;
        for (int j = 0; j < len_nl; j++) {
            xmlNode = nl.item(j);
            if (xmlNode.getNodeType() == Node.ELEMENT_NODE) {
                Object o = XMLUtils.readObjectFromXml((Element) xmlNode);
                Array.set(array, i, o);
                i++;
            }
        }

        return array;
    }
    // XMLization
    else if (nodeName.equals("xmlizable")) {
        String className = node.getAttribute("classname");

        Node xmlNode = findChildNode(node, Node.ELEMENT_NODE);
        Object xmlizable = Class.forName(className).newInstance();
        ((XMLizable) xmlizable).readXml(xmlNode);

        return xmlizable;
    }
    // Serialization
    else if (nodeName.equals("serializable")) {
        Node cdata = findChildNode(node, Node.CDATA_SECTION_NODE);
        String objectSerializationData = cdata.getNodeValue();
        Engine.logEngine.debug("Object serialization data:\n" + objectSerializationData);
        byte[] objectBytes = org.apache.commons.codec.binary.Base64.decodeBase64(objectSerializationData);

        // We read the object to a bytes array
        ByteArrayInputStream inputStream = new ByteArrayInputStream(objectBytes);
        ObjectInputStream objectInputStream = new ObjectInputStream(inputStream);
        Object object = objectInputStream.readObject();
        inputStream.close();

        return object;
    }

    return null;
}

From source file:wicket.util.lang.Objects.java

/**
 * Returns the value converted numerically to the given class type
 * //from w  ww. j  a  v  a2  s . c  o  m
 * This method also detects when arrays are being converted and converts the
 * components of one array to the type of the other.
 * 
 * @param value
 *            an object to be converted to the given type
 * @param toType
 *            class type to be converted to
 * @return converted value of the type given, or value if the value cannot
 *         be converted to the given type.
 */
public static Object convertValue(Object value, Class toType) {
    Object result = null;

    if (value != null) {
        /* If array -> array then convert components of array individually */
        if (value.getClass().isArray() && toType.isArray()) {
            Class componentType = toType.getComponentType();

            result = Array.newInstance(componentType, Array.getLength(value));
            for (int i = 0, icount = Array.getLength(value); i < icount; i++) {
                Array.set(result, i, convertValue(Array.get(value, i), componentType));
            }
        } else {
            if ((toType == Integer.class) || (toType == Integer.TYPE)) {
                result = new Integer((int) longValue(value));
            }
            if ((toType == Double.class) || (toType == Double.TYPE)) {
                result = new Double(doubleValue(value));
            }
            if ((toType == Boolean.class) || (toType == Boolean.TYPE)) {
                result = booleanValue(value) ? Boolean.TRUE : Boolean.FALSE;
            }
            if ((toType == Byte.class) || (toType == Byte.TYPE)) {
                result = new Byte((byte) longValue(value));
            }
            if ((toType == Character.class) || (toType == Character.TYPE)) {
                result = new Character((char) longValue(value));
            }
            if ((toType == Short.class) || (toType == Short.TYPE)) {
                result = new Short((short) longValue(value));
            }
            if ((toType == Long.class) || (toType == Long.TYPE)) {
                result = new Long(longValue(value));
            }
            if ((toType == Float.class) || (toType == Float.TYPE)) {
                result = new Float(doubleValue(value));
            }
            if (toType == BigInteger.class) {
                result = bigIntValue(value);
            }
            if (toType == BigDecimal.class) {
                result = bigDecValue(value);
            }
            if (toType == String.class) {
                result = stringValue(value);
            }
        }
    } else {
        if (toType.isPrimitive()) {
            result = primitiveDefaults.get(toType);
        }
    }
    return result;
}