示例#1
0
 /**
  * Helper method used to get default value for wrappers used for primitive types (0 for Integer
  * etc)
  *
  * @since 1.6.1
  */
 public static Object defaultValue(Class<?> cls) {
   if (cls == Integer.TYPE) {
     return Integer.valueOf(0);
   }
   if (cls == Long.TYPE) {
     return Long.valueOf(0L);
   }
   if (cls == Boolean.TYPE) {
     return Boolean.FALSE;
   }
   if (cls == Double.TYPE) {
     return Double.valueOf(0.0);
   }
   if (cls == Float.TYPE) {
     return Float.valueOf(0.0f);
   }
   if (cls == Byte.TYPE) {
     return Byte.valueOf((byte) 0);
   }
   if (cls == Short.TYPE) {
     return Short.valueOf((short) 0);
   }
   if (cls == Character.TYPE) {
     return '\0';
   }
   throw new IllegalArgumentException("Class " + cls.getName() + " is not a primitive type");
 }
示例#2
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;
  }
示例#3
0
 public static Number toWrapper(int i) {
   if (i >= Byte.MIN_VALUE && i <= Byte.MAX_VALUE) {
     return Byte.valueOf((byte) i);
   } else if (i >= Short.MIN_VALUE && i <= Short.MAX_VALUE) {
     return Short.valueOf((short) i);
   } else {
     return Integer.valueOf(i);
   }
 }
 /** {@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;
 }
示例#5
0
  public Object getFieldValue(_Fields field) {
    switch (field) {
      case ID:
        return Long.valueOf(getId());

      case FLAGS:
        return Integer.valueOf(getFlags());

      case PARTITION:
        return Byte.valueOf(getPartition());
    }
    throw new IllegalStateException();
  }
示例#6
0
 @Override
 public Response getattr(String path, Map<Byte, Long> instanceMap) throws TException {
   // can be sent to ANY partition that replicates the path - we send it to the first returned by
   // the oracle
   path = makePathAbsolute(path);
   Set<Byte> parts = Sets.newHashSet(Byte.valueOf(partition));
   Command cmd = newCommand(CommandType.ATTR, parts, instanceMap);
   AttrCmd attr = new AttrCmd(path, parts);
   cmd.setAttr(attr);
   Attr result = (Attr) replica.submitCommand(cmd);
   Response r = new Response(replica.getInstanceMap());
   r.setGetattr(result);
   return r;
 }
示例#7
0
 @Override
 public Response readlink(String path, Map<Byte, Long> instanceMap) throws TException {
   path = makePathAbsolute(path);
   // can be sent to ANY partition that replicates the path - we send it to the first returned by
   // the oracle
   Set<Byte> parts = Sets.newHashSet(Byte.valueOf(partition));
   Command cmd = newCommand(CommandType.READLINK, parts, instanceMap);
   ReadlinkCmd readlink = new ReadlinkCmd(path, parts);
   cmd.setReadlink(readlink);
   String result = (String) replica.submitCommand(cmd);
   Response r = new Response(replica.getInstanceMap());
   r.setReadlink(result);
   return r;
 }
示例#8
0
 @Override
 public Response getdir(String path, Map<Byte, Long> instanceMap) throws TException {
   // can be sent to ANY partition that replicates the path - we send it to the first returned by
   // the oracle
   path = makePathAbsolute(path);
   Set<Byte> parts = Sets.newHashSet(Byte.valueOf(partition));
   Command cmd = newCommand(CommandType.GETDIR, parts, instanceMap);
   GetdirCmd getdir = new GetdirCmd(path, parts);
   cmd.setGetdir(getdir);
   @SuppressWarnings("unchecked")
   List<DirEntry> entries = (List<DirEntry>) replica.submitCommand(cmd);
   Response r = new Response(replica.getInstanceMap());
   r.setGetdir(entries);
   return r;
 }
示例#9
0
 @Override
 public Response readBlocks(
     String path, FileHandle fh, long offset, long bytes, Map<Byte, Long> instanceMap)
     throws TException {
   path = makePathAbsolute(path);
   // assuming this replica replicates the file, send to own partition
   Set<Byte> parts = Sets.newHashSet(Byte.valueOf(partition));
   Command cmd = newCommand(CommandType.READ_BLOCKS, parts, instanceMap);
   ReadBlocksCmd read = new ReadBlocksCmd(path, fh, offset, bytes, parts);
   cmd.setRead(read);
   ReadResult readResult = (ReadResult) replica.submitCommand(cmd);
   Response r = new Response(replica.getInstanceMap());
   r.setReadBlocks(readResult);
   return r;
 }
示例#10
0
  @Override
  public Response debug(Debug debug) throws TException {
    Set<Byte> partitions;
    if (debug.getType() == DebugCommands.POPULATE_FILE.getId()) {
      partitions = oracle.partitionsOf("/");
    } else {
      partitions = new HashSet<>();
      partitions.add(Byte.valueOf(Byte.parseByte(debug.getData().get("partition"))));
    }

    Command cmd = newCommand(CommandType.DEBUG, partitions, null);
    cmd.setDebug(debug);
    replica.submitCommand(cmd);
    Response r = new Response(replica.getInstanceMap());
    return r;
  }
 @Override
 public <T> T next(InstanceType<T> instanceType, FixtureContract fixture) {
   try {
     if (instanceType.isCompatibleWith(Integer.class)) {
       return (T) Integer.valueOf(this.getNextRandom().intValue());
     } else if (instanceType.isCompatibleWith(Short.class)) {
       return (T) Short.valueOf(getNextRandom().shortValue());
     } else if (instanceType.isCompatibleWith(Long.class)) {
       return (T) getNextRandom();
     } else if (instanceType.isCompatibleWith(Byte.class)) {
       return (T) Byte.valueOf(getNextRandom().byteValue());
     } else if (instanceType.isCompatibleWith(Character.class)) {
       return (T)
           Character.valueOf(new String(new byte[] {getNextRandom().byteValue()}).charAt(0));
     }
     return (T) this.getNextRandom();
   } catch (Exception e) {
     throw new ObjectCreationException(instanceType, e);
   }
 }
示例#12
0
 @SuppressWarnings("UnnecessaryBoxing")
 private static Object box(final Object value) {
   Object newBoxedValue;
   if (value instanceof Integer) {
     newBoxedValue = Integer.valueOf(((Integer) value).intValue());
   } else if (value instanceof Byte) {
     newBoxedValue = Byte.valueOf(((Byte) value).byteValue());
   } else if (value instanceof Short) {
     newBoxedValue = Short.valueOf(((Short) value).shortValue());
   } else if (value instanceof Long) {
     newBoxedValue = Long.valueOf(((Long) value).longValue());
   } else if (value instanceof Boolean) {
     newBoxedValue = Boolean.valueOf(((Boolean) value).booleanValue());
   } else if (value instanceof Character) {
     newBoxedValue = Character.valueOf(((Character) value).charValue());
   } else {
     return new Object();
   }
   return newBoxedValue;
 }
示例#13
0
  static {
    scancodeTable.put(Integer.valueOf(KeyEvent.VK_ESCAPE), Byte.valueOf((byte) 0x01));
    scancodeTable.put(Integer.valueOf(KeyEvent.VK_1), Byte.valueOf((byte) 0x02));
    scancodeTable.put(Integer.valueOf(KeyEvent.VK_2), Byte.valueOf((byte) 0x03));
    scancodeTable.put(Integer.valueOf(KeyEvent.VK_3), Byte.valueOf((byte) 0x04));
    scancodeTable.put(Integer.valueOf(KeyEvent.VK_4), Byte.valueOf((byte) 0x05));
    scancodeTable.put(Integer.valueOf(KeyEvent.VK_5), Byte.valueOf((byte) 0x06));
    scancodeTable.put(Integer.valueOf(KeyEvent.VK_6), Byte.valueOf((byte) 0x07));
    scancodeTable.put(Integer.valueOf(KeyEvent.VK_7), Byte.valueOf((byte) 0x08));
    scancodeTable.put(Integer.valueOf(KeyEvent.VK_8), Byte.valueOf((byte) 0x09));
    scancodeTable.put(Integer.valueOf(KeyEvent.VK_9), Byte.valueOf((byte) 0x0a));
    scancodeTable.put(Integer.valueOf(KeyEvent.VK_0), Byte.valueOf((byte) 0x0b));
    scancodeTable.put(Integer.valueOf(KeyEvent.VK_MINUS), Byte.valueOf((byte) 0x0c));
    scancodeTable.put(Integer.valueOf(KeyEvent.VK_EQUALS), Byte.valueOf((byte) 0x0d));
    scancodeTable.put(Integer.valueOf(KeyEvent.VK_BACK_SPACE), Byte.valueOf((byte) 0x0e));

    scancodeTable.put(Integer.valueOf(KeyEvent.VK_TAB), Byte.valueOf((byte) 0xf));
    scancodeTable.put(Integer.valueOf(KeyEvent.VK_Q), Byte.valueOf((byte) 0x10));
    scancodeTable.put(Integer.valueOf(KeyEvent.VK_W), Byte.valueOf((byte) 0x11));
    scancodeTable.put(Integer.valueOf(KeyEvent.VK_E), Byte.valueOf((byte) 0x12));
    scancodeTable.put(Integer.valueOf(KeyEvent.VK_R), Byte.valueOf((byte) 0x13));
    scancodeTable.put(Integer.valueOf(KeyEvent.VK_T), Byte.valueOf((byte) 0x14));
    scancodeTable.put(Integer.valueOf(KeyEvent.VK_Y), Byte.valueOf((byte) 0x15));
    scancodeTable.put(Integer.valueOf(KeyEvent.VK_U), Byte.valueOf((byte) 0x16));
    scancodeTable.put(Integer.valueOf(KeyEvent.VK_I), Byte.valueOf((byte) 0x17));
    scancodeTable.put(Integer.valueOf(KeyEvent.VK_O), Byte.valueOf((byte) 0x18));
    scancodeTable.put(Integer.valueOf(KeyEvent.VK_P), Byte.valueOf((byte) 0x19));
    scancodeTable.put(Integer.valueOf(KeyEvent.VK_OPEN_BRACKET), Byte.valueOf((byte) 0x1a));
    scancodeTable.put(Integer.valueOf(KeyEvent.VK_CLOSE_BRACKET), Byte.valueOf((byte) 0x1b));

    scancodeTable.put(Integer.valueOf(KeyEvent.VK_ENTER), Byte.valueOf((byte) 0x1c));

    scancodeTable.put(Integer.valueOf(KeyEvent.VK_CONTROL), Byte.valueOf((byte) 0x1d));

    scancodeTable.put(Integer.valueOf(KeyEvent.VK_A), Byte.valueOf((byte) 0x1e));
    scancodeTable.put(Integer.valueOf(KeyEvent.VK_S), Byte.valueOf((byte) 0x1f));
    scancodeTable.put(Integer.valueOf(KeyEvent.VK_D), Byte.valueOf((byte) 0x20));
    scancodeTable.put(Integer.valueOf(KeyEvent.VK_F), Byte.valueOf((byte) 0x21));
    scancodeTable.put(Integer.valueOf(KeyEvent.VK_G), Byte.valueOf((byte) 0x22));
    scancodeTable.put(Integer.valueOf(KeyEvent.VK_H), Byte.valueOf((byte) 0x23));
    scancodeTable.put(Integer.valueOf(KeyEvent.VK_J), Byte.valueOf((byte) 0x24));
    scancodeTable.put(Integer.valueOf(KeyEvent.VK_K), Byte.valueOf((byte) 0x25));
    scancodeTable.put(Integer.valueOf(KeyEvent.VK_L), Byte.valueOf((byte) 0x26));
    scancodeTable.put(Integer.valueOf(KeyEvent.VK_SEMICOLON), Byte.valueOf((byte) 0x27));
    scancodeTable.put(Integer.valueOf(KeyEvent.VK_QUOTE), Byte.valueOf((byte) 0x28));

    scancodeTable.put(Integer.valueOf(KeyEvent.VK_BACK_QUOTE), Byte.valueOf((byte) 0x29));

    scancodeTable.put(Integer.valueOf(KeyEvent.VK_SHIFT), Byte.valueOf((byte) 0x2a));

    scancodeTable.put(Integer.valueOf(KeyEvent.VK_BACK_SLASH), Byte.valueOf((byte) 0x2b));

    scancodeTable.put(Integer.valueOf(KeyEvent.VK_Z), Byte.valueOf((byte) 0x2c));
    scancodeTable.put(Integer.valueOf(KeyEvent.VK_X), Byte.valueOf((byte) 0x2d));
    scancodeTable.put(Integer.valueOf(KeyEvent.VK_C), Byte.valueOf((byte) 0x2e));
    scancodeTable.put(Integer.valueOf(KeyEvent.VK_V), Byte.valueOf((byte) 0x2f));
    scancodeTable.put(Integer.valueOf(KeyEvent.VK_B), Byte.valueOf((byte) 0x30));
    scancodeTable.put(Integer.valueOf(KeyEvent.VK_N), Byte.valueOf((byte) 0x31));
    scancodeTable.put(Integer.valueOf(KeyEvent.VK_M), Byte.valueOf((byte) 0x32));
    scancodeTable.put(Integer.valueOf(KeyEvent.VK_COMMA), Byte.valueOf((byte) 0x33));
    scancodeTable.put(Integer.valueOf(KeyEvent.VK_PERIOD), Byte.valueOf((byte) 0x34));
    scancodeTable.put(Integer.valueOf(KeyEvent.VK_SLASH), Byte.valueOf((byte) 0x35));
    scancodeTable.put(Integer.valueOf(KeyEvent.VK_SHIFT), Byte.valueOf((byte) 0x36));

    // 37 KPad *

    // 38 Missing L-Alt - Java does not pickup
    scancodeTable.put(Integer.valueOf(KeyEvent.VK_ALT), Byte.valueOf((byte) 0x38));
    scancodeTable.put(Integer.valueOf(KeyEvent.VK_SPACE), Byte.valueOf((byte) 0x39));

    scancodeTable.put(Integer.valueOf(KeyEvent.VK_CAPS_LOCK), Byte.valueOf((byte) 0x3a));

    scancodeTable.put(Integer.valueOf(KeyEvent.VK_F1), Byte.valueOf((byte) 0x3b));
    scancodeTable.put(Integer.valueOf(KeyEvent.VK_F2), Byte.valueOf((byte) 0x3c));
    scancodeTable.put(Integer.valueOf(KeyEvent.VK_F3), Byte.valueOf((byte) 0x3d));
    scancodeTable.put(Integer.valueOf(KeyEvent.VK_F4), Byte.valueOf((byte) 0x3e));
    scancodeTable.put(Integer.valueOf(KeyEvent.VK_F5), Byte.valueOf((byte) 0x3f));
    scancodeTable.put(Integer.valueOf(KeyEvent.VK_F6), Byte.valueOf((byte) 0x40));
    scancodeTable.put(Integer.valueOf(KeyEvent.VK_F7), Byte.valueOf((byte) 0x41));
    scancodeTable.put(Integer.valueOf(KeyEvent.VK_F8), Byte.valueOf((byte) 0x42));
    scancodeTable.put(Integer.valueOf(KeyEvent.VK_F9), Byte.valueOf((byte) 0x43));
    scancodeTable.put(Integer.valueOf(KeyEvent.VK_F10), Byte.valueOf((byte) 0x44));

    // 45 Missing Num-Lock - Java does not pickup

    scancodeTable.put(Integer.valueOf(KeyEvent.VK_SCROLL_LOCK), Byte.valueOf((byte) 0x46));

    // 47-53 are Numpad keys

    // 54-56 are not used

    scancodeTable.put(Integer.valueOf(122), Byte.valueOf((byte) 0x57)); // F11
    scancodeTable.put(Integer.valueOf(123), Byte.valueOf((byte) 0x58)); // F12

    // 59-ff are unused (for normal keys)

    // Extended Keys
    // e0,1c KPad Enter
    // e0,1d R-Ctrl
    // e0,2a fake L-Shift
    // e0,35 KPad /
    // e0,36 fake R-Shift
    // e0,37 Ctrl + Print Screen
    scancodeTable.put(Integer.valueOf(KeyEvent.VK_ALT_GRAPH), Byte.valueOf((byte) (0x38 | 0x80)));
    // e0,46 Ctrl + Break
    scancodeTable.put(Integer.valueOf(KeyEvent.VK_HOME), Byte.valueOf((byte) (0x47 | 0x80)));
    scancodeTable.put(Integer.valueOf(KeyEvent.VK_UP), Byte.valueOf((byte) (0x48 | 0x80)));
    scancodeTable.put(Integer.valueOf(KeyEvent.VK_PAGE_UP), Byte.valueOf((byte) (0x49 | 0x80)));
    scancodeTable.put(Integer.valueOf(KeyEvent.VK_LEFT), Byte.valueOf((byte) (0x4b | 0x80)));
    scancodeTable.put(Integer.valueOf(KeyEvent.VK_RIGHT), Byte.valueOf((byte) (0x4d | 0x80)));
    scancodeTable.put(Integer.valueOf(KeyEvent.VK_END), Byte.valueOf((byte) (0x4f | 0x80)));
    scancodeTable.put(Integer.valueOf(KeyEvent.VK_DOWN), Byte.valueOf((byte) (0x50 | 0x80)));
    scancodeTable.put(Integer.valueOf(KeyEvent.VK_PAGE_DOWN), Byte.valueOf((byte) (0x51 | 0x80)));
    scancodeTable.put(Integer.valueOf(KeyEvent.VK_INSERT), Byte.valueOf((byte) (0x52 | 0x80)));
    scancodeTable.put(Integer.valueOf(KeyEvent.VK_DELETE), Byte.valueOf((byte) (0x53 | 0x80)));
    // e0,5b L-Win
    // e0,5c R-Win
    // e0,5d Context-Menu

    scancodeTable.put(Integer.valueOf(19), Byte.valueOf((byte) 0xFF)); // Pause
  }
示例#14
0
 // ---- format -------------------------------------------------------
 public static String format(byte value, String format) {
   return NumberUtils.format(Byte.valueOf(value), format);
 }
示例#15
0
  public static Object element(Object arg, ExecutionContext context)
      throws FunctionDomainException, TypeMismatchException {
    if (arg == null || arg == QueryService.UNDEFINED) return QueryService.UNDEFINED;

    if (arg instanceof Collection) {
      Collection c = (Collection) arg;
      // for remote distinct queries, the result of sub query could contain a
      // mix of String and PdxString which could be duplicates, so convert all
      // PdxStrings to String
      if (context.isDistinct() && ((DefaultQuery) context.getQuery()).isRemoteQuery()) {
        Set tempResults = new HashSet();
        for (Object o : c) {
          if (o instanceof PdxString) {
            o = ((PdxString) o).toString();
          }
          tempResults.add(o);
        }
        c.clear();
        c.addAll(tempResults);
        tempResults = null;
      }
      checkSingleton(c.size());
      return c.iterator().next();
    }

    // not a Collection, must be an array
    Class clazz = arg.getClass();
    if (!clazz.isArray())
      throw new TypeMismatchException(
          LocalizedStrings.Functions_THE_ELEMENT_FUNCTION_CANNOT_BE_APPLIED_TO_AN_OBJECT_OF_TYPE_0
              .toLocalizedString(clazz.getName()));

    // handle arrays
    if (arg instanceof Object[]) {
      Object[] a = (Object[]) arg;
      if (((DefaultQuery) context.getQuery()).isRemoteQuery() && context.isDistinct()) {
        for (int i = 0; i < a.length; i++) {
          if (a[i] instanceof PdxString) {
            a[i] = ((PdxString) a[i]).toString();
          }
        }
      }
      checkSingleton(a.length);
      return a[0];
    }

    if (arg instanceof int[]) {
      int[] a = (int[]) arg;
      checkSingleton(a.length);
      return Integer.valueOf(a[0]);
    }

    if (arg instanceof long[]) {
      long[] a = (long[]) arg;
      checkSingleton(a.length);
      return Long.valueOf(a[0]);
    }

    if (arg instanceof boolean[]) {
      boolean[] a = (boolean[]) arg;
      checkSingleton(a.length);
      return Boolean.valueOf(a[0]);
    }

    if (arg instanceof byte[]) {
      byte[] a = (byte[]) arg;
      checkSingleton(a.length);
      return Byte.valueOf(a[0]);
    }

    if (arg instanceof char[]) {
      char[] a = (char[]) arg;
      checkSingleton(a.length);
      return new Character(a[0]);
    }

    if (arg instanceof double[]) {
      double[] a = (double[]) arg;
      checkSingleton(a.length);
      return Double.valueOf(a[0]);
    }

    if (arg instanceof float[]) {
      float[] a = (float[]) arg;
      checkSingleton(a.length);
      return new Float(a[0]);
    }

    if (arg instanceof short[]) {
      short[] a = (short[]) arg;
      checkSingleton(a.length);
      return new Short(a[0]);
    }

    // did I miss something?
    throw new TypeMismatchException(
        LocalizedStrings.Functions_THE_ELEMENT_FUNCTION_CANNOT_BE_APPLIED_TO_AN_OBJECT_OF_TYPE_0
            .toLocalizedString(clazz.getName()));
  }
示例#16
0
 private Object createObject(
     Node node, String name, String classPackage, String type, String value, boolean setProperty) {
   Bean parentBean = null;
   if (beansStack.size() > 0) parentBean = (Bean) beansStack.peek();
   Object object = null;
   // param is either an XSD type or a bean,
   // check if it can be converted to an XSD type
   XSDatatype dt = null;
   try {
     dt = DatatypeFactory.getTypeByName(type);
   } catch (DatatypeException dte) {
     // the type is not a valid XSD data type
   }
   // convert null value to default
   if ((dt != null) && (value == null)) {
     Class objType = dt.getJavaObjectType();
     if (objType == String.class) value = "";
     else if ((objType == java.math.BigInteger.class)
         || (objType == Long.class)
         || (objType == Integer.class)
         || (objType == Short.class)
         || (objType == Byte.class)) value = "0";
     else if ((objType == java.math.BigDecimal.class)
         || (objType == Double.class)
         || (objType == Float.class)) value = "0.0";
     else if (objType == Boolean.class) value = "false";
     else if (objType == java.util.Date.class) value = DateUtils.getCurrentDate();
     else if (objType == java.util.Calendar.class) value = DateUtils.getCurrentDateTime();
   }
   //  check whether the type was converted to an XSD datatype
   if ((dt != null) && dt.isValid(value, null)) {
     // create and return an XSD Java object (e.g. String, Integer, Boolean, etc)
     object = dt.createJavaObject(value, null);
     if (object instanceof java.util.Calendar) {
       // check that the object is truly a Calendar
       // because DatatypeFactory converts xsd:date
       // types to GregorianCalendar instead of Date.
       if (type.equals("date")) {
         java.text.DateFormat df = new java.text.SimpleDateFormat("yyyy-MM-dd");
         try {
           object = df.parse(value);
         } catch (java.text.ParseException pe) {
           object = new java.util.Date();
         }
       }
     }
   } else {
     // Create a bean object
     if (topLevelBean == null) topLevelBean = parentBean;
     object = pushBeanOnStack(classPackage, type);
     // Check fields to see if this property is the 'value' for the object
     Field[] fields = object.getClass().getDeclaredFields();
     for (int i = 0; i < fields.length; i++) {
       if (fields[i].isAnnotationPresent(ObjectXmlAsValue.class)) {
         try {
           StringBuffer fieldName = new StringBuffer(fields[i].getName());
           char c = fieldName.charAt(0);
           if (c >= 'a' && c <= 'z') {
             c += 'A' - 'a';
           }
           fieldName.setCharAt(0, c);
           fieldName.insert(0, "set");
           Method method =
               object
                   .getClass()
                   .getMethod(fieldName.toString(), new Class[] {fields[i].getType()});
           method.invoke(object, value);
           break;
         } catch (Exception e) {
           System.err.println(e.getMessage());
         }
       }
     }
     NamedNodeMap nodeAttrs = node.getAttributes();
     // iterate attributes and set field values for property attributes
     for (int i = 0; i < nodeAttrs.getLength(); i++) {
       String nodePrefix = nodeAttrs.item(i).getPrefix();
       if (nodePrefix.equals(nsPrefix)) {
         String nodeName = nodeAttrs.item(i).getLocalName();
         String nodeValue = nodeAttrs.item(i).getNodeValue();
         try {
           Field field = object.getClass().getDeclaredField(nodeName);
           if (field.isAnnotationPresent(ObjectXmlAsAttribute.class)) {
             StringBuffer fieldName = new StringBuffer(field.getName());
             char c = fieldName.charAt(0);
             if (c >= 'a' && c <= 'z') {
               c += 'A' - 'a';
             }
             fieldName.setCharAt(0, c);
             fieldName.insert(0, "set");
             Method method =
                 object.getClass().getMethod(fieldName.toString(), new Class[] {field.getType()});
             if (field.getType() == String.class) method.invoke(object, nodeValue);
             else if (field.getType() == Boolean.TYPE)
               method.invoke(object, StringUtils.strToBool(nodeValue, "true"));
             else if (field.getType() == Byte.TYPE)
               method.invoke(object, Byte.valueOf(nodeValue).byteValue());
             else if (field.getType() == Character.TYPE)
               method.invoke(object, Character.valueOf(nodeValue.charAt(0)));
             else if (field.getType() == Double.TYPE)
               method.invoke(object, Double.valueOf(nodeValue).doubleValue());
             else if (field.getType() == Float.TYPE)
               method.invoke(object, Float.valueOf(nodeValue).floatValue());
             else if (field.getType() == Integer.TYPE)
               method.invoke(object, Integer.valueOf(nodeValue).intValue());
             else if (field.getType() == Long.TYPE)
               method.invoke(object, Long.valueOf(nodeValue).longValue());
             else if (field.getType() == Short.TYPE)
               method.invoke(object, Short.valueOf(nodeValue).shortValue());
           }
         } catch (Exception e) {
           System.err.println(e.getMessage());
         }
       }
     }
   }
   if ((parentBean != null) && (setProperty)) {
     parentBean.setProperty(name, object);
   }
   return object;
 }
示例#17
0
 public static Object wrapAsObject(byte i) {
   return Byte.valueOf(i);
 }
示例#18
0
 public static Byte asByte(Object value) {
   if (value == null) return null;
   if (value instanceof Number) return ((Number) value).byteValue();
   return Byte.valueOf(value.toString());
 }
示例#19
0
 protected void entityInit() {
   super.entityInit();
   dataWatcher.addObject(16, Byte.valueOf((byte) 0));
   dataWatcher.addObject(17, Byte.valueOf((byte) 0));
 }
示例#20
0
  /**
   * Primary Constructor
   *
   * @param parmObjTypes The object instances of the classes containing command line parsing
   *     annotations. Non-null. Non-empty.
   * @param args
   * @param prefix
   */
  public JCommanderModule(Collection<Class<?>> parmObjTypes, String[] args, String prefix) {
    checkNotNull(parmObjTypes);
    checkNotNull(args);
    checkNotNull(prefix);
    checkArgument(!parmObjTypes.isEmpty());
    checkArgument(args.length != 0);

    this.parmObjTypes.addAll(parmObjTypes);
    this.args = args;
    this.prefix = prefix;

    /*
     * Populate the binding functions
     */

    bindingFxns.put(
        int.class,
        (name, val) ->
            bindConstant().annotatedWith(named((String) name)).to(Integer.valueOf((int) val)));
    bindingFxns.put(
        byte.class,
        (name, val) ->
            bindConstant().annotatedWith(named((String) name)).to(Byte.valueOf((byte) val)));
    bindingFxns.put(
        long.class,
        (name, val) ->
            bindConstant().annotatedWith(named((String) name)).to(Long.valueOf((long) val)));
    bindingFxns.put(
        short.class,
        (name, val) ->
            bindConstant().annotatedWith(named((String) name)).to(Short.valueOf((short) val)));
    bindingFxns.put(
        float.class,
        (name, val) ->
            bindConstant().annotatedWith(named((String) name)).to(Float.valueOf((float) val)));
    bindingFxns.put(
        double.class,
        (name, val) ->
            bindConstant().annotatedWith(named((String) name)).to(Double.valueOf((double) val)));
    bindingFxns.put(
        char.class,
        (name, val) ->
            bindConstant().annotatedWith(named((String) name)).to(Character.valueOf((char) val)));
    bindingFxns.put(
        boolean.class,
        (name, val) ->
            bindConstant().annotatedWith(named((String) name)).to(Boolean.valueOf((boolean) val)));

    bindingFxns.put(
        Integer.class,
        (name, val) -> bindConstant().annotatedWith(named((String) name)).to((Integer) val));
    bindingFxns.put(
        Byte.class,
        (name, val) -> bindConstant().annotatedWith(named((String) name)).to((Byte) val));
    bindingFxns.put(
        Long.class,
        (name, val) -> bindConstant().annotatedWith(named((String) name)).to((Long) val));
    bindingFxns.put(
        Short.class,
        (name, val) -> bindConstant().annotatedWith(named((String) name)).to((Short) val));
    bindingFxns.put(
        Float.class,
        (name, val) -> bindConstant().annotatedWith(named((String) name)).to((Float) val));
    bindingFxns.put(
        Double.class,
        (name, val) -> bindConstant().annotatedWith(named((String) name)).to((Double) val));
    bindingFxns.put(
        Character.class,
        (name, val) -> bindConstant().annotatedWith(named((String) name)).to((Character) val));
    bindingFxns.put(
        Boolean.class,
        (name, val) -> bindConstant().annotatedWith(named((String) name)).to((Boolean) val));
    bindingFxns.put(
        String.class,
        (name, val) -> bindConstant().annotatedWith(named((String) name)).to((String) val));

    bindingFxns.put(
        File.class,
        (name, val) ->
            bindConstant().annotatedWith(named((String) name)).to(((File) val).getAbsolutePath()));
    bindingFxns.put(
        Path.class,
        (name, val) ->
            bindConstant().annotatedWith(named((String) name)).to(((Path) val).toString()));
    bindingFxns.put(
        URL.class,
        (name, val) ->
            bindConstant().annotatedWith(named((String) name)).to(((URL) val).getFile()));

    bindingFxns.put(
        LocalDate.class,
        (name, val) ->
            bindConstant().annotatedWith(named((String) name)).to(((LocalDate) val).toString()));
    bindingFxns.put(
        LocalDateTime.class,
        (name, val) ->
            bindConstant()
                .annotatedWith(named((String) name))
                .to(((LocalDateTime) val).toString()));
    bindingFxns.put(
        LocalTime.class,
        (name, val) ->
            bindConstant().annotatedWith(named((String) name)).to(((LocalTime) val).toString()));

    bindingFxnsForGenerics.put(
        new TypeLiteral<List<String>>() {},
        (name, val) ->
            bind(new TypeLiteral<List<String>>() {})
                .annotatedWith(named((String) name))
                .toInstance((List<String>) val));
    bindingFxnsForGenerics.put(
        new TypeLiteral<Set<String>>() {},
        (name, val) ->
            bind(new TypeLiteral<Set<String>>() {})
                .annotatedWith(named((String) name))
                .toInstance((Set<String>) val));
  }
 /**
  * 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);
 }
示例#22
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;
  }