Example usage for java.lang Byte MAX_VALUE

List of usage examples for java.lang Byte MAX_VALUE

Introduction

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

Prototype

byte MAX_VALUE

To view the source code for java.lang Byte MAX_VALUE.

Click Source Link

Document

A constant holding the maximum value a byte can have, 27-1.

Usage

From source file:libra.common.hadoop.io.datatypes.CompressedIntArrayWritable.java

private byte makeFlag(int count, int[] arr) throws IOException {
    byte flag = 0;
    // size/*from ww w  .j a  va2 s. com*/
    if (count <= Byte.MAX_VALUE) {
        flag = 0x00;
    } else if (count <= Short.MAX_VALUE) {
        flag = 0x01;
    } else if (count <= Integer.MAX_VALUE) {
        flag = 0x02;
    } else {
        throw new IOException("Array size overflow");
    }

    // datatype
    int max = 0;
    for (int i = 0; i < arr.length; i++) {
        max = Math.max(max, Math.abs(arr[i]));
    }

    if (max <= Byte.MAX_VALUE) {
        flag |= 0x00;
    } else if (max <= Short.MAX_VALUE) {
        flag |= 0x10;
    } else if (max <= Integer.MAX_VALUE) {
        flag |= 0x20;
    } else {
        throw new IOException("MaxValue overflow");
    }

    return flag;
}

From source file:pt.ist.vaadinframework.ui.DefaultFieldFactory.java

/**
 * @see pt.ist.vaadinframework.ui.AbstractFieldFactory#makeField(com.vaadin.data.Item, java.lang.Object,
 *      com.vaadin.ui.Component)// w  w  w . j a v  a 2 s  .c  o m
 */
@Override
protected Field makeField(Item item, Object propertyId, Component uiContext) {
    Class<?> type = item.getItemProperty(propertyId).getType();
    if (String.class.isAssignableFrom(type)) {
        TextField field = new TextField();
        field.setNullSettingAllowed(true);
        field.setNullRepresentation(StringUtils.EMPTY);
        return field;
    }
    if (Collection.class.isAssignableFrom(type)
            && item.getItemProperty(propertyId) instanceof AbstractBufferedContainer) {
        return new ContainerEditor<Object>(this, bundlename,
                ((AbstractBufferedContainer<?, ?, ?>) item.getItemProperty(propertyId)).getElementType());
    }
    if (AbstractDomainObject.class.isAssignableFrom(type)) {
        Select select = new Select();
        select.setWidth(100, Sizeable.UNITS_PERCENTAGE);
        select.setImmediate(true);
        return select;
    }
    if (Collection.class.isAssignableFrom(type)) {
        OptionGroup group = new OptionGroup();
        group.setMultiSelect(true);
        group.setWidth(100, Sizeable.UNITS_PERCENTAGE);
        group.setImmediate(true);
        return group;
    }
    if (Byte.class.isAssignableFrom(type)) {
        return new PrimitiveField(new ByteValidator(), Byte.toString(Byte.MAX_VALUE).length() + 1);
    }
    if (Short.class.isAssignableFrom(type)) {
        return new PrimitiveField(new ShortValidator(), Short.toString(Short.MAX_VALUE).length() + 1);
    }
    if (Integer.class.isAssignableFrom(type)) {
        return new PrimitiveField(new IntegerValidator(), Integer.toString(Integer.MAX_VALUE).length() + 1);
    }
    if (Long.class.isAssignableFrom(type)) {
        return new PrimitiveField(new LongValidator(), Long.toString(Long.MAX_VALUE).length() + 1);
    }
    if (Float.class.isAssignableFrom(type)) {
        return new PrimitiveField(new FloatValidator(), Float.toString(Float.MAX_VALUE).length() + 1);
    }
    if (Double.class.isAssignableFrom(type)) {
        return new PrimitiveField(new DoubleValidator(), Double.toString(Double.MAX_VALUE).length() + 1);
    }
    if (Boolean.class.isAssignableFrom(type)) {
        return new CheckBox();
    }
    if (Character.class.isAssignableFrom(type)) {
        return new PrimitiveField(new CharacterValidator(), 1);
    }
    if (BigDecimal.class.isAssignableFrom(type)) {
        return new PrimitiveField(new BigDecimalValidator(), -1);
    }
    if (Enum.class.isAssignableFrom(type)) {
        return new EnumField((Class<? extends Enum<?>>) item.getItemProperty(propertyId).getType());
    }
    if (Date.class.isAssignableFrom(type)) {
        DateField field = new DateField();
        field.setResolution(DateField.RESOLUTION_DAY);
        return field;
    }
    if (Item.class.isAssignableFrom(type)) {
        Form form = new Form() {
            @Override
            public void setPropertyDataSource(Property newDataSource) {
                setItemDataSource((Item) newDataSource);
            };
        };
        form.setImmediate(true);
        form.setFormFieldFactory(this);
        return form;
    }
    if (MultiLanguageString.class.isAssignableFrom(type)) {
        return new MultiLanguageStringField(bundlename, Language.pt, Language.en);
    }
    if (DateTime.class.isAssignableFrom(type)) {
        PopupDateTimeField field = new PopupDateTimeField();
        field.setResolution(DateField.RESOLUTION_SEC);
        return field;
    }
    if (LocalDate.class.isAssignableFrom(type)) {
        PopupLocalDateField field = new PopupLocalDateField();
        field.setResolution(DateField.RESOLUTION_DAY);
        return field;
    }
    if (URL.class.isAssignableFrom(type)) {
        TextField field = new TextField();
        field.setNullSettingAllowed(true);
        field.setNullRepresentation(StringUtils.EMPTY);
        field.addValidator(new URLValidator());
        return field;
    }
    Select select = new Select();
    select.setWidth(100, Sizeable.UNITS_PERCENTAGE);
    select.setImmediate(true);
    return select;
}

