id stringlengths 36 36 | text stringlengths 1 1.25M |
|---|---|
5d04e64a-29f7-407f-bbd8-d94710149ec7 | private static String unescape_space(String s) {
s = s.replace("%20", " ");
return s;
} |
2a2f61be-8fac-4674-9456-12ed149569e1 | private static String unescape_unicode_rus(String s) {
for (int index = 0; index < ESCAPE_CHARS.length; ++index)
s = s.replace(ESCAPE_CHARS[index], RUSSIAN_CHARS[index]);
return s;
} |
3acf0688-8b91-418f-903f-c98f9abd1a82 | private static String unescape_win1251_rus(String s) {
for (int index = 0; index < WIN1251_CHARS.length; ++index)
s = s.replace(WIN1251_CHARS[index], RUSSIAN_CHARS[index]);
return s;
} |
cc684ba0-2e9c-4750-ac17-88a5905db4a4 | public static String replaceToUpCase(String s, Pattern p) {
StringBuilder text = new StringBuilder(s);
Matcher m2 = p.matcher(text);
int matchPointer = 0;// First search begins at the start of the string
while (m2.find(matchPointer)) {
matchPointer = m2.end(); // Next search starts from where this one
// ... |
653c202a-b118-4f7d-9df7-274484b1a053 | public static byte[] readRawLine(InputStream inputStream) throws IOException {
ByteArrayOutputStream buf = new ByteArrayOutputStream();
int ch;
while ((ch = inputStream.read()) >= 0) {
buf.write(ch);
if (ch == '\n') {
break;
}
}
if (buf.size() == 0) {
return null;
}
return buf.toByteArray... |
d8005484-0333-498c-981b-c8ad808e8e1f | public static String readLine(InputStream inputStream) throws IOException {
byte[] rawdata = readRawLine(inputStream);
if (rawdata == null) {
return null;
}
int len = rawdata.length;
int offset = 0;
if (len > 0) {
if (rawdata[len - 1] == '\n') {
offset++;
if (len > 1) {
if (rawdata[len - ... |
7ae7a215-8eee-46ef-8a35-f905e5557197 | public static String getString(final byte[] data, int offset, int length) {
if (data == null) {
throw new IllegalArgumentException("Parameter may not be null");
}
try {
return new String(data, offset, length, HTTP_ELEMENT_CHARSET);
} catch (Exception e) {
return new String(data, offset, length);
}
... |
581055bc-e68d-4492-98b2-70eb24d17150 | public static void main(String[] args) throws UnknownHostException,
IOException {
try {
ServerSocket serverSocket = new ServerSocket(3132, 50, InetAddress.getByName("localhost"));
// ServerSocket serverSocket = new ServerSocket(3132, 1000, InetAddress.getByName("192.168.117.1... |
c517ebee-7c69-4504-afb2-0153aa954bba | private ThreadPool() {
} |
7fc98177-7370-427b-a0aa-b7d8ca60c30a | public static ThreadPool getInstance() {
return INSTANCE;
} |
9308f429-6e9f-4b7f-bd7a-3f11fd804e57 | public void addOrPut(Socket s) throws Exception {
InputStream is; // входящий поток от сокета
OutputStream os; // исходящий поток от сокета
is = s.getInputStream();
os = s.getOutputStream();
byte buf[] = new byte[64 * 1024];
int r = is.read(buf);
String header =... |
ce3469a5-c08a-4f30-99c2-3bef83de1749 | protected void printError(OutputStream os, String err) throws Exception {
os.write((new String(PROXY_ERROR + err)).getBytes());
} |
c55a0c4e-51cf-4bab-8bd2-8f18197a3bf6 | public AppTest( String testName )
{
super( testName );
} |
6079e89f-7376-4eac-b419-9247a22d32bf | public static Test suite()
{
return new TestSuite( AppTest.class );
} |
ee787dab-cb7b-4795-bc74-536dbb21f70d | public void testApp()
{
assertTrue( true );
} |
10301af9-f1c5-4923-945f-1bf0759891b7 | public Agent(Simulation controller) {
sim = controller;
age = 0;
energy = 6;
} |
7aedbc5e-c575-45a2-9433-a979ceab59f8 | public void act() {
// This function handles all of an Agents' behavior in
// any given step.
// First, check if the Agent has enough energy to survive
// the step, otherwise remove it.
if (energy < metabolism) {
remove();
} else {
// Let the Agent kn... |
5b653354-b9fb-4f6c-8606-f921f8367f93 | public Site findBestSite(Vector<Site> freeSites) {
// Your own code determining what the best Site is of all
// possible freeSites for the agent to move to;
Iterator<Site> i = freeSites.iterator();
Site bestSite = new Site();
double gain = Double.NEGATIVE_INFINITY;
double ne... |
e2a1f03f-6cc5-4e26-bdc7-77bc57e00fda | public void move(Site newSite) {
sim.grid[this.xPosition][this.yPosition].setAgent(null);
energy -= moveCost*pythagoras(this.xPosition, newSite.getXPosition(), this.yPosition, newSite.getYPosition());
this.xPosition = newSite.getXPosition();
this.yPosition = newSite.getYPosition();
... |
40b08245-58ca-4732-8cc9-02e1e982a08c | public void reap(Site s) {
this.energy += s.getFood();
s.setFood(0.0);
} |
79e85db8-159c-4a6a-9041-ea45043fff38 | public void procreate(Vector<Site> babySites) {
energy -= procreateCost;
Agent baby = new Agent(sim);
sim.agents.add(baby);
Site babySite = (Site) babySites.elementAt(0);
baby.setPosition(babySite.getXPosition(), babySite.getYPosition());
babySite.setAgent(baby);
} |
6e64db56-75b3-46e1-b984-a53ff8180667 | public void remove() {
sim.agents.remove(this);
sim.grid[xPosition][yPosition].setAgent(null);
} |
490abd69-4d84-49ca-a3a6-c60d115fc47c | public Vector<Site> findFreeSites() {
Vector<Site> freeSites = new Vector<Site>();
for (int m = -vision; m <= vision; m++) {
for (int n = -vision; n <= vision; n++) {
Site site;
int x = xPosition + m;
int y = yPosition + n;
if ... |
7dd0e9b6-a132-472f-b4be-48c3f27c468a | public Vector<Site> findBabySites() {
Vector<Site> babySites = new Vector<Site>();
for (int m = -1; m <= 1; m++) {
for (int n = -1; n <= 1; n++) {
Site site;
int x = xPosition + m;
int y = yPosition + n;
if (x >= 0 && x < sim.x... |
65a7c65e-d6cf-4019-990a-71ba55c8ba27 | public double calculateDistance(int x, int y) {
return Math.sqrt(Math.pow((x - xPosition), 2) + Math.pow((y - yPosition), 2));
} |
4db16093-0b8b-4d34-ad23-31909eb9d90a | public void setPosition(int x, int y) {
xPosition = x;
yPosition = y;
} |
59ab0c48-fa7b-4759-9eb8-b3d62964c1d4 | public int getXPosition() {
return xPosition;
} |
3f47ab58-5853-47a9-bb41-32b4ae69cd5e | public int getYPosition() {
return yPosition;
} |
ce1428da-6a10-48cc-a5ef-4718f4797137 | public double getEnergy() {
return energy;
} |
3bf5458c-3a75-4d5a-8765-445fa9ea2606 | public int getAge() {
return age;
} |
86b983f3-875e-4966-a038-a17a848ab5ef | private double pythagoras(int x1, int x2, int y1, int y2){
return Math.sqrt(Math.pow(Math.abs(x1-x2), 2) + Math.pow(Math.abs(y1-y2), 2));
} |
ea262067-fc60-4979-8015-13a81be7a975 | public static void main(String args[]) {
Simulation sim = new Simulation();
sim.run();
} |
271510ee-de8b-470c-a420-f6bc4cd2313f | public Simulation() {
epochs = 0;
initGrid();
initAgents();
} |
eb40d821-faf4-4656-85f9-515e0fd2b453 | public void run() {
createAndShowGUI();
} |
b79d4c0f-a2d9-4b88-9657-47b2c303ae8a | private void createAndShowGUI() {
//Create and set up the window.
frame = new JFrame("Scape");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setResizable(false);
//Set up the content pane.
buildUI(frame.getContentPane());
//Display the window.
... |
05237203-0d17-4290-a98d-690fdd4af3cd | private void buildUI(Container pane) {
pane.setLayout(new FlowLayout());
mainPanel = new MainPanel(this);
pane.add(mainPanel);
buttonPanel = new ButtonPanel(this);
pane.add(buttonPanel);
} |
1229c55c-5609-4bb4-b21e-08587774b983 | private void initGrid() {
grid = new Site[xSize][ySize];
for(int x = 0; x < xSize; x++) {
for(int y = 0; y < ySize; y++) {
double distance = Math.sqrt(Math.pow((center1 - x), 2) + Math.pow((center1 - y), 2));
double distance2 = Math.sqrt(Math.pow((center2 - x), 2) + Math.pow((center2 - y), 2));
doubl... |
52c35e54-6162-4a2b-aa1d-b034f4a5a5da | private void initAgents() {
agents = new Vector<Agent>();
for(int a = 0; a < numAgents; a++) {
agents.add(new Agent(this));
}
for(int a = 0; a < agents.size(); a++) {
int x = 0;
int y = 0;
boolean free = false;
while (!free) {
x = gen.nextInt(xSize);
... |
e0575b8c-a91b-42d3-a41a-e82d55a44800 | public void step() {
for(int x = 0; x < xSize; x++) {
for(int y = 0; y < ySize; y++) {
grid[x][y].grow();
// YOU WILL NEED TO IMPLEMENT GROW() YOURSELF.
}
}
Collections.shuffle(agents);
for(int a = agents.size()-1; a >= 0; a--) {
Agent agent = agents.elementAt(a);
agent.act();
... |
5f439efb-95a6-4148-ba2d-737024c2e264 | public ButtonPanel(Simulation controller) {
scape = controller;
setLayout(new BorderLayout());
setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
info = new JTextPane();
info.setPreferredSize(new Dimension(270, 300));
info.setMaximumSize(new Dimension(270, 300));
info.setEditable(false);
info.... |
9db498a2-373e-4d7a-9893-091fa57162bd | public Dimension getPreferredSize() {
return preferredSize;
} |
56286f19-46b7-4d97-b3f1-9348028b00b7 | public void actionPerformed(ActionEvent e) {
if ("next".equals(e.getActionCommand())) {
update(1);
}
if ("forward".equals(e.getActionCommand())) {
Integer num = new Integer(forwardEpochs.getText());
update(num.intValue());
}
if ("restart".equals(e.getActionCommand())) {
scape.frame.dispose();
... |
23d8a090-ff37-4fe8-a780-28c3a4dc8f85 | private void update(int cycles) {
if (cycles < 0) {
while (true) {
scape.step();
addInfo(scape.grid[scape.mainPanel.xSelected][scape.mainPanel.ySelected]);
scape.epochs++;
String ep = "Epochs: " + scape.epochs;
epochsLabel.setText(ep);
}
}
else {
for (int c = 0; c < cycles; c++) {
... |
d988dce9-2292-4ef0-8bf1-2d9b08d26d89 | private void addStylesToDocument(StyledDocument doc) {
// Initialize some styles.
Style def = StyleContext.getDefaultStyleContext().getStyle(StyleContext.DEFAULT_STYLE);
Style regular = doc.addStyle("regular", def);
StyleConstants.setFontFamily(def, "SansSerif");
StyleConstants.setFontSize(regular, 14);
S... |
7aebe142-7481-4ee0-9f4c-3d2cdbe6cb3a | public void addInfo(Site s) {
content[0] = "Scape";
content[1] = "Agents: " + scape.agents.size();
content[2] = newline + "Site";
content[3] = "Coordinates: (" + s.getXPosition() + ", " + s.getYPosition() + ")";
content[4] = "Site food: " + round(s.getFood());
content[5] = newline + "Agent on Site";
Agen... |
5e94f802-4a01-40f0-a802-8276b824209f | private void updateInfo() {
StyledDocument doc = info.getStyledDocument();
try {
doc.remove(0, doc.getLength());
for (int i = 0; i < content.length; i++) {
doc.insertString(doc.getLength(), content[i] + newline, doc.getStyle(style[i]));
}
}
catch (BadLocationException ble) {
System.err.println("... |
f797274e-00ff-4ef1-86cd-3c2284e51ce0 | public String round(double value) {
DecimalFormat df = new DecimalFormat("0.00");
String stringValue = df.format(value);
return stringValue;
} |
02fb4113-7cb0-4b77-a2d7-b2bc2ea94aad | public Site () {
food = 0;
} |
7f4d8986-8486-4b12-b37b-42ba4f41d712 | public Site(double cap, int x, int y) {
food = foodMax = cap;
xPosition = x;
yPosition = y;
} |
87209eb9-930c-4eca-a58b-e90d3ed0a742 | public void grow() {
double growthFactor = 0.15;
food += (foodMax-food)*growthFactor;
} |
6eb838e5-499a-4694-bd09-8f9e303c4128 | public double getFood() {
return food;
} |
993f7b90-62b5-4533-b07d-34f8dbe8dc89 | public void setFood(double f) {
food = f;
} |
fe12c51c-120c-41ad-bb46-a05330662e73 | public Agent getAgent() {
return agent;
} |
ca1cba26-1317-4e49-ad5d-9856121aa0ef | public void setAgent(Agent a) {
agent = a;
} |
0e93a461-4ac1-4a91-91c7-750e3e2f2b22 | public int getXPosition() {
return xPosition;
} |
b9798b62-499d-43fa-99d8-3853f04fb1a4 | public int getYPosition() {
return yPosition;
} |
33e084db-0363-4a46-87ea-546423839232 | public MainPanel(Simulation controller) {
this.scape = controller;
xSize = scape.xSize;
ySize = scape.ySize;
setLayout(new GridLayout(xSize, ySize));
addMouseListener(this);
labels = new JLabel[xSize][ySize];
for (int y = 0; y < ySize; y++) {
for (int x = 0; x < xSize; x++) {
labels[x][y] = new JLa... |
774ae406-8901-4b8e-9ed9-e7278174858e | public void update() {
for (int y = 0; y < ySize; y++) {
for (int x = 0; x < ySize; x++) {
Site site = scape.grid[x][y];
JLabel label = labels[x][y];
double energy = site.getFood();
double div = (255 / scape.maxFood) * energy;
int gradient = (int) (255 - div);
Color background;
backgr... |
0e96b58d-61f4-4054-9c82-516cdb0d0394 | public Dimension getPreferredSize() {
return preferredSize;
} |
dfadb17b-ab0d-4d59-9e42-8ff301e60324 | public void mouseClicked(MouseEvent e) {
labels[xSelected][ySelected].setBorder(BorderFactory.createLineBorder(Color.black));
xSelected = e.getX() / (650 / xSize);
ySelected = e.getY() / (650 / ySize);
labels[xSelected][ySelected].setBorder(BorderFactory.createLineBorder(Color.red));
scape.buttonPanel.addInfo... |
c65951d6-bd2d-4bd2-b55c-c1ca9ed3be0b | public void mouseMoved(MouseEvent e) {
} |
67d64c8d-9bd3-4824-8291-50ec84d3cbce | public void mouseExited(MouseEvent e) {
} |
e682b102-ca00-40a8-926b-5401d9426f75 | public void mouseReleased(MouseEvent e) {
} |
2c3ae05e-55c7-47ad-82de-1a2bfbad9230 | public void mouseEntered(MouseEvent e) {
} |
051eac88-b658-496a-b501-c3027d33a754 | public void mousePressed(MouseEvent e) {
} |
703b653b-430f-47d3-839f-cef25ef88507 | public void mouseDragged(MouseEvent e) {
} |
e7bb6031-0d2b-4a2b-a0f0-a38cc901e2e7 | @Override
public void start(Stage primaryStage) throws Exception{
PresenterImpl mainPresenter = new PresenterImpl(primaryStage);
mainPresenter.show();
} |
572d4fd2-aecc-4521-b645-8c2f46b9f2cf | public static void main(String[] args) {
// System.out.println("os.name="+System.getProperty("os.name"));
launch(args);
} |
69dd0347-c1ec-4426-9a38-5d86be996a0e | @Override
public int check(int attempt) {
this.lastAttempt = attempt;
this.noAttepts++;
if (attempt > this.number) return 1;
if (attempt < this.number) return -1;
return 0;
} |
8d52d835-4ae4-4eff-8afa-f2827a5bf9b3 | @Override
public void generateRandomNumber(int maxNumber) {
this.lastAttempt = 0;
this.noAttepts=0;
Random r = new Random();
this.number = r.nextInt(maxNumber);
System.out.println("generated number: "+this.number);
} |
d88fd023-5cf4-4f34-871c-bf8df9acf0e0 | @Override
public int getLastTry() {
return this.lastAttempt;
} |
107502f0-5445-48e3-b70e-857f21132306 | @Override
public int getNoAttepts() {
return this.noAttepts;
} |
11f9ced1-8ff2-47c4-81f9-c0abd24994f6 | public int check(int number); |
f8b8c6c8-1d68-4ec0-a66d-53aed0ad3484 | public void generateRandomNumber(int maxNumber); |
1c5f1f6b-3b39-46ab-bea1-aa2b9adec9f3 | public int getLastTry(); |
062e1670-c954-440b-bdc5-39e0aa62faab | public int getNoAttepts(); |
6760faee-0b8b-44af-81af-763e7caaf8b7 | public PresenterImpl(Stage stage) {
this.stage = stage;
this.model = getModel();
} |
0b9b14e0-6043-4897-ad0b-ef436184fc9b | public void show() throws Exception {
gamePresenter = getGamePresenter();
newGame();
Scene scene = new Scene(gamePresenter.getViewRoot());
stage.setScene(scene);
stage.setTitle("FindNumber FXML");
// setScreenSize();
// stage.setMaximised(true);// available in Jav... |
74f50e41-2ece-4f52-8680-21a957fce6b9 | public void handle(final WindowEvent e) {
e.consume(); // Consuming the event by default. Wymagane zeby klikniecie w krzyzyk otwarlo popup zamiast zamknac aplikacji
// new CloseAppDialog(stage, "Question");
applicationExitShowConfirmDialog();
} |
ead8a7ff-4c51-4677-95b8-dbe8eb995f85 | private void setScreenSize() {
Rectangle2D screenBounds = Screen.getPrimary().getVisualBounds();
stage.setX(0);
stage.setY(0);
stage.setWidth(screenBounds.getWidth());
stage.setHeight(screenBounds.getHeight());
} |
88c5e36e-d76b-4a79-a089-52a552fc5bc1 | private void setWindowStyle() {
stage.initStyle(StageStyle.DECORATED);
// stage.initStyle(StageStyle.UNDECORATED);
} |
cc60dd80-a42b-46c9-8530-4e5ee3493cac | public GamePresenter getGamePresenter() {
if (gamePresenter == null) {
try {
FXMLLoader loader = new FXMLLoader(getClass().getResource("../view/game/game.fxml"));
loader.load();
gamePresenter = loader.getController();
if (gamePresenter... |
e2196115-b13a-4833-b8e4-859400c5a729 | public ModelInterface getModel() {
if (model == null) {
model = new Model();
// initMock();
}
return model;
} |
6674b84b-c1c3-43eb-8ce0-7fb3d8a53170 | private void initMock() {
model = Mockito.mock(Model.class);
Mockito.when(model.check(Mockito.anyInt())).thenReturn(100);
Mockito.when(model.check(501)).thenReturn(0);
Mockito.when(model.check(400)).thenReturn(-1);
Mockito.when(model.check(600)).thenReturn(1);
} |
8e58f173-d7ba-45f5-8fd6-4ce642290f30 | @Override
public void applicationExitShowConfirmDialog() {
System.out.println("application exit");
closeAppDialog = new CloseAppDialog(stage, "Question");
closeAppDialog.setPresenterImpl(this);
} |
b9d11940-9b9f-4708-9585-40bb9d53939a | @Override
public void applicationExit() {
if (closeAppDialog == null) return;
if (!closeAppDialog.isButtonOkPressed()) return;
stage.close();
} |
54d5679c-33c3-40ff-8f80-e81d494ccf00 | @Override
public void showInfoVictory() {
String m = "victory: correct number";
System.out.println(m);
gamePresenter.addTryHistory(getMessageForAttemptsHistory(m));
gamePresenter.showInfo(m);
} |
dd8444a0-fb3c-4296-8c98-ecb1ba9f20e0 | @Override
public void showInfoNumberToLow() {
String m = "number to low";
System.out.println(m);
gamePresenter.addTryHistory(getMessageForAttemptsHistory(m));
gamePresenter.showInfo(m);
} |
e44b8a19-588f-406d-96dc-288ebf63ec70 | private String getMessageForAttemptsHistory(String m) {
return model.getNoAttepts() + ": " + model.getLastTry() + " " + m;
} |
6f6a26d0-9b14-460d-b28c-9903857afe93 | @Override
public void showInfoNumberToBig() {
String m = "number to big";
System.out.println(m);
gamePresenter.addTryHistory(getMessageForAttemptsHistory(m));
gamePresenter.showInfo(m);
} |
9f23d7a4-ebfe-4b80-9b38-a47a054ec22f | @Override
public void setFieldsActive(boolean active) {
gamePresenter.setFieldsActive(active);
} |
64779685-5f93-4c89-a8d1-6068e9487f5b | @Override
public void newGame() {
model.generateRandomNumber(1000);
gamePresenter.setFieldsActive(true);
gamePresenter.clearAtteptsHistory();
} |
cb5f4158-cbfc-403b-a978-123138c30943 | @Override
public void processTry(int number) {
int wynik = model.check(number);
System.out.println("wynik=" + wynik);
if (wynik == 0) showInfoVictory();
else if (wynik < 0) showInfoNumberToLow();
else if (wynik > 0) showInfoNumberToBig();
if (wynik == 0) setFieldsAct... |
f9739791-ef2b-4b2c-9cef-646b236a9dd9 | public void applicationExit(); |
a5ac9bcc-722e-4123-b0b6-1f63f9766396 | public void applicationExitShowConfirmDialog(); |
37abc20e-cc80-4819-8808-64e241e4a450 | public void showInfoVictory(); |
d04ffcd9-b888-406a-a279-00badc95534e | public void showInfoNumberToLow(); |
2e0c1f6b-4b13-4117-8f22-05100f1f7d9c | public void showInfoNumberToBig(); |
d168d4cd-1711-437e-9a39-5d2acce2607a | public void setFieldsActive(boolean active); |
d0ba21d6-cbc5-4e39-849e-9335e3cde9b7 | public void newGame(); |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.