List of usage examples for java.lang Boolean TYPE
Class TYPE
To view the source code for java.lang Boolean TYPE.
Click Source Link
From source file:org.apache.syncope.core.provisioning.java.MappingManagerImpl.java
@Transactional(readOnly = true) @Override/*from ww w. ja va 2 s . com*/ public List<PlainAttrValue> getIntValues(final Provision provision, final Item mapItem, final IntAttrName intAttrName, final Any<?> any) { LOG.debug("Get internal values for {} as '{}' on {}", any, mapItem.getIntAttrName(), provision.getResource()); Any<?> reference = null; Membership<?> membership = null; if (intAttrName.getEnclosingGroup() == null && intAttrName.getRelatedAnyObject() == null) { reference = any; } if (any instanceof GroupableRelatable) { GroupableRelatable<?, ?, ?, ?, ?> groupableRelatable = (GroupableRelatable<?, ?, ?, ?, ?>) any; if (intAttrName.getEnclosingGroup() != null) { Group group = groupDAO.findByName(intAttrName.getEnclosingGroup()); if (group == null || !groupableRelatable.getMembership(group.getKey()).isPresent()) { LOG.warn("No membership for {} in {}, ignoring", intAttrName.getEnclosingGroup(), groupableRelatable); } else { reference = group; } } else if (intAttrName.getRelatedAnyObject() != null) { AnyObject anyObject = anyObjectDAO.findByName(intAttrName.getRelatedAnyObject()); if (anyObject == null || groupableRelatable.getRelationships(anyObject.getKey()).isEmpty()) { LOG.warn("No relationship for {} in {}, ignoring", intAttrName.getRelatedAnyObject(), groupableRelatable); } else { reference = anyObject; } } else if (intAttrName.getMembershipOfGroup() != null) { Group group = groupDAO.findByName(intAttrName.getMembershipOfGroup()); membership = groupableRelatable.getMembership(group.getKey()).orElse(null); } } if (reference == null) { LOG.warn("Could not determine the reference instance for {}", mapItem.getIntAttrName()); return Collections.emptyList(); } List<PlainAttrValue> values = new ArrayList<>(); boolean transform = true; AnyUtils anyUtils = anyUtilsFactory.getInstance(reference); if (intAttrName.getField() != null) { PlainAttrValue attrValue = anyUtils.newPlainAttrValue(); switch (intAttrName.getField()) { case "key": attrValue.setStringValue(reference.getKey()); values.add(attrValue); break; case "realm": attrValue.setStringValue(reference.getRealm().getFullPath()); values.add(attrValue); break; case "password": // ignore break; case "userOwner": case "groupOwner": Mapping uMapping = provision.getAnyType().equals(anyTypeDAO.findUser()) ? provision.getMapping() : null; Mapping gMapping = provision.getAnyType().equals(anyTypeDAO.findGroup()) ? provision.getMapping() : null; if (reference instanceof Group) { Group group = (Group) reference; String groupOwnerValue = null; if (group.getUserOwner() != null && uMapping != null) { groupOwnerValue = getGroupOwnerValue(provision, group.getUserOwner()); } if (group.getGroupOwner() != null && gMapping != null) { groupOwnerValue = getGroupOwnerValue(provision, group.getGroupOwner()); } if (StringUtils.isNotBlank(groupOwnerValue)) { attrValue.setStringValue(groupOwnerValue); values.add(attrValue); } } break; case "suspended": if (reference instanceof User) { attrValue.setBooleanValue(((User) reference).isSuspended()); values.add(attrValue); } break; case "mustChangePassword": if (reference instanceof User) { attrValue.setBooleanValue(((User) reference).isMustChangePassword()); values.add(attrValue); } break; default: try { Object fieldValue = FieldUtils.readField(reference, intAttrName.getField(), true); if (fieldValue instanceof Date) { // needed because ConnId does not natively supports the Date type attrValue.setStringValue(DateFormatUtils.ISO_8601_EXTENDED_DATETIME_TIME_ZONE_FORMAT .format((Date) fieldValue)); } else if (Boolean.TYPE.isInstance(fieldValue)) { attrValue.setBooleanValue((Boolean) fieldValue); } else if (Double.TYPE.isInstance(fieldValue) || Float.TYPE.isInstance(fieldValue)) { attrValue.setDoubleValue((Double) fieldValue); } else if (Long.TYPE.isInstance(fieldValue) || Integer.TYPE.isInstance(fieldValue)) { attrValue.setLongValue((Long) fieldValue); } else { attrValue.setStringValue(fieldValue.toString()); } values.add(attrValue); } catch (Exception e) { LOG.error("Could not read value of '{}' from {}", intAttrName.getField(), reference, e); } } } else if (intAttrName.getSchemaType() != null) { switch (intAttrName.getSchemaType()) { case PLAIN: PlainAttr<?> attr; if (membership == null) { attr = reference.getPlainAttr(intAttrName.getSchemaName()).orElse(null); } else { attr = ((GroupableRelatable<?, ?, ?, ?, ?>) reference) .getPlainAttr(intAttrName.getSchemaName(), membership).orElse(null); } if (attr != null) { if (attr.getUniqueValue() != null) { values.add(anyUtils.clonePlainAttrValue(attr.getUniqueValue())); } else if (attr.getValues() != null) { attr.getValues().forEach(value -> values.add(anyUtils.clonePlainAttrValue(value))); } } break; case DERIVED: DerSchema derSchema = derSchemaDAO.find(intAttrName.getSchemaName()); if (derSchema != null) { String value = membership == null ? derAttrHandler.getValue(reference, derSchema) : derAttrHandler.getValue(reference, membership, derSchema); if (value != null) { PlainAttrValue attrValue = anyUtils.newPlainAttrValue(); attrValue.setStringValue(value); values.add(attrValue); } } break; case VIRTUAL: // virtual attributes don't get transformed transform = false; VirSchema virSchema = virSchemaDAO.find(intAttrName.getSchemaName()); if (virSchema != null) { LOG.debug("Expire entry cache {}-{}", reference, intAttrName.getSchemaName()); virAttrCache.expire(reference.getType().getKey(), reference.getKey(), intAttrName.getSchemaName()); List<String> virValues = membership == null ? virAttrHandler.getValues(reference, virSchema) : virAttrHandler.getValues(reference, membership, virSchema); virValues.stream().map(value -> { PlainAttrValue attrValue = anyUtils.newPlainAttrValue(); attrValue.setStringValue(value); return attrValue; }).forEachOrdered(attrValue -> values.add(attrValue)); } break; default: } } LOG.debug("Internal values: {}", values); List<PlainAttrValue> transformed = values; if (transform) { for (ItemTransformer transformer : MappingUtils.getItemTransformers(mapItem)) { transformed = transformer.beforePropagation(mapItem, any, transformed); } LOG.debug("Transformed values: {}", values); } else { LOG.debug("No transformation occurred"); } return transformed; }
From source file:net.sourceforge.pmd.typeresolution.ClassTypeResolverTest.java
@Test public void testUnaryLogicalOperators() throws JaxenException { ASTCompilationUnit acu = parseAndTypeResolveForClass15(Operators.class); List<ASTExpression> expressions = convertList(acu.findChildNodesWithXPath( "//Block[preceding-sibling::MethodDeclarator[@Image = 'unaryLogicalOperators']]//Expression"), ASTExpression.class); int index = 0; assertEquals(Boolean.TYPE, expressions.get(index++).getType()); assertEquals(Boolean.TYPE, expressions.get(index++).getType()); // Make sure we got them all. assertEquals("All expressions not tested", index, expressions.size()); }
From source file:org.apache.syncope.core.provisioning.java.ConnectorFacadeProxy.java
private Object getPropertyValue(final String propType, final List<?> values) { Object value = null;//from w w w.j a v a 2 s. c o m try { Class<?> propertySchemaClass = ClassUtils.forName(propType, ClassUtils.getDefaultClassLoader()); if (GuardedString.class.equals(propertySchemaClass)) { value = new GuardedString(values.get(0).toString().toCharArray()); } else if (GuardedByteArray.class.equals(propertySchemaClass)) { value = new GuardedByteArray((byte[]) values.get(0)); } else if (Character.class.equals(propertySchemaClass) || Character.TYPE.equals(propertySchemaClass)) { value = values.get(0) == null || values.get(0).toString().isEmpty() ? null : values.get(0).toString().charAt(0); } else if (Integer.class.equals(propertySchemaClass) || Integer.TYPE.equals(propertySchemaClass)) { value = Integer.parseInt(values.get(0).toString()); } else if (Long.class.equals(propertySchemaClass) || Long.TYPE.equals(propertySchemaClass)) { value = Long.parseLong(values.get(0).toString()); } else if (Float.class.equals(propertySchemaClass) || Float.TYPE.equals(propertySchemaClass)) { value = Float.parseFloat(values.get(0).toString()); } else if (Double.class.equals(propertySchemaClass) || Double.TYPE.equals(propertySchemaClass)) { value = Double.parseDouble(values.get(0).toString()); } else if (Boolean.class.equals(propertySchemaClass) || Boolean.TYPE.equals(propertySchemaClass)) { value = Boolean.parseBoolean(values.get(0).toString()); } else if (URI.class.equals(propertySchemaClass)) { value = URI.create(values.get(0).toString()); } else if (File.class.equals(propertySchemaClass)) { value = new File(values.get(0).toString()); } else if (String[].class.equals(propertySchemaClass)) { value = values.toArray(new String[] {}); } else { value = values.get(0) == null ? null : values.get(0).toString(); } } catch (Exception e) { LOG.error("Invalid ConnConfProperty specified: {} {}", propType, values, e); } return value; }
From source file:bammerbom.ultimatecore.bukkit.resources.utils.BossbarUtil.java
public Object getMetaPacket(Object watcher) { Class<?> DataWatcher = Util.getCraftClass("DataWatcher"); Class<?> PacketPlayOutEntityMetadata = Util.getCraftClass("PacketPlayOutEntityMetadata"); Object packet = null;//from w w w . ja va2 s.c om try { packet = PacketPlayOutEntityMetadata .getConstructor(new Class[] { Integer.TYPE, DataWatcher, Boolean.TYPE }) .newInstance(new Object[] { Integer.valueOf(this.id), watcher, Boolean.valueOf(true) }); } catch (IllegalArgumentException e) { e.printStackTrace(); } catch (SecurityException e) { e.printStackTrace(); } catch (InstantiationException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } catch (InvocationTargetException e) { e.printStackTrace(); } catch (NoSuchMethodException e) { e.printStackTrace(); } return packet; }
From source file:acmi.l2.clientmod.xdat.Controller.java
private static List<PropertySheetItem> loadProperties(Object obj) { Class<?> objClass = obj.getClass(); List<PropertySheetItem> list = new ArrayList<>(); while (objClass != Object.class) { try {//from w w w . j a va 2 s.c o m List<String> names = Arrays.stream(objClass.getDeclaredFields()) .map(field -> field.getName().replace("Prop", "")).collect(Collectors.toList()); BeanInfo beanInfo = Introspector.getBeanInfo(objClass, objClass.getSuperclass()); PropertyDescriptor[] propertyDescriptors = beanInfo.getPropertyDescriptors(); Arrays.sort(propertyDescriptors, (pd1, pd2) -> Integer.compare(names.indexOf(pd1.getName()), names.indexOf(pd2.getName()))); for (PropertyDescriptor descriptor : propertyDescriptors) { if ("metaClass".equals(descriptor.getName())) continue; if (Collection.class.isAssignableFrom(descriptor.getPropertyType())) continue; AnnotatedElement getter = descriptor.getReadMethod(); if (getter.isAnnotationPresent(Deprecated.class) || getter.isAnnotationPresent(Hide.class)) continue; String description = ""; if (getter.isAnnotationPresent(Description.class)) description = getter.getAnnotation(Description.class).value(); Class<? extends PropertyEditor<?>> propertyEditorClass = null; if (descriptor.getPropertyType() == Boolean.class || descriptor.getPropertyType() == Boolean.TYPE) { propertyEditorClass = BooleanPropertyEditor.class; } else if (getter.isAnnotationPresent(Tex.class)) { propertyEditorClass = TexturePropertyEditor.class; } else if (getter.isAnnotationPresent(Sysstr.class)) { propertyEditorClass = SysstringPropertyEditor.class; } BeanProperty property = new BeanProperty(descriptor, objClass.getSimpleName(), description, propertyEditorClass); list.add(property); } } catch (IntrospectionException e) { e.printStackTrace(); } objClass = objClass.getSuperclass(); } return list; }
From source file:net.sourceforge.pmd.typeresolution.ClassTypeResolverTest.java
@Test public void testBinaryLogicalOperators() throws JaxenException { ASTCompilationUnit acu = parseAndTypeResolveForClass15(Operators.class); List<ASTExpression> expressions = convertList(acu.findChildNodesWithXPath( "//Block[preceding-sibling::MethodDeclarator[@Image = 'binaryLogicalOperators']]//Expression"), ASTExpression.class); int index = 0; assertEquals(Boolean.TYPE, expressions.get(index++).getType()); assertEquals(Boolean.TYPE, expressions.get(index++).getType()); assertEquals(Boolean.TYPE, expressions.get(index++).getType()); assertEquals(Boolean.TYPE, expressions.get(index++).getType()); assertEquals(Boolean.TYPE, expressions.get(index++).getType()); assertEquals(Boolean.TYPE, expressions.get(index++).getType()); assertEquals(Boolean.TYPE, expressions.get(index++).getType()); assertEquals(Boolean.TYPE, expressions.get(index++).getType()); assertEquals(Boolean.TYPE, expressions.get(index++).getType()); assertEquals(Boolean.TYPE, expressions.get(index++).getType()); assertEquals(Boolean.TYPE, expressions.get(index++).getType()); assertEquals(Boolean.TYPE, expressions.get(index++).getType()); assertEquals(Boolean.TYPE, expressions.get(index++).getType()); // Make sure we got them all. assertEquals("All expressions not tested", index, expressions.size()); }
From source file:org.apache.hadoop.hbase.io.HbaseObjectWritable.java
/** * Read a {@link Writable}, {@link String}, primitive type, or an array of * the preceding.//from w w w .ja va 2 s .c om * @param in * @param objectWritable * @param conf * @return the object * @throws IOException */ @SuppressWarnings("unchecked") public static Object readObject(DataInput in, HbaseObjectWritable objectWritable, Configuration conf) throws IOException { Class<?> declaredClass = CODE_TO_CLASS.get(WritableUtils.readVInt(in)); 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 if (declaredClass.equals(byte[].class)) { instance = Bytes.readByteArray(in); } else if (declaredClass.equals(Result[].class)) { instance = Result.readArray(in); } else { 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.equals(Array.class)) { //an array not declared in CLASS_TO_CODE Class<?> componentType = readClass(conf, in); int length = in.readInt(); instance = Array.newInstance(componentType, length); for (int i = 0; i < length; i++) { Array.set(instance, i, readObject(in, conf)); } } else if (List.class.isAssignableFrom(declaredClass)) { // List int length = in.readInt(); instance = new ArrayList(length); for (int i = 0; i < length; i++) { ((ArrayList) instance).add(readObject(in, conf)); } } else if (declaredClass == String.class) { // String instance = Text.readString(in); } else if (declaredClass.isEnum()) { // enum instance = Enum.valueOf((Class<? extends Enum>) declaredClass, Text.readString(in)); } else if (declaredClass == Message.class) { String className = Text.readString(in); try { declaredClass = getClassByName(conf, className); instance = tryInstantiateProtobuf(declaredClass, in); } catch (ClassNotFoundException e) { LOG.error("Can't find class " + className, e); throw new IOException("Can't find class " + className, e); } } else { // Writable or Serializable Class instanceClass = null; int b = (byte) WritableUtils.readVInt(in); if (b == NOT_ENCODED) { String className = Text.readString(in); try { instanceClass = getClassByName(conf, className); } catch (ClassNotFoundException e) { LOG.error("Can't find class " + className, e); throw new IOException("Can't find class " + className, e); } } else { instanceClass = CODE_TO_CLASS.get(b); } if (Writable.class.isAssignableFrom(instanceClass)) { Writable writable = WritableFactories.newInstance(instanceClass, conf); try { writable.readFields(in); } catch (Exception e) { LOG.error("Error in readFields", e); throw new IOException("Error in readFields", e); } instance = writable; if (instanceClass == NullInstance.class) { // null declaredClass = ((NullInstance) instance).declaredClass; instance = null; } } else { int length = in.readInt(); byte[] objectBytes = new byte[length]; in.readFully(objectBytes); ByteArrayInputStream bis = null; ObjectInputStream ois = null; try { bis = new ByteArrayInputStream(objectBytes); ois = new ObjectInputStream(bis); instance = ois.readObject(); } catch (ClassNotFoundException e) { LOG.error("Class not found when attempting to deserialize object", e); throw new IOException("Class not found when attempting to " + "deserialize object", e); } finally { if (bis != null) bis.close(); if (ois != null) ois.close(); } } } if (objectWritable != null) { // store values objectWritable.declaredClass = declaredClass; objectWritable.instance = instance; } return instance; }
From source file:bammerbom.ultimatecore.bukkit.resources.utils.BossbarUtil.java
public Object getTeleportPacket(Location loc) { Class<?> PacketPlayOutEntityTeleport = Util.getCraftClass("PacketPlayOutEntityTeleport"); Object packet = null;// w ww . j a va2 s.c o m try { packet = PacketPlayOutEntityTeleport .getConstructor(new Class[] { Integer.TYPE, Integer.TYPE, Integer.TYPE, Integer.TYPE, Byte.TYPE, Byte.TYPE, Boolean.TYPE }) .newInstance(new Object[] { Integer.valueOf(this.id), Integer.valueOf(loc.getBlockX() * 32), Integer.valueOf(loc.getBlockY() * 32), Integer.valueOf(loc.getBlockZ() * 32), Byte.valueOf((byte) ((int) loc.getYaw() * 256 / 360)), Byte.valueOf((byte) ((int) loc.getPitch() * 256 / 360)), Boolean.valueOf(false) }); } catch (IllegalArgumentException e) { e.printStackTrace(); } catch (SecurityException e) { e.printStackTrace(); } catch (InstantiationException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } catch (InvocationTargetException e) { e.printStackTrace(); } catch (NoSuchMethodException e) { e.printStackTrace(); } return packet; }
From source file:org.apache.hadoop.hbase.security.access.HbaseObjectWritableFor96Migration.java
/** * Read a {@link Writable}, {@link String}, primitive type, or an array of * the preceding./*w ww. jav a 2s . com*/ * @param in * @param objectWritable * @param conf * @return the object * @throws IOException */ @SuppressWarnings("unchecked") static Object readObject(DataInput in, HbaseObjectWritableFor96Migration objectWritable, Configuration conf) throws IOException { Class<?> declaredClass = CODE_TO_CLASS.get(WritableUtils.readVInt(in)); 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 if (declaredClass.equals(byte[].class)) { instance = Bytes.readByteArray(in); } else { 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.equals(Array.class)) { //an array not declared in CLASS_TO_CODE Class<?> componentType = readClass(conf, in); int length = in.readInt(); instance = Array.newInstance(componentType, length); for (int i = 0; i < length; i++) { Array.set(instance, i, readObject(in, conf)); } } else if (List.class.isAssignableFrom(declaredClass)) { // List int length = in.readInt(); instance = new ArrayList(length); for (int i = 0; i < length; i++) { ((ArrayList) instance).add(readObject(in, conf)); } } else if (declaredClass == String.class) { // String instance = Text.readString(in); } else if (declaredClass.isEnum()) { // enum instance = Enum.valueOf((Class<? extends Enum>) declaredClass, Text.readString(in)); } else if (declaredClass == Message.class) { String className = Text.readString(in); try { declaredClass = getClassByName(conf, className); instance = tryInstantiateProtobuf(declaredClass, in); } catch (ClassNotFoundException e) { LOG.error("Can't find class " + className, e); throw new IOException("Can't find class " + className, e); } } else if (Scan.class.isAssignableFrom(declaredClass)) { int length = in.readInt(); byte[] scanBytes = new byte[length]; in.readFully(scanBytes); ClientProtos.Scan.Builder scanProto = ClientProtos.Scan.newBuilder(); instance = ProtobufUtil.toScan(scanProto.mergeFrom(scanBytes).build()); } else { // Writable or Serializable Class instanceClass = null; int b = (byte) WritableUtils.readVInt(in); if (b == NOT_ENCODED) { String className = Text.readString(in); try { instanceClass = getClassByName(conf, className); } catch (ClassNotFoundException e) { LOG.error("Can't find class " + className, e); throw new IOException("Can't find class " + className, e); } } else { instanceClass = CODE_TO_CLASS.get(b); } if (Writable.class.isAssignableFrom(instanceClass)) { Writable writable = WritableFactories.newInstance(instanceClass, conf); try { writable.readFields(in); } catch (Exception e) { LOG.error("Error in readFields", e); throw new IOException("Error in readFields", e); } instance = writable; if (instanceClass == NullInstance.class) { // null declaredClass = ((NullInstance) instance).declaredClass; instance = null; } } else { int length = in.readInt(); byte[] objectBytes = new byte[length]; in.readFully(objectBytes); ByteArrayInputStream bis = null; ObjectInputStream ois = null; try { bis = new ByteArrayInputStream(objectBytes); ois = new ObjectInputStream(bis); instance = ois.readObject(); } catch (ClassNotFoundException e) { LOG.error("Class not found when attempting to deserialize object", e); throw new IOException("Class not found when attempting to " + "deserialize object", e); } finally { if (bis != null) bis.close(); if (ois != null) ois.close(); } } } if (objectWritable != null) { // store values objectWritable.declaredClass = declaredClass; objectWritable.instance = instance; } return instance; }
From source file:org.xmlsh.util.JavaUtils.java
public static boolean isBooleanClass(Class<?> c) { return c == Boolean.TYPE || Boolean.class.isAssignableFrom(c); }