Enum or EnumMap to store String constants using enums?
I have decided to use enums to store some String
constants. What are the pros and cons of using a
simple enum versus using EnumMap? What are
the differences?
If going with the simple enum option, I would just
do as in the following example:
// The typesafe enum pattern
public class Suit {
private final String name;
private Suit(String name) { this.name = name; }
public String toString() { return name; }
public static final Suit CLUBS =
new Suit("clubs");
public static final Suit DIAMONDS =
new Suit("diamonds");
public static final Suit HEARTS =
new Suit("hearts");
public static final Suit SPADES =
new Suit("spades");
}A System.out.println(CLUBS); prints out "clubs".
Or is EnumMap a better choice? If so, why? If not,
then why?
jverd wrote:
sunfun99 wrote:
+3.1459378192030194732612839423...+ is a constant, but not a named constant. If I give the constant a name, like "PI", then I can use that name to access the constant (instead of having to repeat the long constant literal every time I want to use it). Now, I want to use a number of constants across various classes, so I give each of these constants a name. What I then have is a number of named constants. To name a constant means that I map a name to a value:That's not what "mapping" means in this context. Really? Even the Collections tutorial says it, "Map � an object that maps keys to values". And - not surprising - the classes/interfaces "Map", "Set", etc. are named so because they mimic these mathematical concepts.
It appears you don't know what java.util.Map is for. java.util.Map is "an object that maps keys to values". It's an interface that also provides various methods that allows for various dealings with the data, such as removing or adding mappings, provide the value given the name, give the total number of mappings, etc.
Then define an enum.As I said earlier, I believe you, and that's what I will do.
What makes you think that EnumMap is a "more advanced implementation" of enums? (It's not. It's not an implementation of enums at all.) What does "more advanced" even mean here?Sorry, my mistake. It's not an implementation of enums. However, it takes enums as parameters. In that sense, using EnumMap would indirectly imply a more complicated way of using enums, since not only do I create enums, but then I have to put the into EnumMap.
Similar Messages
-
What is the difference between String Constant and Empty String Constant
What is the difference between string constant which does not contain any value and the Empty string constant?
While testing a VI which contain a normal string constant in VI analyzer, it gives error to change string constant with the empty string constant?
Please Reply
prabhakant
Regards
Prabhakant PatilReadability.
Functionally, they are the same. From a coding standpoint, the Empty String Constant is unambiguous.
It is empty and will always be; good for initialization. Also, because you can not type a value into and Empty String Constant, someone would need to conciously replace it to set a 'default' value that is something other than NULL.
Now is the right time to use %^<%Y-%m-%dT%H:%M:%S%3uZ>T
If you don't hate time zones, you're not a real programmer.
"You are what you don't automate"
Inplaceness is synonymous with insidiousness -
How do I input multiple string constants into VISA Write
I am trying to put in multiple string commands into VISA Write to control a motor arm. However, when I use "concatenate strings" to link together my multiple string constants, only the first command is executed, and neglects the other commands below it. Should I be using something other then "concatenate strings" or do I need to use a delay so that the next command executes when the one before it is finished? Help.
Concatenate strings should work or just use one string constant with multiple lines. The problem you're having could be that the instrument requires some sort of delay but without details on the instrument, only you or the vendor can answer that. Some instruments will have a queue and others won't. The other possiblity is that you need some kind of termination character between commands. This might be a carriage return for a serial instrument or the ; character for a GPIB one. Check the instrument manual or provide the make and model and maybe someone here has some experience with it.
-
String str = "Hello " + "World";
If I write like the above, how many string objects are created? One or Three? I am asking this because somewhere I found an advice that we should use a StringBuffer and its append() method to concatenate strings in order to reduce the number of string constants generated when we want to create a long string and it does not fit into a single line (hence break it up into multiple lines) or dynamically create a string depending on several conditions. Like the following:
String sql = "INSERT INTO MYTAB "
+ "( x, y, z)"
+ " VALUES(1,2,3)";
The above can be done as below:
StringBuffer sb = new StringBuffer();
sb.append( "INSERT INTO MYTAB " );
sb.append( "( x, y, z)" );
sb.append( " VALUES(1,2,3)" );
It was advised that, in such cases, StringBuffer should be used since it maintains an array internally and does not create a new string every time a new string constant is appended.maity wrote:
Well, thanks. One more question, is there any way that I can count the number of objects created by my java program when it is running?I would use a profiler if I wanted to know that. But why do you need to know? -
Whats a String constant pool?
I was reading an article about weak references and came across a peice of code
Map<String,String> map = new WeakHashMap<String, String>();
map.put(new String("Scott"), "McNealey");They also said
if you don't call new String(), the reference for the map key will be to the system's string constant pool. This never goes away, so the weak reference will never be released. To get around this, new String("Scott") creates a reference to the reference in the string constant pool. The string contents are never duplicated. They stay in the constant pool. This simply creates a separate pointer to the string constant in the pool.
I never heard of String constant pool could any one enlighten me. I didnt get the point of what above paragraph says also.
JubsNo it won't: it will only be removed when the garbage collector rears
its ugly head. Until then the reference will be present in the map.Okay it was unprecise. The item MAY be removed immediately after it
has been inserted because the key object is only referenced from the
Map itself.Yes, that is true, but mind though: any object that still has a strong
reference to it will not be removed from that map. I use such weak maps
for localization reasons a lot. When a localization changes (while the
application is running), a whole lot of visual components must have
their text part changed. They are all stored in such a weak reference map.
Of course quite some visual components can be garbage collected
at some time (think of labels etc. in JDialogs after the dialog has been
disposed).
These maps are ideal for those purposes.
kind regards,
Jos -
What is the little square box in the string constant input?
Hello LabVIEW World -
I am attempting to understand a LabVIEW code that I did not write. At one point, there is a string (Equal?) comparison that is comparing a string from a VISA Read to a string constant input. The string constant has a little square box inside of it.
Does anyone know what this little square box is? (See attached screenshot)
Thanks.
DS
Attachments:
LittleSquare.JPG 69 KBWhen I place string constants like this I will display then either as hex or in the codes mode. Either of these will make the code more readable. Using the default ASCII string display is useless other than letting you know it is an unprintable character.
Mark Yedinak
"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot -
How to store string with "?" without binding parameters
I would like to store string which contains following characters 'bla bla bla "?" bla bla'. When I set this string into some object and commit UOW, than TopLink generates UPDATE command and I receive SQLException "Number of input values does not match number of question marks". It seems that TopLink tries to store this object via PreparedStatement.
How can I say to TopLink: "Don't use PrepareStatement"?
Thank you for any help.
Jan Kostrhun
TopLink version: 9.3.0.6
JDBC: Informix JDBC 2.21.JC5
// modifications made to DatabaseLogin in preLogin event
DatabaseLogin dl = srv.getLogin();
dl.useBatchWriting();
dl.useJDBCBatchWriting();
dl.useNativeSQL();Hi King,
the problem is, that I am storing string which contains a part of Java code. And the Java code contains question mark surrounded by quotation marks.
Thank you for your answer
Jan
08:45:15,997 INFO [1571] toplink UnitOfWork(22544730)--begin unit of work commit
08:45:16,004 INFO [1571] toplink ClientSession(5676128)--Connection(3972145)--begin transaction
... some lines
08:45:16,047 INFO [1571] toplink UnitOfWork(22544730)--Connection(3972145)--UPDATE char_moc_body SET cast_retezce = ' ERROR_EX (ex, "Error while running algoritmus!");
result = "aaaaaaaaa";
} else {
result = "?";
* Implementace metody udalosti CommandEvent.
* @param event data udalosti.
public void process ', obj_verze = 11 WHERE ((obj_id = 901699) AND (obj_verze = 10))
08:45:16,117 ERROR [1571] toplink UnitOfWork(22544730)--EXCEPTION [TOPLINK-4002] (TopLink - 9.0.3.4 (Build 432)): oracle.toplink.exceptions.DatabaseException
EXCEPTION DESCRIPTION: java.sql.SQLException: Number of input values does not match number of question marks
INTERNAL EXCEPTION: java.sql.SQLException: Number of input values does not match number of question marks
ERROR CODE: -79749LOCAL EXCEPTION STACK:
EXCEPTION [TOPLINK-4002] (TopLink - 9.0.3.4 (Build 432)): oracle.toplink.exceptions.DatabaseException
EXCEPTION DESCRIPTION: java.sql.SQLException: Number of input values does not match number of question marks
INTERNAL EXCEPTION: java.sql.SQLException: Number of input values does not match number of question marks
ERROR CODE: -79749
at oracle.toplink.exceptions.DatabaseException.sqlException(Unknown Source)
at oracle.toplink.internal.databaseaccess.DatabaseAccessor.executeDirectNoSelect(Unknown Source)
at oracle.toplink.internal.databaseaccess.DatabaseAccessor.executeNoSelect(Unknown Source)
at oracle.toplink.internal.databaseaccess.DatabaseAccessor.executeCall(Unknown Source)
at oracle.toplink.publicinterface.UnitOfWork.executeCall(Unknown Source)
at oracle.toplink.internal.queryframework.CallQueryMechanism.executeCall(Unknown Source)
at oracle.toplink.internal.queryframework.CallQueryMechanism.executeCall(Unknown Source)
at oracle.toplink.internal.queryframework.CallQueryMechanism.executeNoSelectCall(Unknown Source)
at oracle.toplink.internal.queryframework.CallQueryMechanism.updateObject(Unknown Source)
at oracle.toplink.internal.queryframework.StatementQueryMechanism.updateObject(Unknown Source)
at oracle.toplink.internal.queryframework.DatabaseQueryMechanism.updateObjectForWrite(Unknown Source)
at oracle.toplink.queryframework.WriteObjectQuery.executeCommit(Unknown Source)
at oracle.toplink.internal.queryframework.DatabaseQueryMechanism.executeWrite(Unknown Source)
at oracle.toplink.queryframework.WriteObjectQuery.execute(Unknown Source)
at oracle.toplink.queryframework.DatabaseQuery.execute(Unknown Source)
at oracle.toplink.publicinterface.Session.internalExecuteQuery(Unknown Source)
at oracle.toplink.publicinterface.UnitOfWork.internalExecuteQuery(Unknown Source)
at oracle.toplink.publicinterface.Session.executeQuery(Unknown Source)
at oracle.toplink.publicinterface.Session.executeQuery(Unknown Source)
at oracle.toplink.internal.sessions.CommitManager.commitAllObjects(Unknown Source)
at oracle.toplink.publicinterface.Session.writeAllObjects(Unknown Source)
at oracle.toplink.publicinterface.UnitOfWork.commitToDatabase(Unknown Source)
at oracle.toplink.publicinterface.UnitOfWork.commitRootUnitOfWork(Unknown Source)
at oracle.toplink.publicinterface.UnitOfWork.commit(Unknown Source)
... more rows
INTERNAL EXCEPTION STACK:
java.sql.SQLException: Number of input values does not match number of question marks
at com.informix.util.IfxErrMsg.getSQLException(IfxErrMsg.java:348)
at com.informix.jdbc.IfxSqli.sendExecute(IfxSqli.java:1256)
at com.informix.jdbc.IfxSqli.sendCommand(IfxSqli.java:814)
at com.informix.jdbc.IfxSqli.executeCommand(IfxSqli.java:699)
at com.informix.jdbc.IfxResultSet.executeUpdate(IfxResultSet.java:316)
at com.informix.jdbc.IfxStatement.executeUpdateImpl(IfxStatement.java:846)
at com.informix.jdbc.IfxPreparedStatement.executeUpdate(IfxPreparedStatement.java:269)
at oracle.toplink.internal.databaseaccess.DatabaseAccessor.executeDirectNoSelect(Unknown Source)
at oracle.toplink.internal.databaseaccess.DatabaseAccessor.executeNoSelect(Unknown Source)
at oracle.toplink.internal.databaseaccess.DatabaseAccessor.executeCall(Unknown Source)
at oracle.toplink.publicinterface.UnitOfWork.executeCall(Unknown Source)
at oracle.toplink.internal.queryframework.CallQueryMechanism.executeCall(Unknown Source)
at oracle.toplink.internal.queryframework.CallQueryMechanism.executeCall(Unknown Source)
at oracle.toplink.internal.queryframework.CallQueryMechanism.executeNoSelectCall(Unknown Source)
at oracle.toplink.internal.queryframework.CallQueryMechanism.updateObject(Unknown Source)
at oracle.toplink.internal.queryframework.StatementQueryMechanism.updateObject(Unknown Source)
at oracle.toplink.internal.queryframework.DatabaseQueryMechanism.updateObjectForWrite(Unknown Source)
at oracle.toplink.queryframework.WriteObjectQuery.executeCommit(Unknown Source)
at oracle.toplink.internal.queryframework.DatabaseQueryMechanism.executeWrite(Unknown Source)
at oracle.toplink.queryframework.WriteObjectQuery.execute(Unknown Source)
at oracle.toplink.queryframework.DatabaseQuery.execute(Unknown Source)
at oracle.toplink.publicinterface.Session.internalExecuteQuery(Unknown Source)
at oracle.toplink.publicinterface.UnitOfWork.internalExecuteQuery(Unknown Source)
at oracle.toplink.publicinterface.Session.executeQuery(Unknown Source)
at oracle.toplink.publicinterface.Session.executeQuery(Unknown Source)
at oracle.toplink.internal.sessions.CommitManager.commitAllObjects(Unknown Source)
at oracle.toplink.publicinterface.Session.writeAllObjects(Unknown Source)
at oracle.toplink.publicinterface.UnitOfWork.commitToDatabase(Unknown Source)
at oracle.toplink.publicinterface.UnitOfWork.commitRootUnitOfWork(Unknown Source)
at oracle.toplink.publicinterface.UnitOfWork.commit(Unknown Source)
... more rows
08:45:16,121 INFO [1571] toplink ClientSession(5676128)--Connection(3972145)--rollback transaction
08:45:16,146 INFO [1571] toplink UnitOfWork(22544730)--release unit of work -
Richt Click Mouse with user32.dll and String Constant for Escape Key
Hi, could some one provide the input parameters to use with Mouse_Event function in user32.dll to Right Click the Mouse? Also, what is the string constant to send if one want to type the Escape Key (Esc)?
I have searched this forrum but only find the parameters for Left Mouse Click. Thanks for any help.Hi,
The mouse_event function has been superseded by the sendinput command. To learn more about the function calls with user32.dll, have a look at the msdn.com website. The user32.dll website is shown here. The syntax for the mouse_event function is shown below:
Syntax
VOID mouse_event(
DWORD dwFlags,
DWORD dx,
DWORD dy,
DWORD dwData,
ULONG_PTR dwExtraInfo
);I hope this helps,
Regards,
Nadim
Applications Engineering
National Instruments -
Can any body tell me How to store string array in a array
Can any body tell me How to store string array in a array
YesNot quite sure what question you're answering but here's how to copy an array.// given a String[] strArr
// pre Java 6
String[] newStrArr = new String[strArr.length];
System.arrayCopy(strArr, 0, newStrArr, 0, strArr.length);
// post Java 6
String[] newStrArr = Arrays.copyOf(strArr, strArr.length);Edit:
Or in fact use clone() as mark pointed out.
Message was edited by:
dwg -
Deprecated conversion from string constant to 'char*'
Hi all
I am working with strings and i cant figure out why the following
warning appears at time of build.
warning: deprecated conversion from string constant to 'char*'
It appears for the line
char *myName = "Apple.txt";
Is there anyone who can help me?
Help is welcome.
Thanks in advance.Any reason why you aren't using NSString in place of char?
char *myName = "Apple.txt";
NSString *myName = @"Apple.txt"; -
Remove Recessed Box on String Constant
Hello -
I have created a subvi that will present a "hint" whenever the "show hint" button is pressed. I want this hint (a simple string constant) to simply appear when called, and then disappear when the "hide hint" button is pressed. To do this, I am using the visible property node for a string control.
Here's the problem - When I show the hint, I can see the Recessed Box behind the words... Is there a way to remove the Recessed Box from the String Constant?
Or - Is there a better / more professional-looking way to do this type of thing?
I have attached my code to this post. I have also attached a *.jpg that points to the outline/border that I would like to remove.
Thanks!
Dan
Attachments:
Hint_Pic.JPG 31 KB
HINT.vi 13 KBExcellent points - Thanks for the corrections. I have re-posted the code with the changes that you suggested, just in case others wanted to see it.
Is there an easy way to change the format style of what I am trying to do to look something more like the "Show Details" button that you see in Windows? (see example attached image). I suppose that I could use a picture of the little downward arrow (as used in my ShowDetails.JPG attachment), overlay that with a transparent circular boolean button that says "show details", and use a subvi that appears and presents the details when called, but I feel like there should be a better alternative - perhaps this type of thing already exists....
Thanks in advance for your suggestions!
Attachments:
HINT.vi 13 KB
ShowDetails.JPG 14 KB -
i have an apple id registered in Indian store. can i use the same apple id to register for U.S store. I have the credit card of my brother in U.S. I want to access both the stores using the same apple id. Can you tell me how. I dont want to create a new id as far as possible.
Appreciating your answers....
I wanna ask that if one of my family member lives aboard in US and if he has an apple id too.. so can I use his id on my ipad here in Pakistan? Will it effect the applications that I have been installing recently?
Thank you. -
Hi, I have made a new Apple ID and logged in on my phone, settings > iTunes & app stores, but the app store is still using my old Apple ID. How do I get rid of the old ID and replace it with the new one?
HAYDONISRAD wrote:
... Maybe I'll stick with hers for now :-)
OR...
You could use your preferred Apple ID from now on, but you can still access your purchased items such as music, movies, or software using your other Apple IDs.
From Here http://support.apple.com/kb/HE37
I have multiple Apple IDs. Is there a way for me to merge them into a single Apple ID? -
I have moved from the US to Norway, and want to change my apple ID to the Norwegian appstore. However, I am not allowed ot change from the US store before I use up my balance, which is 0.17 dollar. The problem is that nothing costs 0.17 dollar and I do no longer have an american visa card, only Norwegian. Is there any way I can erase the credit on my account so I can change the appstore country? Or osmething I can use this credit on? Thank you very much
Try contacting the store support staff at: http://www.apple.com/emea/support/itunes/contact.html they are usually pretty good at sorting out these issues.
-
Hi,
I want to pass multiple query string values using the same parameter in Query String (URL) Filter Web Part like mentioned below:
http://server/pages/Default.aspx?Title=Arup&Title=Ratan
But it always return those items whose "Title" value is "Arup". It is not returned any items whose "Title" is "Ratan".
I have followed the
http://office.microsoft.com/en-us/sharepointserver/HA102509991033.aspx#1
Please suggest me.
Thanks | Arup
THanks! Arup R(MCTS)
SucCeSS DoEs NOT MatTer.Hi DH, sorry for not being clear.
It works when I create the connection from that web part that you want to be connected with the Query String Filter Web part. So let's say you created a web part page. Then you could connect a parameterized Excel Workbook to an Excel Web Access Web Part
(or a Performance Point Dashboard etc.) and you insert it into your page and add
a Query String Filter Web Part . Then you can connect them by editing the Query String Filter Web Part but also by editing the Excel Web Access Web Part. And only when I created from the latter it worked
with multiple values for one parameter. If you have any more questions let me know. See you, Ingo
Maybe you are looking for
-
Will online number send call to phone with Freetal...
Hello, I am interested in online number but I can't enough information. I have a phone hooked to skype via freetalk with a subscription. With online number, can I receive calls on that phone? What if I am logged in on mobile skype on my cell phone, w
-
hi all, i want to link two tables i.e. pa0105 and usr01. for userid. pls tell me how to link them. best regards, ashok reddy.
-
Hi, Jdev 11.1.1.0.31.51.56 If somebody of you get the following trace stack when running a jspx using ViewCriteriaRow.setOperator : There is bug 7534359 and metalink note 747353.1 available. java.lang.NullPointerException at java.util.regex.Matcher.g
-
XE instance won't start up - ORA-03113
Hi all, I've had an Oracle 11g XE (11.2.0.2.0) database running on my workstation for several months now, and not experienced any problems until just the other day when I found out it wasn't starting up properly any more. Despite extensive googling,
-
Hi folks, you might know how to fix this: my wifi shows (no hardware installed) then I went to system preferences and deleted the wifi connection, I went also to system information and I can not see wifi listed on Network, how can I create a new wifi