本文整理匯總了Java中org.yaml.snakeyaml.introspector.Property類的典型用法代碼示例。如果您正苦於以下問題:Java Property類的具體用法?Java Property怎麽用?Java Property使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
Property類屬於org.yaml.snakeyaml.introspector包,在下文中一共展示了Property類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getSequencePropertyName
import org.yaml.snakeyaml.introspector.Property; //導入依賴的package包/類
/**
* Provide the name of the property which is used when the entries form a
* sequence. The property must be a List.
*
*/
protected String getSequencePropertyName(Class<?> bean) {
Set<Property> properties = getPropertyUtils().getProperties(bean);
for (Iterator<Property> iterator = properties.iterator(); iterator.hasNext();) {
Property property = iterator.next();
if (!List.class.isAssignableFrom(property.getType())) {
iterator.remove();
}
}
if (properties.size() == 0) {
throw new YAMLException("No list property found in " + bean);
} else if (properties.size() > 1) {
throw new YAMLException(
"Many list properties found in "
+ bean
+ "; Please override getSequencePropertyName() to specify which property to use.");
}
return properties.iterator().next().getName();
}
示例2: getSequencePropertyName
import org.yaml.snakeyaml.introspector.Property; //導入依賴的package包/類
/**
* Provide the name of the property which is used when the entries form a
* sequence. The property must be a List.
* @param bean the class to provide exactly one List property
* @return name of the List property
* @throws IntrospectionException if the bean cannot be introspected
*/
protected String getSequencePropertyName(Class<?> bean) throws IntrospectionException {
Set<Property> properties = getPropertyUtils().getProperties(bean);
for (Iterator<Property> iterator = properties.iterator(); iterator.hasNext();) {
Property property = iterator.next();
if (!List.class.isAssignableFrom(property.getType())) {
iterator.remove();
}
}
if (properties.size() == 0) {
throw new YAMLException("No list property found in " + bean);
} else if (properties.size() > 1) {
throw new YAMLException(
"Many list properties found in "
+ bean
+ "; Please override getSequencePropertyName() to specify which property to use.");
}
return properties.iterator().next().getName();
}
示例3: notNullMapProperty
import org.yaml.snakeyaml.introspector.Property; //導入依賴的package包/類
@Test
public void notNullMapProperty() {
bean.setMapProperty(ImmutableMap.<String, Long> builder().put("first", 1L).put("second", 2L).build());
Property property = new MethodProperty(getPropertyDescriptor("mapProperty"));
NodeTuple nodeTuple = representer.representJavaBeanProperty(bean, property, bean.getMapProperty(), null);
assertThat(nodeTuple, is(notNullValue()));
assertThat(nodeTuple.getKeyNode(), is(instanceOf(ScalarNode.class)));
assertThat(((ScalarNode) nodeTuple.getKeyNode()).getValue(), is("map-property"));
assertThat(nodeTuple.getValueNode(), is(instanceOf(MappingNode.class)));
assertThat(((MappingNode) nodeTuple.getValueNode()).getValue().size(), is(2));
assertThat(((MappingNode) nodeTuple.getValueNode()).getValue().get(0), is(instanceOf(NodeTuple.class)));
assertThat(((ScalarNode) ((MappingNode) nodeTuple.getValueNode()).getValue().get(0).getKeyNode()).getValue(),
is("first"));
assertThat(((ScalarNode) ((MappingNode) nodeTuple.getValueNode()).getValue().get(0).getValueNode()).getValue(),
is("1"));
assertThat(((ScalarNode) ((MappingNode) nodeTuple.getValueNode()).getValue().get(1).getKeyNode()).getValue(),
is("second"));
assertThat(((ScalarNode) ((MappingNode) nodeTuple.getValueNode()).getValue().get(1).getValueNode()).getValue(),
is("2"));
}
示例4: createPropertySet
import org.yaml.snakeyaml.introspector.Property; //導入依賴的package包/類
@Override protected Set<Property> createPropertySet(Class<?> type, BeanAccess bAccess) {
try {
Set<Property> properties = super.createPropertySet(type, bAccess);
if (Tape.class.isAssignableFrom(type)) {
return sort(properties, "name", "interactions");
} else if (YamlRecordedInteraction.class.isAssignableFrom(type)) {
return sort(properties, "recorded", "request", "response");
} else if (YamlRecordedRequest.class.isAssignableFrom(type)) {
return sort(properties, "method", "uri", "headers", "body");
} else if (YamlRecordedResponse.class.isAssignableFrom(type)) {
return sort(properties, "status", "headers", "body");
} else {
return properties;
}
} catch (IntrospectionException e) {
throw new RuntimeException(e);
}
}
示例5: getSequencePropertyName
import org.yaml.snakeyaml.introspector.Property; //導入依賴的package包/類
protected String getSequencePropertyName(Class<?> bean) {
Set<Property> properties = getPropertyUtils().getProperties(bean);
for (Iterator<Property> iterator = properties.iterator(); iterator.hasNext();) {
Property property = iterator.next();
if (!List.class.isAssignableFrom(property.getType())) {
iterator.remove();
}
}
if (properties.size() == 0) {
throw new YAMLException("No list property found in " + bean);
} else if (properties.size() > 1) {
throw new YAMLException(
"Many list properties found in "
+ bean
+ "; Please override getSequencePropertyName() to specify which property to use.");
}
return properties.iterator().next().getName();
}
示例6: getProperties
import org.yaml.snakeyaml.introspector.Property; //導入依賴的package包/類
@Override
protected Set<Property> getProperties(Class<?> type)
throws IntrospectionException {
Set<Property> set = super.getProperties(type);
Set<Property> filtered = new TreeSet<>();
BeanInfo info = Introspector.getBeanInfo(type, Object.class);
PropertyDescriptor[] properties = info.getPropertyDescriptors();
ArrayList<String> hiddenProperties = new ArrayList<>();
// We don't want to save Hidden properties
for (PropertyDescriptor p : properties) {
Method setter = p.getWriteMethod();
if (setter != null && setter.isAnnotationPresent(Hidden.class) || p.isHidden()) {
hiddenProperties.add(p.getName());
}
}
for (Property prop : set) {
String name = prop.getName();
if (!hiddenProperties.contains(name)) {
filtered.add(prop);
}
}
return filtered;
}
示例7: getRepresenter
import org.yaml.snakeyaml.introspector.Property; //導入依賴的package包/類
protected Representer getRepresenter() {
return new Representer() {
@Override
protected Set<Property> getProperties(Class<? extends Object> type) throws IntrospectionException {
Set<Property> props = super.getProperties(type);
Property toRemove = null;
for (Property prop : props) {
if (prop.getName().equals("metaClass")) {
toRemove = prop;
break;
}
}
if (toRemove != null)
props.remove(toRemove);
return props;
}
};
}
示例8: addPropertyAlias
import org.yaml.snakeyaml.introspector.Property; //導入依賴的package包/類
/**
* Adds an alias for a Javabean property name on a particular type. The values of YAML
* keys with the alias name will be mapped to the Javabean property.
* @param alias the alias to map
* @param type the type of property
* @param name the property name
*/
protected final void addPropertyAlias(String alias, Class<?> type, String name) {
Map<String, Property> typeMap = this.properties.get(type);
if (typeMap == null) {
typeMap = new HashMap<String, Property>();
this.properties.put(type, typeMap);
}
try {
typeMap.put(alias, this.propertyUtils.getProperty(type, name));
}
catch (IntrospectionException ex) {
throw new RuntimeException(ex);
}
}
示例9: getProperties
import org.yaml.snakeyaml.introspector.Property; //導入依賴的package包/類
@Override
protected Set<Property> getProperties(Class<? extends Object> type)
throws IntrospectionException {
List<String> order = null;
if (type.isAssignableFrom(YamlCluster.class)) {
order = CLUSTER_ORDER;
} else if (type.isAssignableFrom(YamlGroup.class)) {
order = GROUP_ORDER;
}
if (order != null) {
Set<Property> standard = super.getProperties(type);
Set<Property> sorted = new TreeSet<>(new PropertyComparator(order));
sorted.addAll(standard);
return sorted;
} else {
return super.getProperties(type);
}
}
示例10: getSequencePropertyName
import org.yaml.snakeyaml.introspector.Property; //導入依賴的package包/類
/**
* Provide the name of the property which is used when the entries form a
* sequence. The property must be a List.
*
* @throws IntrospectionException
*/
protected String getSequencePropertyName(Class<?> bean) throws IntrospectionException {
Set<Property> properties = getPropertyUtils().getProperties(bean);
for (Iterator<Property> iterator = properties.iterator(); iterator.hasNext();) {
Property property = iterator.next();
if (!List.class.isAssignableFrom(property.getType())) {
iterator.remove();
}
}
if (properties.size() == 0) {
throw new YAMLException("No list property found in " + bean);
} else if (properties.size() > 1) {
throw new YAMLException(
"Many list properties found in "
+ bean
+ "; Please override getSequencePropertyName() to specify which property to use.");
}
return properties.iterator().next().getName();
}
示例11: getProperties
import org.yaml.snakeyaml.introspector.Property; //導入依賴的package包/類
@Override
protected Set<Property> getProperties(Class<? extends Object> type)
throws IntrospectionException {
Set<Property> set = super.getProperties(type);
Set<Property> filtered = new TreeSet<Property>();
if (type.equals(BeanToRemoveProperty.class)) {
// filter properties
for (Property prop : set) {
String name = prop.getName();
if (!name.equals("id")) {
filtered.add(prop);
}
}
}
return filtered;
}
示例12: representJavaBeanProperty
import org.yaml.snakeyaml.introspector.Property; //導入依賴的package包/類
@Override
protected NodeTuple representJavaBeanProperty(Object javaBean, Property property, Object propertyValue,
Tag customTag)
{
if (javaBean instanceof AbstractElement)
{
if ("path".equals(property.getName()) || "buildPath".equals(property.getName())) //$NON-NLS-1$ //$NON-NLS-2$
{
String path = (String) propertyValue;
IPath relative = Path.fromOSString(path).makeRelativeTo(
Path.fromOSString(bundleDirectory.getAbsolutePath()));
propertyValue = relative.toOSString();
}
}
return super.representJavaBeanProperty(javaBean, property, propertyValue, customTag);
}
示例13: getProperties
import org.yaml.snakeyaml.introspector.Property; //導入依賴的package包/類
@Override
protected Set<Property> getProperties(Class<? extends Object> type) throws IntrospectionException
{
if (type.equals(Ruby.class) || type.equals(KCode.class) || type.equals(RubyProc.class))
{
return Collections.emptySet();
}
Set<Property> set = super.getProperties(type);
if (CommandElement.class.isAssignableFrom(type) || type.equals(EnvironmentElement.class))
{
// drop runtime, invoke, and invoke block properties
Set<Property> toRemove = new HashSet<Property>();
for (Property prop : set)
{
if ("invokeBlock".equals(prop.getName()) || "runtime".equals(prop.getName()) //$NON-NLS-1$ //$NON-NLS-2$
|| "invoke".equals(prop.getName())) //$NON-NLS-1$
{
toRemove.add(prop);
}
}
set.removeAll(toRemove);
}
return set;
}
示例14: getProperties
import org.yaml.snakeyaml.introspector.Property; //導入依賴的package包/類
@Override
protected Set<Property> getProperties(Class<?> type) throws IntrospectionException {
Set<Property> set = super.getProperties(type);
Set<Property> filtered = new TreeSet<>();
BeanInfo beanInfo = Introspector.getBeanInfo(type);
PropertyDescriptor[] propertyDescriptors = beanInfo.getPropertyDescriptors();
Map<String, PropertyDescriptor> propMap = Arrays.asList(propertyDescriptors).stream().collect(Collectors.toMap(PropertyDescriptor::getName, Function.identity()));
for (Property prop : set) {
PropertyDescriptor pd = propMap.get(prop.getName());
if (pd != null) {
Method readMethod = pd.getReadMethod();
AUTIL.runIfMethodAnnotated(readMethod, () -> filtered.add(prop), false, Transient.class);
}
}
return filtered;
}
示例15: getProperties
import org.yaml.snakeyaml.introspector.Property; //導入依賴的package包/類
@Override
/**
* This method is not called. It was earlier and we had to filter the representation of URI in the yaml
* Leaving this method here as an example of how to use filters for YAML for any future use.
*
* @author skurup00c
*/
protected Set< Property > getProperties( Class< ? extends Object > type ) throws IntrospectionException
{
Set< Property > set = super.getProperties( type );
Set< Property > filtered = new TreeSet< Property >();
for ( Property prop : set )
{
Class typeClass = prop.getType();
if ( !typeClass.equals( URI.class ) )
{
filtered.add( prop );
}
}
return filtered;
}