import CtCILibrary.*;
public class RotateMatrix {
public static boolean rotate (int [][]matrix) {
if ( matrix.length == 0 || matrix.length != matrix[0].length) {
return false;
}
int n = matrix.length;
for ( int layer = 0 ; layer < n / 2 ; layer++ ) {
int first = layer;
int last = n - 1 - first;
for ( int i = first ; i < last; i++ ) {
int offset = i - first;
int top = matrix[first][i];
//left-> top
matrix[first][i] = matrix [last-offset][first];
//bottom -> left
matrix[last-offset][first] = matrix [last][last-offset];
//right -> bottom
matrix[last][last-offset]= matrix[i][last];
//top->right
matrix[i][last]=top;
}
}
return true;
}
Hi there, I'm trying to import the CtCI library to solve the problem but there's an error message. And from her GitHub, that was how she imported this class. I know we can import the class from java built-in library. But I'm not sure how import works when trying to import from someone else. Could someone explain it to me?
If you are doing serious programming for a long term app, and by import you refer to libraries/dependencies, I highly recommend you using maven for it.
If you don't use maven yet, you can just add the .jar files from you IDE to your project path, but with maven is way better.
If you mean importing a .java file written by someone else, to use part of it in your code, just put the file at your project path, you probably need to adapt its libraries and imports, and once ready you can just use its methods ans stuff. Just make sure you have tipped at the top of your current file the import sentence of that file.
Related
The mupdf-x11 has WM_CLASS(STRING) = "mupdf", "MuPDF", but mupdf-gl has no. I need wm_class to use mupdf-gl correctly in FVWM. How can I solve this problem? Maybe by some small changing the source code before compilation? The solution suggested here is not working.
My friend programmer helped me and we found a solution by changing the source code of mupdf before compilation. In the file thirdparty/freeglut/src/x11/fg_menu_x11.c two changes made
After definition the function fgPlatformOpenWindow add XClassHint *classhint;. This block now read
void fgPlatformOpenWindow( SFG_Window* window, const char* title,
GLboolean positionUse, int x, int y,
GLboolean sizeUse, int w, int h,
GLboolean gameMode, GLboolean isSubWindow )
{
XClassHint *classhint;
After XSetWMProtocols add:
classhint = XAllocClassHint();
if (classhint)
{
classhint->res_name = "mupdf-gl";
classhint->res_class = "MuPDF-gl";
XSetClassHint(fgDisplay.pDisplay.Display, window->Window.Handle, classhint);
XFree(classhint);
}
After compilation, the window of mupdf-gl is identified as WM_CLASS(STRING) = "mupdf-gl", "MuPDF-gl".
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)?
Did anybody see this as well, or am I doing something wrong?
I am working on a test case with Katalon Studio, in script mode. I have some Groovy script in it, (in particular a class definition, see start of code below). When I switch mode to work in manual or record mode, and then back to script mode, the groovy code (the class declaration in the example below) has disappeared...
Not very practical! Anything that should be done to avoid this?
Many thanks!
E.
Code example:
//Katalon Imports here
class Product {
String nozo
String price_string
Number qty = 1
Number price_ht = 0
Number price_ttc = 0
Product(String nozo, String price_string, Number qty = 1) {
this.nozo = nozo
this.price_string = price_string
def get_price = (this.price_string =~/(\d+)\s(\d+\.\d{2})/)
if(get_price) {
this.price_ttc = get_price[1] + get_price[2]
}
else this.price_ttc = 0
this.price_ht = this.price_ttc / 1.2
}
def get_price_order_line_ht() {
return this.price_ht * this.qty
}
}
// Intialisation of test data
Number qty_pdt1 = 2
'Open home page'
WebUI.openBrowser('http://localhost:8080/')
'Navigate to subrange'
WebUI.doubleClick(findTestObject('Object Repository/vb_desktop/home_page_desktop_fr/a_Lampadaire'))
// Etc...
I already have some code to generate 2D kml files, but I am interested in reproducing an image similar to this, with an associated depth profile to each position:
Is there a good reference (or perhaps python library) for doing this? I have not managed to find anything.
Image reference:
Baird, R.W., S.W. Martin, D.L. Webster, and B.L. Southall. 2014. Assessment of Modeled Received Sound Pressure Levels and Movements of Satellite-Tagged Odontocetes Exposed to Mid-Frequency Active Sonar at the Pacific Missile Range Facility: February 2011 Through February 2013. Prepared for U.S. Pacific Fleet, submitted to NAVFAC PAC by HDR Environmental, Operations and Construction, Inc.
You may use other language to generate some kml files like the one in the following link:
https://sites.google.com/site/canadadennischen888/home/kml/3d-tracking
click download the attached file
select "save as" to see the KML content
select "open" to see result in Google Earth
hope this help
If you are using java, I have code to generate kml to display 3D tracking in google earth. (plus, a vertical line from air to ground for each point).
(assumption: Since you had code for 2D, you may already have java pojo code that converted from kml21.xsd.)
(p.s. I can attached you an image if you know any free site for me to upload image.)
Hope this help:
package com.googleearth.util;
import java.util.List;
import javax.xml.bind.JAXBElement;
import com.a.googleearth.entities.GoogleEarthView;
import com.a.googleearth.model.AltitudeModeEnum;
import com.a.googleearth.model.DocumentType;
import com.a.googleearth.model.FolderType;
import com.a.googleearth.model.KmlType;
import com.a.googleearth.model.LineStringType;
import com.a.googleearth.model.LineStyleType;
import com.a.googleearth.model.ObjectFactory;
import com.a.googleearth.model.PlacemarkType;
import com.a.googleearth.model.StyleType;
public class KmlService {
public static final byte[] blue = new byte[]{(byte)0x64,(byte)0xF0,(byte)0x00,(byte)0xFF};
private static ObjectFactory factory = new ObjectFactory();
static final String DEFAULT_REGISTRATION_FOR_EMPTY = "EMPTY";
public static JAXBElement<KmlType> createKml(List<GoogleEarthView> listGoogleEarthDBView) {
KmlType kml = factory.createKmlType();
DocumentType document = factory.createDocumentType();
kml.setFeature(factory.createDocument(document));
{
LineStyleType redLineStyle = factory.createLineStyleType();
// http://www.zonums.com/gmaps/kml_color/
redLineStyle.setColor(new byte[]{(byte)0xFF,(byte)0xF0,(byte)0x00,(byte)0x14});
redLineStyle.setWidth(5f);
StyleType style = factory.createStyleType();
style.setId("blueLine");
style.setLineStyle(redLineStyle);
document.getStyleSelector().add(factory.createStyle(style));
}
FolderType folder = factory.createFolderType();
folder.setName(listGoogleEarthDBView.get(0).getFolderName());
document.getFeature().add(factory.createFolder(folder));
PlacemarkType currentPlacemark = null;
for (GoogleEarthView view : listGoogleEarthDBView) {
if (currentPlacemark == null || currentPlacemark.getName().equalsIgnoreCase("F0001") == false) {
if (currentPlacemark != null) {
JAXBElement<LineStringType> lineString = (JAXBElement<LineStringType>) currentPlacemark.getGeometry();
lineString.getValue().getCoordinates().add(view.getLongitude() + "," + view.getLatitude() + "," + view.getPressureAltitude()+"\n");
}
currentPlacemark = createF0001Placemark();
folder.getFeature().add(factory.createPlacemark(currentPlacemark));
}
JAXBElement<LineStringType> lineString = (JAXBElement<LineStringType>) currentPlacemark.getGeometry();
lineString.getValue().getCoordinates().add(view.getLongitude() + "," + view.getLatitude() + "," + view.getPressureAltitude()+"\n");
}
JAXBElement<KmlType> kmlElement = factory.createKml(kml);
return kmlElement;
}
private static PlacemarkType createF0001Placemark() {
PlacemarkType placeMark = factory.createPlacemarkType();
placeMark.setName("F0001");
placeMark.setStyleUrl("#blueLine");
LineStringType flyhtStreamLineString = factory.createLineStringType();
flyhtStreamLineString.setAltitudeMode(AltitudeModeEnum.ABSOLUTE);
flyhtStreamLineString.setExtrude(Boolean.TRUE);
placeMark.setGeometry(factory.createLineString(flyhtStreamLineString));
return placeMark;
}
}
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.