MutableProgram.java

Index Score
tvdataservice
TV-Browser

View: Reasons, Metrics, Source Code

These are the metrics that contribute to the Enerjy Score for this file, ranked by impact. So the metrics listed at the top influence the score to a greater extent that the metrics listed at the bottom.

MetricDescription
DECL_COMMENTSComments in declarations
DOC_COMMENTNumber of javadoc comment lines
COMPARISONSNumber of comparison operators
BLOCKSNumber of blocks
CYCLOMATICCyclomatic complexity
EXITSProcedure exits
COMMENTSComment lines
FUNCTIONSNumber of function declarations
LINESNumber of lines in the source file
RETURNSNumber of return points from functions
SIZESize of the file in bytes
INTERFACE_COMPLEXITYInterface complexity
JAVA0076JAVA0076 Use of magic number
OPERATORSNumber of operators
PROGRAM_LENGTHHalstead program length
LOCLines of code
OPERANDSNumber of operands
UNIQUE_OPERANDSNumber of unique operands
PARAMSNumber of formal parameter declarations
PROGRAM_VOCABHalstead program vocabulary
ELOCEffective lines of code
LOGICAL_LINESNumber of statements
WHITESPACENumber of whitespace lines
JAVA0034JAVA0034 Missing braces in if statement
EXEC_COMMENTSComments in executable code
UNIQUE_OPERATORSNumber of unique operators
JAVA0110JAVA0110 Incorrect javadoc: no @return tag
JAVA0144JAVA0144 Line exceeds maximum M characters
NEST_DEPTHMaximum nesting depth
PROGRAM_VOLUMEHalstead program volume
JAVA0136JAVA0136 N methods defined in class (maximum: M)
JAVA0126JAVA0126 Method declares unchecked exception in throws
JAVA0132JAVA0132 Method overload with compatible signature
JAVA0179JAVA0179 Local variable hides visible field
JAVA0100JAVA0100 Class contains N non-final fields (maximum: M)
JAVA0254JAVA0254 Use enhanced for loop construct instead of Iterator
JAVA0130JAVA0130 Non-static method does not use instance fields
JAVA0145JAVA0145 Tab character used in source file
/* * TV-Browser * Copyright (C) 04-2003 Martin Oberhauser (martin_oat@yahoo.de) * * This program 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 * of the License, or (at your option) any later version. * * This program 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 this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * CVS information: * $RCSfile$ * $Source$ * $Date: 2008-07-16 04:12:18 -0400 (Wed, 16 Jul 2008) $ * $Author: Bananeweizen $ * $Revision: 4866 $ */ package tvdataservice; import util.misc.StringPool; import util.program.ProgramUtilities; import devplugin.Channel; import devplugin.Date; import devplugin.Marker; import devplugin.Plugin; import devplugin.PluginAccess; import devplugin.Program; import devplugin.ProgramFieldType; import tvbrowser.core.TvDataBase; import tvbrowser.core.plugin.PluginProxy; import tvbrowser.core.plugin.PluginProxyManager; import util.io.IOUtilities; import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; import javax.swing.event.EventListenerList; import java.util.ArrayList; import java.util.Arrays; import java.util.Comparator; import java.util.HashMap; import java.util.Iterator; import java.util.TimeZone; import java.util.Vector; /** * One program. Consists of the Channel, the time, the title and some extra * information. * * @author Til Schneider, www.murfman.de */ public class MutableProgram implements Program { private static java.util.logging.Logger mLog = java.util.logging.Logger.getLogger(MutableProgram.class.getName()); private static TimeZone localTimeZone = TimeZone.getDefault(); /** * The maximum length of a short info. Used for generating a short info out of a * (long) description. */ public static final int MAX_SHORT_INFO_LENGTH = 200; /** A plugin array that can be shared by all the programs that are not marked * by any plugin. */ protected static final Marker[] EMPTY_MARKER_ARR = new Marker[0]; /** Contains all listeners that listen for events from this program. */ private Vector<ChangeListener> mListenerList; /** Contains all Plugins that mark this program. We use a simple array, * because it takes less memory. */ private Marker[] mMarkerArr; /** Tracks if the program is current loading/ being created. */ private boolean mIsLoading; /** The cached ID of this program. */ private String mId; /** The channel object of this program. */ private Channel mChannel; /** The date of the program in the channel's time zone. */ private Date mLocalDate; /** The normalized date of this program. (in the client's time zone) */ private Date mNormalizedDate; /** The normalized start time of the program. (in the client's time zone) */ private int mNormalizedStartTime; /** Contains for a {@link ProgramFieldType} (key) the field value. */ private HashMap<ProgramFieldType,Object> mFieldHash; /** The state of this program */ private int mState; /** Contains the title of the program if the program is marked */ private String mTitle; /** Contains the current mark priority of this program */ private int mMarkPriority = Program.NO_MARK_PRIORITY; /** * Creates a new instance of MutableProgram. * <p> * The parameters channel, date, hours and minutes build the ID. That's why they * are not mutable. * * @param channel The channel object of this program. * @param localDate The date of this program. * @param localHours The hour-component of the start time of the program. * @param localMinutes The minute-component of the start time of the program. * * @deprecated Since 2.2.2. Use {@link #MutableProgram(Channel, devplugin.Date, int, int, boolean)} instead. */ public MutableProgram(Channel channel, devplugin.Date localDate, int localHours, int localMinutes) { this (channel, localDate, localHours, localMinutes, false); } /** * Creates a new instance of MutableProgram. * <p> * The parameters channel, date, hours and minutes build the ID. That's why they * are not mutable. * * @param channel The channel object of this program. * @param localDate The date of this program. * @param localHours The hour-component of the start time of the program. * @param localMinutes The minute-component of the start time of the program. * @param isLoading If the program is curently being created. * * @see #setProgramLoadingIsComplete() */ public MutableProgram(Channel channel, devplugin.Date localDate, int localHours, int localMinutes, boolean isLoading) { this (channel, localDate, isLoading); int localStartTime = localHours * 60 + localMinutes; setTimeField(ProgramFieldType.START_TIME_TYPE, localStartTime); } /** * Creates a new instance of MutableProgram. * <p> * The parameters channel, date, hours and minutes build the ID. That's why they * are not mutable. * * @param channel The channel object of this program. * @param localDate The date of this program. * @param isLoading If the program is currently loading. * @see #setProgramLoadingIsComplete() */ public MutableProgram(Channel channel, devplugin.Date localDate, boolean isLoading) { if (channel == null) { throw new NullPointerException("channel is null"); } if (localDate == null) { throw new NullPointerException("localDate is null"); } mFieldHash = new HashMap<ProgramFieldType,Object>(8); mListenerList = null; // defer initialization until needed, to save memory mMarkerArr = EMPTY_MARKER_ARR; mIsLoading = isLoading; mTitle = null; // These attributes are not mutable, because they build the ID. mChannel = channel; mLocalDate = localDate; // The title is not-null. setTextField(ProgramFieldType.TITLE_TYPE, ""); mMarkerArr = EMPTY_MARKER_ARR; mState = IS_VALID_STATE; } private void normalizeTimeZone(Date localDate, int localStartTime) { TimeZone channelTimeZone=mChannel.getTimeZone(); int timeZoneOffset=(localTimeZone.getRawOffset()-channelTimeZone.getRawOffset())/60000; timeZoneOffset+=mChannel.getDayLightSavingTimeCorrection()*60; mNormalizedStartTime = localStartTime + timeZoneOffset; mNormalizedDate=localDate; if (mNormalizedStartTime >= (24 * 60)) { mNormalizedStartTime -= (24 * 60); mNormalizedDate = mNormalizedDate.addDays(1); } else if (mNormalizedStartTime < 0) { mNormalizedStartTime += (24 * 60); mNormalizedDate = mNormalizedDate.addDays(-1); } } /** * Adds a ChangeListener to the program. * * @param listener the ChangeListener to add * @see #fireStateChanged * @see #removeChangeListener */ public void addChangeListener(ChangeListener listener) { if (mListenerList == null) { mListenerList = new Vector<ChangeListener>(1); } if (!mListenerList.contains(listener)) { mListenerList.add(listener); } } /** * Removes a ChangeListener from the program. * * @param listener the ChangeListener to remove * @see #fireStateChanged * @see #addChangeListener */ public void removeChangeListener(ChangeListener listener) { if (mListenerList == null) { return; } mListenerList.remove(listener); } /** * Send a ChangeEvent, whose source is this program, to each listener. * * @see #addChangeListener * @see EventListenerList */ protected void fireStateChanged() { if (mListenerList == null) { return; } ChangeEvent changeEvent = new ChangeEvent(this); for (int i = 0; i < mListenerList.size(); i++) { mListenerList.get(i).stateChanged(changeEvent); } } public final String getTimeString() { return IOUtilities.timeToString(getStartTime()); } public final String getEndTimeString() { return IOUtilities.timeToString(getStartTime() + getLength()); } public final String getDateString() { Date d = getDate(); if (d == null) { mLog.info(mChannel.getName() + " at " + getHours() + ":" + getMinutes() + ", NO DATE : '" + getTitle() + "'"); return ""; } return d.toString(); } /** * Gets whether this program is marked as "on air". */ public boolean isOnAir() { return ProgramUtilities.isOnAir(this); } /** * Marks the program for a Java plugin. * * @param javaPlugin The plugin to mark the program for. */ public final void mark(Plugin javaPlugin) { PluginAccess plugin = PluginProxyManager.getInstance().getPluginForId(javaPlugin.getId()); mark(plugin); } /** * Removes the marks from the program for a Java plugin. * <p> * If the program wasn't marked for the plugin, nothing happens. * * @param javaPlugin The plugin to remove the mark for. */ public final void unmark(Plugin javaPlugin) { PluginAccess plugin = PluginProxyManager.getInstance().getPluginForId(javaPlugin.getId()); unmark(plugin); } /** * Marks the program for a plugin. * * @param marker The plugin to mark the program for. */ public final void mark(Marker marker) { if(mState == Program.IS_VALID_STATE) { boolean alreadyMarked = getMarkedByPluginIndex(marker) != -1; int oldCount = mMarkerArr.length; if (! alreadyMarked) { // Append the new plugin Marker[] newArr = new Marker[oldCount + 1]; System.arraycopy(mMarkerArr, 0, newArr, 0, oldCount); newArr[oldCount] = marker; mMarkerArr = newArr; Arrays.sort(mMarkerArr,new Comparator<Marker>() { public int compare(Marker o1, Marker o2) { return o1.getId().compareTo(o2.getId()); } }); mMarkPriority = Math.max(mMarkPriority,marker.getMarkPriorityForProgram(this)); // add program to artificial plugin tree if (marker instanceof PluginProxy) { PluginProxy proxy = (PluginProxy) marker; if (! proxy.canUseProgramTree() || proxy.hasArtificialPluginTree() ) { if (proxy.getArtificialRootNode() == null || proxy.getArtificialRootNode().size() < 100) { proxy.addToArtificialPluginTree(this); } } } fireStateChanged(); } if(oldCount < 1) { mTitle = getTitle(); MarkedProgramsList.getInstance().addProgram(this); } } else if(mState == Program.WAS_UPDATED_STATE) { Program p = Plugin.getPluginManager().getProgram(getDate(), getID()); if(p != null) { p.mark(marker); } } } /** * Removes the marks from the program for a plugin. * <p> * If the program wasn't marked for the plugin, nothing happens. * * @param marker The plugin to remove the mark for. */ public final void unmark(Marker marker) { if(mState == Program.IS_VALID_STATE) { int idx = getMarkedByPluginIndex(marker); if (idx != -1) { if (mMarkerArr.length == 1) { // This was the only plugin mMarkerArr = EMPTY_MARKER_ARR; mMarkPriority = Program.NO_MARK_PRIORITY; } else { int oldCount = mMarkerArr.length; Marker[] newArr = new Marker[oldCount - 1]; System.arraycopy(mMarkerArr, 0, newArr, 0, idx); System.arraycopy(mMarkerArr, idx + 1, newArr, idx, oldCount - idx - 1); mMarkPriority = Program.NO_MARK_PRIORITY; for(Marker mark : newArr) { mMarkPriority = Math.max(mMarkPriority,mark.getMarkPriorityForProgram(this)); } mMarkerArr = newArr; } // remove from artificial plugin tree if (marker instanceof PluginProxy) { PluginProxy proxy = (PluginProxy) marker; if (proxy.hasArtificialPluginTree() && proxy.getArtificialRootNode().size() < 100) { proxy.getArtificialRootNode().removeProgram(this); } } fireStateChanged(); } if(mMarkerArr.length < 1) { mTitle = null; MarkedProgramsList.getInstance().removeProgram(this); } } else if(mState == Program.WAS_UPDATED_STATE) { Program p = Plugin.getPluginManager().getProgram(getDate(), getID()); if(p != null) { p.unmark(marker); } } } private int getMarkedByPluginIndex(Marker plugin) { for (int i = 0; i < mMarkerArr.length; i++) { if (mMarkerArr[i].getId().compareTo(plugin.getId()) == 0) { return i; } } return -1; } /** * Gets all {@link devplugin.Plugin}s that have marked this program. * @deprecated use {@link #getMarkerArr} */ public PluginAccess[] getMarkedByPlugins() { PluginAccess plugin; ArrayList<PluginAccess> list = new ArrayList<PluginAccess>(); for (Marker marker : mMarkerArr) { plugin = PluginProxyManager.getInstance().getPluginForId(marker.getId()); if (plugin != null) { list.add(plugin); } } return list.toArray(new PluginAccess[list.size()]); } public Marker[] getMarkerArr() { return mMarkerArr; } /** * Gets whether this program is expired. */ public boolean isExpired() { devplugin.Date today = Date.getCurrentDate(); int comp = today.compareTo(getDate()); if (comp < 0) { return false; } if (comp > 0) { return ! isOnAir(); } // This program is (or was) today -> We've got to check the time int currentMinutesAfterMidnight = IOUtilities.getMinutesAfterMidnight(); int programMinutesAfterMidnight = getStartTime() + getLength() - 1; return (programMinutesAfterMidnight < currentMinutesAfterMidnight); } /** * Gets the ID of this program. This ID is unique for a certain date. * * @return The ID of this program. */ public String getID() { if (mId == null) { if (mChannel.getDataServiceProxy() != null) { String dataServiceId = mChannel.getDataServiceProxy().getId(); String groupId = mChannel.getGroup().getId(); String channelId = mChannel.getId(); String country = mChannel.getCountry(); mId = (new StringBuffer(dataServiceId).append("_").append(groupId).append("_").append(country).append("_").append(channelId).append("_").append(getHours()).append(":").append(getMinutes()).append(":").append(TimeZone.getDefault().getRawOffset()/60000)).toString(); } } return mId; } // FieldHash public byte[] getBinaryField(ProgramFieldType type) { return (byte[]) getField(type, ProgramFieldType.BINARY_FORMAT); } public String getTextField(ProgramFieldType type) { String value = (String) getField(type, ProgramFieldType.TEXT_FORMAT); if (type == ProgramFieldType.SHORT_DESCRIPTION_TYPE) { value = validateShortInfo(value); } return value; } public int getIntField(ProgramFieldType type) { Integer value = (Integer) getField(type, ProgramFieldType.INT_FORMAT); if (value == null) { return -1; } else { return value.intValue(); } } /** * Gets the value of a int field as String. * * @param type The type of the wanted field. Must have a int format. * @return The value of the field as String or <code>null</code>, if there is * no value for this field. */ public String getIntFieldAsString(ProgramFieldType type) { int value = getIntField(type); if (value == -1) { return null; } else { return Integer.toString(value); } } public int getTimeField(ProgramFieldType type) { Integer value = (Integer) getField(type, ProgramFieldType.TIME_FORMAT); if (value == null) { return -1; } else { return value.intValue(); } } /** * Gets the value of a time field as String of the pattern "h:mm". * * @param type The type of the wanted field. Must have a time format. * @return The value of the field as String or <code>null</code>, if there is * no value for this field. */ public String getTimeFieldAsString(ProgramFieldType type) { int value = getTimeField(type); if (value == -1) { return null; } else { int hours = value / 60; int minutes = value % 60; // Correct the TimeZone TimeZone channelTimeZone=mChannel.getTimeZone(); TimeZone localTimeZone=TimeZone.getDefault(); int timeZoneOffset=(localTimeZone.getRawOffset()-channelTimeZone.getRawOffset())/3600000; timeZoneOffset+=mChannel.getDayLightSavingTimeCorrection(); hours = hours + timeZoneOffset; if (hours >= 24) { hours -= 24; } else if (hours < 0) { hours += 24; } return new StringBuffer().append(hours).append(":").append((minutes < 10) ? "0" : "").append(minutes).toString(); } } protected Object getField(ProgramFieldType type, int fieldFormat) { if (type.getFormat() != fieldFormat) { throw new IllegalArgumentException("The field " + type.getName() + " can't be read as " + ProgramFieldType.getFormatName(fieldFormat) + ", because it is " + ProgramFieldType.getFormatName(type.getFormat())); } synchronized (mFieldHash) { return mFieldHash.get(type); } } /** * Gets the number of fields this program has. * * @return the number of fields this program has. */ public int getFieldCount() { return mFieldHash.size(); } /** * Gets an iterator over the types of all fields this program has. * * @return an iterator over {@link ProgramFieldType}s. */ public Iterator<ProgramFieldType> getFieldIterator() { return mFieldHash.keySet().iterator(); } /** * Set a binary field. * * @param type The type of the field. * @param value The binary value to set. */ public void setBinaryField(ProgramFieldType type, byte[] value) { setField(type, ProgramFieldType.BINARY_FORMAT, value); } /** * Set a text field. * * @param type The type of the field. * @param value The text value to set. */ public void setTextField(ProgramFieldType type, String value) { // Special field treating if (type == ProgramFieldType.SHORT_DESCRIPTION_TYPE) { value = validateShortInfo(value); } // filter all the duplicate origin fields if (type == ProgramFieldType.ORIGIN_TYPE) { setField(type, ProgramFieldType.TEXT_FORMAT, StringPool.getString(value)); } else { setField(type, ProgramFieldType.TEXT_FORMAT, value); } } /** * Set an int field. * * @param type The type of the field. * @param value The int value to set. */ public void setIntField(ProgramFieldType type, int value) { if (type == ProgramFieldType.RATING_TYPE && (value < 0 || (value > 100))) { mLog.warning("The value for field " + type.getName() + " must be between in [0..100], but it was set to " + value+"; program: "+toString()); value = -1; } Integer obj = null; if (value != -1) { obj = new Integer(value); } setField(type, ProgramFieldType.INT_FORMAT, obj); } /** * Set a time field. * * @param type The type of the field. * @param value The time value to set. */ public void setTimeField(ProgramFieldType type, int value) { if ((value < 0) || (value >= (24 * 60))) { mLog.warning("The time value for field " + type.getName() + " must be between in [0..1439], but it was set to " + value+"; program: "+toString()); } Integer obj = null; if (value != -1) { obj = new Integer(value); } setField(type, ProgramFieldType.TIME_FORMAT, obj); if (type == ProgramFieldType.START_TIME_TYPE) { normalizeTimeZone(mLocalDate, value); } } protected void setField(ProgramFieldType type, int fieldFormat, Object value) { if (type.getFormat() != fieldFormat) { throw new IllegalArgumentException("The field " + type.getName() + " can't be written as " + ProgramFieldType.getFormatName(fieldFormat) + ", because it is " + ProgramFieldType.getFormatName(type.getFormat())); } synchronized (mFieldHash) { if (value == null) { mFieldHash.remove(type); } else { if (value.equals("")) { mFieldHash.put(type, StringPool.getString("")); } else { mFieldHash.put(type, value); } } } try { if(!mIsLoading) { ((MutableChannelDayProgram)TvDataBase.getInstance().getDayProgram(getDate(),getChannel())).setWasChangedByPlugin(); } }catch(Exception e) {} fireStateChanged(); } /** * Trim text for shortinfo-field * @param shortInfo generate Text from this field * @return Text that fits into shortInfo * @since 2.7 */ public static String generateShortInfoFromDescription(String shortInfo) { // Get the end of the last fitting sentence int lastDot = shortInfo.lastIndexOf('.', MAX_SHORT_INFO_LENGTH); int n = shortInfo.lastIndexOf('!', MAX_SHORT_INFO_LENGTH); if (n > lastDot) { lastDot = n; } n = shortInfo.lastIndexOf('?', MAX_SHORT_INFO_LENGTH); if (n > lastDot) { lastDot = n; } n = shortInfo.lastIndexOf(" - ", MAX_SHORT_INFO_LENGTH); if (n > lastDot) { lastDot = n; } int lastMidDot = shortInfo.lastIndexOf('\u00b7', MAX_SHORT_INFO_LENGTH); int cutIdx = Math.max(lastDot, lastMidDot); // But show at least half the maximum length if (cutIdx < (MAX_SHORT_INFO_LENGTH / 2)) { cutIdx = shortInfo.lastIndexOf(' ', MAX_SHORT_INFO_LENGTH); } return shortInfo.substring(0, cutIdx + 1) + "..."; } private String validateShortInfo(String shortInfo) { if ((shortInfo != null) && (shortInfo.length() > MAX_SHORT_INFO_LENGTH + 4)) { shortInfo = generateShortInfoFromDescription(shortInfo); mLog.warning("Short description longer than " + MAX_SHORT_INFO_LENGTH + " characters: ("+shortInfo.length()+") " + this.toString()); } return shortInfo; } /** * Sets the title of this program. * * @param title the new title of this program. */ public void setTitle(String title) { if(mTitle != null) { mTitle = title; } setTextField(ProgramFieldType.TITLE_TYPE, title); } /** * Returns the title of this program. * * @return the title of this program. */ public String getTitle() { if(mTitle != null) { return mTitle; } else { return getTextField(ProgramFieldType.TITLE_TYPE); } } /** * Sets a short information about the program (about three lines). May be null. * <p> * If the length of the short info exceeds 100 characters it will be cut using * a smart algorithm. * * @param shortInfo The new short info. */ public void setShortInfo(String shortInfo) { setTextField(ProgramFieldType.SHORT_DESCRIPTION_TYPE, shortInfo); } /** * Returns a short information about the program (about three lines). May be null. * * @return The short info. */ public String getShortInfo() { return getTextField(ProgramFieldType.SHORT_DESCRIPTION_TYPE); } /** * Sets a description about the program. May be null. * * @param description The description. */ public void setDescription(String description) { setTextField(ProgramFieldType.DESCRIPTION_TYPE, description); } /** * Returns a description about the program. May be null. * * @return The description. */ public String getDescription() { return getTextField(ProgramFieldType.DESCRIPTION_TYPE); } /** * Gets the the start time of the program in minutes after midnight. * * @return the start time. */ public int getStartTime() { return mNormalizedStartTime; } /** * Gets the hour-component of the start time of the program. * * @return the hour-component of the start time. */ public int getHours() { return mNormalizedStartTime / 60; } /** * Gets the minute-component of the start time of the program. * * @return the minute-component of the start time. */ public int getMinutes() { return mNormalizedStartTime % 60; } /** * @return The local start time. */ public int getLocalStartTime() { return getTimeField(ProgramFieldType.START_TIME_TYPE); } /** * Sets the length of this program in minutes. * * @param length the new length. */ public void setLength(int length) { int startTime = getTimeField(ProgramFieldType.START_TIME_TYPE); int endTime = startTime + length; if (endTime >= (24 * 60)) { endTime -= (24 * 60); } setTimeField(ProgramFieldType.END_TIME_TYPE, endTime); } /** * Gets the length of this program in minutes. * * @return the length. */ public int getLength() { int endTime = getTimeField(ProgramFieldType.END_TIME_TYPE); if (endTime == -1) { return -1; } int startTime = getTimeField(ProgramFieldType.START_TIME_TYPE); if (endTime < startTime) { endTime += (24 * 60); } return endTime - startTime; } /** * Sets additional information of the program (or zero). * * @param info The new additional information. */ public void setInfo(int info) { setIntField(ProgramFieldType.INFO_TYPE, info); } /** * Returns additional information of the program (or zero). * * @return the new additional information. */ public int getInfo() { return getIntField(ProgramFieldType.INFO_TYPE); } /** * Returns the channel object of this program. * * @return The channel. */ public Channel getChannel() { return mChannel; } /** * Returns the date of this program. * * @return the date. */ public devplugin.Date getDate() { return mNormalizedDate; } /** * @return The local date */ public devplugin.Date getLocalDate() { return mLocalDate; } /** * Gets a String representation of this program for debugging. * * @return A String representation for debugging. */ public String toString() { return "On " + mChannel.getName() + " at " + getHours() + ":" + getMinutes() + ", " + getDateString() + ": '" + getTitle() + "'"; } public boolean equals(Object o) { if (o instanceof devplugin.Program) { devplugin.Program program = (devplugin.Program)o; return program!=null && getStartTime() == program.getStartTime() && equals(mChannel, program.getChannel()) && equals(getDate(), program.getDate()) && getTitle().compareTo(program.getTitle()) == 0; } return false; } /** * check if two programs are identical by their field contents * * @param program * @return <code>true</code>, if all fields are equal * @since 2.6 */ public boolean equalsAllFields(MutableProgram program) { if (!equals(program)) { return false; } if (mFieldHash.size() != program.mFieldHash.size()) { return false; } Iterator<ProgramFieldType> it = mFieldHash.keySet().iterator(); while (it.hasNext()) { ProgramFieldType fieldType = it.next(); Object thisValue = getField(fieldType, fieldType.getFormat()); Object otherValue = program.getField(fieldType, fieldType.getFormat()); if (!thisValue.equals(otherValue)) { return false; } } return true; } /** * Gets whether two objects are equal. Can handle null values. * * @param o1 The first object. * @param o2 The second object. * @return Whether the two objects are equal. */ private boolean equals(Object o1, Object o2) { if ((o1 == null) || (o2 == null)) { return (o1 == o2); } else { return o1.equals(o2); } } /** * Sets the state of this program to a * program state. * * @param state The state of this program. * @since 2.2 */ protected void setProgramState(int state) { mState = state; } /** * Returns the state of this program. * * @return The program state. * @since 2.2 */ public int getProgramState() { return mState; } /** * Informs the ChangeListeners for repainting if a Plugin * uses more than one Icon for the Program. * * @since 2.2.2 */ public final void validateMarking() { mMarkPriority = Program.NO_MARK_PRIORITY; for(Marker mark : mMarkerArr) { mMarkPriority = Math.max(mMarkPriority,mark.getMarkPriorityForProgram(this)); } fireStateChanged(); } /** * Sets the marker array of this program. * * @param marker The marker array. * @since 2.2.1 */ protected void setMarkerArr(Marker[] marker) { if (marker.length == 0) { mMarkerArr = EMPTY_MARKER_ARR; } else { mMarkerArr = marker; if(marker.length > 0) { mTitle = getTitle(); } } //fireStateChanged(); } /** * Sets the loading state to false. * Call this after creation of the program from the data service. * * @since 2.2.2 */ public void setProgramLoadingIsComplete() { mIsLoading = false; } /** * Gets the priority of the marking of this program. * * @return The mark priority. * @since 2.5.1 */ public int getMarkPriority() { return mMarkPriority; } /** * Sets the mark priority for this program * * @since 2.5.1 */ protected void setMarkPriority(int markPriority) { mMarkPriority = markPriority; } }

The table below shows all metrics for MutableProgram.java.

MetricValueDescription
BLOCKS153.00Number of blocks
BLOCK_COMMENT25.00Number of block comment lines
COMMENTS360.00Comment lines
COMMENT_DENSITY 0.86Comment density
COMPARISONS114.00Number of comparison operators
CYCLOMATIC149.00Cyclomatic complexity
DECL_COMMENTS67.00Comments in declarations
DOC_COMMENT321.00Number of javadoc comment lines
ELOC421.00Effective lines of code
EXEC_COMMENTS13.00Comments in executable code
EXITS110.00Procedure exits
FUNCTIONS65.00Number of function declarations
HALSTEAD_DIFFICULTY92.63Halstead difficulty
HALSTEAD_EFFORT 0.00Halstead effort
INTERFACE_COMPLEXITY142.00Interface complexity
JAVA0001 0.00JAVA0001 Package name does not contain only lower case letters
JAVA0002 1.00JAVA0002 Package name does not begin with a top level domain name or country code
JAVA0003 0.00JAVA0003 Minimize use of on-demand (.*) imports
JAVA0004 0.00JAVA0004 Unnecessary import from java.lang
JAVA0005 1.00JAVA0005 Imports not in specified order
JAVA0006 0.00JAVA0006 Empty finally block
JAVA0007 0.00JAVA0007 Should not declare public field
JAVA0008 1.00JAVA0008 Empty catch block
JAVA0009 0.00JAVA0009 Protected member in final class
JAVA0010 0.00JAVA0010 Non-instantiable class does not contain a non-private static member
JAVA0011 0.00JAVA0011 Abstract class does not contain an abstract method
JAVA0012 0.00JAVA0012 Non-constructor method with same name as declaring class
JAVA0013 0.00JAVA0013 Non-blank final field is not static
JAVA0014 0.00JAVA0014 Class with only static members has non-private constructor
JAVA0015 0.00JAVA0015 Package class contains public nested type
JAVA0016 0.00JAVA0016 Abstract class contains public constructor
JAVA0017 0.00JAVA0017 Class name does not have required form
JAVA0018 0.00JAVA0018 Method name does not have required form
JAVA0019 0.00JAVA0019 Interface name does not have required form
JAVA0020 0.00JAVA0020 Field name does not have required form
JAVA0021 0.00JAVA0021 Interface method name does not have required form
JAVA0022 0.00JAVA0022 Static final field name does not have required form
JAVA0023 0.00JAVA0023 Empty finalize method
JAVA0024 0.00JAVA0024 Empty class
JAVA0025 0.00JAVA0025 Method override is empty
JAVA0026 0.00JAVA0026 Finalize method with parameters
JAVA0029 0.00JAVA0029 Private method not used
JAVA0030 0.00JAVA0030 Private field not used
JAVA0031 0.00JAVA0031 Case statement not properly closed
JAVA0032 0.00JAVA0032 Switch statement missing default
JAVA0033 0.00JAVA0033 default: not last case in switch statement
JAVA0034 0.00JAVA0034 Missing braces in if statement
JAVA0035 0.00JAVA0035 Missing braces in for statement
JAVA0036 0.00JAVA0036 Missing braces in while statement
JAVA0038 0.00JAVA0038 Non-case label in switch statement
JAVA0039 0.00JAVA0039 Break statement with label
JAVA0040 0.00JAVA0040 Switch statement contains N cases (maximum: M)
JAVA0041 0.00JAVA0041 Nested synchronized block
JAVA0042 0.00JAVA0042 Empty synchronized statement
JAVA0043 0.00JAVA0043 Inner class does not use outer class
JAVA0044 0.00JAVA0044 Serializable class with no instance variables
JAVA0045 0.00JAVA0045 Serializable class with only transient fields
JAVA0046 0.00JAVA0046 Name of class not derived from Exception ends with 'Exception'
JAVA0047 0.00JAVA0047 Serializable class derives from invalid base class
JAVA0048 0.00JAVA0048 Name of class derived from Exception does not end with 'Exception'
JAVA0049 1.00JAVA0049 Nested block at depth N (maximum: M)
JAVA0050 0.00JAVA0050 Class derives from java.lang.Error
JAVA0051 0.00JAVA0051 Class derives from java.lang.RuntimeException
JAVA0052 0.00JAVA0052 Class derives from java.lang.Throwable
JAVA0053 0.00JAVA0053 Unused label
JAVA0054 0.00JAVA0054 Inheritance depth N exceeds maximum M
JAVA0055 0.00JAVA0055 Class should be interface
JAVA0056 0.00JAVA0056 Unnecessary abstract modifier for interface or annotation
JAVA0057 0.00JAVA0057 Unnecessary default constructor
JAVA0058 0.00JAVA0058 Constructor calls super()
JAVA0059 0.00JAVA0059 Method override only calls super()
JAVA0061 0.00JAVA0061 Inaccessible member in anonymous class
JAVA0062 0.00JAVA0062 Public class missing public member or protected constructor
JAVA0063 0.00JAVA0063 Identifier name should not contain '$'
JAVA0064 0.00JAVA0064 N variations of identifier name (maximum: M)
JAVA0065 0.00JAVA0065 Unnecessary final modifier for method in final class
JAVA0066 0.00JAVA0066 Unnecessary modifier for interface nested type
JAVA0067 0.00JAVA0067 Array descriptor on identifier name
JAVA0068 0.00JAVA0068 Modifiers not declared in recommended order
JAVA0071 0.00JAVA0071 Strings compared with ==
JAVA0073 0.00JAVA0073 Integer division in floating-point context
JAVA0074 0.00JAVA0074 Use of Object.notify()
JAVA0075 0.00JAVA0075 Method parameter hides field
JAVA007628.00JAVA0076 Use of magic number
JAVA0077 0.00JAVA0077 Private field not used in declaring class
JAVA0078 0.00JAVA0078 Floating point values compared with ==
JAVA0079 0.00JAVA0079 Use of instance to reference static member
JAVA0080 0.00JAVA0080 Import declaration not used
JAVA0081 0.00JAVA0081 Boolean literal in comparison
JAVA0082 0.00JAVA0082 Unnecessary widening cast
JAVA0083 0.00JAVA0083 Unnecessary instanceof test
JAVA0084 1.00JAVA0084 Should use compound assignment operator
JAVA0085 0.00JAVA0085 Use of sun.* class
JAVA0087 0.00JAVA0087 Use of Thread.sleep()
JAVA0089 0.00JAVA0089 Use of restricted package
JAVA0092 0.00JAVA0092 Use of restricted type
JAVA0093 0.00JAVA0093 Redundant assignment
JAVA0094 0.00JAVA0094 Field hides a superclass field
JAVA0095 0.00JAVA0095 Uninitialized private field
JAVA0096 0.00JAVA0096 Field in nested class hides outer field
JAVA0098 0.00JAVA0098 Minimize use of implicit field initializers
JAVA0100 1.00JAVA0100 Class contains N non-final fields (maximum: M)
JAVA0101 0.00JAVA0101 Unnecessary modifier for field in interface
JAVA0102 0.00JAVA0102 Last statement in finalize() not super.finalize()
JAVA0103 0.00JAVA0103 Explicit call to finalize()
JAVA0104 0.00JAVA0104 finalize() only calls super.finalize()
JAVA0105 0.00JAVA0105 Duplicate import declaration
JAVA0106 0.00JAVA0106 Unnecessary import from current package
JAVA0108 1.00JAVA0108 Incorrect javadoc: no @param tag for 'parameter'
JAVA0109 0.00JAVA0109 Incorrect javadoc: no parameter 'parameter'
JAVA0110 3.00JAVA0110 Incorrect javadoc: no @return tag
JAVA0111 0.00JAVA0111 Incorrect javadoc: @return tag for void method
JAVA0112 0.00JAVA0112 Incorrect javadoc: no exception 'exception' in throws
JAVA0113 0.00JAVA0113 Incorrect javadoc: no @author tag
JAVA0114 1.00JAVA0114 Incorrect javadoc: no @version tag
JAVA0115 0.00JAVA0115 Incorrect javadoc: no @throws or @exception tag for 'exception'
JAVA0116 0.00JAVA0116 Missing javadoc: field 'field'
JAVA0117 2.00JAVA0117 Missing javadoc: method 'method'
JAVA0118 0.00JAVA0118 Missing javadoc: type 'type'
JAVA0119 0.00JAVA0119 Control variable changed within body of for loop
JAVA0123 0.00JAVA0123 Use all three components of for loop
JAVA0125 0.00JAVA0125 Continue statement with label
JAVA0126 0.00JAVA0126 Method declares unchecked exception in throws
JAVA0128 0.00JAVA0128 Public constructor in non-public class
JAVA0130 1.00JAVA0130 Non-static method does not use instance fields
JAVA0131 0.00JAVA0131 Compatible method does not override base
JAVA0132 2.00JAVA0132 Method overload with compatible signature
JAVA0133 0.00JAVA0133 Non-synchronized method overrides synchronized method
JAVA0135 1.00JAVA0135 Only one of Object.equals and Object.hashCode defined: missing 'method'
JAVA0136 1.00JAVA0136 N methods defined in class (maximum: M)
JAVA0137 0.00JAVA0137 Non-abstract class missing constructor
JAVA0138 0.00JAVA0138 N parameters defined for method (maximum: M)
JAVA0139 0.00JAVA0139 Definition of main other than public static void main(java.lang.String[])
JAVA0141 0.00JAVA0141 Unnecessary modifier for method in interface
JAVA0143 0.00JAVA0143 Synchronized method
JAVA0144 2.00JAVA0144 Line exceeds maximum M characters
JAVA0145 2.00JAVA0145 Tab character used in source file
JAVA0150 0.00JAVA0150 java.lang.Error (or subclass) thrown
JAVA0153 0.00JAVA0153 Inefficient conversion of integer to string
JAVA0159 0.00JAVA0159 Inefficient conversion of string to integer
JAVA0160 0.00JAVA0160 Method does not throw specified exception
JAVA0161 0.00JAVA0161 Conditional wait() not in loop
JAVA0163 0.00JAVA0163 Empty statement
JAVA0165 0.00JAVA0165 Conflicting return statement in finally block
JAVA0166 1.00JAVA0166 Generic exception caught
JAVA0167 0.00JAVA0167 ThreadDeath not rethrown
JAVA0169 0.00JAVA0169 Unnecessary catch block: exception 'exception'
JAVA0170 0.00JAVA0170 Caught exception not derived from java.lang.Exception
JAVA0171 0.00JAVA0171 Unused local variable
JAVA0173 0.00JAVA0173 Unused method parameter
JAVA0174 0.00JAVA0174 Assigned local variable never used
JAVA0175 0.00JAVA0175 Successive assignment to variable
JAVA0176 0.00JAVA0176 Local variable name does not have required form
JAVA0177 1.00JAVA0177 Variable declaration missing initializer
JAVA0179 1.00JAVA0179 Local variable hides visible field
JAVA0233 0.00JAVA0233 Definition of serialVersionUID other than 'private static final long serialVersionUID'
JAVA0234 0.00JAVA0234 Class is Serializable but does not define serialVersionUID
JAVA0235 0.00JAVA0235 Class defines serialVersionUID but does not implement Serializable
JAVA0236 0.00JAVA0236 Attempt to clone an object which does not implement Cloneable
JAVA0237 0.00JAVA0237 Class implements Cloneable but does not have public clone method
JAVA0238 0.00JAVA0238 Clone method does not call super.clone()
JAVA0239 0.00JAVA0239 Class declares 'readObject' or 'writeObject' but does not implement Serializable
JAVA0240 0.00JAVA0240 Serializable class which declares readObject or writeObject but not both
JAVA0241 0.00JAVA0241 'readObject' or 'writeObject' should be declared private in Serializable class
JAVA0242 0.00JAVA0242 Transient field in non-Serializable class
JAVA0243 0.00JAVA0243 'readResolve' or 'writeReplace' should be declared private or protected
JAVA0244 0.00JAVA0244 Field or method name in subclass differs only by case from inherited field or method
JAVA0245 0.00JAVA0245 JUnit TestCase with non-trivial constructor
JAVA0246 0.00JAVA0246 JUnit assertXXX statement missing message parameter
JAVA0247 0.00JAVA0247 JUnit 'setUp()' and 'tearDown()' should call super method
JAVA0248 0.00JAVA0248 JUnit method 'setUp' or 'tearDown' with incorrect signature
JAVA0249 0.00JAVA0249 JUnit TestCase 'suite()' should be declared static
JAVA0250 0.00JAVA0250 JUnit TestCase declares testXXX method with incorrect signature
JAVA0251 0.00JAVA0251 Use '%n' for line breaks in printf/format for platform independence
JAVA0252 0.00JAVA0252 'enum' is a Java 1.5 reserved word
JAVA0253 0.00JAVA0253 Not all enum constants consumed in switch statement
JAVA0254 1.00JAVA0254 Use enhanced for loop construct instead of Iterator
JAVA0255 0.00JAVA0255 Result of method invocation not used
JAVA0256 1.00JAVA0256 Assignment of external collection/array to field
JAVA0257 0.00JAVA0257 Use of 'Constant Interface' anti-pattern
JAVA0258 1.00JAVA0258 Implement Iterable for foreach compatibility
JAVA0259 1.00JAVA0259 Return of collection/array field
JAVA0260 0.00JAVA0260 Use 'enum' instead of Enumerated Type pattern
JAVA0261 0.00JAVA0261 Use specialized Enum collection types
JAVA0262 0.00JAVA0262 Use of char in integer context
JAVA0263 0.00JAVA0263 Long literal ends with 'l' instead of 'L'
JAVA0264 0.00JAVA0264 Integer math in long context - check for overflow
JAVA0265 0.00JAVA0265 Use of Throwable.printStackTrace()
JAVA0266 0.00JAVA0266 Use of System.out
JAVA0267 0.00JAVA0267 Use of System.err
JAVA0269 0.00JAVA0269 Contents of StringBuffer never used
JAVA0270 0.00JAVA0270 Use Java 5.0 enhanced for loop construct to iterate over all elements in an array
JAVA0271 0.00JAVA0271 Minimize use of on-demand (.*) static imports
JAVA0272 0.00JAVA0272 Thread.run() called
JAVA0273 0.00JAVA0273 Non-final derivative of Thread calls start() in constructor
JAVA0274 0.00JAVA0274 Serializable class has a synchronized readObject()
JAVA0275 0.00JAVA0275 Serializable class has a synchronized writeObject() and no other synchronized methods
JAVA0276 0.00JAVA0276 Unnecessary use of String constructor
JAVA0277 0.00JAVA0277 Iterator.next() implementation does not throw NoSuchElementException
JAVA0278 0.00JAVA0278 Unnecessary use of Boolean constructor
JAVA0279 0.00JAVA0279 Serialization method readObject or readObjectNoData calls an overridable method
JAVA0280 0.00JAVA0280 IllegalMonitorStateException caught
JAVA0281 0.00JAVA0281 Iterator.next() not called in loop
JAVA0282 0.00JAVA0282 Call to Iterator.next() in loop which does not test Iterator.hasNext()
JAVA0283 0.00JAVA0283 Control variable not updated in loop body
JAVA0284 0.00JAVA0284 Explicit garbage collection
JAVA0285 0.00JAVA0285 Dereference of potentially null variable
JAVA0286 0.00JAVA0286 Dereference of null variable
JAVA0287 0.00JAVA0287 Unnecessary null check
JAVA0288 0.00JAVA0288 Inconsistent null check
LINES1117.00Number of lines in the source file
LINE_COMMENT14.00Number of line comments
LOC568.00Lines of code
LOGICAL_LINES255.00Number of statements
LOOPS 3.00Number of loops
NEST_DEPTH 6.00Maximum nesting depth
OPERANDS1277.00Number of operands
OPERATORS2546.00Number of operators
PARAMS56.00Number of formal parameter declarations
PROGRAM_LENGTH3823.00Halstead program length
PROGRAM_VOCAB442.00Halstead program vocabulary
PROGRAM_VOLUME 0.00Halstead program volume
RETURNS86.00Number of return points from functions
SIZE30121.00Size of the file in bytes
UNIQUE_OPERANDS386.00Number of unique operands
UNIQUE_OPERATORS56.00Number of unique operators
WHITESPACE189.00Number of whitespace lines