Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit eaf8822f authored by Vincent Bourgmayer's avatar Vincent Bourgmayer
Browse files

update licence in some classes, and remove DataBundle class as it wasn't used anymore

parent ae48cec3
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
/*
 * Copyright 2019-2020 - ECORP SAS 
 * Copyright 2019-2021 - ECORP SAS 

 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
+0 −159
Original line number Diff line number Diff line
/*
 * Copyright 2019-2020 - ECORP SAS 

 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.

 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
 */
package ecorp.easy.installer.models;

import java.util.AbstractMap.SimpleImmutableEntry;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 * This class represent a "Bundle" object that can contains 
 * many different kind of data.
 * To pass them between mainThread and background Thread
 * @author Vincent Bourgmayer
 */
public class DataBundle {
    private final static String STRING = "String";
    private final static String INT = "int";
    private final static String BOOLEAN = "boolean";
    private final static String LIST ="List<%s>";
    
    private final Map<String, SimpleImmutableEntry<String, Object>> datas;
    /**
     * Constructor that instanciate an empty bundle
     */
    public DataBundle(){
        datas = new HashMap<>();
    }
    
    /**
     * Add a boolean data
     * @param key the key to retrieve the value
     * @param value 
     */
    public void putBoolean(String key, Boolean value){
        datas.put(key, new SimpleImmutableEntry("boolean", value));
    }
    
    /**
     * add an integer value
     * @param key
     * @param value 
     */
    public void putInteger(String key, Integer value){
        datas.put(key, new SimpleImmutableEntry("int", value));
    }
    
    /**
     * Add a string value
     * @param key
     * @param value 
     */
    public void putString(String key, String value){
        datas.put(key, new SimpleImmutableEntry("String", value));
    }
    
    /**
     * Add a generic object
     * @param key
     * @param value 
     */
    public void putObject(String key, Object value){
        datas.put(key, new SimpleImmutableEntry(value.getClass().getSimpleName(), value));
    }
    /**
     * put a list of <itemClassName> object
     * @param key
     * @param itemClassName
     * @param list 
     */
    public void putList(String key, String itemClassName, List list){
        datas.put(key, new SimpleImmutableEntry(String.format(LIST, itemClassName), list));
    }
    
    /**
     * Return an List of Object
     * @param key the key of the list in the bundle
     * @param itemClassName the Object's type
     * @return 
     */
    public List getList(String key, String itemClassName){
        SimpleImmutableEntry p = datas.get(key);
        if(p != null && p.getKey().equals(String.format(LIST, itemClassName) )){
            return (List) p.getValue();
        }else{
            return null;
        }
    }
    
    /**
     * Get a generic object from the container
     * @param key
     * @param className
     * @return null if the key doesn't match
     */
    public Object getObject(String key, String className){
        SimpleImmutableEntry p = datas.get(key);
        if(p != null && p.getKey() == className){
            return p.getValue();
        }else{
            return null;
        }
    }
    /**
     * Get integer from the bundle
     * @param key
     * @return null if no key matches
     */
    public Integer getInt(String key) {
        SimpleImmutableEntry p = datas.get(key);
        if(p != null && p.getKey() == INT){
            return (Integer) p.getValue();
        }else{
            return null;
        }
    }
    
    /**
     * Get string from bundle
     * @param key
     * @return null if no key matches
     */
    public String getString(String key){
        SimpleImmutableEntry p = datas.get(key);
        if(p != null && p.getKey() == STRING){
            return (String) p.getValue();
        }else{
            return null;
        }
    }
    /**
     * Get a Boolean(object not primitiv) from bundle
     * @param key
     * @return null if no key matches
     */
    public Boolean getBoolean(String key){
        SimpleImmutableEntry p = datas.get(key);
        if(p != null && p.getKey() == BOOLEAN){
            return (Boolean) p.getValue();
        }else{
            return null;
        }
    }
}
+8 −3
Original line number Diff line number Diff line
/*
 * Copyright 2019-2020 - ECORP SAS 
 * Copyright 2019-2021 - ECORP SAS 
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
@@ -28,6 +28,11 @@ import org.slf4j.LoggerFactory;

/**
 * This class provide task which run ADB command in background to detect that a device is reachable
 * 
 * First design made this class to extend CommandExecutionTask<P> but since i defined
 * CommandExecutionTask<CommandExecutionResult> this isn't possible anymore. Instead,
 * this task will call the CommandExecutionTask in the same thread as a blocking job. Thanks to a future.
 * 
 * @author vincent Bourgmayer
 * @author Ingo
 */
@@ -45,9 +50,9 @@ public class DeviceDetectionTask extends Task<Phone>{
    }
    
    /**
     * @return 
     * @throws java.lang.Exception
     * @inheritDoc 
     * @return Device object
     * @throws Exception 
     */
    @Override
    protected Phone call() throws Exception{
+1 −1
Original line number Diff line number Diff line
/*
 * Copyright 2019-2020 - ECORP SAS 
 * Copyright 2019-2021 - ECORP SAS 
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by