# HG changeset patch # User Omair Majid # Date 1370619513 14400 # Node ID 85cd7afdf70f95315ab56434265c4bf42b297711 # Parent f747a057d7a192eec487ba0f3fc538df2897ea36 Convert LongRange into the more generic Range Reviewed-by: neugens, vanaltj Review-thread: http://icedtea.classpath.org/pipermail/thermostat/2013-June/007055.html diff -r f747a057d7a1 -r 85cd7afdf70f client/swing/src/main/java/com/redhat/thermostat/client/swing/components/timeline/TimelineRulerHeader.java --- a/client/swing/src/main/java/com/redhat/thermostat/client/swing/components/timeline/TimelineRulerHeader.java Fri Jun 07 11:29:06 2013 -0400 +++ b/client/swing/src/main/java/com/redhat/thermostat/client/swing/components/timeline/TimelineRulerHeader.java Fri Jun 07 11:38:33 2013 -0400 @@ -51,7 +51,7 @@ import com.redhat.thermostat.client.swing.GraphicsUtils; import com.redhat.thermostat.client.swing.components.GradientPanel; import com.redhat.thermostat.client.ui.Palette; -import com.redhat.thermostat.common.model.LongRange; +import com.redhat.thermostat.common.model.Range; @SuppressWarnings("serial") public abstract class TimelineRulerHeader extends GradientPanel { @@ -75,9 +75,9 @@ */ public static final long DEFAULT_INCREMENT_IN_MILLIS = 1_000; - private LongRange range; + private Range range; - public TimelineRulerHeader(LongRange range) { + public TimelineRulerHeader(Range range) { super(Palette.LIGHT_GRAY.getColor(), Palette.WHITE.getColor()); setFont(TimelineUtils.FONT); @@ -85,7 +85,7 @@ this.range = range; } - public LongRange getRange() { + public Range getRange() { return range; } diff -r f747a057d7a1 -r 85cd7afdf70f client/swing/src/main/java/com/redhat/thermostat/client/swing/components/timeline/TimelineUtils.java --- a/client/swing/src/main/java/com/redhat/thermostat/client/swing/components/timeline/TimelineUtils.java Fri Jun 07 11:29:06 2013 -0400 +++ b/client/swing/src/main/java/com/redhat/thermostat/client/swing/components/timeline/TimelineUtils.java Fri Jun 07 11:38:33 2013 -0400 @@ -41,12 +41,12 @@ import java.awt.Rectangle; import com.redhat.thermostat.client.ui.Palette; -import com.redhat.thermostat.common.model.LongRange; +import com.redhat.thermostat.common.model.Range; public class TimelineUtils { public static final Font FONT = new Font("SansSerif", Font.PLAIN, 10); - public static void drawMarks(LongRange range, Graphics2D graphics, Rectangle bounds, + public static void drawMarks(Range range, Graphics2D graphics, Rectangle bounds, int currentValue, boolean darkerTop, int increment) { int inc = currentValue % increment; diff -r f747a057d7a1 -r 85cd7afdf70f common/core/src/main/java/com/redhat/thermostat/common/model/LongRange.java --- a/common/core/src/main/java/com/redhat/thermostat/common/model/LongRange.java Fri Jun 07 11:29:06 2013 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,86 +0,0 @@ -/* - * Copyright 2012, 2013 Red Hat, Inc. - * - * This file is part of Thermostat. - * - * Thermostat is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published - * by the Free Software Foundation; either version 2, or (at your - * option) any later version. - * - * Thermostat is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Thermostat; see the file COPYING. If not see - * . - * - * Linking this code with other modules is making a combined work - * based on this code. Thus, the terms and conditions of the GNU - * General Public License cover the whole combination. - * - * As a special exception, the copyright holders of this code give - * you permission to link this code with independent modules to - * produce an executable, regardless of the license terms of these - * independent modules, and to copy and distribute the resulting - * executable under terms of your choice, provided that you also - * meet, for each linked independent module, the terms and conditions - * of the license of that module. An independent module is a module - * which is not derived from or based on this code. If you modify - * this code, you may extend this exception to your version of the - * library, but you are not obligated to do so. If you do not wish - * to do so, delete this exception statement from your version. - */ - -package com.redhat.thermostat.common.model; - - -/** - * A class representing a span of units from min to max.

