Skip to content

Commit

Permalink
Uklonjen suvišan whitespace u Java kodu.
Browse files Browse the repository at this point in the history
  • Loading branch information
topofkeks committed Nov 10, 2021
1 parent afb6cbe commit 47a6240
Show file tree
Hide file tree
Showing 28 changed files with 89 additions and 322 deletions.
7 changes: 1 addition & 6 deletions os2/2006/11/k1-sol.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,31 +45,27 @@ end; (* client *)
network
```java
public class CoderProxy extends Usluga {

public CoderProxy (String host, int port){
super(host, port);
}

public String code(String op1, String op2){
String message = "#code1#" + op1 + "#" + op2 + "#";
sendMessage(message);

return receiveMessage();
}

public String code(String op){
String message = "#code2#" + op + "#";
sendMessage(message);

return receiveMessage();
}
}

public class RequestHandler extends Thread{
protected Coder coder;
...
public RequestHandler(...,Coder k){
...
...
coder = k;
}
protected void processRequest(String request){
Expand All @@ -86,7 +82,6 @@ protected void processRequest(String request){
String rezultat = coder.code(op);
sendMessage(result);
}

}
...
}
Expand Down
8 changes: 0 additions & 8 deletions os2/2007/11/k1-sol.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,13 @@ network
```java
import java.net.*;
import java.io.*;

