public void ShouldGetElementFromLinkedSet() { LinkedSet <String> list = new LinkedSet <String>(); list.Add("Fred"); list.Add("Barney"); list.Add("Wilma"); Assert.AreEqual("Barney", ListElementUtil.GetElement(list, 1), "element"); }
public void ShouldGetElementFromHl7List() { IList <String> list = new LISTImpl <ST, String>(typeof(STImpl)).RawList(); list.Add("Fred"); list.Add("Barney"); list.Add("Wilma"); Assert.AreEqual("Barney", ListElementUtil.GetElement(list, 1), "element"); }
public void ShouldGetElementFromArrayList() { ArrayList list = new ArrayList(); list.Add("Fred"); list.Add("Barney"); list.Add("Wilma"); Assert.AreEqual("Barney", ListElementUtil.GetElement(list, 1), "element"); }
private AssociationBridge CreateAssociationBridge(Relationship relationship, RelationshipSorter sorter, Interaction interaction , MessagePartHolder currentMessagePart, BridgeContext context) { if (sorter.IsCollapsedRelationship(relationship)) { if (relationship.Cardinality.Multiple) { return(CreateCollectionRelationshipBridge(relationship, sorter, interaction)); } else { RelationshipSorter collapsedSorter = sorter.GetAsRelationshipSorter(relationship); PartBridge bridge = CreatePartBridge(collapsedSorter, interaction, GetMessagePart(interaction, relationship, collapsedSorter .GetBean()), new BridgeContext(true, context.GetOriginalIndex()), false); return(new AssociationBridgeImpl(relationship, bridge)); } } else { object o = sorter.Get(relationship); BeanProperty property = (BeanProperty)o; object value = property.Get(); if (relationship.Cardinality.Multiple && value is IEnumerable) { this.log.Debug("Association " + Describer.Describe(currentMessagePart, relationship) + " maps to collection property " + Describer.Describe(sorter.GetBeanType(), property)); return(CreateCollectionOfCompositeBeanBridges(property.Name, relationship, (IEnumerable)value, interaction)); } else { if (context.IsIndexed() && property.Collection) { this.log.Debug("Association " + Describer.Describe(currentMessagePart, relationship) + " maps to index " + context.GetIndex () + " of collection property " + Describer.Describe(sorter.GetBeanType(), property)); object elementValue = ListElementUtil.GetElement(value, context.GetIndex()); // use the indexed object's part instead MessagePartHolder part = GetMessagePart(interaction, relationship, elementValue); return(new AssociationBridgeImpl(relationship, CreatePartBridgeFromBean(property.Name + "[" + context.GetIndex() + "]", elementValue , interaction, part))); } else { this.log.Debug("Association " + Describer.Describe(currentMessagePart, relationship) + " maps to property " + Describer.Describe (sorter.GetBeanType(), property)); // Bug 13050 - should handle a single cardinality relationship if mapped to a collection if (ListElementUtil.IsCollection(value)) { value = ListElementUtil.IsEmpty(value) ? null : ListElementUtil.GetElement(value, 0); } MessagePartHolder part = GetMessagePart(interaction, relationship, value); return(new AssociationBridgeImpl(relationship, CreatePartBridgeFromBean(property.Name, value, interaction, part))); } } } }
public virtual BareANY GetHl7Value(int index) { object list = this.property == null ? null : new DataTypeFieldHelper(property.Bean, property.Name).Get <object>(); if (this.property.Collection && ListElementUtil.Count(list) < index) { return((BareANY)ListElementUtil.GetElement(list, index)); } else { return(null); } }
private PartBridge CreatePartBridge(RelationshipSorter sorter, Interaction interaction, MessagePartHolder currentMessagePart , BridgeContext context, bool nullPart) { IList <BaseRelationshipBridge> relationships = new List <BaseRelationshipBridge>(); foreach (Relationship relationship in currentMessagePart.GetRelationships()) { object o = sorter.Get(relationship); if (relationship.Attribute && relationship.HasFixedValue()) { relationships.Add(new FixedValueAttributeBeanBridge(relationship, (BareANY)null)); } else { if (relationship.Attribute) { if (o == null) { CreateWarningIfPropertyIsNotMapped(sorter, currentMessagePart, relationship); relationships.Add(new AttributeBridgeImpl(relationship, null)); } else { if (context.IsIndexed()) { CreateWarningIfConformanceLevelIsNotAllowed(relationship); object field = sorter.GetField(relationship); if (ListElementUtil.IsCollection(field)) { relationships.Add(new CollapsedAttributeBridge(((BeanProperty)o).Name, relationship, ListElementUtil.GetElement(field, context .GetIndex()))); } else { throw new MarshallingException("Expected relationship " + relationship.Name + " on " + sorter + " to resolve to a List because we think it's a collapsed " + " attribute"); } } else { CreateWarningIfConformanceLevelIsNotAllowed(relationship); relationships.Add(CreateAttributeBridge(relationship, (BeanProperty)o, sorter, currentMessagePart)); } } } else { if (IsIndicator(relationship)) { CreateWarningIfConformanceLevelIsNotAllowed(relationship); relationships.Add(CreateIndicatorAssociationBridge(relationship, sorter, interaction, context, (BeanProperty)o)); } else { if (o == null) { CreateWarningIfPropertyIsNotMapped(sorter, currentMessagePart, relationship); if (ConformanceLevelUtil.IsMandatory(relationship) || ConformanceLevelUtil.IsPopulated(relationship)) { relationships.Add(new AssociationBridgeImpl(relationship, CreateNullPartBridge(relationship, interaction))); } } else { CreateWarningIfConformanceLevelIsNotAllowed(relationship); relationships.Add(CreateAssociationBridge(relationship, sorter, interaction, currentMessagePart, context)); } } } } } // if (sorter.getPropertyName() == null || sorter.getPropertyName().equals("null")) { // System.out.println("not correct"); // } return(new PartBridgeImpl(sorter.GetPropertyName(), sorter.GetBean(), currentMessagePart.GetName(), relationships, context .IsCollapsed(), nullPart)); }