Java 类org.apache.commons.collections.keyvalue.MultiKey 实例源码

项目:maf-desktop-app    文件:BudgetTrackingServiceImpl.java   
/**
 * Put a timesheet log.
 * 
 * @param timesheetLog
 *            the timesheet log
 */
public void put(TimesheetLog timesheetLog) {

    this.values.put(timesheetLog.id, timesheetLog.hours);

    Long actorId = timesheetLog.timesheetEntry.timesheetReport.actor.id;

    Long orgUnitId = timesheetLog.timesheetEntry.timesheetReport.orgUnit != null ? timesheetLog.timesheetEntry.timesheetReport.orgUnit.id
            : timesheetLog.timesheetEntry.timesheetReport.actor.orgUnit != null ? timesheetLog.timesheetEntry.timesheetReport.actor.orgUnit.id
            : null;
    Long packageId = timesheetLog.timesheetEntry.portfolioEntryPlanningPackage != null ? timesheetLog.timesheetEntry.portfolioEntryPlanningPackage.id
            : null;

    MultiKey byActorKey = new MultiKey(actorId, packageId);
    MultiKey byOrgUnitKey = new MultiKey(orgUnitId, packageId);

    List<Long> byActorList = this.byActor.containsKey(byActorKey) ? this.byActor.get(byActorKey) : new ArrayList<>();
    List<Long> byOrgUnitList = this.byOrgUnit.containsKey(byOrgUnitKey) ? this.byOrgUnit.get(byOrgUnitKey) : new ArrayList<>();

    byActorList.add(timesheetLog.id);
    byOrgUnitList.add(timesheetLog.id);

    this.byActor.put(byActorKey, byActorList);
    this.byOrgUnit.put(byOrgUnitKey, byOrgUnitList);

}
项目:guidoless-python    文件:MyNode.java   
/**
 * A method which is used to remove variables and functions from the
 * symbol table when they are out of scope.
 */
protected void removeScope()
{
    MapIterator mp = symtab.mapIterator();
    ArrayList<String> variables = new ArrayList<String>();

    while(mp.hasNext())
    {
        MultiKey mult = ((MultiKey)mp.next());
        if(mult.getKey(1) == scope)
        {
            variables.add(mult.getKey(0).toString());
        }
    }

    for(int i = 0; i < variables.size(); i++)
    {
        symtab.remove(variables.get(i), scope);
    }
    scope--;
}
项目:DigitalMediaServer    文件:CredMgr.java   
public boolean verify(String owner, String tag, String user, String pwd) {
    MultiKey key = createKey(owner, tag);
    ArrayList<Cred> list = credentials.get(key);
    if(list == null)
        return false;
    for(Cred c : list) {
        if(user.equals(c.username)) {
            // found user compare pwd
            return pwd.equals(c.password);
        }
    }
    // nothing found
    return false;
}
项目:PhET    文件:MoleculePaints.java   
public static Color getDuotoneHue( Class moleculeType, EnergyProfile profile ) {
    Color color = (Color)cpToColor.get( new MultiKey( moleculeType, profile ) );

    if( color == null ) {
        throw new InternalError( "A duotone hue for the molecule " + moleculeType.getName() + " and the profile " + profile + " was not found." );
    }

    return color;
}
项目:maf-desktop-app    文件:BudgetTrackingServiceImpl.java   
/**
 * Get the total hours for a tuple [actorId, packageId] and consume the
 * corresponding timesheet logs.
 * 
 * @param actorId
 *            the actor id
 * @param packageId
 *            the package id
 */
public Double consumeByActor(Long actorId, Long packageId) {
    MultiKey byActorKey = new MultiKey(actorId, packageId);
    Double total = 0.0;
    if (this.byActor.containsKey(byActorKey)) {
        for (Long timesheetLogId : this.byActor.get(byActorKey)) {
            total += this.values.containsKey(timesheetLogId) ? this.values.get(timesheetLogId) : 0.0;
            this.values.remove(timesheetLogId);
        }
        this.byActor.remove(byActorKey);
    }
    return total;
}
项目:maf-desktop-app    文件:BudgetTrackingServiceImpl.java   
/**
 * Get the total hours for a tuple [orgUnitId, packageId] and consume
 * the corresponding timesheet logs.
 * 
 * @param orgUnitId
 *            the org unit id
 * @param packageId
 *            the package id
 */