private class ChannelServer extends Thread {
private ServerSocket mySocket;
private int myPort;

public ChannelServer (int port) {
myPort = port;
mySocket = new ServerSocket(port);
}

public void run () {
try {
Socket client = mySocket.accept();
Expand All @@ -60,13 +57,10 @@ private class ChannelServer extends Thread {
}
}
}


public class MainServer {
private final static int N = 10;
private final static int port0 = 1050;
private static bool[] allocatedPorts = new bool[N];

private static int getFreePort () {
for (int i=0; i<N; i++) {
if (allocatedPorts[i]) continue;
Expand All @@ -75,13 +69,11 @@ public class MainServer {
}
return 0;
}

public static void freePort (int i) {
i = i – port0 - 1;
if (i>=0 && i < N)
allocatedPorts[i]=false;
}

public static void main (String[] args) {
try {
ServerSocket sock = new ServerSocket(port0);
Expand Down
2 changes: 0 additions & 2 deletions os2/2008/11/k1-sol.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,8 @@ network
```java
import java.net.*;
import java.io.*;

public class MainServer {
private final static int port0 = 1050;

public static void main (String[] args) {
try {
ServerSocket sock = new ServerSocket(port0);
Expand Down
27 changes: 7 additions & 20 deletions os2/2009/10/k1-sol.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ public class Beleznica {
private int opsluzuje_se;
private int vozAB;
private int vozBA;

public Beleznica(){
redni_broj = 0;
opsluzuje_se = 0;
Expand All @@ -86,46 +85,36 @@ public class Beleznica {
public void kreniAB(){
vozAB++;
opsluzuje_se++;
}

}
public boolean stigaoAB(){
return --vozAB == 0;
}

}
public boolean zauzetaAB(){
return vozAB>0;
}

public void kreniBA(){
vozBA++;
opsluzuje_se++;
}

public boolean stigaoBA(){
return --vozBA == 0;
}

public boolean zauzetaBA(){
return vozBA>0;
}

public int uzmi_redni_broj(){
return redni_broj++;
}

public boolean dosao_na_red(int i){
return i == opsluzuje_se;
}
}

//Server_voz
public class Server_voz extends Thread {
private Socket s;

public Server_voz(Socket soc) {
s = soc;
}

public void run(){
BufferedReader r = null;
BufferedWriter w = null;
Expand Down Expand Up @@ -174,9 +163,7 @@ public class Server_voz extends Thread {
public class Dispecer {
public Dispecer() {
}

public static Beleznica beleznica = new Beleznica();

private static ServerSocket s;
public static void main(String[] args) {
try {
Expand All @@ -196,11 +183,11 @@ public class Dispecer {
}
}
}
//masinovodja koji krece iz mesta A
salje poruku "startA"
ceka da primi poruku "kreni"
//putuje
salje poruku "stigao"
// masinovodja koji krece iz mesta A
// salje poruku "startA"
// ceka da primi poruku "kreni"
// putuje
// salje poruku "stigao"
```

--------------------------------------------------------------------------------
Expand Down
5 changes: 0 additions & 5 deletions os2/2010/11/k1-sol.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ network
public class Main {
public Main() {
}

public static void main(String[] args) {
ServerSocket ss;
try{
Expand Down Expand Up @@ -154,7 +153,6 @@ public class fetch_and_increment {
Socket s;
PrintWriter out;
BufferedReader in;

public fetch_and_increment(String host, int port) {
try {
s = new Socket(host,port);
Expand All @@ -163,9 +161,7 @@ public class fetch_and_increment {
} catch (Exception e) {
//greska
}

}

public int fetch_and_increment1(){
try{
out.println("#fetch_and_increment#");
Expand All @@ -175,7 +171,6 @@ public class fetch_and_increment {
}
return -1;
}

}
```

Expand Down
117 changes: 56 additions & 61 deletions os2/2011/10/k1-sol.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,70 +44,65 @@ network
import java.io.*;
import java.net.*;
import java.util.StringTokenizer;

public class Agent {

static int bestOffer;
static String bestClientHost = null;
static int bestClientPort;
static boolean auctionOver = false;
static int badOfferCounter = 0;
static BufferedReader in;
static PrintWriter out;

public static void main(String[] args) {
try {
ServerSocket sock = new ServerSocket(1025);
Socket clientSocket = sock.accept();
in = new BufferedReader(new InputStreamReader(
clientSocket.getInputStream()));
StringTokenizer st = new StringTokenizer(in.readLine(), "#");
if (!st.nextToken().equals("StartAuction")) {
auctionOver = true;
}else {
bestOffer = Integer.parseInt(st.nextToken());}

static int bestOffer;
static String bestClientHost = null;
static int bestClientPort;
static boolean auctionOver = false;
static int badOfferCounter = 0;
static BufferedReader in;
static PrintWriter out;
public static void main(String[] args) {
try {
ServerSocket sock = new ServerSocket(1025);
Socket clientSocket = sock.accept();
in = new BufferedReader(new InputStreamReader(
clientSocket.getInputStream()));
StringTokenizer st = new StringTokenizer(in.readLine(), "#");
if (!st.nextToken().equals("StartAuction")) {
auctionOver = true;
} else {
bestOffer = Integer.parseInt(st.nextToken());}

clientSocket.close();

while (!auctionOver) {
clientSocket = sock.accept();

in = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
out = new PrintWriter(clientSocket.getOutputStream(), true);
st = new StringTokenizer(in.readLine(), "#");
String clientHost = st.nextToken();
String clientPort = st.nextToken();
int newOffer = Integer.parseInt(st.nextToken());

if (newOffer > bestOffer) {
if (bestClientHost != null) sendMsgToBestClient("BetterOfferReceived");
bestOffer = newOffer;
bestClientHost = clientHost;
bestClientPort = Integer.parseInt(clientPort);
out.println("OfferAccepted");
badOfferCounter = 0;
} else {
out.println("OfferRejected");
badOfferCounter++;
}
clientSocket.close();

if (badOfferCounter == 5) {
if (bestClientHost != null) sendMsgToBestClient("YouWon!");
auctionOver = true;
}
}
} catch (Exception e) { System.err.println(e);}
}
static void sendMsgToBestClient(String msg) throws UnknownHostException, IOException {
Socket clientSocket = new Socket(bestClientHost,bestClientPort);
PrintWriter oldOut = new PrintWriter(clientSocket.getOutputStream(),true);
oldOut.println(msg);
clientSocket.close();

while (!auctionOver) {
clientSocket = sock.accept();

in = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
out = new PrintWriter(clientSocket.getOutputStream(), true);
st = new StringTokenizer(in.readLine(), "#");
String clientHost = st.nextToken();
String clientPort = st.nextToken();
int newOffer = Integer.parseInt(st.nextToken());

if (newOffer > bestOffer) {
if (bestClientHost != null) sendMsgToBestClient("BetterOfferReceived");
bestOffer = newOffer;
bestClientHost = clientHost;
bestClientPort = Integer.parseInt(clientPort);
out.println("OfferAccepted");
badOfferCounter = 0;
} else {
out.println("OfferRejected");
badOfferCounter++;
}

clientSocket.close();

if (badOfferCounter == 5) {
if (bestClientHost != null) sendMsgToBestClient("YouWon!");
auctionOver = true;
}
}
} catch (Exception e) { System.err.println(e);}
}

static void sendMsgToBestClient(String msg) throws UnknownHostException, IOException {
Socket clientSocket = new Socket(bestClientHost,bestClientPort);
PrintWriter oldOut = new PrintWriter(clientSocket.getOutputStream(),true);
oldOut.println(msg);
clientSocket.close();
}
}
}
```

--------------------------------------------------------------------------------
Expand Down
5 changes: 0 additions & 5 deletions os2/2011/9/k1-sol.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,21 +86,17 @@ network
import java.io.*;
import java.net.*;
import java.util.*;

public class Server {
static final int N = ...;
static int count = N;
static LinkedList<Socket> blockedList = new LinkedList<Socket>();

public static void main(String[] args) {
try {
ServerSocket sock = new ServerSocket(1033);

while (true) {
Socket clientSocket = sock.accept();
BufferedReader in = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
String request = in.readLine();

if (request.equals("GetToken")) {
if(count>0){
sendMsgToClient(clientSocket, "Continue");
Expand All @@ -122,7 +118,6 @@ public class Server {
clientSocket.close();
}
}

public class Client {
public static void main(String[] args) {
try {
Expand Down
Loading

0 comments on commit 47a6240

Please sign in to comment.