- * - * The units and the meaning of the range are left to the user, including the - * fact that the range are inclusive or exclusive of the extremes. - */ -public class LongRange { - - long min; - long max; - - /** - * Creates a new LongRange with a span of 0 units. - */ - public LongRange() { - } - - /** - * Creates a new Range that span from min to max. - */ - public LongRange(long min, long max) { - this.min = min; - this.max = max; - } - - public void setMax(long max) { - this.max = max; - } - - public long getMax() { - return max; - } - - public void setMin(long min) { - this.min = min; - } - - public long getMin() { - return min; - } - - @Override - public String toString() { - return "[" + min + " ->" + max + "("+ (max - min) + ")]"; - } -} - diff -r f747a057d7a1 -r 85cd7afdf70f common/core/src/main/java/com/redhat/thermostat/common/model/LongRangeNormalizer.java --- a/common/core/src/main/java/com/redhat/thermostat/common/model/LongRangeNormalizer.java Fri Jun 07 11:29:06 2013 -0400 +++ b/common/core/src/main/java/com/redhat/thermostat/common/model/LongRangeNormalizer.java Fri Jun 07 11:38:33 2013 -0400 @@ -51,19 +51,19 @@ private long value; - private LongRange range; + private Range range; - public LongRangeNormalizer(LongRange range) { + public LongRangeNormalizer(Range range) { this.range = range; } - public LongRangeNormalizer(LongRange range, long minNormalized, long maxNormalized) { + public LongRangeNormalizer(Range range, long minNormalized, long maxNormalized) { this.range = range; this.maxNormalized = maxNormalized; this.minNormalized = minNormalized; } - public LongRangeNormalizer(LongRange range, LongRange normilizedRange) { + public LongRangeNormalizer(Range range, Range normilizedRange) { this.range = range; maxNormalized = normilizedRange.max; minNormalized = normilizedRange.min; diff -r f747a057d7a1 -r 85cd7afdf70f common/core/src/main/java/com/redhat/thermostat/common/model/Range.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/common/core/src/main/java/com/redhat/thermostat/common/model/Range.java Fri Jun 07 11:38:33 2013 -0400 @@ -0,0 +1,99 @@ +/* + * Copyright 2012, 2013 Red Hat, Inc. + * + * This file is part of Thermostat. + * + * Thermostat is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published + * by the Free Software Foundation; either version 2, or (at your + * option) any later version. + * + * Thermostat is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Thermostat; see the file COPYING. If not see + * . + * + * Linking this code with other modules is making a combined work + * based on this code. Thus, the terms and conditions of the GNU + * General Public License cover the whole combination. + * + * As a special exception, the copyright holders of this code give + * you permission to link this code with independent modules to + * produce an executable, regardless of the license terms of these + * independent modules, and to copy and distribute the resulting + * executable under terms of your choice, provided that you also + * meet, for each linked independent module, the terms and conditions + * of the license of that module. An independent module is a module + * which is not derived from or based on this code. If you modify + * this code, you may extend this exception to your version of the + * library, but you are not obligated to do so. If you do not wish + * to do so, delete this exception statement from your version. + */ + +package com.redhat.thermostat.common.model; + +import java.util.Objects; + +/** + * A class representing a span of units from min to max.

+ * + * The units and the meaning of the range are left to the user, including the + * fact that the range are inclusive or exclusive of the extremes. + */ +public class Range { + + T min; + T max; + + /** + * Creates a new Range that span from min to max. + */ + public Range(T min, T max) { + this.min = min; + this.max = max; + } + + public void setMax(T max) { + this.max = max; + } + + public T getMax() { + return max; + } + + public void setMin(T min) { + this.min = min; + } + + public T getMin() { + return min; + } + + @Override + public String toString() { + return "[" + min + " -> " + max + "]"; + } + + @Override + public boolean equals(Object obj) { + if (obj == null) { + return false; + } + if (!obj.getClass().equals(getClass())) { + return false; + } + Range other = (Range) obj; + return Objects.equals(this.min, other.min) && Objects.equals(this.max, other.max); + } + + /** Note: It's not a good idea to use mutable values (like {@code Range}) as a hash */ + @Override + public int hashCode() { + return Objects.hash(min, max); + } +} + diff -r f747a057d7a1 -r 85cd7afdf70f common/core/src/test/java/com/redhat/thermostat/common/model/LongRangeNormalizerTest.java --- a/common/core/src/test/java/com/redhat/thermostat/common/model/LongRangeNormalizerTest.java Fri Jun 07 11:29:06 2013 -0400 +++ b/common/core/src/test/java/com/redhat/thermostat/common/model/LongRangeNormalizerTest.java Fri Jun 07 11:38:33 2013 -0400 @@ -36,12 +36,11 @@ package com.redhat.thermostat.common.model; -import static org.junit.Assert.*; import junit.framework.Assert; import org.junit.Test; -import com.redhat.thermostat.common.model.LongRange; +import com.redhat.thermostat.common.model.Range; import com.redhat.thermostat.common.model.LongRangeNormalizer; public class LongRangeNormalizerTest { @@ -49,9 +48,7 @@ @Test public void testSameRange() { - LongRange range = new LongRange(); - range.setMax(10); - range.setMin(0); + Range range = new Range<>(0l, 10l); LongRangeNormalizer model = new LongRangeNormalizer(range); @@ -67,9 +64,7 @@ @Test public void testDoubleRange() { - LongRange range = new LongRange(); - range.setMax(10); - range.setMin(0); + Range range = new Range<>(0l, 10l); LongRangeNormalizer model = new LongRangeNormalizer(range); @@ -85,9 +80,7 @@ @Test public void testRanges() { - LongRange range = new LongRange(); - range.setMax(10); - range.setMin(0); + Range range = new Range<>(0l, 10l); LongRangeNormalizer model = new LongRangeNormalizer(range); @@ -108,8 +101,8 @@ Assert.assertEquals(150, model.getValueNormalized()); - range.setMax(100); - range.setMin(0); + range.setMax(100l); + range.setMin(0l); model.setValue(50); model.setMaxNormalized(1); diff -r f747a057d7a1 -r 85cd7afdf70f thread/client-common/src/main/java/com/redhat/thermostat/thread/client/common/model/timeline/Page.java --- a/thread/client-common/src/main/java/com/redhat/thermostat/thread/client/common/model/timeline/Page.java Fri Jun 07 11:29:06 2013 -0400 +++ b/thread/client-common/src/main/java/com/redhat/thermostat/thread/client/common/model/timeline/Page.java Fri Jun 07 11:38:33 2013 -0400 @@ -36,16 +36,16 @@ package com.redhat.thermostat.thread.client.common.model.timeline; -import com.redhat.thermostat.common.model.LongRange; +import com.redhat.thermostat.common.model.Range; public class Page { - private LongRange range; - public Page(LongRange range) { + private Range range; + public Page(Range range) { this.range = range; } - public LongRange getSpan() { + public Range getSpan() { return range; } } diff -r f747a057d7a1 -r 85cd7afdf70f thread/client-common/src/main/java/com/redhat/thermostat/thread/client/common/view/ThreadTimelineView.java --- a/thread/client-common/src/main/java/com/redhat/thermostat/thread/client/common/view/ThreadTimelineView.java Fri Jun 07 11:29:06 2013 -0400 +++ b/thread/client-common/src/main/java/com/redhat/thermostat/thread/client/common/view/ThreadTimelineView.java Fri Jun 07 11:38:33 2013 -0400 @@ -41,7 +41,7 @@ import com.redhat.thermostat.client.core.views.BasicView; import com.redhat.thermostat.common.ActionListener; import com.redhat.thermostat.common.ActionNotifier; -import com.redhat.thermostat.common.model.LongRange; +import com.redhat.thermostat.common.model.Range; import com.redhat.thermostat.thread.client.common.Timeline; public abstract class ThreadTimelineView extends BasicView { @@ -63,6 +63,6 @@ threadTimelineNotifier.removeActionListener(listener); } - public abstract void displayStats(List timelines, LongRange range); + public abstract void displayStats(List timelines, Range range); } diff -r f747a057d7a1 -r 85cd7afdf70f thread/client-controllers/src/main/java/com/redhat/thermostat/thread/client/controller/impl/ThreadTimelineController.java --- a/thread/client-controllers/src/main/java/com/redhat/thermostat/thread/client/controller/impl/ThreadTimelineController.java Fri Jun 07 11:29:06 2013 -0400 +++ b/thread/client-controllers/src/main/java/com/redhat/thermostat/thread/client/controller/impl/ThreadTimelineController.java Fri Jun 07 11:38:33 2013 -0400 @@ -37,17 +37,14 @@ package com.redhat.thermostat.thread.client.controller.impl; import java.util.ArrayList; -import java.util.Date; -import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.Stack; import com.redhat.thermostat.client.ui.Palette; import com.redhat.thermostat.common.ActionEvent; import com.redhat.thermostat.common.ActionListener; import com.redhat.thermostat.common.Timer; -import com.redhat.thermostat.common.model.LongRange; +import com.redhat.thermostat.common.model.Range; import com.redhat.thermostat.thread.client.common.Timeline; import com.redhat.thermostat.thread.client.common.TimelineInfo; import com.redhat.thermostat.thread.client.common.chart.ChartColors; @@ -85,7 +82,7 @@ synchronized (lock) { // FIXME: only load latest, not all the info all the time - LongRange range = new LongRange(Long.MAX_VALUE, Long.MIN_VALUE); + Range range = new Range(Long.MAX_VALUE, Long.MIN_VALUE); List infos = collector.getThreadInfo(); if(infos.size() > 0) { Map> stats = ThreadInfoHelper.getThreadInfoDataMap(infos); diff -r f747a057d7a1 -r 85cd7afdf70f thread/client-controllers/src/test/java/com/redhat/thermostat/thread/client/controller/impl/ThreadTimelineControllerTest.java --- a/thread/client-controllers/src/test/java/com/redhat/thermostat/thread/client/controller/impl/ThreadTimelineControllerTest.java Fri Jun 07 11:29:06 2013 -0400 +++ b/thread/client-controllers/src/test/java/com/redhat/thermostat/thread/client/controller/impl/ThreadTimelineControllerTest.java Fri Jun 07 11:38:33 2013 -0400 @@ -55,11 +55,10 @@ import com.redhat.thermostat.common.ActionEvent; import com.redhat.thermostat.common.ActionListener; import com.redhat.thermostat.common.Timer; -import com.redhat.thermostat.common.model.LongRange; +import com.redhat.thermostat.common.model.Range; import com.redhat.thermostat.thread.client.common.Timeline; import com.redhat.thermostat.thread.client.common.TimelineInfo; import com.redhat.thermostat.thread.client.common.chart.ChartColors; -//import com.redhat.thermostat.thread.client.common.ThreadTimelineBean; import com.redhat.thermostat.thread.client.common.collector.ThreadCollector; import com.redhat.thermostat.thread.client.common.view.ThreadTableView; import com.redhat.thermostat.thread.client.common.view.ThreadTimelineView; @@ -145,15 +144,15 @@ action.run(); ArgumentCaptor listCaptor = ArgumentCaptor.forClass(List.class); - ArgumentCaptor rangeCaptor = ArgumentCaptor.forClass(LongRange.class); + ArgumentCaptor rangeCaptor = ArgumentCaptor.forClass(Range.class); verify(view).displayStats(listCaptor.capture(), rangeCaptor.capture()); List viewResult = listCaptor.getValue(); - LongRange rangeResult = rangeCaptor.getValue(); + Range rangeResult = rangeCaptor.getValue(); assertEquals(2, viewResult.size()); - assertEquals(100, rangeResult.getMin()); - assertEquals(3000, rangeResult.getMax()); + assertEquals(100l, (long) rangeResult.getMin()); + assertEquals(3000l, (long) rangeResult.getMax()); Timeline timeline = (Timeline) viewResult.get(0); assertEquals(2, timeline.getId()); diff -r f747a057d7a1 -r 85cd7afdf70f thread/client-swing/src/main/java/com/redhat/thermostat/thread/client/swing/impl/SwingThreadTimelineView.java --- a/thread/client-swing/src/main/java/com/redhat/thermostat/thread/client/swing/impl/SwingThreadTimelineView.java Fri Jun 07 11:29:06 2013 -0400 +++ b/thread/client-swing/src/main/java/com/redhat/thermostat/thread/client/swing/impl/SwingThreadTimelineView.java Fri Jun 07 11:38:33 2013 -0400 @@ -38,7 +38,6 @@ import java.awt.BorderLayout; import java.awt.Component; - import java.util.List; import javax.swing.DefaultListModel; @@ -52,14 +51,10 @@ import com.redhat.thermostat.client.swing.ComponentVisibleListener; import com.redhat.thermostat.client.swing.SwingComponent; - import com.redhat.thermostat.client.swing.components.timeline.TimelineRulerHeader; - -import com.redhat.thermostat.common.model.LongRange; - +import com.redhat.thermostat.common.model.Range; import com.redhat.thermostat.thread.client.common.Timeline; import com.redhat.thermostat.thread.client.common.view.ThreadTimelineView; - import com.redhat.thermostat.thread.client.swing.impl.timeline.ThreadTimelineHeader; import com.redhat.thermostat.thread.client.swing.impl.timeline.TimelineCellRenderer; import com.redhat.thermostat.thread.client.swing.impl.timeline.TimelineComponent; @@ -115,7 +110,7 @@ scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED); long now = System.currentTimeMillis(); - header = new ThreadTimelineHeader(new LongRange(now, now + TimelineRulerHeader.DEFAULT_INCREMENT_IN_MILLIS), + header = new ThreadTimelineHeader(new Range(now, now + TimelineRulerHeader.DEFAULT_INCREMENT_IN_MILLIS), scrollPane); scrollPane.setColumnHeaderView(header); @@ -146,7 +141,7 @@ } @Override - public void displayStats(final List timelines, final LongRange range) { + public void displayStats(final List timelines, final Range range) { SwingUtilities.invokeLater(new Runnable() { @Override diff -r f747a057d7a1 -r 85cd7afdf70f thread/client-swing/src/main/java/com/redhat/thermostat/thread/client/swing/impl/timeline/ThreadTimelineHeader.java --- a/thread/client-swing/src/main/java/com/redhat/thermostat/thread/client/swing/impl/timeline/ThreadTimelineHeader.java Fri Jun 07 11:29:06 2013 -0400 +++ b/thread/client-swing/src/main/java/com/redhat/thermostat/thread/client/swing/impl/timeline/ThreadTimelineHeader.java Fri Jun 07 11:38:33 2013 -0400 @@ -39,7 +39,7 @@ import javax.swing.JScrollPane; import com.redhat.thermostat.client.swing.components.timeline.TimelineRulerHeader; -import com.redhat.thermostat.common.model.LongRange; +import com.redhat.thermostat.common.model.Range; /** * @@ -49,7 +49,7 @@ private JScrollPane scrollpane; - public ThreadTimelineHeader(LongRange range, JScrollPane scrollpane) { + public ThreadTimelineHeader(Range range, JScrollPane scrollpane) { super(range); this.scrollpane = scrollpane; } diff -r f747a057d7a1 -r 85cd7afdf70f thread/client-swing/src/main/java/com/redhat/thermostat/thread/client/swing/impl/timeline/TimelineComponent.java --- a/thread/client-swing/src/main/java/com/redhat/thermostat/thread/client/swing/impl/timeline/TimelineComponent.java Fri Jun 07 11:29:06 2013 -0400 +++ b/thread/client-swing/src/main/java/com/redhat/thermostat/thread/client/swing/impl/timeline/TimelineComponent.java Fri Jun 07 11:38:33 2013 -0400 @@ -46,24 +46,14 @@ import java.awt.Rectangle; import java.beans.Transient; -import javax.swing.DefaultListModel; -import javax.swing.JFrame; -import javax.swing.JList; import javax.swing.JScrollPane; -import javax.swing.SwingUtilities; -import javax.swing.event.ChangeEvent; -import javax.swing.event.ChangeListener; import com.redhat.thermostat.client.swing.GraphicsUtils; import com.redhat.thermostat.client.swing.components.GradientPanel; - import com.redhat.thermostat.client.swing.components.timeline.TimelineUtils; - import com.redhat.thermostat.client.ui.Palette; - -import com.redhat.thermostat.common.model.LongRange; import com.redhat.thermostat.common.model.LongRangeNormalizer; - +import com.redhat.thermostat.common.model.Range; import com.redhat.thermostat.thread.client.common.Timeline; import com.redhat.thermostat.thread.client.common.TimelineInfo; @@ -74,12 +64,12 @@ private Timeline timeline; private JScrollPane scrollPane; - private LongRange range; + private Range range; private long millsUnitIncrement; private int pixelUnitIncrement; - public TimelineComponent(LongRange range, Timeline timeline, JScrollPane scrollPane) + public TimelineComponent(Range range, Timeline timeline, JScrollPane scrollPane) { super(Palette.LIGHT_GRAY.getColor(), Palette.WHITE.getColor()); this.range = range; @@ -210,7 +200,7 @@ } } - public LongRange getRange() { + public Range getRange() { return range; } diff -r f747a057d7a1 -r 85cd7afdf70f vm-heap-analysis/client-swing/src/main/java/com/redhat/thermostat/vm/heap/analysis/client/swing/internal/stats/HeapChartPanelLayout.java --- a/vm-heap-analysis/client-swing/src/main/java/com/redhat/thermostat/vm/heap/analysis/client/swing/internal/stats/HeapChartPanelLayout.java Fri Jun 07 11:29:06 2013 -0400 +++ b/vm-heap-analysis/client-swing/src/main/java/com/redhat/thermostat/vm/heap/analysis/client/swing/internal/stats/HeapChartPanelLayout.java Fri Jun 07 11:38:33 2013 -0400 @@ -46,7 +46,7 @@ import org.jfree.chart.axis.DateAxis; import org.jfree.chart.plot.XYPlot; -import com.redhat.thermostat.common.model.LongRange; +import com.redhat.thermostat.common.model.Range; import com.redhat.thermostat.common.model.LongRangeNormalizer; /** @@ -88,7 +88,7 @@ long max = domainAxis.getMaximumDate().getTime(); long min = domainAxis.getMinimumDate().getTime(); - LongRange offset = new LongRange(min, max); + Range offset = new Range(min, max); LongRangeNormalizer normaliser = new LongRangeNormalizer(offset); chartPanel.getScreenDataArea();