From source file:com.alvermont.terraj.fracplanet.colour.ByteRGBA.java

/**
 * Creates a new instance of ByteRGBA from byte colour values
 *
 * @param r The colour value for red/*from w  w w.j a v  a 2 s.com*/
 * @param g The colour value for green
 * @param b The colour value for blue
 */
public ByteRGBA(byte r, byte g, byte b) {
    this.r = r;
    this.g = g;
    this.b = b;
    this.a = Byte.MAX_VALUE;
}

From source file:com.alvermont.terraj.fracplanet.geom.TriangleMeshCloud.java

/**
 * Do the cloud alpha colouring based on a noise function
 *
 * @param parameters The cloud parameters
 *//* w ww . j  a v  a  2  s  . c o  m*/
protected void doCloud(final CloudParameters parameters) {
    computeVertexNormals();

    getProgress().progressStart(100, "Cloud colouring");

    final ByteRGBA c = new ByteRGBA(parameters.getColour());

    //! \todo Wire up terms, decay and base fequency and thresholds
    MultiscaleNoise noise = new MultiscaleNoise(new MathUtils(new Random(parameters.getSeed())), 6, 0.5f);

    for (int i = 0; i < getVertexCount(); ++i) {
        getProgress().progressStep((100 * i) / getVertexCount());

        final float v = 0.5f
                + 0.5f * noise.getNoise(XYZMath.opMultiply(4.0f, getVertices().get(i).getPosition()));
        final float v_min = 0.5f;
        final float v_max = 0.6f;
        final float v_k = 1.0f / (v_max - v_min);
        final float vs = Math.min(1.0f, Math.max(0.0f, (v - v_min) * v_k));

        ByteRGBA col = new ByteRGBA(c.getR(), c.getG(), c.getB(), (byte) (Byte.MAX_VALUE * vs));

        getVertices().get(i).setColour(0, col);

        // Set other colour (unused) to red for debug
        getVertices().get(i).setColour(1, new ByteRGBA(255, 0, 0, 255));
    }

    getProgress().progressComplete("Cloud colouring completed");

    // TODO: Eliminate all-transparent triangles & unused vertices.
    // Leave if nothing left

    // TODO: Bias weather into temperate bands (maybe not)
    getProgress().progressStart(100, "Weather systems");

    MathUtils utils = new MathUtils(new Random(parameters.getSeed()));

    final int steps = 100 * getVertexCount();
    int step = 0;

    // note following block was commented out in C++ and hasn't been
    // translated to Java yet.

    //        if (false) //for (uint i=0;i<0;i++) // Number of twisters parameter
    //        {
    //            final uint random_vertex=static_cast<uint>(r01()*vertices());
    //            final XYZ position(vertex(random_vertex).position());
    //            final XYZ axis(geometry().up(position));
    //            
    //            // Rotate opposite direction in other hemisphere
    //            final float strength=r01()*(position.z<0.0 ? -M_PI : M_PI);
    //            
    //            for (uint j=0;j<vertices();j++)
    //            {
    //                progress_step((100*step)/steps);
    //                step++;
    //                
    //                final XYZ p(vertex(j).position());
    //                final XYZ pn=geometry().up(p);
    //                final float pna=pn%axis;
    //                
    //                if (pna>0.0f)  // Don't create same feature on other side of planet (actually the distance would be big so could drop this)
    //                {
    //                    final float distance=(p-position).magnitude();
    //                    final float rotation_angle=strength*exp(-10.0*distance);
    //                    
    //                    // Now rotate p about axis through position by the rotation angle
    //                    // TODO: Optimise.  axis and position is the same for all points; we're constantly recomputing the basis change matrices.
    //                    // Create a stateful version of Matrix34RotateAboutAxisThrough.
    //                    vertex(j).position
    //                            (
    //                            Matrix34RotateAboutAxisThrough(axis,rotation_angle,position)*p
    //                            );
    //                }
    //            }
    //        }
    getProgress().progressComplete("Weather systems completed");

    setSwitchColour(getTriangleCount());
}

