Sunday 1 September 2013

Java Generics difference between wildcard and generic parameter type

Java Generics difference between wildcard and generic parameter type

Could someone explain to me why the third method doesnt compile?
public class Test{
public <K> void test(List<K> list){ //Compiles
K n = list.get(0);
}
public void test(List<? extends Number> list){ //Compiles
Number n = list.get(0);
}
public <K> void test(List<K extends Number> list){ //Doesn't compile !!
Number n = list.get(0);
}
}

Python regex on numbers

Python regex on numbers

Is it possible to use regex on a number instead of a string?
For example: I have a field in a mongodb that contains the numeric value
1234567 (not stored as a string for sorting purposes etc.). Now I want to
use regex to find parts of this number, i.e. 456.
On a database-field that contains a string "1234567" this is easy: I just
pass re.compile("456") to my database query. However re.compile(456) gets
me the following: "TypeError: first argument must be string or compiled
pattern" :-(
Any hints on how to accomplish this? Storing my numbers as strings is not
really an option, since I would loose lots of other possibilities (like
gt/lt, sorting etc.)
Thanks in advance.

spool out put to particular file from command prompt

spool out put to particular file from command prompt

i want to spool my out put to particular file .my database in sql server.i
given code in command prompt like this: first i am connecting to my data
base like this: sqlcmd -S SUPPORT2/SUPPORT2 -U sa -P solutions
SUPPORT2/SUPPORT2 is a my server name then i am giving my databse
name(vallett)
then i am taking Ename from EmployeeMaster_tbl i want to spool this out
put to particular word file how i can do this?

Saturday 31 August 2013

Update to the database error when enter more than 1 value

Update to the database error when enter more than 1 value

