Is there a way I can get rid of some elements in an array.
for instance, if i have this array
int testArray[] = {0,2,0,3,0,4,5,6}
Is there a "fast" way to get rid of the elements that equal 0
int resultArray[] = {2,3,4,5,6}
I tried this function but I got lost using Lists
public int[] getRidOfZero(int []s){
List<> result=new ArrayList<>();
for(int i=0; i<s.length; i++){
if(s[i]<0){
int temp = s[i];
result.add(temp);
}
}
return result.toArray(new int[]);
}
I'm having trouble parsing a date format that I'm getting back from an API and that I have never seen (I believe is a custom format). An example of a date:
/Date(1353447000000+0000)/
When I first encountered this format it didn't take me long to see that it was the time in milliseconds with a time zone offset. I'm having trouble extracting this date using SimpleDateFormat though. Here was my first attempt:
String weirdDate = "/Date(1353447000000+0000)/";
SimpleDateFormat sdf = new SimpleDateFormat("'/Date('SSSSSSSSSSSSSZ')/'");
Date d1 = sdf.parse(weirdDate);
System.out.println(d1.toString());
System.out.println(d1.getTime());
System.out.println();
Date d2 = new Date(Long.parseLong("1353447000000"));
System.out.println(d2.toString());
System.out.println(d2.getTime());
And output:
Tue Jan 06 22:51:41 EST 1970
532301760
Tue Nov 20 16:30:00 EST 2012
1353447000000
The date (and number of milliseconds parsed) is not even close and I haven't been able to figure out why. After some troubleshooting, I discovered that the way I'm trying to use SDF is clearly flawed. Example:
String weirdDate = "1353447000000";
SimpleDateFormat sdf = new SimpleDateFormat("S");
Date d1 = sdf.parse(weirdDate);
System.out.println(d1.toString());
System.out.println(d1.getTime());
And output:
Wed Jan 07 03:51:41 EST 1970
550301760
I can't say I've ever tried to use SDF in this way to just parse a time in milliseconds because I would normally use Long.parseLong() and just pass it straight into new Date(long) (and in fact the solution I have in place right now is just a regular expression and parsing a long). I'm looking for a cleaner solution that I can easily extract this time in milliseconds with the timezone and quickly parse out into a date without the messy manual handling. Anyone have any ideas or that can spot the errors in my logic above? Help is much appreciated.
I have designed the following class that should work kind of like a method (usually the user will just run Execute()):
public abstract class ??? {
protected bool hasFailed = false;
protected bool hasRun = false;
public bool HasFailed { get { return hasFailed; } }
public bool HasRun { get { return hasRun; } }
private void Restart() {
hasFailed = false;
hasRun = false;
}
public bool Execute() {
ExecuteImplementation();
bool returnValue = hasFailed;
Restart();
return returnValue;
}
protected abstract void ExecuteImplementation();
}
My question is: how should I name this class? Runnable? Method(sounds awkward)?
I've the same problem as described here
In the generated SQL Informix expects catalog:schema.table but what's actually generated is
catalog.schema.table
which leads to a syntax error.
Setting:
hibernate.default_catalog=
hibernate.default_schema=
had no effect.
I even removed schema and catalog from the table annotation, this caused a different issues : the query looked like that ..table same for setting catalog and schema to an empty string.
Versions
seam 2.1.2
Hibernate Annotations 3.3.1.GA.CP01
Hibernate 3.2.4.sp1.cp08
Hibernate EntityManager 3.3.2.GAhibernate
Jboss 4.3 (similar to 4.2.3)
A quartz scheduler is being used in an Application I am working on. A process that runs using the quartz scheduler spawns new threads. I was wondering if it is possible for these threads to continue living after the server is killed?
Hi Guru,
I want to use a property as a param of an object's method.
<s:property value="orderProductId" />
returns correct value (e.g. 1)
<s:iterator value="%{order.getProductById(1).activations}">
gives me correct value too. But
<s:iterator value="%{order.getProductById(#orderProductId).activations}">
doesn't. Not sure why #orderProductId doesn't interpret correctly.
I'm using iBATIS to create select statements. Now I would like to implement the following SQL statement with iBATIS:
SELECT * FROM table WHERE col1 IN ('value1', 'value2');
With the following approach, the statement is not prepared correctly and no result returns:
SELECT * FROM table WHERE col1 IN #listOfValues#;
iBATIS seems to restructure this list and tries to interpret it as a string.
How can I use the IN clause correctly?
I have this function which returns a datatype InetAddress[]
public InetAddress []
lookupAllHostAddr(String host) throws UnknownHostException {
Name name = null;
try {
name = new Name(host);
}
catch (TextParseException e) {
throw new UnknownHostException(host);
}
Record [] records = null;
if (preferV6)
records = new Lookup(name, Type.AAAA).run();
if (records == null)
records = new Lookup(name, Type.A).run();
if (records == null && !preferV6)
records = new Lookup(name, Type.AAAA).run();
if (records == null)
throw new UnknownHostException(host);
InetAddress[] array = new InetAddress[records.length];
for (int i = 0; i < records.length; i++) {
Record record = records[i];
if (records[i] instanceof ARecord) {
ARecord a = (ARecord) records[i];
array[i] = a.getAddress();
} else {
AAAARecord aaaa = (AAAARecord) records[i];
array[i] = aaaa.getAddress();
}
}
return array;
}
Eclipse complains that the return type should be byte[][] but when I change the return type to byte[][], it complains that the function is returning the wrong data type. I'm stuck in a loop. Does anyone know what is happening here?
I'm doing an application, which uses Swing JTable. I used drag and drop in NetBeans, to add the JTable. When I add the JTable, JScrollPane is added automaticly.
All the look is done with drag and drop. By pressing the first button, I set the number of rows in the table. This is the code to set my DataModel
int size = 50;
String[] colNames = {"Indeks", "Ime", "Priimek", "Drzava"};
DefaultTableModel model = new DefaultTableModel(size, colNames.length);
model.setColumnIdentifiers(colNames);
table.setModel(model);
So if the size is, let's say 10, it works OK, since there is no scroll bar. When I add 50 empty rows, when trying to scroll for 5 seconds, it doesn't work properly and crashes in some time.
I added the picture, for better understanding (this is what happens to the rows when I scroll up and down for a while).
What could be wrong? Am I not using the DataModel as it is supposed to be used, should I .revalidate() or .repaint() the JTable?
I'm trying to make a class where I put a key and value into the put method which puts the key in the k string array and value into the v string array, however it is not being saved in the array when I do get or display.
For example: put(dan,30) get(dan) returns null
display returns null null 10 times. Anyone know whats wrong?
public class Memory
{
final int INITIAL_CAPACITY = 10;
String[] k = new String[INITIAL_CAPACITY];
String[] v = new String[INITIAL_CAPACITY];
int count = 0;
public Memory()
{
count = 0;
}
public int size()
{
return count;
}
public void put(String key, String value)
{
int a = 0;
boolean found = false;
for (int i = 0; i < k.length; i++)
{
//System.out.println("key is " + key.equals(k[i]));
if (key.equalsIgnoreCase(k[i]))
{
v[i] = value;
found = true;
}
if (found)
break;
a++;
}
//System.out.println(a == k.length);
if (a == k.length);
{
k[count] = key;
v[count] = value;
//System.out.println(k[count] + " " + v[count]);
count++;
//System.out.println(count);
}
}
public String get(String key)
{
String output = "a";
for(int i = 0; i < k.length; i++)
{
if(!key.equalsIgnoreCase(k[i]))
{
output = null;
}
else
{
output = v[i];
return output;
}
}
return output;
}
public void clear()
{
for (int i = 0; i < k.length; i++)
{
k[i] = null;
v[i] = null;
}
count = 0;
}
public void display()
{
for (int i = 0; i < k.length; i++)
{
System.out.println(k[i] + " " + v[i]);
}
}
}
I'm using a BorderHighlighter on my JXTreeTable to put a border above each of the table cells on non-leaf rows to give a more clear visual separator for users.
The problem is that when I expand the hierarchical column, all cells in the hierarchical column, for all rows, include the Border from the Highlighter. The other columns are displaying just fine.
My BorderHighlighter is defined like this:
Highlighter topHighlighter = new BorderHighlighter(new HighlightPredicate() {
@Override
public boolean isHighlighted(Component component, ComponentAdapter adapter) {
TreePath path = treeTable.getPathForRow(adapter.row);
TreeTableModel model = treeTable.getTreeTableModel();
Boolean isParent = !model.isLeaf(path.getLastPathComponent());
return isParent;
}
}, BorderFactory.createMatteBorder(2, 0, 0, 0, Color.RED));
I'm using SwingX 1.6.5.
We are currently planning to launch a couple of internal web projects in the future. Our company's dev teams are mostly experienced in J2EE and have worked with it for years. Today, we have the choice of launching a couple of our projects on .net. I have checked out a couple of sources on the net, and it seems like the "J2EE vs ASP.net" combat brings out as much discord as the overseen "Apple vs Microsoft" or "Free Eclipse vs Visual Studio"...
Nevertheless, I have been somewhat quite impressed with ASP.net's abilities to create great things with huge simplicity (for ex. asp.net ajax's demos). No more tons of xmls to play with, no more tons of frameworks to configure (we usually use the famous combo struts/spring/hibernate)... It just seemed to me that ASP.net had some good advantages over J2EE, but then again, I may speak by ignorance.
What I want to know is this : What are the real advantages of using J2EE over ASP.net? Is there anything that cannot be done in ASP.net that can be done in J2EE? Once the frameworks are all in place and configured, is it faster to develop apps in J2EE than it is in .net? Are the applications generally easier to maintain in J2EE than in ASP.net? Is it worth it for some developpers to leave their J2EE knowledge on the side and move on to ASP.net if it does exactly the same thing?
what is this exception and how to remove this
in my problem i am creating an arraylist of objects, and after checking some condition,i want to remove some objects. but the program is giving this exception ConcurrentModificationException. how to remove this
thanks in advance
I have a data set with multiple layers of annotation over the underlying text, such as part-of-tags, chunks from a shallow parser, name entities, and others from various natural language processing (NLP) tools. For a sentence like The man went to the store, the annotations might look like:
Word POS Chunk NER
==== === ===== ========
The DT NP Person
man NN NP Person
went VBD VP -
to TO PP -
the DT NP Location
store NN NP Location
I'd like to index a bunch of documents with annotations like these using Lucene and then perform searches across the different layers. An example of a simple query would be to retrieve all documents where Washington is tagged as a person. While I'm not absolutely committed to the notation, syntactically end-users might enter the query as follows:
Query: Word=Washington,NER=Person
I'd also like to do more complex queries involving the sequential order of annotations across different layers, e.g. find all the documents where there's a word tagged person followed by the words arrived at followed by a word tagged location. Such a query might look like:
Query: "NER=Person Word=arrived Word=at NER=Location"
What's a good way to go about approaching this with Lucene? Is there anyway to index and search over document fields that contain structured tokens?
I've been trying to create a Compound Control in Android 1.5 (as described here) but havn't been able to find any good examples on how to do this using an XML file to specify a layout. I'm fine with creating an Activity and then loading an xml file using the following in the constructor:
setContentView(R.layout.main);
However, I want to do this in subclass of LinearLayout - so I can use this compound component in other XML layouts. Something along the lines of:
public class CustomView extends LinearLayout
{
public CustomView(Context context) {
super(context);
setupView();
}
public CustomView(Context context, AttributeSet attrs)
{
super(context, attrs);
setupView();
}
public void setupView()
{
setContentView(R.layout.custom); // Not possible
}
}
What is the correct way of going about doing this?
In a managed bean you have fields, and the fields have getters and setters.
But I also need to save values back to, in this case, a Notes profile document.
So I have a loadProfileDocument and a saveProfileDocument method.
I was thinking of using the bean in the application scope.
How do I make sure the profile document is saved?
Do I have to call the saveProfileDocument from the setter?
Do I call the saveProfileDocument() explisitly?
Could I use a destructor (finalize)?
Or what...???...
Is there any specific protocol for handling exceptions in public methods? Consider this eg.
public int someMethod()
{
try{
code that might throw an exception
}
catch(Exception e)
{
log the exception
}
}
Say that this method might throw an ArrayIndexOutOfBoundsException. So, is it correct to handle this Exception in the method itself (as in the example) or throw it and assume that the calling method will handle the Exception?
hi,
I'm using GWT-EXT combobox. My problem is when I render the combobox, it's having as many rows as it has values but all the rows are empty means text is not shown. Here's my code.
Combobox cb = new Combobox();
cb.setForceSelection(true);
cb.setMinChars(1);
cb.setWidth(200);
cb.setStore(store); // Store is perfectly loaded in combobox
cb.setDisplayField("ReportName");
cb.setMode(ComboBox.LOCAL);
cb.setTriggerAction(ALL);
cb.setEmptyText("--Select--");
cb.setLoadingText("Searching...");
cb.setTypeAhead(true);
cb.setSelectOnFocus(true);
All other code is working fine. I'm sure for one thing that this problem is related to one of the functions of Combobox.
Thanks in advance.
I have these long statements that I will refer to as x,y etc. here.
My conditional statements' structure goes like this:
if(x || y || z || q){
if(x)
do someth
else if (y)
do something
if(z)
do something
else if(q)
do something
}
else
do smthing
Is there a better, shorter way to write this thing? Thanks
What is the total number of comparisons necessary to locate all the n sorted distinct integers in an array using binary search, I think it is nlogn, but I am not sure. What do u guys think?
Hi I have below pseudo code with throws an exception like this
throw new MyException("Bad thing happened","com.stuff.errorCode");
where MyException extends Exception class. So the problem is when I try to get the message from MyException class by calling myEx.getMessage() it returns
???en_US.Bad thing happened???
instead of my original message i.e. Bad thing happened
I have checked that MyException class doesn't overrides Throwable class's getMessage() behavior.
Below is the how the call passes from MyException.getMessage() to Throwable.getMessage()
public MyException(String msg, String sErrorCode){
super(msg);
this.sErrorCode = sErrorCode;
this.iSeverity = 0;
}
which then calls
public Exception(String message) {
super(message);
}
and finally
public Throwable(String message) {
fillInStackTrace();
detailMessage = message;
}
when I do a getMessage on myexception it calls Throwable's getMessage as below
public String getMessage() {
return detailMessage;
}
So ideally it should return the original message as I set when throwing the exception. What's the ???en_US thing ?
Hello,
So i need to create a tree with tree items for my gwt project. i am using the composite pattern to store all the information i need to be placed within a tree.
A User has a root Folder that extends Hierarchy, this root Folder then has a list of Hierarchy objects, that can be FileLocations or Folders. Trouble i am having is building my tree based on this pattern. this data is all stored using hibernate in a mysql database
How would i be able to implement this as a tree in gwt.
Also the tree item that i create would have to reference back to the object so i can rename or move it.
Hi all,
I am using the PropertySheetView component to visualize and edit the properties of a node. This view should always reflect the most recent properties of the object; if there is a change to the object in another process, I want to somehow refresh the view and see the updated properties.
The best way I was able to do this is something like the following (making use of EventBus library to publish and subscribe to changes in objects):
public DomainObjectWrapperNode(DomainObject obj) {
super (Children.LEAF, Lookups.singleton(obj));
EventBus.subscribe(DomainObject.class, this);
}
public void onEvent(DomainObject event) {
// Do a check to determine if the updated object is the one wrapped by this node;
// if so fire a property sets change
firePropertySetsChange(null, this.getPropertySets());
}
This works, but my place in the scrollpane is lost when the sheet refreshes; it resets the view to the top of the list and I have to scroll back down to where I was before the refresh action.
So my question is, is there a better way to refresh the property sheet view of a node, specifically so my place in the property list is not lost upon refresh?
I am writing a tomcat app, and have a need to do authentication within the URL like this:
https://user:[email protected]
Except for the life of me i'm not sure how to set it up or able to find the docs to read up on it, clearly my google skills need work.
Can anyone tell me where i should be looking for this kind of info or where to start?
Cheers
Andy