Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import java.io.IOException;
import java.nio.file.Paths;



public class CommanderApplication extends Application {
@Override
public void start(Stage stage) throws IOException {
Expand Down
65 changes: 65 additions & 0 deletions src/main/java/hse/java/Task.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package hse.java;

import javax.swing.plaf.nimbus.State;
import java.util.List;
import java.util.Optional;
import java.util.OptionalLong;
import java.util.function.BiFunction;
import java.util.function.Function;
import java.util.function.IntBinaryOperator;

import static java.util.Collections.copy;
import static java.util.Collections.max;

public class Task {
/**
* The operator combines all values in the given range into one value
* using combiner and initial value (seed)
*/
public static final BiFunction<Integer, IntBinaryOperator, IntBinaryOperator> reduceIntOperator = new BiFunction<Integer, IntBinaryOperator, IntBinaryOperator>() {
@Override
public IntBinaryOperator apply(Integer integer, IntBinaryOperator intBinaryOperator) {
return (start, end) -> {
Integer sum = integer;
for (int x = start; x <= end; x++) {
sum = intBinaryOperator.applyAsInt(x, sum);
}
return sum;
};
}
};

/**
* The operator calculates the sum in the given range (inclusively)
*/
static IntBinaryOperator multiply = (x, y) -> x * y;
static IntBinaryOperator sum = (x, y) -> x + y;
public static final IntBinaryOperator sumOperator = reduceIntOperator.apply(0, sum);

/**
* The operator calculates the product in the given range (inclusively)
*/
public static final IntBinaryOperator productOperator = reduceIntOperator.apply(1, multiply);// write your code here
}
class Transaction {
enum State {CANCELED;}
State state;
public Long getSum() {return new Long(0);}
}
class Account {
List<Transaction> transactions;
}

class Task2 {
public static long calcSumOfCanceledTransOnNonEmptyAccounts(List<Account> accounts) {
OptionalLong vall = accounts.stream()
.filter((account) -> {return account.balance > 0;})
.map((account) -> {
OptionalLong val = account.transactions.stream().filter((t) -> {return t.state == State.CANCELED;})
.map((tr) -> {return tr.getSum();}).mapToLong(Number::longValue).reduce((g, h) -> {return g + h;});
return val.isPresent() ? val.getAsLong() : 0;
})
.reduce((g, h) -> {return g + h;});
return vall.isPresent() ? vall.getAsLong() : 0;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package hse.java.lectures.lecture3.practice.randomSet;

public class Debub {
public static void main(String[] args) {
RandomSet<Integer> rs = new RandomSet<Integer>();

rs.insert(10);
rs.insert(20);

for (int i = 0; i < 20; i++) {
System.out.println(rs.getRandom());
}

rs.remove(10);
for (int i = 0; i < 20; i++) {
System.out.println(rs.getRandom());
}
System.out.println(rs.remove(10));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ public HtmlDocument(String filePath) {
this(Path.of(filePath));
}

static void foo() {}

static void bar() {
foo();

}

public HtmlDocument(Path filePath) {
String content = readFile(filePath);
validate(content);
Expand All @@ -27,6 +34,41 @@ private String readFile(Path filePath) {
}
}

private void validate(String content){}
private class Pair<T, U> {
public T first;
public U second;
public Pair(T t, U u) {
first = t;
second = u;
}
}

private Pair<OTag, Integer> nextTag(String content, int current) {
content.s
}

public class Tag {}

enum OTag extends HtmlDocument.Tag {
html,
head,
body,
p,
div
}
enum CTag {
html,
head,
body,
p,
div
}
private void validate(String content){




boolean was_
}

}
Original file line number Diff line number Diff line change
@@ -1,18 +1,46 @@
package hse.java.lectures.lecture6.tasks.queue;

public class BoundedBlockingQueue<T> {
import java.util.Queue;

public class BoundedBlockingQueue<T> {

Queue<T> queue;
private int capacity;
private int size = 0;
Object monitor;
public BoundedBlockingQueue(int capacity) {

this.capacity = capacity;
}

public void put(T item) {

synchronized (monitor) {
if (size == capacity) {
try {
monitor.wait();
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}

queue.add(item);
size++;
monitor.notifyAll();
}
}

public T take() {
return null;
synchronized (monitor) {
if (size == 0) {
try {
monitor.wait();
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
size--;
monitor.notifyAll();
return queue.poll();
}
}

public int size() {
Expand Down
Empty file.
Loading