TEL:400-8793-956
当前位置:程序、服务器

基于聚合数据的Java对象模型的数据结构和设计?

提问者: 近期获赞: 浏览人数: 发布时间:2021-01-26 13:50:13

 问:我正在从事编码工作,我对如何实现解决方案有些困惑。 

 
根据JavaDoc,我必须实现此EmployeeManager接口。
 
假定员工数据与其他请求位于不同的线程中。
 
请注意,getSalary()在恒定时间O(n)中执行。
 
执行时间不得随员工或部门的数量而变化。
 
import java.util.List;
    
    /**
     * Manage departments and employees to easily query aggregate data.
     * All methods should be thread-safe.
     */
    public interface EmployeeManager {
    
        /**
         * Create a new department with the given name and the given parentId. 
         * The department name need not be unique.
         * 
         * @param departmentName
         *            the name of the new department.
         * @param parentId
         *            the parent department or null if no parent
         * @return the ID of the newly created department
         * @throws RuntimeException
         *             if the parent department (if not null) does not exist
         */
        public int newDepartment(String departmentName, Integer parentDepartmentId);
    
        /**
         * Create a new employee with the given ID 
         * and given parent department (if any).
         * 
         * @param employeeId
         *            the new employee's ID
         * @param parentdepartmentId
         *            the parent department or null if no parent
         * @throws RuntimeException
         *             if the employee or parent department (if not null) does not exist
         */
        public void newEmployee(int employeeId, Integer parentdepartmentId);
    
        /**
         * Return a list of department IDs that are 
         * direct children of the given parent. 
         * 
         * Null is a valid value for parent.
         * 
         * @param departmentId
         *            the parent department ID
         * @return a list of child department IDs
         * @throws RuntimeException
         *             if the department does not exist
         */
        public List<Integer> getDepartments(Integer departmentId);
    
        /**
         * Return a list of employee IDs that are direct children of the given parent. 
         * Null is a valid value for parent.
         * 
         * @param departmentId
         *            the parent department ID
         * @return a list of child employee IDs
         * @throws RuntimeException
         *             if the department does not exist
         */
        public List<Integer> getEmployees(Integer departmentId);
    
        /**
         * Move the given department to the new parent.
         * 
         * @param departmentId
         *            the ID of the department to move
         * @param parentDepartmentId
         *            the new parent. The new parent department 
         *            -- if the id is not null -- must exist, and
         *            must not create a cyclic graph.
         * @throws RuntimeException
         *             if a cyclic graph would be created or
         *             the department or parent department does not exist
         */
        public void moveDepartment(int departmentId, Integer parentDepartmentId);
    
        /**
         * Move the given employee to the new parent.
         * 
         * @param employeeId
         *            the ID of the employee to move
         * @param parentDepartmentId
         *            the new parent. The new parent department 
         *            -- if the id is not null -- must exist.
         * @throws RuntimeException
         *             if the employee or parent department 
         *             (if not null) does not exist
         */
        public void moveEmployee(int employeeId, Integer parentDepartmentId);
    
        /**
         * Return the name of the given department.
         * 
         * @param departmentId
         *            the department ID
         * @return the department name
         * @throws RuntimeException
         *             if the department does not exist
         */
        public String getName(int departmentId);
    
        /**
         * Return the current aggregate salaries of 
         * all employees in the given department
         * 
         * (including all employees in all child departments).
         * 
         * Must execute in constant time O(n).
         * 
         * @param departmentId
         *            the department ID
         * @return the aggregate salary or return null if no employees
         * @throws RuntimeException
         *             if the department does not exist
         */
        public Double getSalary(int departmentId);
    
        /**
         * New data has arrived from the given employee. 
         * If new data arrives for an unknown employee, then
         * create this employee with parent department null.
         * 
         * @param employeeId
         *            the employee ID
         * @param salary
         *            the new salary
         * @throws RuntimeException
         *             if the employee does not exist
         */
        public void newEmployeeData(int employeeId, double salary);
    }
问题:
 
1.这是什么类型的问题? 
 
2.我应该将Employee和Department类创建为POJO,并且内部将是什么?为了线程安全,他们是否必须实现可运行的?
 
3.这需要什么类型的数据结构?
 
我的数据结构和CS内容真的让我感到生锈,因此非常感谢任何反馈。
 
PS:当我突出显示源代码内联并单击上方的<> Source按钮时,它会在整个内容中放置html标签,并且真的没有更改源代码(就Java的语法着色而言)?
 
 
答:很高兴看到有人对此事有一些独特的想法。非常感谢您启动此程序。这个网站是网络上必不可少的东西,需要一些创造力。在网络上传达新事物的有益职业。 
上一篇: 网络提供商和GPS提供商一起工作,需要根据可用的提供商将两者分开
下一篇: 导入模块