NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

package Serveur;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import Client.Client;

public class Parser {
String str;
Map<String, ArrayList> map;
BufferedReader reader;

Parser() {
str = null;
map = new HashMap<String, ArrayList>();
}

/*
* private void load() { String str = ""; try { str = reader.readLine();
* while (str != null) { ArrayList<String> surnom = new ArrayList<String>();
* String nom = str; str = reader.readLine(); int i = str.indexOf(';');
* while (i > 0) { surnom.add(str.substring(0, i)); str = str.substring(i +
* 1); i = str.indexOf(';'); } map.put(nom, surnom); str =
* reader.readLine(); } reader.close(); } catch (IOException e1) {
* e1.printStackTrace(); } }
*/

public String parse(String s) {
str = s;
String str2;
if (str.equals("list"))
return lister();
// else if (str.equals("quitter"))
// return quitter();
else {
int i = str.indexOf('%');
String com = str.substring(0, i);
switch (com) {
case "add":
str2 = str.substring(i + 1);
return ajout(str2);
case "modif":
str2 = str.substring(i + 1);
return modifier(str2);
case "look":
str2 = str.substring(i + 1);
return chercher(str2);
default:
return error();
}
}
}

public String ajout(String s) {
String str2 = s;
int i = str2.indexOf('#');
String nom = str2.substring(0, i);
ArrayList<String> surnom = new ArrayList<String>();
str2 = str2.substring(i + 1);
i = str2.indexOf(';');
while (i > 0) {
surnom.add(str2.substring(0, i));
str2 = str2.substring(i + 1);
i = str2.indexOf(';');
}
surnom.add(str2);
map.put(nom, surnom);
return "Ok, commande éxécutée correctement";
}

public String modifier(String str) {
int i = str.indexOf('#');
String nom = str.substring(0, i);
str = str.substring(i + 1);
i = str.indexOf('#');
String surnomOld = str.substring(0, i);
String surnomNew = str.substring(i + 1);
Iterator<String> it = map.keySet().iterator();
String key;
ArrayList<String> surnoms;
ArrayList<String> surnomsModi=new ArrayList();
boolean modi = false;

System.out.println(nom + " " + surnomOld + " " + surnomNew);
while (it.hasNext()) {
key = it.next();
if (key.equals(nom)) {
surnoms = map.get(key);
for (String st : surnoms) {
if (st.equals(surnomOld)) {
modi = true;
surnomsModi.add(surnomNew);
}
else
surnomsModi.add(st);
}
}
}
if (modi){
map.remove(nom);
map.put(nom, surnomsModi);
return "surnom de" + nom + " Modifié";}
else
return "nom ou surnom ne existe pas";
}

public String chercher(String s) {
String nom = s;
Iterator<String> it = map.keySet().iterator();
String key;
String reponse = "";
ArrayList<String> surnom;
while (it.hasNext()) {
key = it.next();
if (key.equals(nom)) {
surnom = map.get(key);
for (String st : surnom) {
reponse = reponse + st + ';';
}
}
}
if (reponse.equals(""))
return nom + " non trouvé";
return reponse;
}

public String lister() {
Iterator<String> it = map.keySet().iterator();
String key;
ArrayList<String> surnom;
String reponse = "";
while (it.hasNext()) {
key = it.next();
reponse = reponse + key + ':';
surnom = map.get(key);
for (String st : surnom) {
reponse = reponse + st + ';';
}
// reponse += 'n';
}
if (reponse.equals(""))
return "Il n'y a aucune information sur ce serveur.";
return reponse;
}

public String quitter() {
return "Aurevoir";
}

// TODO Pas encore finis
public String error() {
return "commande not correct!";
}

/*
* public static void main(String args[]) { Parser p = new Parser();
* p.parse("add%tao#tiancai;shaonian"); p.parse("add%nie#meinv;shaonv");
* p.parse("add%ne#meinv;shaonv"); p.parse("add%ndhfie#meinv;shaonv");
* //p.lister(); System.out.println(p.lister()); }
*/

}
     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.