Пример #1
0
  public static List readWatchableObjects(DataInputStream par0DataInputStream) throws IOException {
    ArrayList arraylist = null;

    for (byte byte0 = par0DataInputStream.readByte();
        byte0 != 127;
        byte0 = par0DataInputStream.readByte()) {
      if (arraylist == null) {
        arraylist = new ArrayList();
      }

      int i = (byte0 & 0xe0) >> 5;
      int j = byte0 & 0x1f;
      WatchableObject watchableobject = null;

      switch (i) {
        case 0:
          watchableobject = new WatchableObject(i, j, Byte.valueOf(par0DataInputStream.readByte()));
          break;

        case 1:
          watchableobject =
              new WatchableObject(i, j, Short.valueOf(par0DataInputStream.readShort()));
          break;

        case 2:
          watchableobject =
              new WatchableObject(i, j, Integer.valueOf(par0DataInputStream.readInt()));
          break;

        case 3:
          watchableobject =
              new WatchableObject(i, j, Float.valueOf(par0DataInputStream.readFloat()));
          break;

        case 4:
          watchableobject = new WatchableObject(i, j, Packet.readString(par0DataInputStream, 64));
          break;

        case 5:
          short word0 = par0DataInputStream.readShort();
          byte byte1 = par0DataInputStream.readByte();
          short word1 = par0DataInputStream.readShort();
          watchableobject = new WatchableObject(i, j, new ItemStack(word0, byte1, word1));
          break;

        case 6:
          int k = par0DataInputStream.readInt();
          int l = par0DataInputStream.readInt();
          int i1 = par0DataInputStream.readInt();
          watchableobject = new WatchableObject(i, j, new ChunkCoordinates(k, l, i1));
          break;
      }

      arraylist.add(watchableobject);
    }

    return arraylist;
  }
 /** {@inheritDoc} */
 @SuppressWarnings({"SuspiciousMethodCalls"})
 public boolean retainAll(Collection<?> collection) {
   boolean modified = false;
   TByteIterator iter = iterator();
   while (iter.hasNext()) {
     if (!collection.contains(Byte.valueOf(iter.next()))) {
       iter.remove();
       modified = true;
     }
   }
   return modified;
 }
Пример #3
0
 public boolean giveItemDrop(String name, int id, int quant, int data) throws Exception {
   try {
     Player p = getPlayerExact(name);
     ItemStack stack = new ItemStack(id, quant);
     stack.setData(new MaterialData(id, Byte.valueOf(String.valueOf(data)).byteValue()));
     p.getWorld().dropItem(p.getLocation(), stack);
     p.saveData();
     return true;
   } catch (NullPointerException e) {
     return false;
   }
 }
Пример #4
0
 public boolean giveItem(String name, int id, int quant, int data) throws Exception {
   try {
     byte realData = Byte.valueOf(String.valueOf(data));
     Player p = getPlayerExact(name);
     MaterialData materialData = new MaterialData(id, realData);
     p.getInventory().addItem(materialData.toItemStack(quant));
     p.saveData();
     return true;
   } catch (NullPointerException e) {
     return false;
   }
 }
  // [Issue#381]
  public void testSingleElementArray() throws Exception {
    final int intTest = 932832;
    final double doubleTest = 32.3234;
    final long longTest = 2374237428374293423L;
    final short shortTest = (short) intTest;
    final float floatTest = 84.3743f;
    final byte byteTest = (byte) 43;
    final char charTest = 'c';

    final ObjectMapper mapper = new ObjectMapper();
    mapper.enable(DeserializationFeature.UNWRAP_SINGLE_VALUE_ARRAYS);

    final int intValue = mapper.readValue(asArray(intTest), Integer.TYPE);
    assertEquals(intTest, intValue);
    final Integer integerWrapperValue =
        mapper.readValue(asArray(Integer.valueOf(intTest)), Integer.class);
    assertEquals(Integer.valueOf(intTest), integerWrapperValue);

    final double doubleValue = mapper.readValue(asArray(doubleTest), Double.class);
    assertEquals(doubleTest, doubleValue);
    final Double doubleWrapperValue =
        mapper.readValue(asArray(Double.valueOf(doubleTest)), Double.class);
    assertEquals(Double.valueOf(doubleTest), doubleWrapperValue);

    final long longValue = mapper.readValue(asArray(longTest), Long.TYPE);
    assertEquals(longTest, longValue);
    final Long longWrapperValue = mapper.readValue(asArray(Long.valueOf(longTest)), Long.class);
    assertEquals(Long.valueOf(longTest), longWrapperValue);

    final short shortValue = mapper.readValue(asArray(shortTest), Short.TYPE);
    assertEquals(shortTest, shortValue);
    final Short shortWrapperValue =
        mapper.readValue(asArray(Short.valueOf(shortTest)), Short.class);
    assertEquals(Short.valueOf(shortTest), shortWrapperValue);

    final float floatValue = mapper.readValue(asArray(floatTest), Float.TYPE);
    assertEquals(floatTest, floatValue);
    final Float floatWrapperValue =
        mapper.readValue(asArray(Float.valueOf(floatTest)), Float.class);
    assertEquals(Float.valueOf(floatTest), floatWrapperValue);

    final byte byteValue = mapper.readValue(asArray(byteTest), Byte.TYPE);
    assertEquals(byteTest, byteValue);
    final Byte byteWrapperValue = mapper.readValue(asArray(Byte.valueOf(byteTest)), Byte.class);
    assertEquals(Byte.valueOf(byteTest), byteWrapperValue);

    final char charValue =
        mapper.readValue(asArray(quote(String.valueOf(charTest))), Character.TYPE);
    assertEquals(charTest, charValue);
    final Character charWrapperValue =
        mapper.readValue(asArray(quote(String.valueOf(charTest))), Character.class);
    assertEquals(Character.valueOf(charTest), charWrapperValue);

    final boolean booleanTrueValue = mapper.readValue(asArray(true), Boolean.TYPE);
    assertTrue(booleanTrueValue);

    final boolean booleanFalseValue = mapper.readValue(asArray(false), Boolean.TYPE);
    assertFalse(booleanFalseValue);

    final Boolean booleanWrapperTrueValue =
        mapper.readValue(asArray(Boolean.valueOf(true)), Boolean.class);
    assertEquals(Boolean.TRUE, booleanWrapperTrueValue);
  }
