1 11 package org.eclipse.ui.internal.console; 12 13 14 import org.eclipse.jface.text.TypedRegion; 15 import org.eclipse.ui.console.ConsolePlugin; 16 import org.eclipse.ui.console.MessageConsoleStream; 17 18 21 public class MessageConsolePartition extends TypedRegion { 22 23 26 private MessageConsoleStream fStream; 27 28 31 public static final String MESSAGE_PARTITION_TYPE = ConsolePlugin.getUniqueIdentifier() + ".MESSAGE_PARTITION_TYPE"; 33 public MessageConsolePartition(MessageConsoleStream stream, int offset, int length) { 34 super(offset, length, MESSAGE_PARTITION_TYPE); 35 fStream = stream; 36 } 37 38 41 public boolean equals(Object partition) { 42 if (super.equals(partition)) { 43 fStream.equals(((MessageConsolePartition)partition).getStream()); 44 } 45 return false; 46 } 47 48 51 public int hashCode() { 52 return super.hashCode() + fStream.hashCode(); 53 } 54 55 60 public MessageConsoleStream getStream() { 61 return fStream; 62 } 63 64 71 public boolean canBeCombinedWith(MessageConsolePartition partition) { 72 int start = getOffset(); 73 int end = start + getLength(); 74 int otherStart = partition.getOffset(); 75 int otherEnd = otherStart + partition.getLength(); 76 boolean overlap = (otherStart >= start && otherStart <= end) || (start >= otherStart && start <= otherEnd); 77 return overlap && getType().equals(partition.getType()) && getStream().equals(partition.getStream()); 78 } 79 80 87 public MessageConsolePartition combineWith(MessageConsolePartition partition) { 88 int start = getOffset(); 89 int end = start + getLength(); 90 int otherStart = partition.getOffset(); 91 int otherEnd = otherStart + partition.getLength(); 92 int theStart = Math.min(start, otherStart); 93 int theEnd = Math.max(end, otherEnd); 94 return createNewPartition(theStart, theEnd - theStart); 95 } 96 97 105 public MessageConsolePartition createNewPartition(int offset, int length) { 106 return new MessageConsolePartition(getStream(), offset, length); 107 } 108 } | Popular Tags |