i have a problem, the program just read the first entered Quantity value
in the program and apply it to all rows in database and the value of first
and second row are same, even though in the beginning, first and second
row value are different.
Note: The Database 1 until 1.3 and Program 1 until 1.2 are working
properly, i just want to show you to not confuse you later. My problem is
on Database 1.5 and Program 1.4 , Database 1.6 are just wanted to show
you, the Database supposed to be like that.
First of all, my database is like this:
Product Code || Quantity (Database 1)
0001 100
0002 150
And when i run the program and entered the first "Product Code" in first
row and want to change the first Quantity value to 25, so i just enter 75
in Quantity in the program at the first row like this:
Product Code || Quantity (Program 1, 0001 is at the **first row**)
0001 75
And when i click update, the database changed to this (it works fine):
Product Code || Quantity (Database 1.1)
0001 25
0002 150
When i change the first "Product Code" in first row to second "Product
Code" in first row and want to change the second Quantity value to 100, so
i just enter 50 in Quantity in the program in the first row like this:
Product Code || Quantity (Program 1.2, 0002 still at the **first row**)
0002 50
And when i click update, the database changed to this (it works fine):
Product Code || Quantity (Database 1.3)
0001 25
0002 100
But, when i enter the first "Product Code" in first row and second
"Product code in second row in my program like this:
Product Code || Quantity (Program 1.4, 0001 at **first row** and 0002 at
**second row**)
0001 10
0002 25
And when i click update, the database changed to this (it supposed to be
like Database below):
Product Code || Quantity (Database 1.6)
0001 15
0002 85
But instead of the Database above, it changed to this (it is not working
like i want):
Product Code || Quantity (Database 1.5)
0001 15
0002 15
So, it is like the second row at the database are being ignored and
changed to the same value like in the first row, when i enter both value
at the same time in the program.
Here is the code:
private void UpdateQuantity()
{
int codeValue = 0;
int index = 0;
List<int> integers = new List<int>();
foreach (var tb in textBoxCodeContainer)
{
if (int.TryParse(tb.Text, out codeValue))
{
integers.Add(codeValue);
}
}
using (OleDbConnection conn = new
OleDbConnection(connectionString))
{
conn.Open();
string commandSelect = "SELECT [Quantity], [Description],
[Price] FROM [Seranne] WHERE [Code] = @Code";
string commandUpdate = "UPDATE [Seranne] SET [Quantity] =
@Quantity WHERE [Code] IN(" + string.Join(", ", integers)
+ ")";
using (OleDbCommand cmdSelect = new
OleDbCommand(commandSelect, conn))
using (OleDbCommand cmdUpdate = new
OleDbCommand(commandUpdate, conn))
{
cmdSelect.Parameters.Add("Code",
System.Data.OleDb.OleDbType.Integer);
cmdSelect.Parameters["Code"].Value =
this.textBoxCodeContainer[index].Text;
cmdUpdate.Parameters.Add("Quantity",
System.Data.OleDb.OleDbType.Integer);
using (OleDbDataReader dReader =
cmdSelect.ExecuteReader())
{
while (dReader.Read())
{
if (textBoxQuantityContainer[index].Value != 0)
{
newVal =
Convert.ToInt32(dReader["Quantity"].ToString())
- textBoxQuantityContainer[index].Value;
cmdUpdate.Parameters["Quantity"].Value =
newVal;
int numberOfRows =
cmdUpdate.ExecuteNonQuery();
}
index += 1;
}
dReader.Close();
}
}
conn.Close();
}
}
Could you guys please help me? Thanks.

Code to draw a star

Code to draw a star

I looked up how to draw a star in Java, and I found the following code:
public void paint(Graphics g) {
drawStar(g,Color.BLACK,5,300,300,100,1…
drawStar(g,Color.RED,6,100,100,20,20);
drawStar(g,Color.BLUE,9,200,400,40,40)…
drawStar(g,Color.YELLOW,27,400,200,10,…
drawStar(g,Color.GREEN,400,300,300,250…
}
public double circleX(int sides, int angle) {
double coeff = (double)angle/(double)sides;
return Math.cos(2*coeff*Math.PI-halfPI);
}
public double circleY(int sides, int angle) {
double coeff = (double)angle/(double)sides;
return Math.sin(2*coeff*Math.PI-halfPI);
}
public void drawStar(Graphics g, Color c, int sides, int x, int y, int w,
int h) {
Color colorSave = g.getColor();
g.setColor(c);
for(int i = 0; i < sides; i++) {
int x1 = (int)(circleX(sides,i) * (double)(w)) + x;
int y1 = (int)(circleY(sides,i) * (double)(h)) + y;
int x2 = (int)(circleX(sides,(i+2)%sides) * (double)(w)) + x;
int y2 = (int)(circleY(sides,(i+2)%sides) * (double)(h)) + y;
g.drawLine(x1,y1,x2,y2);
}
}
}
halfPI is defined as a private static variable outside the body
I don't quite get the logic behind these methods. Could someone offer an
explanation?

Eclipse Color Theme is not working

Eclipse Color Theme is not working

I am Ubuntu 13.04, Eclipse 4.2.1(ADT v22) user.
I encounted error when I might add plugin which is Eclipse Color Theme for
eclipse.
And in Preferences-General-Appearance, when I click Color Theme output
error log...
(Eclipse Color Theme get on Help-install new software
http://eclipse-color-theme.github.com/update
errTitle: Unhandled event loop exception
org.eclipse.swt.SWTException: Failed to execute runnable
(org.eclipse.swt.SWTError: No more handles [Unknown Mozilla path
(MOZILLA_FIVE_HOME not set)])
at org.eclipse.swt.SWT.error(SWT.java:4361)
at org.eclipse.swt.SWT.error(SWT.java:4276)
at
org.eclipse.swt.widgets.Synchronizer.runAsyncMessages(Synchronizer.java:138)
at org.eclipse.swt.widgets.Display.runAsyncMessages(Display.java:3537)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3189)
at org.eclipse.jface.window.Window.runEventLoop(Window.java:825)
at org.eclipse.jface.window.Window.open(Window.java:801)
at
org.eclipse.ui.internal.dialogs.WorkbenchPreferenceDialog.open(WorkbenchPreferenceDialog.java:215)
at
org.eclipse.ui.internal.OpenPreferencesAction.run(OpenPreferencesAction.java:65)
at org.eclipse.jface.action.Action.runWithEvent(Action.java:498)
..
..
..
at org.eclipse.jface.util.OpenStrategy$3.run(OpenStrategy.java:433)
at org.eclipse.swt.widgets.RunnableLock.run(RunnableLock.java:35)
at
org.eclipse.swt.widgets.Synchronizer.runAsyncMessages(Synchronizer.java:135)
... 35 more
and close Preference, more error happened.
errTitle: java.lang.ArrayIndexOutOfBoundsException: 0
java.lang.ArrayIndexOutOfBoundsException: 0
at
com.github.eclipsecolortheme.preferences.ColorThemePreferencePage.performOk(ColorThemePreferencePage.java:207)
at
org.eclipse.jface.preference.PreferenceDialog$13.run(PreferenceDialog.java:965)
at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
at org.eclipse.ui.internal.JFaceUtil$1.run(JFaceUtil.java:49)
at org.eclipse.jface.util.SafeRunnable.run(SafeRunnable.java:175)
at
org.eclipse.jface.preference.PreferenceDialog.okPressed(PreferenceDialog.java:945)
at
org.eclipse.ui.internal.dialogs.FilteredPreferenceDialog.okPressed(FilteredPreferenceDialog.java:448)
at
org.eclipse.ui.internal.dialogs.WorkbenchPreferenceDialog.okPressed(WorkbenchPreferenceDialog.java:171)
at
org.eclipse.jface.preference.PreferenceDialog.buttonPressed(PreferenceDialog.java:233)
at org.eclipse.jface.dialogs.Dialog$2.widgetSelected(Dialog.java:624)
at org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListener.java:248)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1276)
at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:3562)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3186)
at org.eclipse.jface.window.Window.runEventLoop(Window.java:825)
at org.eclipse.jface.window.Window.open(Window.java:801)
at
org.eclipse.ui.internal.dialogs.WorkbenchPreferenceDialog.open(WorkbenchPreferenceDialog.java:215)
at
org.eclipse.ui.internal.OpenPreferencesAction.run(OpenPreferencesAction.java:65)
at org.eclipse.jface.action.Action.runWithEvent(Action.java:498)
at
org.eclipse.jface.action.ActionContributionItem.handleWidgetSelection(ActionContributionItem.java:584)
at
org.eclipse.jface.action.ActionContributionItem.access$2(ActionContributionItem.java:501)
at
org.eclipse.jface.action.ActionContributionItem$5.handleEvent(ActionContributionItem.java:411)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1276)
at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:3562)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3186)
at
org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$9.run(PartRenderingEngine.java:1053)
at
org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
at
org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.run(PartRenderingEngine.java:942)
at
org.eclipse.e4.ui.internal.workbench.E4Workbench.createAndRunUI(E4Workbench.java:86)
at org.eclipse.ui.internal.Workbench$5.run(Workbench.java:588)
at
org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
at
org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:543)
at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
at
org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:124)
at
org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
at
org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110)
at
org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79)
at
org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:353)
at
org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:180)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:629)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:584)
at org.eclipse.equinox.launcher.Main.run(Main.java:1438)
How do I fix it for Eclipse Color Theme working?

