1 11 package org.eclipse.debug.internal.ui.views.console; 12 13 14 import org.eclipse.jface.text.TypedRegion; 15 16 19 public abstract class StreamPartition extends TypedRegion { 20 21 24 private String fStreamIdentifier; 25 26 public StreamPartition(String streamIdentifier, int offset, int length, String type) { 27 super(offset, length, type); 28 fStreamIdentifier = streamIdentifier; 29 } 30 31 32 35 public boolean equals(Object partition) { 36 if (super.equals(partition)) { 37 fStreamIdentifier.equals(((StreamPartition)partition).getStreamIdentifier()); 38 } 39 return false; 40 } 41 42 45 public int hashCode() { 46 return super.hashCode() + fStreamIdentifier.hashCode(); 47 } 48 49 54 public String getStreamIdentifier() { 55 return fStreamIdentifier; 56 } 57 58 65 public boolean canBeCombinedWith(StreamPartition partition) { 66 int start = getOffset(); 67 int end = start + getLength(); 68 int otherStart = partition.getOffset(); 69 int otherEnd = otherStart + partition.getLength(); 70 boolean overlap = (otherStart >= start && otherStart <= end) || (start >= otherStart && start <= otherEnd); 71 return overlap && getType().equals(partition.getType()) && getStreamIdentifier().equals(partition.getStreamIdentifier()); 72 } 73 74 81 public StreamPartition combineWith(StreamPartition partition) { 82 int start = getOffset(); 83 int end = start + getLength(); 84 int otherStart = partition.getOffset(); 85 int otherEnd = otherStart + partition.getLength(); 86 int theStart = Math.min(start, otherStart); 87 int theEnd = Math.max(end, otherEnd); 88 return createNewPartition(getStreamIdentifier(), theStart, theEnd - theStart); 89 } 90 91 100 public abstract StreamPartition createNewPartition(String streamIdentifier, int offset, int length); 101 } 102 | Popular Tags |