Skip to content
This repository was archived by the owner on May 18, 2022. It is now read-only.
Open
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
Binary file added .DS_Store
Binary file not shown.
Binary file added mock/.DS_Store
Binary file not shown.
Binary file added mock/machine/.DS_Store
Binary file not shown.
Binary file added mock/machine/coding/.DS_Store
Binary file not shown.
96 changes: 96 additions & 0 deletions mock/machine/coding/pkg3/Board.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package mock.machine.coding.pkg3;

import java.util.ArrayList;
import java.util.List;

/**
*
* @author rajeshkumar.yadav
*/
public class Board extends Item{

//Board: Each board should have a id, name, privacy (PUBLIC/PRIVATE), url, members, lists

private Privacy privacy;
private String url;
private List<User> userList;
private List<ListItem> list;

public Board(Privacy privacy, String name) {

super(name);
this.privacy = privacy;
url = URLGenerator.getURL(getId());
userList = new ArrayList<>();
list = new ArrayList<>();
}

public Privacy getPrivacy() {
return privacy;
}

public String getUrl() {
return url;
}

public void setPrivacy(Privacy privacy) {
this.privacy = privacy;
}

public void setUrl(String url) {
this.url = url;
}

public void addListItemToBoard(ListItem l){
list.add(l);
l.setBoard(this);
}

public void removeListFromBoard(ListItem l){
if(list.contains(l))
list.remove(l);
}

public void addUserToBoard(User u){
userList.add(u);
}

public void removeUserToBoard(User u){
if(userList.contains(u))
userList.remove(u);
}

public String getPrintableString(){
String s = "{ Id: " + getId() + ", Name: " + getName() + " privacy: " + getPrivacy() + ", URL: " + getUrl();
if(userList.size() > 0){
s = s + ", Users: [";
for(int i=0; i<userList.size(); i++){
s = s + userList.get(i).getPrintableString();
if(i<userList.size()-1)
s = s+", ";
}
s = s + "]";
}
if(list.size() > 0){
s = s + ", List: [";
for(int i=0; i<list.size(); i++){
s = s + list.get(i).getPrintableString();
if(i<list.size()-1)
s = s+", ";
}
s = s + "]";
}
s = s + " }";
return s;
}

public void show(){
System.out.println(getPrintableString());
}

}
62 changes: 62 additions & 0 deletions mock/machine/coding/pkg3/Card.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package mock.machine.coding.pkg3;

/**
*
* @author rajeshkumar.yadav
*/
public class Card extends Item{

//Card: Each card should have a id, name, description, assigned user
private String description;
private User assigendUser;
private ListItem litem;

public Card(String name) {
super(name);
//this.assigendUser = assigendUser;
}

public String getDescription() {
return description;
}

public void setDescription(String description) {
this.description = description;
}

public User getAssigendUser() {
return assigendUser;
}

public void setAssigendUser(User assigendUser) {
this.assigendUser = assigendUser;
}

public void unAssigendUser() {
this.assigendUser = null;
}

public ListItem getLitem() {
return litem;
}

public void setLitem(ListItem litem) {
this.litem = litem;
}

public String getPrintableString(){
String s = " { id: " + getId() + ", name: " + getName() + ", description: " + getDescription() + ", AssignedToUser: " + getAssigendUser().getName() + " }";
return s;
}

public void show(){
System.out.println(getPrintableString());
}


}
36 changes: 36 additions & 0 deletions mock/machine/coding/pkg3/IdCreator.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package mock.machine.coding.pkg3;

/**
*
* @author rajeshkumar.yadav
*/
public class IdCreator {

private static int inc = 0;
private static IdCreator idCreator = null;

private IdCreator(){

}

public static IdCreator getInstance(){
if(idCreator == null)
idCreator = new IdCreator();
return idCreator;
}

public static String getNewId(){

String s = String.valueOf(System.currentTimeMillis()).substring(1,9);
inc = (inc + 1)%10;
s = s + inc;
return s;
}


}
40 changes: 40 additions & 0 deletions mock/machine/coding/pkg3/Item.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package mock.machine.coding.pkg3;

/**
*
* @author rajeshkumar.yadav
*/
public class Item {

private String id;
private String name;

public Item(String name) {
this.id = IdCreator.getNewId();
this.name = name;
}

public String getId() {
return id;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public void show(){

}
public String getPrintableString(){
return "";
}
}
71 changes: 71 additions & 0 deletions mock/machine/coding/pkg3/ListItem.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package mock.machine.coding.pkg3;

import java.util.ArrayList;
import java.util.List;

/**
*
* @author rajeshkumar.yadav
*/
public class ListItem extends Item{

// List: Each list should have a id, name and cards
private List<Card> cards;
private Board board;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why does ListItem have access to the Board?


public ListItem(String name) {
super(name);
cards = new ArrayList<>();
}

public List<Card> getCards() {
return cards;
}

//We should also be able to move cards across lists in the same board
public void AddCardToList(Card c){
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

camelCase?

if(c.getLitem() != null && this.getBoard() != c.getLitem().getBoard())
return;
cards.add(c);
c.setLitem(this);
}

// We should also be able to remove cards from lists
public void removeCardFromList(Card c){
if(c.getLitem() != null)
return;
cards.remove(c);
c.setLitem(null);
}

public Board getBoard() {
return board;
}

public void setBoard(Board board) {
this.board = board;
}

public String getPrintableString(){
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can be done by overriding toString

String s = "{ Id: " + getId() + ", Name: " + getName();
if(cards.size() > 0){
s = s + ", cards: [";
for(int i=0; i<cards.size(); i++){
s = s + cards.get(i).getPrintableString();
if(i<cards.size()-1)
s = s+", ";
}
}
return s;
}

public void show(){
System.out.println(getPrintableString());
}

}
Loading