public Double consumeByOrgUnit(Long orgUnitId, Long packageId) {
    MultiKey byOrgUnitKey = new MultiKey(orgUnitId, packageId);
    Double total = 0.0;
    if (this.byOrgUnit.containsKey(byOrgUnitKey)) {
        for (Long timesheetLogId : this.byOrgUnit.get(byOrgUnitKey)) {
            total += this.values.containsKey(timesheetLogId) ? this.values.get(timesheetLogId) : 0.0;
            this.values.remove(timesheetLogId);
        }
        this.byOrgUnit.remove(byOrgUnitKey);
    }
    return total;
}
项目:astor    文件:ExpressionTypeIngredientSpace.java   
@SuppressWarnings("unchecked")
public void toJSON(String output) {
    JSONObject space = new JSONObject();

    JSONArray list = new JSONArray();
    space.put("nrall", this.allElementsFromSpace.size());
    space.put("space", list);

    for (Object key : mkp.keySet()) {
        JSONObject keyjson = new JSONObject();
        MultiKey mk = (MultiKey) key;
        keyjson.put("key", Arrays.toString(mk.getKeys()));
        list.add(keyjson);
        JSONArray ingredients = new JSONArray();
        keyjson.put("ingredients", ingredients);
        List ings = (List) mkp.get(key);
        keyjson.put("nringredients", ings.size());

        for (Object v : ings) {
            ingredients.add(v.toString());
        }
        ;

    }

    String fileName = output + "ingredients.json";
    try (FileWriter file = new FileWriter(fileName)) {

        file.write(space.toJSONString());
        file.flush();
        log.info("Storing ing JSON at " + fileName);

    } catch (IOException e) {
        e.printStackTrace();
        log.error("Problem storing ing json file" + e.toString());
    }

}
项目:utilsj    文件:HashMap4Template.java   
/**
 * Method to get existing [key1,key2,key3,key4] value or create new one if it's
 * absent. Needs implementation of create(key1,key2,key3,key4) in order to work
 */