DetailViewController programmatically iOS

DetailViewController programmatically iOS

Im using a custom ModalViewController called MZFormSheetController to
display a Detail View for UICollectionView. Currently I have created
properties in the modal view controller such as these :
@property (strong,nonatomic) NSString *user;
@property (strong,nonatomic) NSString *caption;
@property (weak, nonatomic) IBOutlet UILabel *username;
@property (weak, nonatomic) IBOutlet UILabel *captiontext;
And I attempt to set the display of the detail view controller when the
user taps on the UICollectionViewCell like this: -
(void)collectionView:(UICollectionView *)collectionView
didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
NSDictionary *entry = [self entries][indexPath.row];
NSDictionary *text = [self entries][indexPath.row];
ModalViewController *m = [self.storyboard
instantiateViewControllerWithIdentifier:@"modalView"];
m.entry = [self entries][indexPath.row];
m.text = [self entries][indexPath.row];
m.user = entry[@"user"][@"full_name"];
m.caption = text[@"caption"][@"text"];
MZFormSheetController *formSheet = [[MZFormSheetController alloc]
initWithViewController:m];
formSheet.transitionStyle = MZFormSheetTransitionStyleDropDown;
formSheet.shouldDismissOnBackgroundViewTap = YES;
[formSheet presentAnimated:YES completionHandler:^(UIViewController
*presentedFSViewController) {
}];
formSheet.didTapOnBackgroundViewCompletionHandler = ^(CGPoint location)
{
};
}
I have created two labels in storyboard for the modalviewcontroller and I
attempt to make them equal the caption and user values from the
MainViewController like this
[self.username.text isEqualToString:self.user];
[self.captiontext.text isEqualToString:self.caption];
However after all this the labels of the modal view controller still say
label like this..