import java.util.Set;
import java.util.HashSet;
/**
* Implementation of the WidgetCatalog interface. Please see the interface
* for the specification.
*/
public class WidgetCatalogImpl implements WidgetCatalog
{
// using JDK 1.5
Set<Widget> set = new HashSet<Widget>();
public void add(Widget widget) {
set.add(widget);
}
/**
* Return the widget for the specified version of the named widget. If
* the exact flag is true then this will only return a widget for an
* exact name/version match. If the exact flag is false then this will
* return the version with a matching major version but the highest
* available minor number.
*
* @param name the name of the widget
* @param major the major version
* @param minor the minor version
* @param exact whether we need an exact match
*/
public Widget get(String name,int major,int minor,boolean exact) {
Widget widgetToReturn = null;
if(exact) {
Widget w = new Widget(name, major, minor);
// for loop using JDK 1.5 version
for(Widget wid : set) {
if((w.getName().equals(wid.getName())) && (wid.getVersion()).equals(w.getVersion())) {
widgetToReturn = w;
break;
}
}
} else {
Widget w = new Widget(name, major, minor);
WidgetVersion widgetVersion = new WidgetVersion(major, minor);
// for loop using JDK 1.5 version
for(Widget wid : set) {
WidgetVersion wv = wid.getVersion();
if((w.getName().equals(wid.getName())) && major == wv.getMajor() && WidgetVersion.isCompatibleAndNewer(wv, widgetVersion)) {
widgetToReturn = wid;
} else if((w.getName().equals(wid.getName())) && wv.equals(widgetVersion.getMajor(), widgetVersion.getMinor())) {
widgetToReturn = w;
}
}
}
return widgetToReturn;
}
/**
* Return the widget for the specified version of the named widget.
* This will return the newest version of the widget that is compatible,
* meaning the major version is the same but the minor version is equal to
* or higher than the desired version.
*
* @param name the name of the widget
* @param major the major version
* @param minor the minor version
*/
public Widget getBest(String name,int major,int minor) {
// THIS METHOD IS NOT GETTING USED ANY WHERE
return null;
}
}
Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.
When asked, what has been your best career decision?
Deciding to stick with EE.
Being involved with EE helped me to grow personally and professionally.
Connect with Certified Experts to gain insight and support on specific technology challenges including:
We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE