@Override public DnsMessage addRecord(DnsSection section, int index, DnsRecord record) { addRecord(sectionOrdinal(section), index, record); return this; }
private void addRecord(int section, DnsRecord record) { checkQuestion(section, record); final Object records = sectionAt(section); if (records == null) { setSection(section, record); return; } if (records instanceof DnsRecord) { final List<DnsRecord> recordList = newRecordList(); recordList.add(castRecord(records)); recordList.add(record); setSection(section, recordList); return; } @SuppressWarnings("unchecked") final List<DnsRecord> recordList = (List<DnsRecord>) records; recordList.add(record); }
private void setRecord(int section, DnsRecord record) { clear(section); setSection(section, checkQuestion(section, record)); }
@Override public DnsMessage clear(DnsSection section) { clear(sectionOrdinal(section)); return this; }
@Override public <T extends DnsRecord> T recordAt(DnsSection section, int index) { return recordAt(sectionOrdinal(section), index); }
private <T extends DnsRecord> T recordAt(int section) { final Object records = sectionAt(section); if (records == null) { return null; } if (records instanceof DnsRecord) { return castRecord(records); } @SuppressWarnings("unchecked") final List<DnsRecord> recordList = (List<DnsRecord>) records; if (recordList.isEmpty()) { return null; } return castRecord(recordList.get(0)); }
@Override public int count(DnsSection section) { return count(sectionOrdinal(section)); }
@Override public <T extends DnsRecord> T removeRecord(DnsSection section, int index) { return removeRecord(sectionOrdinal(section), index); }
private <T extends DnsRecord> T removeRecord(int section, int index) { final Object records = sectionAt(section); if (records == null) { throw new IndexOutOfBoundsException("index: " + index + " (expected: none)"); } if (records instanceof DnsRecord) { if (index != 0) { throw new IndexOutOfBoundsException("index: " + index + " (expected: 0)"); } T record = castRecord(records); setSection(section, null); return record; } @SuppressWarnings("unchecked") final List<DnsRecord> recordList = (List<DnsRecord>) records; return castRecord(recordList.remove(index)); }
@Override public DnsQuery retain(int increment) { return (DnsQuery) super.retain(increment); }
@Override public DnsMessage clear() { for (int i = 0; i < SECTION_COUNT; i ++) { clear(i); } return this; }
@Override public int hashCode() { return id() * 31 + (this instanceof DnsQuery? 0 : 1); }
@Override public DnsQuery addRecord(DnsSection section, int index, DnsRecord record) { return (DnsQuery) super.addRecord(section, index, record); }
@Override public int count() { int count = 0; for (int i = 0; i < SECTION_COUNT; i ++) { count += count(i); } return count; }
@Override public <T extends DnsRecord> T recordAt(DnsSection section) { return recordAt(sectionOrdinal(section)); }
private <T extends DnsRecord> T recordAt(int section, int index) { final Object records = sectionAt(section); if (records == null) { throw new IndexOutOfBoundsException("index: " + index + " (expected: none)"); } if (records instanceof DnsRecord) { if (index == 0) { return castRecord(records); } else { throw new IndexOutOfBoundsException("index: " + index + "' (expected: 0)"); } } @SuppressWarnings("unchecked") final List<DnsRecord> recordList = (List<DnsRecord>) records; return castRecord(recordList.get(index)); }
@Override public int count(DnsSection section) { return count(sectionOrdinal(section)); }
@Override public <T extends DnsRecord> T removeRecord(DnsSection section, int index) { return removeRecord(sectionOrdinal(section), index); }
private <T extends DnsRecord> T removeRecord(int section, int index) { final Object records = sectionAt(section); if (records == null) { throw new IndexOutOfBoundsException("index: " + index + " (expected: none)"); } if (records instanceof DnsRecord) { if (index != 0) { throw new IndexOutOfBoundsException("index: " + index + " (expected: 0)"); } T record = castRecord(records); setSection(section, null); return record; } @SuppressWarnings("unchecked") final List<DnsRecord> recordList = (List<DnsRecord>) records; return castRecord(recordList.remove(index)); }
@Override public DnsResponse retain() { return (DnsResponse) super.retain(); }