id stringlengths 36 36 | text stringlengths 1 1.25M |
|---|---|
b56a63af-a9a2-42c2-afc3-332c5af3f248 | public TrackerImpl(int port) throws RemoteException, MalformedURLException,
AlreadyBoundException {
this.peers = new ArrayList<Peer>();
this.randomGenerator = new Random();
// The tracker is a remotely accessible object: bind it to an RMI
// registry so that we can retrieve it at a well known address
Registry registry = LocateRegistry.createRegistry(port);
registry.bind("tracker", this);
} |
ae1d277f-02db-4042-a7c9-ed46b85398f2 | @Override
public synchronized void register(Peer peer)
throws AlreadyRegisteredException, RemoteException {
if (this.peers.contains(peer)) {
throw new AlreadyRegisteredException(peer.getId());
}
this.peers.add(peer);
} |
db643c9e-7104-4aca-b047-529dc741f12c | @Override
public Peer getRandomPeer() throws RemoteException {
if (this.peers.isEmpty()) {
return null;
}
return this.peers.get(this.randomGenerator.nextInt(this.peers.size()));
} |
7741ade5-95bf-45f8-a3fb-248c4ef162ae | @Override
public synchronized boolean delPeer(Peer peer) throws RemoteException {
return this.peers.remove(peer);
} |
dd24e6e7-0639-4ba9-ab47-7fa60770b329 | public void restoreData(Map<String, String> directoryReplicat) throws RemoteException {
boolean verif = false;
Peer landmarkPeer = this.getRandomPeer();
Peer nextPeer = landmarkPeer;
do {
nextPeer = nextPeer.getSuccessor();
if (nextPeer.getDirectory().isEmpty()) {
nextPeer.setDirectory(directoryReplicat);
System.out.println("Affectation du replicat à un anneau avec un directory vide : " + nextPeer.describe());
verif = true;
}
} while ((!nextPeer.equals(landmarkPeer) || verif != true));
} |
1cb800d9-4db3-4755-95c1-ed9fc531bb21 | public PeerImpl(Identifier id) throws RemoteException {
this.id = id;
this.predecessor = this;
this.successor = this;
this.successorofsuccessor = this;
this.directory = new HashMap<String, String>();
this.directoryReplicat = new HashMap<String, String>();
threadPool = Executors.newScheduledThreadPool(1);
final Runnable r = new Runnable() {
@Override
public void run() {
try {
// The stabilize method is called periodically to update
// the successor and predecessor links of the peer
PeerImpl.this.stabilize();
} catch (RemoteException e) {
try {
System.out.println("Succeseur mort, suppression... " + PeerImpl.this.tracker.delPeer(PeerImpl.this.successor));
PeerImpl.this.successor = PeerImpl.this.successorofsuccessor;
PeerImpl.this.successorofsuccessor = PeerImpl.this.successor.getSuccessor();
PeerImpl.this.successor.setPredecessor(PeerImpl.this);
PeerImpl.this.predecessor.setSuccessorofSuccessor(PeerImpl.this.successor);
System.out.println(PeerImpl.this.describe());
PeerImpl.this.tracker.restoreData(PeerImpl.this.directoryReplicat);
} catch (RemoteException et) {
} catch (IOException ex) {
Logger.getLogger(PeerImpl.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
};
threadPool.scheduleAtFixedRate(r, 0, 500, TimeUnit.MILLISECONDS);
} |
a5354d5b-d96a-4a7d-8e1f-fc9fedb6c6de | @Override
public void run() {
try {
// The stabilize method is called periodically to update
// the successor and predecessor links of the peer
PeerImpl.this.stabilize();
} catch (RemoteException e) {
try {
System.out.println("Succeseur mort, suppression... " + PeerImpl.this.tracker.delPeer(PeerImpl.this.successor));
PeerImpl.this.successor = PeerImpl.this.successorofsuccessor;
PeerImpl.this.successorofsuccessor = PeerImpl.this.successor.getSuccessor();
PeerImpl.this.successor.setPredecessor(PeerImpl.this);
PeerImpl.this.predecessor.setSuccessorofSuccessor(PeerImpl.this.successor);
System.out.println(PeerImpl.this.describe());
PeerImpl.this.tracker.restoreData(PeerImpl.this.directoryReplicat);
} catch (RemoteException et) {
} catch (IOException ex) {
Logger.getLogger(PeerImpl.class.getName()).log(Level.SEVERE, null, ex);
}
}
} |
d6f7b4e6-05c1-4845-9aea-bab7c64cdbbc | @Override
public synchronized void create() throws RemoteException {
this.predecessor = null;
// The bootstrap of the Chord network requires a self loop
this.successor = this;
} |
b400f026-b07c-4fbe-9e19-1ccc6cec7eed | @Override
public synchronized void join(Peer landmarkPeer) throws RemoteException {
this.predecessor = null;
// To join the network, ask a peer that is already in the network to
// find which peer must be the successor of the joining peer, using
// the identifier of the joining peer
this.successor = landmarkPeer.findSuccessor(this.id);
// The stabilize method will then update all the other links correctly
} |
d2b948d3-a42b-48ed-92a1-7436c2326691 | @Override
public Peer findSuccessor(Identifier id) throws RemoteException {
// There is only one peer in the network
if (this.successor.equals(this)) {
return this;
}
// The specified identifier is in between the current peer identifier
// and the successor identifier: the successor is then the peer we are
// looking for
if (id.isBetweenOpenClosed(this.id, this.successor.getId())) {
return this.successor;
} // Nothing can be deduced from the specified identifier here:
// propagate the request in case the successor knows more about it
else {
return this.successor.findSuccessor(id);
}
} |
e85f0401-8dad-4b25-a1a0-97b2f434fe55 | @Override
public Identifier getId() throws RemoteException {
return this.id;
} |
ce361089-b164-4a73-ba64-276062390d30 | @Override
public Peer getPredecessor() throws RemoteException {
return this.predecessor;
} |
a88ffbc0-1afd-4abf-a007-0d73b1e0896f | @Override
public Peer getSuccessor() throws RemoteException {
return this.successor;
} |
1eec3188-5658-4103-95f6-11c608fab8d4 | @Override
public synchronized void setPredecessor(Peer peer) throws RemoteException {
this.predecessor = peer;
} |
728e7a6c-afb2-4f40-ba24-36e017be61c4 | @Override
public synchronized void setSuccessor(Peer peer) throws RemoteException {
this.successor = peer;
} |
7fa7d976-9558-43ca-bfd4-7da0f5c2aa20 | @Override
public boolean equals(Object obj) {
try {
// Two peers are equal if they have the same identifier
return this.id.equals(((Peer) obj).getId());
} catch (RemoteException e) {
return false;
}
} |
d3198d1e-b357-4ca0-96ee-28324237933f | @Override
public int hashCode() {
// The hashcode of a peer is the hashcode of its identifier
return this.id.hashCode();
} |
b41b0de2-e7ca-479b-9556-ed48dcdbc8cd | @Override
public int compareTo(Peer p) {
try {
return this.id.compareTo(p.getId());
} catch (RemoteException e) {
e.printStackTrace();
return -1;
}
} |
b58b16f3-4d3a-427c-9f8d-5193d4811bff | @Override
public synchronized void stabilize() throws RemoteException {
// x should be this itself, but it is not always the case, typically
// if the successor has recently taken a new peer as predecessor
//System.out.println("On peer "+ this.getId());
Peer x = null;
try {
x = this.successor.getPredecessor();
} catch (NoSuchObjectException e) {
System.err.println("Objet succeseur mort");
}
// If x is this itself, then this condition is not valid. This
// condition is valid if the successor has another peer as predecessor,
// then in this case we check if this other peer is indeed included in
// the current identifier and the identifier of the successor. If it
// is, then it mean that x must be the new successor.
if (x != null
&& x.getId().isBetweenOpenOpen(this.id, this.successor.getId())) {
this.successor = x;
}
this.successorofsuccessor = this.successor.getSuccessor();
// The current peer needs to inform its successor that it is indeed its
// successor
this.successor.notify(PeerImpl.this);
} |
c2a6d6e3-562e-4860-9804-9690339bbecd | @Override
public synchronized void notify(Peer peer) throws RemoteException {
// If a new peer notify itself as a predecessor of the current peer,
// check if it fits in the interval of the previous predecessor
// identifier and it own identifier. If yes, take it as predecessor.
// Otherwise, nothing needs to be done.
if (this.predecessor == null
|| peer.getId().isBetweenOpenOpen(
this.predecessor.getId(), this.id)) {
this.predecessor = peer;
}
} |
9ad14397-e7d2-4add-973c-ccd45f187177 | @Override
public synchronized void put(String restaurant, String dailySpecial)
throws RemoteException {
this.directory.put(restaurant, dailySpecial);
} |
148594ed-cf42-48c3-945a-a9aeffedbe94 | @Override
public String get(String restaurant) throws RemoteException {
return this.directory.get(restaurant);
} |
97297c87-45ab-48c6-878e-12063c87e0e9 | @Override
public String describe() throws RemoteException {
StringBuilder s = new StringBuilder("Peer [id=" + this.id
+ ", successor=" + this.successor.getId() + ", predecessor="
+ this.predecessor.getId() + ", values=[");
int cpt = 0;
int size = this.directory.size();
for (Entry<String, String> entry : this.directory.entrySet()) {
s.append("(" + entry.getKey() + ";" + entry.getValue() + ")");
if (++cpt != size) {
s.append(", ");
}
}
s.append("]]");
return s.toString();
} |
1c1e6d13-5fc3-4865-bcbe-bab2de6a4242 | public void die() throws RemoteException {
// Removes this from the RMI runtime. It will prevent all RMI calls
// from executing on this object. A further RMI call on this will
// cause a java.rmi.NoSuchObjectException.
threadPool.shutdown();
UnicastRemoteObject.unexportObject(this, true);
System.out.println("Peer with id " + this.id + " has died.");
} |
18a0c759-12e7-40c2-b395-b74662c27495 | public void setSuccessorofSuccessor(Peer peer) throws RemoteException {
this.successorofsuccessor = peer;
} |
2746d07a-852e-4ac5-8643-1f21c71ce613 | public Tracker getTracker() throws RemoteException {
return tracker;
} |
290b4636-7312-4733-bea7-58f8f4ee2d24 | public void setTracker(Tracker tracker) throws RemoteException {
this.tracker = tracker;
} |
971f39ac-7783-459b-b82f-cb958bc25c9a | public String returnKey() throws RemoteException {
StringBuilder s = new StringBuilder();
int cpt = 0;
int size = this.directory.size();
for (Entry<String, String> entry : this.directory.entrySet()) {
s.append(entry.getKey());
}
return s.toString();
} |
e3c8bebb-c98b-4f4d-ac2b-f788b6a49f9c | public String returnValue() throws RemoteException {
StringBuilder s = new StringBuilder();
int cpt = 0;
int size = this.directory.size();
for (Entry<String, String> entry : this.directory.entrySet()) {
s.append(entry.getValue());
}
return s.toString();
} |
a9b71940-47ae-4cfa-b30d-1e0e0532f8fb | public void saveReplicat() throws RemoteException {
Peer temp = this.successor;
for (int i = 0; i < nbReplicat; i++) {
tabReplicat[i][0] = temp.returnKey();
tabReplicat[i][1] = temp.returnValue();
temp = temp.getSuccessor();
}
} |
664ed39f-634b-4f6a-9143-022b2fd5b672 | public void printReplicat() throws RemoteException {
System.out.println(this.describe());
for (int i = 0; i < tabReplicat.length; i++) {
System.out.println("Key : " + tabReplicat[i][0] + " Value : " + tabReplicat[i][1]);
}
System.out.println("");
} |
2826e995-c5f1-44a9-916a-d7b8fa912361 | @Override
public void update() throws RemoteException {
/*for(int i = 0 ; i < nbReplicat ; i++){
}*/
int i = 0;
Peer nextPeer = this;
do {
if (!tabReplicat[i][0].equals(nextPeer.getSuccessor().returnKey())) {
tabReplicat[i][0] = nextPeer.getSuccessor().returnKey();
System.out.println("Mise à jour des réplicats faites...");
}
if (!tabReplicat[i][1].equals(nextPeer.getSuccessor().returnValue())) {
tabReplicat[i][1] = nextPeer.getSuccessor().returnValue();
System.out.println("Mise à jour des réplicats faites...");
}
i = i + 1;
nextPeer = nextPeer.getSuccessor();
} while (i != nbReplicat);
this.directoryReplicat = this.getSuccessor().getDirectory();
} |
c70c9189-7ff6-45b2-af47-de7cd4f2635a | @Override
public boolean chercheValeurKeyReplicat(String recherche) throws RemoteException {
for (int i = 0; i < tabReplicat.length; i++) {
if (tabReplicat[i][0].equals(recherche)) {
System.out.println("Trouvé, Value : " + tabReplicat[i][1]);
return true;
}
}
return false;
} |
7b3cbec0-4dd3-454a-af8b-6b7810d7fa67 | public Map<String, String> getDirectory() throws RemoteException {
return this.directory;
} |
24852d9d-ffa7-4fb8-8467-bba1543b3b13 | @Override
public void setDirectory(Map<String, String> directoryReplicat) {
this.directory = directoryReplicat;
} |
90b99bb8-3451-4fcc-8bd0-a5a07441ac69 | public Identifier(int value) {
if (value < 0 || value > MAX_VALUE) {
throw new IllegalArgumentException("Invalid identifier value: "
+ value);
}
this.value = value;
} |
a072f11e-eb02-4beb-a3f2-d667d46ec5bd | public boolean isBetweenOpenClosed(Identifier a, Identifier b) {
if (a.compareTo(b) < 0) {
return this.compareTo(a) > 0 && this.compareTo(b) <= 0;
} else {
return this.compareTo(a) > 0 || this.compareTo(b) <= 0;
}
} |
d507a1d3-493e-4d8e-b99b-36d6a901ea2a | public boolean isBetweenOpenOpen(Identifier a, Identifier b) {
if (a.compareTo(b) < 0) {
return this.compareTo(a) > 0 && this.compareTo(b) < 0;
} else {
return this.compareTo(a) > 0 || this.compareTo(b) < 0;
}
} |
b1c26406-5fde-4d12-b7fe-166e41faaa85 | @Override
public int compareTo(Identifier id) {
return this.value - id.value;
} |
c626e77c-7787-4918-a958-cf023e49cab5 | @Override
public boolean equals(Object obj) {
return obj instanceof Identifier
&& this.value == ((Identifier) obj).value;
} |
3848ad1d-ee15-40e0-a083-a4fcd786a486 | @Override
public int hashCode() {
return Long.valueOf(this.value).hashCode();
} |
2a153197-d5d1-4b1e-bcb4-5e324ce5d4ca | @Override
public String toString() {
return Long.toString(this.value);
} |
fd56f2c8-2baa-40bc-bf4f-8d944a14d3d6 | void register(Peer peer)
throws AlreadyRegisteredException, RemoteException; |
97115e3a-c9fe-494c-a976-d8b5d0c046e6 | Peer getRandomPeer() throws RemoteException; |
804b4a34-244d-4e13-8234-c0b61d1cd0d3 | public boolean delPeer(Peer peer) throws RemoteException; |
b19de3ce-e612-42d7-b763-0238f507bc2c | public void restoreData(Map<String, String> directoryReplicat) throws RemoteException; |
88c62b63-8537-4ba4-9c3d-d717bec60566 | public static void test(Peer landmarkPeer) throws RemoteException {
Peer nextPeer = landmarkPeer;
boolean verif = false;
Identifier id = new Identifier(700);
do {
nextPeer = nextPeer.getSuccessor();
if (nextPeer.getId().equals(id)) {
System.out.println(nextPeer.getId());
nextPeer.die();
System.out.println("Mort");
verif = true;
}
} while ((verif != true));
} |
70002864-c69f-43f0-840d-d0721f1d433e | public static void test(Peer landmarkPeer) throws RemoteException {
System.out.println("Test de cohérence :");
Peer nextPeer = landmarkPeer;
int i = 0;
int j = 0;
do {
i = i + 1;
j = j + 1;
nextPeer = nextPeer.getSuccessor();
nextPeer.put(Integer.toString(i), Integer.toString(j));
} while (!nextPeer.equals(landmarkPeer));
System.out.println("Mise à jour des liens :");
nextPeer = landmarkPeer;
do {
nextPeer = nextPeer.getSuccessor();
nextPeer.update();
} while (!nextPeer.equals(landmarkPeer));
System.out.println("Verification :");
nextPeer = landmarkPeer;
do {
nextPeer = nextPeer.getSuccessor();
System.out.println("\n");
System.out.println("Pour l'ID : " + nextPeer.getId());
nextPeer.printReplicat();
System.out.println("\n");
} while (!nextPeer.equals(landmarkPeer));
} |
33195f89-c4d7-4978-b2f3-429b61f5981b | public static void testRecherche(Peer landmarkPeer) throws RemoteException{
Peer nextPeer = landmarkPeer;
boolean verif = false;
System.out.println("Recherche pour le restaurant Clovis");
String recherche = "Clovis";
do {
nextPeer = nextPeer.getSuccessor();
if(nextPeer.chercheValeurKeyReplicat(recherche) == true){
verif = true;
}
} while((!nextPeer.equals(landmarkPeer)) || (verif != true));
} |
72a2f8c5-7273-40a3-b5b3-41209382cb3e | public void generateIndividual() {
for (int i = 0; i < size(); i++) {
byte gene = (byte) Math.round(Math.random());
genes[i] = gene;
}
} |
c8af8788-e2fe-4728-b828-0aca8bcf32ef | public static void setDefaultGeneLength(int length) {
defaultGeneLength = length;
} |
02535cce-6751-4900-a525-8ac1a2c75a3f | public byte getGene(int index) {
return genes[index];
} |
45f26abc-8ac4-47fd-a4f2-efcd11d72fef | public void setGene(int index, byte value) {
genes[index] = value;
fitness = 0;
} |
685030bc-3925-470d-a255-e5543e10e1b9 | public int size() {
return genes.length;
} |
ff3ff012-fbb6-495d-95bb-6898092c5994 | public int getFitness() {
if (fitness == 0) {
fitness = FitnessCalc.getFitness(this);
}
return fitness;
} |
5e582ccd-dc0a-4347-bb86-b17a77cd00c7 | public String toString() {
String geneString = "";
for (int i = 0; i < size(); i++) {
geneString += getGene(i);
}
return geneString;
} |
d3efe0ca-cffe-4e7b-a528-ad66658c7900 | public static void main(String[] args) {
// Set a candidate solution
FitnessCalc.setSolution("1111000000000000000000000000000000000000000000000000000000001111");
// Create an initial population
Population myPop = new Population(50, true);
// Evolve our population until we reach an optimum solution
int generationCount = 0;
while (myPop.getFittest().getFitness() < FitnessCalc.getMaxFitness()) {
generationCount++;
System.out.println("Generation: " + generationCount + " Fittest: " + myPop.getFittest().getFitness());
myPop = Algorithm.evolvePopulation(myPop);
}
System.out.println("Solution found!");
System.out.println("Generation: " + generationCount);
System.out.println("Genes:");
System.out.println(myPop.getFittest());
} |
d6d83a8a-8737-42c9-9881-1c709f852e9d | public static Population evolvePopulation(Population pop) {
Population newPopulation = new Population(pop.size(), false);
// Keep our best individual
if (elitism) {
newPopulation.saveIndividual(0, pop.getFittest());
}
// Crossover population
int elitismOffset;
if (elitism) {
elitismOffset = 1;
} else {
elitismOffset = 0;
}
// Loop over the population size and create new individuals with
// crossover
for (int i = elitismOffset; i < pop.size(); i++) {
Individual indiv1 = tournamentSelection(pop);
Individual indiv2 = tournamentSelection(pop);
Individual newIndiv = crossover(indiv1, indiv2);
newPopulation.saveIndividual(i, newIndiv);
}
// Mutate population
for (int i = elitismOffset; i < newPopulation.size(); i++) {
mutate(newPopulation.getIndividual(i));
}
return newPopulation;
} |
c1497b87-7561-458d-83cc-9d1066f827e0 | private static Individual crossover(Individual indiv1, Individual indiv2) {
Individual newSol = new Individual();
// Loop through genes
for (int i = 0; i < indiv1.size(); i++) {
// Crossover
if (Math.random() <= uniformRate) {
newSol.setGene(i, indiv1.getGene(i));
} else {
newSol.setGene(i, indiv2.getGene(i));
}
}
return newSol;
} |
dabe30c4-6540-41c0-9841-02a953805f81 | private static void mutate(Individual indiv) {
// Loop through genes
for (int i = 0; i < indiv.size(); i++) {
if (Math.random() <= mutationRate) {
// Create random gene
byte gene = (byte) Math.round(Math.random());
indiv.setGene(i, gene);
}
}
} |
7f1b4e52-f617-4e07-a2de-143790572603 | private static Individual tournamentSelection(Population pop) {
// Create a tournament population
Population tournament = new Population(tournamentSize, false);
// For each place in the tournament get a random individual
for (int i = 0; i < tournamentSize; i++) {
int randomId = (int) (Math.random() * pop.size());
tournament.saveIndividual(i, pop.getIndividual(randomId));
}
// Get the fittest
Individual fittest = tournament.getFittest();
return fittest;
} |
0f8a446f-ca0c-4159-b7ac-c341826f738a | public static void setSolution(byte[] newSolution) {
solution = newSolution;
} |
d94a7399-ddbd-41ed-863e-14fc046b1752 | static void setSolution(String newSolution) {
solution = new byte[newSolution.length()];
// Loop through each character of our string and save it in our byte
// array
for (int i = 0; i < newSolution.length(); i++) {
String character = newSolution.substring(i, i + 1);
if (character.contains("0") || character.contains("1")) {
solution[i] = Byte.parseByte(character);
} else {
solution[i] = 0;
}
}
} |
7a908980-1daf-4ac4-8126-4b39075d82d5 | static int getFitness(Individual individual) {
int fitness = 0;
// Loop through our individuals genes and compare them to our cadidates
for (int i = 0; i < individual.size() && i < solution.length; i++) {
if (individual.getGene(i) == solution[i]) {
fitness++;
}
}
return fitness;
} |
2d97cf4b-2600-4037-b00a-b50a19b41301 | static int getMaxFitness() {
int maxFitness = solution.length;
return maxFitness;
} |
54b430cf-d34f-47f1-ad69-43f39b6a9c17 | public Population(int populationSize, boolean initialise) {
individuals = new Individual[populationSize];
// Initialise population
if (initialise) {
// Loop and create individuals
for (int i = 0; i < size(); i++) {
Individual newIndividual = new Individual();
newIndividual.generateIndividual();
saveIndividual(i, newIndividual);
}
}
} |
b235e87e-42b5-422c-8c11-43521f1291d5 | public Individual getIndividual(int index) {
return individuals[index];
} |
650ee3be-7fa6-4350-96e2-49d7a8909dc2 | public Individual getFittest() {
Individual fittest = individuals[0];
// Loop through individuals to find fittest
for (int i = 0; i < size(); i++) {
if (fittest.getFitness() <= getIndividual(i).getFitness()) {
fittest = getIndividual(i);
}
}
return fittest;
} |
b862077c-da8e-4cde-8e68-99271b6a7a86 | public int size() {
return individuals.length;
} |
243c8749-2ea8-485f-8de4-3f144bd84ce6 | public void saveIndividual(int index, Individual indiv) {
individuals[index] = indiv;
} |
1e82d60c-b744-4da4-b62f-e47e2d15eb97 | public static void main( String[] args ) {
Area a = Area.EUROPE;
a.initializeTimeSlots();
} |
ab2de0bc-4c69-438c-a216-b42378890117 | static Set< Cell > analyze( Area _a ) {
//place holder for results from > 1 recursive calls
SortedSet< Cell > result = new TreeSet();
_a.populate( oneHourBefore, twoHoursBefore );
SortedSet< Cell > cellsForArea = _a.getCells();
cellsForArea.stream().forEach((c) -> {
//we could merge this functionality into the Area.populate() method body...?
_a.computeHourlyDeltaFor( c );
});
double _threshold = _a.getOverallThreshold();
SortedSet< Cell > cellsAboveThreshold = getCellsAboveThreshold( cellsForArea, _threshold );
//stopping criterium for recursive calls is here:
if( cellsAboveThreshold.size() == 0 ) return cellsForArea;
else {
cellsAboveThreshold.stream().forEach((_c) -> {
//zoom in upon the cell and treat it as a new Area just before
//initiating the next recursive call to analyze():
result.addAll( analyze( _c.zoom() ) );
});
}
return result;
} |
e81b5634-4f06-4310-b460-36508bbd60ef | private static SortedSet<Cell> getCellsAboveThreshold( SortedSet< Cell > cells, double _threshold) {
SortedSet< Cell > result = new TreeSet();
for( Cell _c: cells ) {
if( _c.percentage > _threshold ) result.add( _c );
}
return result;
} |
eef6de5a-3334-4e88-b6ea-2363ff8bc353 | protected Area( double[] _topLeft, double[] _bottomRight ) {
topLeft = _topLeft;
bottomRight = _bottomRight;
} |
73aae73b-9c0d-4f35-a945-d933c56a9521 | protected Area() {
} |
b08d0560-d107-4ad4-8613-4e8a2ccf70a9 | Set<Cell> populate(long[] oneHourBefore, long[] twoHoursBefore) {
throw new UnsupportedOperationException("Not supported yet.");
} |
3b80a532-b16a-4401-a1e2-adfa3fea8ce5 | public SortedSet< Cell > getCells() {
return myCells;
} |
1a8ef78d-6896-4ab3-80e0-91cbe47557f9 | public final double getOverallThreshold() {
double result = 0;
for( Cell c: myCells ) {
result += c.percentage;
}
return result / myCells.size();
} |
711d5770-9009-4a68-a9d8-cbb2d4670e30 | void computeHourlyDeltaFor(Cell c) {
throw new UnsupportedOperationException("Not supported yet.");
} |
b3362887-75ec-4ac0-912d-175cae1bc9b1 | void initializeTimeSlots() {
throw new UnsupportedOperationException("Not supported yet.");
} |
b544748d-e778-4ab1-b724-2ab12bb43b67 | @Override
/**
*
* @param o
* @return
*/
public final boolean equals( Object o ) {
if ( o == null ) return false;
if( ! ( o instanceof Cell) ) return false;
return this.percentage == ( ( Cell ) o ).percentage ;
} |
43e0bf7d-ee03-4599-b87e-c6b9b43b86cd | protected Cell( double[] _topLeft, double[] _bottomRight ) {
super( _topLeft, _bottomRight );
} |
dba70872-864c-46af-bad9-00cd07eb39c3 | private Cell() {
} |
4fa81218-c0ab-4b4e-9653-d55f80f83137 | @Override
public int hashCode() {
int hash = 7;
hash = 11 * hash + (int) (Double.doubleToLongBits(this.percentage) ^ (Double.doubleToLongBits(this.percentage) >>> 32));
return hash;
} |
dd476c72-d793-4073-8e8e-d36b3e81ce76 | @Override
public int compareTo(Cell o) {
return ( int ) ( 100 * this.percentage - 100 * o.percentage );
} |
34f9c638-94f9-4cd1-8e22-26a26ed1f285 | public final Area zoom() {
Area a = ( Area ) this;
a.myCells = new TreeSet();
double deltaLat = topLeft[ 0 ] - bottomRight[ 0 ] / Analyzer.ZOOM_FACTOR;
double deltaLon = bottomRight[ 1 ] - topLeft[ 1 ] / Analyzer.ZOOM_FACTOR;
for( int i = 0; i < Analyzer.ZOOM_FACTOR; i++ ) {
for( int j = 0; j < Analyzer.ZOOM_FACTOR; j++ ) {
Cell __c = new Cell();
__c.topLeft[ 0 ] = topLeft[ 0 ] - j * deltaLat;
__c.topLeft[ 1 ] = topLeft[ 1 ] + i * deltaLon;
__c.bottomRight[ 0 ] = bottomRight[ 0 ] + ( Analyzer.ZOOM_FACTOR - j ) * deltaLat;
__c.bottomRight[ 1 ] = bottomRight[ 1 ] - ( Analyzer.ZOOM_FACTOR - i ) * deltaLon;
a.myCells.add( __c ) ;
}
}
return a;
} |
ea74421b-dc54-4a80-a269-70c970725645 | public AppTest( String testName )
{
super( testName );
} |
2592c82e-f925-4051-bf65-cbe9bd2721fc | public static Test suite()
{
return new TestSuite( AppTest.class );
} |
7335351c-fd59-4fe6-a690-15f1fef0e946 | public void testApp()
{
assertTrue( true );
} |
8f5537ab-a8f5-48ba-92b6-8810a6aa6962 | public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println("Hello,Github!");
} |
3a844675-f6b0-4f90-9796-aaa23b8c3d78 | public TestThread(String name) {
super(name);// an usage of super keyword to init a field
} |
7293611f-33ac-4af0-97b3-a78cc2ee4b96 | @Override
public void run() {
for (int i = 0; i < 5; i++) {
for (int k = 0; k < 100000000; k++);
System.out.println(this.getName()+" :"+i);
}
} |
5da25e52-3b0b-43f6-94e5-c0adb749b791 | public static void main(String[] args) {
TestThread tt1 = new TestThread("Robert");
TestThread tt2 = new TestThread("Olivia");
tt1.start();
tt2.start();
} |
5d856d71-6d35-48cb-ac7c-5c6441539978 | public static void main(String[] args) {
DoSomething ds1 = new DoSomething("Robert");
DoSomething ds2 = new DoSomething("Olivia");
Thread t1 = new Thread(ds1);
Thread t2 = new Thread(ds2);
t1.start();
t2.start();
} |
f8bec44e-b98e-4fff-8147-0e5618a23624 | public DoSomething(String name) {
this.name = name;
} |
28deeba6-25eb-4b90-8bde-4df528e52a25 | @Override
public void run() {
for (int i= 0; i < 5; i++) {
for (long k = 0; k < 100000000; k++);
System.out.println(name+": "+i);
}
} |
0330558b-ffc0-4f9c-81b3-2dd507e1cfb8 | public static void main(String[] args) {
// TODO Auto-generated method stub
} |
23b59055-617e-4a1f-9ff9-c01fd6c1066a | public static boolean match(char a,char b) {
if(a=='{'){
if(b=='}')return true;
}
if(a=='('){
if(b==')')return true;
}
if(a=='['){
if(b==']')return true;
}
return false;
} |
51edaa90-9012-4cc3-8572-989da92cf4e7 | public static boolean parMatch(String s) {
char[] a = s.toCharArray();
for(int i=0;i<a.length/2;i++){
if(!match(a[i],a[a.length-1-i])){
return false;
}
}
return true;
} |
00a59c53-e577-4a6b-a72c-6606cec2310d | public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner scanner = new Scanner(System.in);
String in = scanner.nextLine();
if (parMatch(in)) {
System.out.println("Match");
}else {
System.out.println("Not match");
}
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.