From source file:it.unipmn.di.dcs.common.conversion.Base64.java

/**
 * Checks input string for invalid Base64 characters
 *
 * @param data//from ww  w .  j a va2  s.c o m
 * @return true, if String contains only valid Base64 characters. false,
 * otherwise
 */
public static boolean IsValidBase64Encoding(String data) {
    for (int i = 0; i < data.length(); i++) {
        char ch = data.charAt(i);

        if (ch == S_BASE64PAD || ch < S_DECODETABLE.length && S_DECODETABLE[ch] != Byte.MAX_VALUE) {
            //valid character.Do nothing
        } else if (ch == '\r' || ch == '\n') {
            //do nothing
        } else {
            return false;
        }
    } //iterate over all characters in the string
    return true;
}

From source file:Base64.java

/**
 * Decode the base64 data./* w w w .ja va  2 s.  co  m*/
 * @param data The base64 encoded data to be decoded
 * @param off The offset within the encoded data at which to start decoding
 * @param len The length of data to decode
 * @param ostream The OutputStream to which the decoded data should be
 *                written
 */
public static void decode(char[] data, int off, int len, OutputStream ostream) throws IOException {
    char[] ibuf = new char[4];
    int ibufcount = 0;
    byte[] obuf = new byte[3];
    for (int i = off; i < off + len; i++) {
        char ch = data[i];
        if (ch == S_BASE64PAD || ch < S_DECODETABLE.length && S_DECODETABLE[ch] != Byte.MAX_VALUE) {
            ibuf[ibufcount++] = ch;
            if (ibufcount == ibuf.length) {
                ibufcount = 0;
                int obufcount = decode0(ibuf, obuf, 0);
                ostream.write(obuf, 0, obufcount);
            }
        }
    }
}

From source file:Base64Utils.java

public static void base64Decode(String data, OutputStream ostream) throws IOException {
    char[] ibuf = new char[4];
    int ibufcount = 0;
    byte[] obuf = new byte[3];
    for (int i = 0; i < data.length(); i++) {
        char ch = data.charAt(i);
        if (ch == S_BASE64PAD || ch < S_DECODETABLE.length && S_DECODETABLE[ch] != Byte.MAX_VALUE) {
            ibuf[ibufcount++] = ch;//from ww w  . j a va 2 s  .c  om
            if (ibufcount == ibuf.length) {
                ibufcount = 0;
                int obufcount = base64Decode0(ibuf, obuf, 0);
                ostream.write(obuf, 0, obufcount);
            }
        }
    }
}

