Wrapper class for HashMap
Why people write Wrapper class for HashMap? Why not directly use the HashMap?
I thought that the term wrapper class is generally
used to signify one class having an instance of
another class inside it. And not one class
deriving from another.
But thats just me.I think that is just you. :)
I consider "wrapping" as having a subset of the functionality of another class. This could be containing or extending, in my opinion.
Consider:
// only partially functional vector for JButtons...
// class containing Vector
public class JButtonVector
Vector vec = new Vector();
public void add(JButton button)
vec.add(button);
public JButton get(int index)
if(index >= vec.size() || index < 0)
throw new IllegalArgumentException(...);
return (JButton)vec.get(index);
// class extending Vector
class JButtonVector2 extends Vector
public void add(JButton but)
super.add(but);
public JButton get(int index)
return (JButton)(super.get(index));
}Problem with the second class is that it also allows adding of regular Objects. That might not be desirable (in this case, it is definitely not).
Similar Messages
-
Is there an efficient wrapper class for reading binary data in cocoa/iPhone
Hi,
I need to read a data from a binary file in my iPhone application. What is the best way to do it? Is there an efficient cocoa wrapper class for this purpose?
Thanks,
NavaA char is a 16-bit unsigned value - depending on what you want, it may help.
I don't understand your reluctance to mask off the upper 16 bits of an integer; all it requires is a single bitwise 'and' statement. I challenge you to measure the impact of such a statement on your program. -
How do I create Wrapper class for Message Box?
I want to create Wrapper class for Message Box class in my project. I am using Telerik Testing FrameWork. In that message box was not recognized in unit testing thats y i want to create wrapper class, for creating the
instance for that mesage box.A wrapper class is simply a class that for example wraps another object or a subset of its methods. You could just create a class that exposes the same methods as the MessageBox and uses the MessageBox internally.
If you define an interface and program against this in your application, you could replace your wrapper object with another object that implements the same interface when you are doing the unit tests. Something like this:
public interface IMessageBoxWrapper
System.Windows.Forms.DialogResult Show(string text, string caption);
public class MessageBoxWrapper
public System.Windows.Forms.DialogResult Show(string text, string caption)
return System.Windows.Forms.MessageBox.Show(text, caption);
public class MockMessageBoxWrapper
public System.Windows.Forms.DialogResult Show(string text, string caption)
return System.Windows.Forms.DialogResult.OK;
private readonly IMessageBoxWrapper _mbw;
public Form1(IMessageBoxWrapper mbw)
InitializeComponent();
_mbw = mbw;
private void SomeMethod()
_mbw.Show("...", "...");
Hope that helps.
Please remember to close your threads by marking all helpful posts as answer and please start a new thread if you have a new question. -
How to get SDKODBC Wrapper class for indesign cs3
Hi,
I have to implement the mysql database with my indesign plugin. I didn't have a SDKODBC Wrapper class. Can any one say how to get SDKODBC Wrapper class from adobe.
Regards,
saravanan.I doubt if change documents are generated for SE78 transaction.
For list of change documents defined, please check table: TCDOB.
Hope this helps.
Kind Regards
Eswar -
How do i set up the wrapper classes in borland c++ for CWIMAQFullParticleReport
I am using the IMAQVision version 1.0 ActiveX control in a Borland C++ 5 environment. I am happy that this is working but cannot find an example or help file that indicates how to create the wrapper classes for this environment, for example _CWIMAQFullParticleReport. I realise this may be a hole in my knowledge but would very much appreciate if somebody could point me in the right direction!
Hello m2ls,
I found a video on HP's YouTube channel, HP Printer Support. I think this will solve your problem.
The video shows how to scan to you Mac Yosemite computer with an HP scanner without installing HP software.
http://youtu.be/HVCE7dq8g6E?list=UUHranSHHa1qo6Pg4JStkL7Q
I hope this helps.
Thanks,
-hjs_19 *I work on behalf of HP
Please click “Accept as Solution” if you feel my post solved your issue, it will help others find the solution. Click the “Kudos Thumbs Up" on the bottom right of this post to say "Thanks" for helping! -
What are the uses of Void wrapper class?
Hi,
Similar to other Wrappers, Void is a wrapper class for the primitive ' void ' . We all know that Void is a final class , we can't instantiate it.
My Question is what are the uses of Void?
thanks,kajbj wrote:
I have at times used it in reflection and jmx.I have used them with SwingWorker if I didn't have anything interesting to return. There is also an example in the tutorial: [http://java.sun.com/docs/books/tutorial/uiswing/concurrency/simple.html] -
What exactly is a wrapper class?
In so far as Integer, Byte, Double et al. are concerned I understand that those wrapper classes are a way to handle primitive types as objects. But I've come across references to wrapper classes in documentation and other technical articles and I don't think I really understand what they are really used for. Why do you need a wrapper class for an object?
Could someone shed me some light on this issue?
Thanks,
JohnAn instance of a wrapper class holds a pointer to and instance of some other class or interface and provides access to it, typically supplying methods equivalent to all the methods of the underlying type.
The basic wrapper class a functional replacement for the underlying object.
When you're passed an object from some code outside your control you often don't know what exact class it is, or have access to it's class definition.
A wrapper object allows you to modify the functionality of such an object. You can extend the wrapper class, for example, adding extra methods. Or you can modify the methods, for example to provide logging of calls made.
As a concrete example, I have a wrapper class LoggedConnection which wraps a java.sql.Connection object. It also implements java.sql.Connection. If you ask a LoggedConnection for a Statement or PreparedStatement it fetches the appropriate object and returns a wrapped version which logs the SQL and the execution times etc..
My "get me a connection" routine can return either a raw Connection or a LoggedConnection according to whether a SQL log file is provided.
The main program doesn't need to know if it's using a genuine Connection object or the wrapped version.
Part of the definition would look like:
public class LoggedConnection implements Connection {
private Connection wrappee;
public LoggedConnection(Connection con) {
wrapee = con;
public createStatement() throws SQLExeception {
return new LoggedStatement(wrappee.createStatement())
}(Of course this was tedious to write by hand because Connection has so many methods, all of which the wrapper must implement. Later I wrote a java program to generate Wrapper classes). -
Hello,
ist it possible to write a wrapper class for a BPEL process? How can i do it?
Thanks,
MatthiasI am not sure you can do it or not. But I am wondering why you need to do this ?
You can initiate any process using the Java API as well as through web service call.
Could you please elaborate your usecase for this ?
Thanks,
Rakesh -
Any quick way of finding the wrapper type for arbitrary primitives?
does anyone know a way of obtaining the equivalent wrapper class for any primitive type? eg, if I have a reference to long.class, is there a way of resolving this to Long.class, other than maintaining a Map<Class, Class> myself?
Last time I had to do this I was using 1.4. I couldn't find an easier way of doing it other than using a map.
AFAIK nothing has come along in java 5 which makes this any easier - but then I dont know very much so don't take my word for it.
~D -
Class for primitive to class for corresponding wrapper?
Is there any way to programmatically get hold of the class object for a primitive wrapper (eg Double.class) from the class object for the primitive type (eg double.class)? What about the reverse mapping?
I can easily initilialize a Map of my own or write a method with if statements, but I'm curious if there is a library method somewhere. Or a simple coding trick. You know, just in case a new primitive type is added at some point ;-)Works with autoboxing.Object o = (byte) 3;
System.out.println(o.getClass().getName());
o = 3;
System.out.println(o.getClass().getName());
o = 3L;
System.out.println(o.getClass().getName());
o = 3.5F;
System.out.println(o.getClass().getName());
o = 3.5;
System.out.println(o.getClass().getName());
o = true;
System.out.println(o.getClass().getName());db
edit Sorry, I see that you want to get the wrapper class
from the class object for the primitive typeNo, I don't know a way to do that.
Edited by: Darryl.Burke -
How to see the wrapper classes generated for CMP 2.1 in jdeveloper10g
I have developed CMP entity bean (2.1) using jdeveloper wizard. I want to see the wrapper class generated for the bean. How can I do that in jdeveloper 10g.
No you got me wrong. I wan't to see the actual implementated classes (extended from the generated bean) by the container. ie the ones that actually run in the container.
rgds,
Jatin -
What are Wrapper classes and what are they used for ?
What are Wrappter classes and what are they used for ?..Also, any examples would be great to understand this concept
Wrapper classes are used to enclose primitive data
types so that they can be used in instances where an
object is required. For example, if you want to add an
integer to an ArrayList, you can't use this:java.util.List al = new ArrayList();
int i=123;
al.add(i);because the ArrayList expects data of type object. In
order to all the integer to the ArrayList, you must wrap
it in the Integer wrapper class. This works:java.util.List al = new ArrayList();
int i=123;
al.add(new Integer(i));Hope that helps.
Mark -
Apache comons logging implemented it with a wrapper classes around
hi friends,
i have an interesting (unsually )problem regaurding apache commons logging, i am using three classes .
one is the logger class where i instantiate the logging instance ie Log log = LogFactory .getLog("some name");
then there is a class called LFactory where i use i hashMap to store the various different logger created or to access the different logger for the hashmap
then the last i have i LoggerAccessor class which links the LFactory.
as u all now that the logger will give the line number of the class where we use the log instance ( Log log)..... but as i am using a wrapper classes around the actually log instance.
in any class where i require the logging to be done.. i used my LoggerAccessor. so instead of giving me the Actuall Classname,methodname,and line number of the class where i give logging statements. I get the name of my class where i have created the instance and specially the line number of the class where the instance is created....( means my first class).
i want to get the name,method,linenumber of the class where i have added logging statements
please find me the solution for it.....
thanksGood Question Nutan !! But i don't have answer !! Hope someone else will answer this !
-
What is the proper way to code a "wrapper" class?
Basically I want to replace an existing Action with a custom Action, but I want the custom Action to be able to invoke the existing Action.
The following code works fine. I can create a custom Action using the existing action and the text on the button "paste-from-clipboard" is taken from the existing Action. So everything works great as long as the existing Action extends from AbstractAction.
However the Action interface does not support the getKeys() method which I used to copy the key/value information from the existing action to the wrapped action. So if you try to create a button from some class that strictly implements the Action interface the key/value data in the wrapped Action will be empy and no text will appear on the button.
So as the solution I thought I would need to override all the methods in the wrapped Action class to invoke the methods from the originalAction object. That is why all the commented code in the class is there. But then the protected methods cause a problem as the class won't compile.
Do I just not worry about overriding those two methods? Is this a general rule when creating wrapper classes, you ignore the protected methods?
import java.awt.*;
import java.awt.event.*;
import java.beans.*;
import javax.swing.*;
import javax.swing.text.*;
public class WrappedAction extends AbstractAction
private Action originalAction;
public WrappedAction(JComponent component, KeyStroke keyStroke)
Object key = getKeyForActionMap(component, keyStroke);
if (key == null)
String message = "no input mapping for KeyStroke: " + keyStroke;
throw new IllegalArgumentException(message);
originalAction = component.getActionMap().get(key);
if (originalAction == null)
String message = "no Action for action key: " + key;
throw new IllegalArgumentException(message);
// Replace the existing Action with this class
component.getActionMap().put(key, this);
// Copy key/value pairs to
if (originalAction instanceof AbstractAction)
AbstractAction action = (AbstractAction)originalAction;
Object[] actionKeys = action.getKeys();
for (int i = 0; i < actionKeys.length; i++)
String actionKey = actionKeys.toString();
putValue(actionKey, action.getValue(actionKey));
private Object getKeyForActionMap(JComponent component, KeyStroke keyStroke)
for (int i = 0; i < 3; i++)
InputMap inputMap = component.getInputMap(i);
if (inputMap != null)
Object key = inputMap.get(keyStroke);
if (key != null)
return key;
return null;
public void invokeOriginalAction(ActionEvent e)
originalAction.actionPerformed(e);
public void actionPerformed(ActionEvent e)
System.out.println("custom code here");
invokeOriginalAction(e);
public void addPropertyChangeListener(PropertyChangeListener listener)
originalAction.addPropertyChangeListener(listener);
protected Object clone()
originalAction.clone();
protected void firePropertyChange(String propertyName, Object oldValue, Object newValue)
originalAction.firePropertyChange(propertyName, oldValue, newValue);
public Object[] getKeys()
return originalAction.getKeys();
public PropertyChangeListener[] getPropertyChangeListeners()
return originalAction.getPropertyChangeListeners();
public Object getValue(String key)
return originalAction.getValue(key);
public boolean isEnabled()
return originalAction.isEnabled();
public void putValue(String key, Object newValue)
originalAction.putValue(key, newValue);
public void removePropertyChangeListener(PropertyChangeListener listener)
originalAction.removePropertyChangeListener(listener);
public void setEnabled(boolean newValue)
originalAction.setEnabled(newValue);
public static void main(String[] args)
JTextArea textArea = new JTextArea(5, 30);
JFrame frame = new JFrame("Wrapped Action");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.add(new JScrollPane(textArea), BorderLayout.NORTH);
frame.add(new JButton(new WrappedAction(textArea, KeyStroke.getKeyStroke("control V"))));
frame.pack();
frame.setLocationRelativeTo( null );
frame.setVisible( true );I can't get the PropertyChangeListener to fire with any source. Here is my test code. Note I am able to add the PropertyChangeListener to the "Paste Action", but I get no output when I add it to the WrappedAction. I must be missing something basic.
import java.awt.*;
import java.awt.event.*;
import java.beans.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.text.*;
public class WrappedAction3 implements Action, PropertyChangeListener
private Action originalAction;
private SwingPropertyChangeSupport changeSupport;
* Replace the default Action for the given KeyStroke with a custom Action
public WrappedAction3(JComponent component, KeyStroke keyStroke)
Object actionKey = getKeyForActionMap(component, keyStroke);
if (actionKey == null)
String message = "no input mapping for KeyStroke: " + keyStroke;
throw new IllegalArgumentException(message);
originalAction = component.getActionMap().get(actionKey);
if (originalAction == null)
String message = "no Action for action key: " + actionKey;
throw new IllegalArgumentException(message);
// Replace the existing Action with this class
component.getActionMap().put(actionKey, this);
changeSupport = new SwingPropertyChangeSupport(this);
originalAction.addPropertyChangeListener(this);
addPropertyChangeListener(this);
* Search the 3 InputMaps to find the KeyStroke binding
private Object getKeyForActionMap(JComponent component, KeyStroke keyStroke)
for (int i = 0; i < 3; i++)
InputMap inputMap = component.getInputMap(i);
if (inputMap != null)
Object key = inputMap.get(keyStroke);
if (key != null)
return key;
return null;
public void invokeOriginalAction(ActionEvent e)
originalAction.actionPerformed(e);
public void actionPerformed(ActionEvent e)
System.out.println("actionPerformed");
// Delegate the Action interface methods to the original Action
public Object getValue(String key)
return originalAction.getValue(key);
public boolean isEnabled()
return originalAction.isEnabled();
public void putValue(String key, Object newValue)
originalAction.putValue(key, newValue);
public void setEnabled(boolean newValue)
originalAction.setEnabled(newValue);
public void xxxaddPropertyChangeListener(PropertyChangeListener listener)
originalAction.addPropertyChangeListener(listener);
public void xxxremovePropertyChangeListener(PropertyChangeListener listener)
originalAction.removePropertyChangeListener(listener);
public void addPropertyChangeListener(PropertyChangeListener listener)
changeSupport.addPropertyChangeListener(listener);
public void removePropertyChangeListener(PropertyChangeListener listener)
changeSupport.removePropertyChangeListener(listener);
public void propertyChange(PropertyChangeEvent evt)
changeSupport.firePropertyChange(evt.getPropertyName(), evt.getOldValue(), evt.getNewValue());
public static void main(String[] args)
JTable table = new JTable(15, 5);
WrappedAction3 action = new WrappedAction3(table, KeyStroke.getKeyStroke("TAB"));
action.addPropertyChangeListener( new PropertyChangeListener()
public void propertyChange(PropertyChangeEvent e)
System.out.println(e.getSource().getClass());
action.putValue(Action.NAME, "name changed");
Action paste = new DefaultEditorKit.PasteAction();
paste.addPropertyChangeListener( new PropertyChangeListener()
public void propertyChange(PropertyChangeEvent e)
System.out.println(e.getSource().getClass());
paste.putValue(Action.NAME, "name changed");
} -
Developing the Wrapper class to log the message in XI server
Hi All,
We are trying to develop wrapper class on the SAP Logging API, in that I am unable to log the message in the log file(whose path is mentioned in the properties file).
We use this for storing when exception raised during message transformation due to certain error conditions...
Procedure:
My Wrapper class will take the parameters from Property file and store/log the message in the specified location,
This is working outside of XI environment
Please suggest how to make to work in XI environment
Also suggest do I need to do any configurations in SAP web As
Thanks,
venu.HI,
With the above blog ref by Michal , see the below links also,
/people/alessandro.guarneri/blog/2006/03/27/sap-xi-lookup-api-the-killer
/people/amjad-ali.khoja/blog/2005/12/16/slaw-a-new-logging-tracing-framework-for-xi
/people/amjad-ali.khoja/blog/2006/02/07/using-dom4j-in-xi--a-more-sophisticated-option-for-xml-processing-than-sap-xml-toolkit
Also my be useful..
/people/community.user/blog/2007/01/09/enterprise-soa-explorations-reflections-on-database-integration
/people/anne.tarnoruder/blog/2006/10/26/reusing-code-with-pdk-for-net
/people/piers.harding/blog/2006/05/18/ruby-on-rails-with-ajax
Regards
Chilla
Maybe you are looking for
-
I just got a new computer and I can not syn all of my music from itunes that is on my ipod! I can not get it to sync onto my new computer! I need help how do I get it to sync.
-
I have tethered my iphone 4 to my pc. Do i still have to update my pc security, antivirus, firewall ect.? the phone has not been jail broken and it is the only device or means of internet connection, connected to my pc.
-
I've installed BO XI Enterprise on a Linux server. Wrote a Java UFL and designed a report to use the Java UFL. I deployed my rpt file & the ufl's jar on the linux server. Re-started tomcat. I can see my report file using "infoview", but when I run my
-
Where is the developer version of SQL 2012
Hi, This seems to have been asked a lot but I can't find a definitive answer. I purchased a copy of SQL2008R2 (Developer) from Amazon a few years ago and I would like to upgrade it to 2012. Looking on MS sites it appears that there is only; Expre
-
User exit for me 51 to put field descryption for ekbn-sakpto in screen 505
hi . i have a requirement to put field descryption in screen 505 for me51 tcode(program sapmm06b) for field g/l account in screen 505(Account Assignment for item 00010). waiting for your resposne. bye. sita.