Whenever I try to use decrement in wrong way Eclipse stops working. Seems it started to happen after I installed Lombok. The code is shown below:
public class Patterns {
public static void main(String[] args) {
pattern31(5);
}
static void pattern31(int n) {
n = 5;
for (int row = 1 ; row <= n; row++) {
int columns = row>n ? 2*n-row:row;
int space=n-columns;
int p='A';
for(int s=0; s<=space; s++) {
System.out.print(" ");
}
for(int col=1; col<columns; col++) {
System.out.print((char) p++ +" ");
}
for(int col=2; col<=columns; col--) {
System.out.print((char) p++ +" ");
}
System.out.println();
}
}
}
I also have this message in the log:
!MESSAGE Warning: The environment variable HOME is not set. The following directory will be used to store the Git
user global configuration and to define the default location to store repositories: 'C:\Users\User'. If this is
not correct please set the HOME environment variable and restart Eclipse. Otherwise Git for Windows and
EGit might behave differently since they see different configuration options.
This warning can be switched off on the Team > Git > Confirmations and Warnings preference page.
Related
I'm trying to make a minimal working example of JUnit5 using Visual Studio code without Maven. The reason is that I'm trying to make a quick demo for 1st year students, and I don't have the time to explain Maven (it will be the subject of a later course).
My VS Code workspace has this structure (I'm on Linux so forward slashes are normal) :
The settings.json file contains:
{
"java.project.referencedLibraries": [
"demojunit/junit-platform-console-standalone-1.8.1.jar"
]
}
The DemoJUnit.java contains:
package demojunit;
import java.util.Scanner;
public class DemoJUnit {
public static void main(String[] args) {
Scanner keyboard = new Scanner(System.in);
int integer = -1;
do {
System.out.print("Enter an integer between 1 and 20 : ");
if (keyboard.hasNextInt())
integer = keyboard.nextInt();
keyboard.nextLine();
} while ((integer < 1) || (integer > 20));
keyboard.close();
long result = computeFactorial(integer);
System.out.println("The factorial " + integer + "! gives " + result);
}
public static long computeFactorial(int number) {
if (number < 1)
return -1;
if (number > 20)
return -2;
long factorial = 1;
for (int i = 2; i <= number; i++) {
factorial = factorial * i;
}
return factorial;
}
}
And the DemoJUnitTest.java contains:
package demojunit;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
public class DemoJUnitTest {
#Test
public static void computeFactorial_CleanTest() {
long expected_value = 120;
long real_value = DemoJUnit.computeFactorial(5);
Assertions.assertEquals(expected_value, real_value);
}
#Test public static void computeFactorial_DirtyTest() {
long expected_value = -1;
long real_value = DemoJUnit.computeFactorial(0);
Assertions.assertEquals(expected_value, real_value);
}
}
The settings.json seems to work since the imports and #Test are not marked as errors in VS Code.
As you can see in the folder image, I downloaded the latest JUnit5 jar file, and it works when running from the command line:
However, running from the command line is not convenient, so I installed the "Test Runner for Java" extension.
The problem is that when running tests, something fails and I don't have any error messages, nor any indication what went wrong. I changed the extensions' settings to be verbose but I still get no error messages in the Terminal, the Debug Console, nor anywhere else.
All I get is :
Any idea why the extension fails (and fails to give any indication on why it fails)?
When I try to execute the first-n-integers extension example:
show noise:first-n-integers 5
I receive an error "ERROR: Expected command. " in the console or in the code tab.
I have mostly copied and pasted the class examples as is, just renaming them and putting them in a different package. I wish the error was a little more descriptive, as I suspect I am making a simple error somewhere.
I'm using 5.0.4 without the JRE and a 1.7.0_45 JRE/JDK on a x64 Windows 7 machine.
My manifest.txt file with fully-qualified class-manager and crlf at the end of the version line--
Manifest-Version: 1.0
Extension-Name: noise
Class-Manager: org.xyz.extensions.NoiseExtension
NetLogo-Extension-API-Version: 5.0 <--there is a crlf here
the jar is in a subfolder with my model file
test/
test.nlogo
noise/
noise.jar
This is my Class-Manager:
package org.xyz.extensions;
import org.nlogo.api.*;
public class NoiseExtension extends DefaultClassManager {
public void load(PrimitiveManager primitiveManager) {
primitiveManager.addPrimitive(
"first-n-integers", new org.xyz.extensions.NoiseGenerator());
}
}
This is the NoiseGenerator file:
package org.xyz.extensions;
import org.nlogo.api.*;
public class NoiseGenerator extends DefaultReporter {
public Syntax getSyntax() {
return Syntax.reporterSyntax(
new int[] {Syntax.NumberType()}, Syntax.ListType());
}
public Object report(Argument args[], Context context) throws ExtensionException {
// create a NetLogo list for the result
LogoListBuilder list = new LogoListBuilder();
int n ;
// use typesafe helper method from
// org.nlogo.api.Argument to access argument
try {
n = args[0].getIntValue();
}
catch(LogoException e) {
throw new ExtensionException( e.getMessage() ) ;
}
if (n < 0) {
// signals a NetLogo runtime error to the modeler
throw new ExtensionException
("input must be positive");
}
// populate the list. note that we use Double objects; NetLogo
// numbers are always Doubles
for (int i = 0; i < n; i++) {
list.add(Double.valueOf(i));
}
return list.toLogoList();
}
}
Thanks for any help.
AJB
This was asked and answered here:
https://groups.google.com/d/msg/netlogo-devel/eIq8drflsc8/7y_Ooh6R0sgJ
The answer was to correct the spelling of getSynax to getSyntax.
I've implemented a TreeGrid, that is bound to a RestDataSource in SmartGWT.
To provide a numeration, i have a TreeGridField called requirementListing, which is calculated on the client-side.
After each update, i run a function that (re)calculates the numeration.
the numeration looks like this.
1. Item 1 in level 0
|_ 1.1 item 1 in level 1
|_ 1.1.1 item 1 in level 2
2. Item 2 in level 0
To trigger the calculation function after an update of a node accured, i've used several Handlers like
DataArrivedHandler
EditCompleteHandler
RemoveRecordClickHandler
All these work properly, the only case the numeration doesn't update is, if I move an item to another folder (or within a folder).
I tried to call the numeration function from DropCompleteHandler and FolderDropHandler, none of them seem to work.
After reading Tree - drag&drop nodes - refresh? I'm using a DeferredComand, which worked in Chrome, but not in Firefox. With the newest version of SmartGWT it won't work in Chrome either.
requirementTreeGrid.addDropCompleteHandler(new DropCompleteHandler() {
#SuppressWarnings("deprecation")
#Override
public void onDropComplete(DropCompleteEvent event) {
SC.logInfo("Drop complete");
DeferredCommand.addCommand(new Command() {
public void execute() {
treeNumerator.addTreeNumeration(requirementTreeGrid);
requirementTreeGrid.refreshFields();
requirementTreeGrid.redraw();
SC.logInfo("tree updated");
}
});
}
});
requirementTreeGrid.addFolderDropHandler(new FolderDropHandler() {
//same code like above
});
}
});
Since DeferredCommand is deprecated I also tried it with Scheduler.scheduleDeferred() but sadly this didn't work out either.
My numeration function:
public void addTreeNumeration(TreeGrid treeGrid) {
this.levels = new Integer[numberOfLevels];
for (int i=0; i<=numberOfLevels-1;i++){ //fill array with 1
levels[i] = 1;
}
TreeNode rootNode = treeGrid.getTree().getRoot(); // root element of tree
int levelIndex = 0;
calculateRequirementTreeNumeration(treeGrid, treeGrid.getTree()
.getChildren(rootNode), levelIndex, levels);
}
private void calculateRequirementTreeNumeration(TreeGrid treeGrid,
TreeNode[] lvlNodes, int levelIndex, Integer[] levels) {
levels[levelIndex]=1;
for (TreeNode lvlNode : lvlNodes) {
String numerationLabel = "";
for (int i = 0; i <= levelIndex; i++) {
numerationLabel = numerationLabel + levels[i] + ".";
}
SC.logInfo("->Req " + numerationLabel);
lvlNode.setAttribute("requirementListing", numerationLabel);
// weitere ebene?
if (treeGrid.getTree().hasChildren(lvlNode)) {
SC.logInfo(numerationLabel + " -> new level");
if (levelIndex + 1 < numberOfLevels) { // nur "numberOfLevels" ebenen werden berechnet.
calculateRequirementTreeNumeration(treeGrid, treeGrid
.getTree().getChildren(lvlNode), levelIndex + 1,
levels);
} else {
deleteRequirementTreeNumeration(treeGrid, treeGrid
.getTree().getChildren(lvlNode), levelIndex + 1);
}
}
levels[levelIndex]++;
}
}
I've also debugged the problem with the client developer console, and it seems to me that the problem is that the numeration is done after the drop but before the RestDataSource sent a response. It looks like the node i just moved is gone, until the DS sends a response. (and therefore the requirementListing field is not updated)
JavaScriptDebug:
12:35:35.724:MUP5:INFO:Log:Drop complete
12:35:35.736:INFO:Log:->Req 1.
12:35:35.736:INFO:Log:1. -> new level
12:35:35.736:INFO:Log:->Req 1.1.
12:35:35.736:INFO:Log:->Req 1.2.
12:35:35.736:INFO:Log:->Req 2.
12:35:35.736:INFO:Log:2. -> new level
12:35:35.737:INFO:Log:->Req 2.1.
12:35:35.737:INFO:Log:->Req 2.2.
12:35:35.737:INFO:Log:->Req 2.3.
12:35:35.737:INFO:Log:->Req 3.
12:35:35.738:INFO:Log:3. -> new level
12:35:35.738:INFO:Log:->Req 3.1.
12:35:35.742:INFO:Log:->Req 3.2.
12:35:35.744:INFO:Log:->Req 3.3.
12:35:35.744:INFO:Log:3.3. new level
12:35:35.744:INFO:Log:->Req 3.3.1.
12:35:35.745:INFO:Log:->Req 3.3.2.
........
12:35:35.756:DEBUG:TreeGrid:isc_TreeGrid_0:delaying adjustOverflow: childClear
12:35:35.866:INFO:Log:tree updated
12:35:35.878:XRP8:INFO:ResultTree:isc_ResultTree_0 (created by: isc_TreeGrid_0):Updating cache: operationType 'update', 1 rows update data:
[
{id: 32,
parentId: 40,
requirement: "g",
typ: undef,
cluster: undef}
]
12:35:35.878:XRP8:DEBUG:ResultTree:isc_ResultTree_0 (created by: isc_TreeGrid_0):updated cache: 0 row(s) added, 1 row(s) updated, 0 row(s) removed.
Maybe someone experienced a similar problem? I'm really not sure how to solve this problem.
My Version of SmartGWT: 4.1d /SmartClient v9.1d_2013-08-11/LGPL (built 2013-08-11)
I don't know about treegrid but i have a simple tree for the menu and i update the nodes by setting a new array with the parent of the nodes set as one integer (converted to string) and the nodes get updated by calling the linknodes(arrayOfNodes) method...
#include<stdio.h>
#include<stdlib.h>
#include<unistd.h>
#include<sys/sem.h>
#include<sys/ipc.h>
int sem_id;
void update_file(int number)
{
struct sembuf sem_op;
FILE* file;
printf("Inside Update Process\n");
/* wait on the semaphore, unless it's value is non-negative. */
sem_op.sem_num = 0;
sem_op.sem_op = -1; /* <-- Amount by which the value of the semaphore is to be decreased */
sem_op.sem_flg = 0;
semop(sem_id, &sem_op, 1);
/* we "locked" the semaphore, and are assured exclusive access to file. */
/* manipulate the file in some way. for example, write a number into it. */
file = fopen("file.txt", "a+");
if (file) {
fprintf(file, " \n%d\n", number);
fclose(file);
}
/* finally, signal the semaphore - increase its value by one. */
sem_op.sem_num = 0;
sem_op.sem_op = 1;
sem_op.sem_flg = 0;
semop( sem_id, &sem_op, 1);
}
void write_file(char* contents)
{
printf("Inside Write Process\n");
struct sembuf sem_op;
sem_op.sem_num = 0;
sem_op.sem_op = -1;
sem_op.sem_flg = 0;
semop( sem_id, &sem_op, 1);
FILE *file = fopen("file.txt","w");
if(file)
{
fprintf(file,contents);
fclose(file);
}
sem_op.sem_num = 0;
sem_op.sem_op = 1;
sem_op.sem_flg = 0;
semop( sem_id, &sem_op, 1);
}
int main()
{
//key_t key = ftok("file.txt",'E');
sem_id = semget( IPC_PRIVATE, 1, 0600 | IPC_CREAT);
/*here 100 is any arbit number to be assigned as the key of the
semaphore,1 is the number of semaphores in the semaphore set, */
if(sem_id == -1)
{
perror("main : semget");
exit(1);
}
int rc = semctl( sem_id, 0, SETVAL, 1);
pid_t u = fork();
if(u == 0)
{
update_file(100);
exit(0);
}
else
{
wait();
}
pid_t w = fork();
if(w == 0)
{
write_file("Hello!!");
exit(0);
}
else
{
wait();
}
}
If I run the above code as a c code, the write_file() function is called after the update_file () function
Whereas if I run the same code as a c++ code, the order of execution is reverse... why is it so??
Just some suggestions, but it looks to me like it could be caused by a combination of things:
The wait() call is supposed to take a pointer argument (that can
be NULL). Compiler should have caught this, but you must be picking
up another definition somewhere that permits your syntax. You are
also missing an include for sys/wait.h. This might be why the
compiler isn't complaining as I'd expect it to.
Depending on your machine/OS configuration the fork'd process may
not get to run until after the parent yields. Assuming the "wait()"
you are calling isn't working the way we would be expecting, it is
possible for the parent to execute completely before the children
get to run.
Unfortunately, I wasn't able to duplicate the same temporal behavior. However, when I generated assembly files for each of the two cases (C & C++), I noticed that the C++ version is missing the "wait" system call, but the C version is as I would expect. To me, this suggests that somewhere in the C++ headers this special version without an argument is being #defined out of the code. This difference could be the reason behind the behavior you are seeing.
In a nutshell... add the #include, and change your wait calls to "wait(0)"
Update sites with RCPs prohibits orphan plugins, otherwise plugins that are not in a feature.
If this condition is not filled, the update manager returns the following error:
Resulting configuration does not contain the platform.
Unfortunately, no way to determine which plugins are orphan.
How to find orphan plugins ?
Here's a starting point (this applies for Eclipse 3.4 and later, when the P2 repository was introduced, earlier versions store their configuration differently. IIRC you could see all the plugins and features in platform.xml).
Create a new plugin project (New->Other->Plug-in Development->Plug-in Project) with the "Hello World" template then drop this code into the run method of the SampleAction.
Run the plugin as a test Eclipse Application and select Sample Menu->Sample Action, the plugins that don't belong to a feature will be output to the parent workspace's console. When I ran this there were quite a few more than I expected, I've had a few looks through and can't spot the logic error.
Edit, found logic error, was using the wrong array index used in innermost loop. Still not quite right though.
Edit 2. (Facepalm moment) Found the problem. Be sure to run the target workspace with all workspace and enabled target plugins enabled, or it will skew your results, obviously. If you install the plugin and dress it up a little bit you won't have this problem.
//get all the plugins that belong to features
IBundleGroupProvider[] providers = Platform.getBundleGroupProviders();
Map<Long, IBundleGroup> bundlesMap = new HashMap<Long, IBundleGroup>();
if (providers != null) {
for (int i = 0; i < providers.length; i++) {
IBundleGroup[] bundleGroups = providers[i].getBundleGroups();
System.out.println("Bundle groups:");
for (int j = 0; j < bundleGroups.length; j++) {
Bundle[] bundles = bundleGroups[j] == null ? new Bundle[0] : bundleGroups[j]
.getBundles();
System.out.println(bundleGroups[j].getIdentifier());
for (int k = 0; k < bundles.length; k++) {
bundlesMap.put(bundles[k].getBundleId(), bundleGroups[j]);
}
}
}
}
BundleContext bundleContext = Activator.getDefault().getBundle().getBundleContext();
if(bundleContext instanceof BundleContextImpl) {
Bundle[] bundles = ((BundleContextImpl)bundleContext).getBundles();
System.out.println("Orphan Bundles:");
for (int i = 0; i < bundles.length; i++) {
if(!bundlesMap.containsKey(bundles[i].getBundleId())) {
System.out.println(bundles[i].getSymbolicName());
}
}
}