public V getOrCreate(K1 key1, K2 key2, K3 key3, K4 key4)
{
    // already got it?
    MultiKey multi_key = new MultiKey(key1, key2, key3, key4);
    if (containsKey(multi_key))
        return get(multi_key);

    // if not, create and add it
    V result = create(key1, key2, key3, key4);
    put(multi_key, result);
    return result;
}
项目:ribbon    文件:NFHttpClientFactory.java   
public static NFHttpClient getNFHttpClient(String host, int port){
    MultiKey mk = new MultiKey(host,port);
    NFHttpClient client = clientMap.get(mk);
    if (client == null){
        client = new NFHttpClient(host, port);
        clientMap.put(mk,client);
    }
    return client;          
}
项目:iConA    文件:MultiKeyMap.java   
public V put(Object key1,Object key2,V value){
    MultiKey key=new MultiKey(key1, key2);
    return this.put((Object)key, value);

}
项目:iConA    文件:MultiKeyMap.java   
public V get(Object key1,Object key2){
    return this.get(new MultiKey(key1,key2));
}
项目:iConA    文件:MultiKeyMap.java   
public boolean containsKey(Object key1,Object key2) {
    // TODO Auto-generated method stub
    return super.containsKey(new MultiKey(key1,key2));
}
项目:DigitalMediaServer    文件:CredMgr.java   
private void readFile() throws IOException{
    // clear all data first, if file is gone so are all creds
    credentials.clear();
    tags.clear();

    if(!credFile.exists())
        return;

    try (BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream(credFile), StandardCharsets.UTF_8))) {
        String str;
        while ((str = in.readLine()) != null) {
            str = str.trim();
            if (StringUtils.isEmpty(str) || str.startsWith("#")) {
                continue;
            }
            String[] s = str.split("\\s*=\\s*", 2);
            if (s.length < 2) {
                continue;
            }
            String[] s1 = s[0].split("\\.", 2);
            String[] s2 = s[1].split(",", 2);
            if (s2.length < 2) {
                continue;
            }
            // s2[0] == usr s2[1] == pwd s1[0] == owner s1[1] == tag
            String tag = "";
            if (s1.length > 1) {
                // there is a tag here
                tag = s1[1];
                // we have a reverse map here for owner+user -> tags
                MultiKey tkey = new MultiKey(s1[0], s2[0]);
                tags.put(tkey, tag);
            }
            MultiKey key = new MultiKey(s1[0], tag);
            Cred val = new Cred();
            val.username = s2[0];
            val.password = s2[1];
            ArrayList<Cred> old = credentials.get(key);
            if(old == null)
                old = new ArrayList<>();
            old.add(val);
            credentials.put(key, old);
        }
    }
}
项目:DigitalMediaServer    文件:CredMgr.java   
private MultiKey createKey(String owner, String tag) {
    // ensure that tag is empty string rather than null
    return new MultiKey(owner, (tag == null ? "" : tag));
}
项目:DigitalMediaServer    文件:CredMgr.java   
public Cred getCred(String owner, String tag) {
    MultiKey key = createKey(owner, tag);
    // this asks for first!!
    ArrayList<Cred> list = credentials.get(key);
    return (list == null ? null : list.get(0));
}
项目:DigitalMediaServer    文件:CredMgr.java   
public String getTag(String owner, String username) {
    MultiKey key =  new MultiKey(owner, username);
    return tags.get(key);
}
项目:PhET    文件:MoleculePaints.java   
private static MultiKey key( Class moleculeType, EnergyProfile profile ) {
    return new MultiKey( moleculeType, profile );
}
项目:sequencetools    文件:DuplicateFeatureCheck.java   
void addMultiKeyAndValue(MultiKey key, Feature feature)
{
    featureMap.put(key, feature);
}
项目:drill    文件:ZKClusterCoordinator.java   
private synchronized void updateEndpoints() {
  try {
    // All active bits in the Zookeeper
    Collection<DrillbitEndpoint> newDrillbitSet =
    transform(discovery.queryForInstances(serviceName),
      new Function<ServiceInstance<DrillbitEndpoint>, DrillbitEndpoint>() {
        @Override
        public DrillbitEndpoint apply(ServiceInstance<DrillbitEndpoint> input) {
          return input.getPayload();
        }
      });

    // set of newly dead bits : original bits - new set of active bits.
    Set<DrillbitEndpoint> unregisteredBits = new HashSet<>();
    // Set of newly live bits : new set of active bits - original bits.
    Set<DrillbitEndpoint> registeredBits = new HashSet<>();


    // Updates the endpoints map if there is a change in state of the endpoint or with the addition
    // of new drillbit endpoints. Registered endpoints is set to newly live drillbit endpoints.
    for ( DrillbitEndpoint endpoint : newDrillbitSet) {
      String endpointAddress = endpoint.getAddress();
      int endpointPort = endpoint.getUserPort();
      if (! endpointsMap.containsKey(new MultiKey(endpointAddress, endpointPort))) {
        registeredBits.add(endpoint);
      }
      endpointsMap.put(new MultiKey(endpointAddress, endpointPort),endpoint);
    }
    // Remove all the endpoints that are newly dead
    for ( MultiKey key: endpointsMap.keySet()) {
      if(!newDrillbitSet.contains(endpointsMap.get(key))) {
        unregisteredBits.add(endpointsMap.get(key));
        endpointsMap.remove(key);
      }
    }
    endpoints = endpointsMap.values();
    if (logger.isDebugEnabled()) {
      StringBuilder builder = new StringBuilder();
      builder.append("Active drillbit set changed.  Now includes ");
      builder.append(newDrillbitSet.size());
      builder.append(" total bits. New active drillbits:\n");
      builder.append("Address | User Port | Control Port | Data Port | Version | State\n");
      for (DrillbitEndpoint bit: newDrillbitSet) {
        builder.append(bit.getAddress()).append(" | ");
        builder.append(bit.getUserPort()).append(" | ");
        builder.append(bit.getControlPort()).append(" | ");
        builder.append(bit.getDataPort()).append(" | ");
        builder.append(bit.getVersion()).append(" |");
        builder.append(bit.getState()).append(" | ");
        builder.append('\n');
      }
      logger.debug(builder.toString());
    }

    // Notify listeners of newly unregistered Drillbits.
    if (!unregisteredBits.isEmpty()) {
      drillbitUnregistered(unregisteredBits);
    }
    // Notify listeners of newly registered Drillbits.
    if (!registeredBits.isEmpty()) {
      drillbitRegistered(registeredBits);
    }
  } catch (Exception e) {
    logger.error("Failure while update Drillbit service location cache.", e);
  }
}
项目:utilsj    文件:HashMap4Template.java   
public void put(K1 key1, K2 key2, K3 key3, K4 key4, V value)
{
    put(new MultiKey(key1, key2, key3, key4), value);
}
项目:utilsj    文件:HashMap4Template.java   
public V get(K1 key1, K2 key2, K3 key3, K4 key4)
{
    return get(new MultiKey(key1, key2, key3, key4));
}