From source file:org.echocat.marquardt.common.CertificateValidatorUnitTest.java

License:asdf

private void givenSignedCertificateWithDefectUserInfo() throws IOException {
    _signable = Certificate.create(_issuerKeys.getPublicKey(), _clientKeys.getPublicKey(), ROLES,
            new SignablePayload(SOME_PAYLOAD));
    whenSigningWithIssuerKey();/*from ww w.j a  va  2 s  . c  o  m*/
    _signedPayload[30] = Byte.MAX_VALUE;
}

From source file:gridool.dht.TcbLocalDirectory.java

private static final byte[] calculateRightEdgeValue(byte[] v) {
    final int vlen = v.length;
    final byte[] b = new byte[vlen + 1];
    System.arraycopy(v, 0, b, 0, vlen);
    b[vlen] = Byte.MAX_VALUE;
    return b;//  w  ww  . j a  v  a2 s .c o m
}

From source file:org.apache.hadoop.hive.hbase.HBaseTestSetup.java

private void createHBaseTable() throws IOException {
    final String HBASE_TABLE_NAME = "HiveExternalTable";
    HTableDescriptor htableDesc = new HTableDescriptor(HBASE_TABLE_NAME.getBytes());
    HColumnDescriptor hcolDesc = new HColumnDescriptor("cf".getBytes());
    htableDesc.addFamily(hcolDesc);// w  w  w  .j  a va2  s  .com

    boolean[] booleans = new boolean[] { true, false, true };
    byte[] bytes = new byte[] { Byte.MIN_VALUE, -1, Byte.MAX_VALUE };
    short[] shorts = new short[] { Short.MIN_VALUE, -1, Short.MAX_VALUE };
    int[] ints = new int[] { Integer.MIN_VALUE, -1, Integer.MAX_VALUE };
    long[] longs = new long[] { Long.MIN_VALUE, -1, Long.MAX_VALUE };
    String[] strings = new String[] { "Hadoop, HBase,", "Hive", "Test Strings" };
    float[] floats = new float[] { Float.MIN_VALUE, -1.0F, Float.MAX_VALUE };
    double[] doubles = new double[] { Double.MIN_VALUE, -1.0, Double.MAX_VALUE };

    HBaseAdmin hbaseAdmin = null;
    HTableInterface htable = null;
    try {
        hbaseAdmin = new HBaseAdmin(hbaseConn.getConfiguration());
        if (Arrays.asList(hbaseAdmin.listTables()).contains(htableDesc)) {
            // if table is already in there, don't recreate.
            return;
        }
        hbaseAdmin.createTable(htableDesc);
        htable = hbaseConn.getTable(HBASE_TABLE_NAME);

        // data
        Put[] puts = new Put[] { new Put("key-1".getBytes()), new Put("key-2".getBytes()),
                new Put("key-3".getBytes()) };

        // store data
        for (int i = 0; i < puts.length; i++) {
            puts[i].add("cf".getBytes(), "cq-boolean".getBytes(), Bytes.toBytes(booleans[i]));
            puts[i].add("cf".getBytes(), "cq-byte".getBytes(), new byte[] { bytes[i] });
            puts[i].add("cf".getBytes(), "cq-short".getBytes(), Bytes.toBytes(shorts[i]));
            puts[i].add("cf".getBytes(), "cq-int".getBytes(), Bytes.toBytes(ints[i]));
            puts[i].add("cf".getBytes(), "cq-long".getBytes(), Bytes.toBytes(longs[i]));
            puts[i].add("cf".getBytes(), "cq-string".getBytes(), Bytes.toBytes(strings[i]));
            puts[i].add("cf".getBytes(), "cq-float".getBytes(), Bytes.toBytes(floats[i]));
            puts[i].add("cf".getBytes(), "cq-double".getBytes(), Bytes.toBytes(doubles[i]));

            htable.put(puts[i]);
        }
    } finally {
        if (htable != null)
            htable.close();
        if (hbaseAdmin != null)
            hbaseAdmin.close();
    }
}