Пример #6
0
 /**
  * Wraps a key
  *
  * @param k key in the underlying map
  * @return an Object representation of the key
  */
 protected Byte wrapKey(byte k) {
   return Byte.valueOf(k);
 }
Пример #7
0
  /** Read a {@link Writable}, {@link String}, primitive type, or an array of the preceding. */
  @SuppressWarnings("unchecked")
  public static Object readObject(DataInput in, ObjectWritable objectWritable, Configuration conf)
      throws IOException {
    String className = UTF8.readString(in);
    Class<?> declaredClass = PRIMITIVE_NAMES.get(className);
    if (declaredClass == null) {
      declaredClass = loadClass(conf, className);
    }

    Object instance;

    if (declaredClass.isPrimitive()) { // primitive types

      if (declaredClass == Boolean.TYPE) { // boolean
        instance = Boolean.valueOf(in.readBoolean());
      } else if (declaredClass == Character.TYPE) { // char
        instance = Character.valueOf(in.readChar());
      } else if (declaredClass == Byte.TYPE) { // byte
        instance = Byte.valueOf(in.readByte());
      } else if (declaredClass == Short.TYPE) { // short
        instance = Short.valueOf(in.readShort());
      } else if (declaredClass == Integer.TYPE) { // int
        instance = Integer.valueOf(in.readInt());
      } else if (declaredClass == Long.TYPE) { // long
        instance = Long.valueOf(in.readLong());
      } else if (declaredClass == Float.TYPE) { // float
        instance = Float.valueOf(in.readFloat());
      } else if (declaredClass == Double.TYPE) { // double
        instance = Double.valueOf(in.readDouble());
      } else if (declaredClass == Void.TYPE) { // void
        instance = null;
      } else {
        throw new IllegalArgumentException("Not a primitive: " + declaredClass);
      }

    } else if (declaredClass.isArray()) { // array
      int length = in.readInt();
      instance = Array.newInstance(declaredClass.getComponentType(), length);
      for (int i = 0; i < length; i++) {
        Array.set(instance, i, readObject(in, conf));
      }

    } else if (declaredClass == String.class) { // String
      instance = UTF8.readString(in);
    } else if (declaredClass.isEnum()) { // enum
      instance = Enum.valueOf((Class<? extends Enum>) declaredClass, UTF8.readString(in));
    } else { // Writable
      Class instanceClass = null;
      String str = UTF8.readString(in);
      instanceClass = loadClass(conf, str);

      Writable writable = WritableFactories.newInstance(instanceClass, conf);
      writable.readFields(in);
      instance = writable;

      if (instanceClass == NullInstance.class) { // null
        declaredClass = ((NullInstance) instance).declaredClass;
        instance = null;
      }
    }

    if (objectWritable != null) { // store values
      objectWritable.declaredClass = declaredClass;
      objectWritable.instance = instance;
    }

    return instance;
  }