Package de.desy.tine.server.devices

Source Code of de.desy.tine.server.devices.TExportDeviceTable

/*
* Created on Nov 5, 2004
*
* To change the template for this generated file go to
* Window>Preferences>Java>Code Generation>Code and Comments
*
*/
package de.desy.tine.server.devices;
import java.util.*;
import de.desy.tine.types.NAME16;
import de.desy.tine.types.NAME32;

/**
* \internal
*
* @author duval
*
*/
public class TExportDeviceTable
{
  private int numDevices;
  private HashMap<String, Integer> devList = new HashMap<String, Integer>(211);

  public TExportDeviceTable(int size)
  {
   numDevices = size;
  }
  public int getNumberOfDevices() { return devList.size(); }
//  private HashSet devList = new HashSet(211);
//  private NAME32[] devList;
 
  public NAME32[] getExportLongDeviceNames()
  {
    int i;
    if (numDevices == 0) return null;
    Object[] o = devList.keySet().toArray();
    Object[] v = devList.values().toArray();
    NAME32[] dn = new NAME32[numDevices];
    for (i=0; i<v.length; i++)
    {
     
      dn[((Integer)v[i]).intValue()] = new NAME32((String)o[i])
    }
    for (i=0; i<numDevices; i++)
    {
      if (dn[i] == null) dn[i] = new NAME32("#" + i);
    }
    return dn;
  }
  public NAME32[] getExportLongDeviceNames(String pattern)
  {
    if (pattern.compareTo("*") == 0) return getExportLongDeviceNames();
    if (numDevices == 0) return null;
    Object[] o = devList.keySet().toArray();
    String ps;
    NAME32[] dn = new NAME32[numDevices];
    // allowed : abc, *abc, abc*, *abc*, a*c
    String lhs = null, rhs = null, mid = null;
    int p = -1;
    if ((p=pattern.indexOf("*")) != -1)
    {
      if (p == 0)
      {
        if (pattern.endsWith("*")) // *abc*
          mid = pattern.substring(1,pattern.length()-2);
        else                       // *abc
          rhs = pattern.substring(1,pattern.length()-1);
      }
      else
      {
        lhs = pattern.substring(0,p-1);
        if (!pattern.endsWith("*")) // abc*
          rhs = pattern.substring(p+1,pattern.length()-1); //a*c
      }
    }
    for (int i=0,n=0; i<o.length && n<numDevices; i++)
    {
      ps = (String)o[i];
      if (rhs != null && !ps.endsWith(rhs)) continue;
      if (lhs != null && !ps.startsWith(lhs)) continue;
      if (mid != null && ps.indexOf(mid) < 0) continue;
      if (p == -1 && ps.compareTo(pattern) != 0) continue;
      dn[n++] = new NAME32(ps);
    }
    return dn;
  }
  public NAME16[] getExportDeviceNames()
  {
    if (numDevices == 0) return null;
    int i;
    Object[] o = devList.keySet().toArray();
    Object[] v = devList.values().toArray();
    NAME16[] dn = new NAME16[numDevices];
    for (i=0; i<v.length; i++)
    {
      dn[((Integer)v[i]).intValue()] = new NAME16((String)o[i])
    }
    for (i=0; i<numDevices; i++)
    {
      if (dn[i] == null) dn[i] = new NAME16("#" + i);
    }
    return dn;
  }
  public NAME16[] getExportDeviceNames(String pattern)
  {
    if (pattern.compareTo("*") == 0) return getExportDeviceNames();
    if (numDevices == 0) return null;
    Object[] o = devList.keySet().toArray();
    String ps;
    NAME16[] dn = new NAME16[numDevices];
    // allowed : abc, *abc, abc*, *abc*, a*c
    String lhs = null, rhs = null, mid = null;
    int p = -1;
    if ((p=pattern.indexOf("*")) != -1)
    {
      if (p == 0)
      {
        if (pattern.endsWith("*")) // *abc*
          mid = pattern.substring(1,pattern.length()-2);
        else                       // *abc
          rhs = pattern.substring(1,pattern.length()-1);
      }
      else
      {
        lhs = pattern.substring(0,p-1);
        if (!pattern.endsWith("*")) // abc*
          rhs = pattern.substring(p+1,pattern.length()-1); //a*c
      }
    }
    for (int i=0,n=0; i<o.length && n<numDevices; i++)
    {
      ps = (String)o[i];
      if (rhs != null && !ps.endsWith(rhs)) continue;
      if (lhs != null && !ps.startsWith(lhs)) continue;
      if (mid != null && ps.indexOf(mid) < 0) continue;
      if (p == -1 && ps.compareTo(pattern) != 0) continue;
      dn[n++] = new NAME16(ps);
    }
    return dn;
  }
  int addDevice(NAME16 devName,int devNumber)
  {
    return addDevice(devName.toString(),devNumber);
  }
  int addDevice(NAME32 devName,int devNumber)
  {
    return addDevice(devName.toString(),devNumber);
  }
  int addDevice(String devName,int devNumber)
  {
    if (devList.containsKey(devName)) return 0;
    if (devNumber >= numDevices) return -1;
    devList.put(devName,new Integer(devNumber));
    return 0;
  }
  int rmvDevice(NAME16 devName)
  {
    return 0;
  }
  int rmvDevice(NAME32 devName)
  {
    return 0;
  }
  int rmvDevice(String devName)
  {
    return 0;
  }
  int getDeviceNumber(String device)
  {
    // all overloaded properties have the same id ...
    if (!devList.containsKey(device)) return -1;
    return ((Integer)devList.get(device)).intValue();
 
}
TOP

Related Classes of de.desy.tine.server.devices.TExportDeviceTable

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.