ECode AttributedString::AddAttributes( /* [in] */ IMap* attributes, /* [in] */ Int32 start, /* [in] */ Int32 end) { VALIDATE_NOT_NULL(attributes) AutoPtr<ISet> entries; attributes->GetEntrySet((ISet**)&entries); AutoPtr<IIterator> it; entries->GetIterator((IIterator**)&it); Boolean hasNext; IMapEntry* entry; while (it->HasNext(&hasNext), hasNext) { AutoPtr<IInterface> obj; it->GetNext((IInterface**)&obj); entry = IMapEntry::Probe(obj); AutoPtr<IInterface> key, value; entry->GetKey((IInterface**)&key); entry->GetValue((IInterface**)&value); AddAttribute(IAttributedCharacterIteratorAttribute::Probe(key), value, start, end); } return NOERROR; }
ECode Request::AddHeaders( /* [in] */ IMap* headers) { if (headers == NULL) { return E_ILLEGAL_ARGUMENT_EXCEPTION; } AutoPtr<ISet> entries; headers->GetEntrySet((ISet**)&entries); AutoPtr<IIterator> it; entries->GetIterator((IIterator**)&it); Boolean hasNext; while (it->HasNext(&hasNext), hasNext) { AutoPtr<IInterface> obj; it->GetNext((IInterface**)&obj); IMapEntry* entry = IMapEntry::Probe(obj); AutoPtr<IInterface> key; entry->GetKey((IInterface**)&key); AutoPtr<IInterface> value; entry->GetValue((IInterface**)&value); String keyStr; ICharSequence::Probe(key)->ToString(&keyStr); String valueStr; ICharSequence::Probe(value)->ToString(&valueStr); AddHeader(keyStr, valueStr); } return NOERROR; }
ECode AttributedString::constructor( /* [in] */ const String& value, /* [in] */ IMap* attributes) { VALIDATE_NOT_NULL(attributes); if (value.IsNull()) { // throw new NullPointerException("value == null"); return E_NULL_POINTER_EXCEPTION; } ICollection* c = ICollection::Probe(attributes); assert(c != NULL); Boolean empty; c->IsEmpty(&empty); if (value.IsEmpty() && !empty) { // throw new IllegalArgumentException("Cannot add attributes to empty string"); return E_ILLEGAL_ARGUMENT_EXCEPTION; } mText = value; AutoPtr<IIterator> it; IIterable::Probe(attributes)->GetIterator((IIterator**)&it); AutoPtr<List<AutoPtr<Range> > > ranges; IAttributedCharacterIteratorAttribute* attr; Boolean hasNext; while (it->HasNext(&hasNext), hasNext) { AutoPtr<IInterface> obj;; it->GetNext((IInterface**)&obj); IMapEntry* entry = IMapEntry::Probe(obj); AutoPtr<IInterface> val; entry->GetValue((IInterface**)&val); AutoPtr<IInterface> key; entry->GetKey((IInterface**)&key); ranges = new List<AutoPtr<Range> >(1); AutoPtr<Range> range = new Range(0, value.GetLength(), val); ranges->PushBack(range); attr = IAttributedCharacterIteratorAttribute::Probe(key); mAttributeMap[attr] = ranges; } return NOERROR; }