Exemplo n.º 1
0
 /**
  * A specialized mapcar that operates on stacks
  *
  * @param coll Stack
  * @param fn Function
  * @param <T> Type
  * @return Returns a AbstractCollection<T> which is the result of operating fn on every element of
  *     coll
  */
 static <T> AbstractCollection<T> mapcar(Stack<T> coll, Function<T> fn) {
   AbstractCollection<T> list = new Stack<>();
   for (T t : coll) {
     list.add(fn.operate(t));
   }
   return list;
 }
  public Alphabet[] getAlphabets() {
    AbstractCollection<Alphabet> alphs = new ArrayList<Alphabet>();

    for (FormalDefinitionComponent comp : this.getComponents()) {
      if (comp instanceof Alphabet) {
        alphs.add((Alphabet) comp);
      }
    }

    return alphs.toArray(new Alphabet[0]);
  }
 private long testingAbstractCollectionLinkedBlockingDeque() {
   AbstractCollection<Object> array = new LinkedBlockingDeque<Object>();
   long start = System.currentTimeMillis();
   for (int i = 0; i < getMax(); i++) {
     array.add(i);
   }
   long end = System.currentTimeMillis();
   long time = (end - start);
   refreshTotalTime(time);
   return time;
 }
Exemplo n.º 4
0
  /** recursively renders a network of spaces */
  protected void renderNetworkRecursive(
      Graphics g, AbstractCollection<Tile> finished, Tile origin, int x, int y, Color hilight) {
    int dummyHeight = 0;

    if (x >= 0 && x < boardWidth && y >= 0 && y < boardHeight) {
      dummyHeight = spaceHeights[x][y];
    }
    renderSpace(g, origin, dummyHeight, x, y);
    g.setColor(hilight);
    g.fillRect((x + 1) * TILE_WIDTH, (y + 1) * TILE_HEIGHT, TILE_WIDTH, TILE_HEIGHT);
    if (x >= 0 && x < boardWidth && y >= 0 && y < boardHeight) {
      renderText(
          g,
          Integer.toString(spaceHeights[x][y]),
          (x + 1) * TILE_WIDTH,
          (y + 1) * TILE_HEIGHT + g.getFont().getSize());
    }
    if (origin.getJoined(Grid.LEFT) != null && !finished.contains(origin.getJoined(Grid.LEFT))) {
      finished.add(origin.getJoined(Grid.LEFT));
      renderNetworkRecursive(g, finished, origin.getJoined(Grid.LEFT), x - 1, y, hilight);
    }
    if (origin.getJoined(Grid.RIGHT) != null && !finished.contains(origin.getJoined(Grid.RIGHT))) {
      finished.add(origin.getJoined(Grid.RIGHT));
      renderNetworkRecursive(g, finished, origin.getJoined(Grid.RIGHT), x + 1, y, hilight);
    }
    if (origin.getJoined(Grid.TOP) != null && !finished.contains(origin.getJoined(Grid.TOP))) {
      finished.add(origin.getJoined(Grid.TOP));
      renderNetworkRecursive(g, finished, origin.getJoined(Grid.TOP), x, y - 1, hilight);
    }
    if (origin.getJoined(Grid.BOTTOM) != null
        && !finished.contains(origin.getJoined(Grid.BOTTOM))) {
      finished.add(origin.getJoined(Grid.BOTTOM));
      renderNetworkRecursive(g, finished, origin.getJoined(Grid.BOTTOM), x, y + 1, hilight);
    }
  }
Exemplo n.º 5
0
  R_result(AbstractCollection c, int items, boolean rules) {
    Iterator it;

    this.rules = rules;

    if (rules) {
      // split rules into two collections
      Vector lhsVec = new Vector(c.size());
      Vector rhsVec = new Vector(c.size());
      Rule rule;

      it = c.iterator();
      while (it.hasNext()) {
        rule = (Rule) it.next();
        lhsVec.add(rule.getLhs());
        rhsVec.add(rule.getRhs());
      }

      lhs = new SparseSetOfItemsets(lhsVec, items);
      rhs = new SparseSetOfItemsets(rhsVec, items);

    } else {
      this.items = new SparseSetOfItemsets(c, items);
    }

    // get precision
    precision = new double[c.size()];
    Association set;
    it = c.iterator();
    int ps = 0;
    while (it.hasNext()) { // I hope the iterator uses the same order
      set = (Association) it.next();
      precision[ps] = set.getPrecision();
      ps++;
    }
  }
Exemplo n.º 6
0
  /* PROTECTED METHODS */
  protected void getBeanElements(
      Element parentElement, String objectName, String objectType, Object bean)
      throws IntrospectionException, IllegalAccessException {
    if (objectName == null) {
      // Get just the class name by lopping off the package name
      StringBuffer sb = new StringBuffer(bean.getClass().getName());
      sb.delete(0, sb.lastIndexOf(".") + 1);
      objectName = sb.toString();
    }

    // Check if the bean is a standard Java object type or a byte[] (encoded as a base 64 array)
    Element element = getStandardObjectElement(document, bean, objectName);
    // If the body element object is null then the bean is not a standard Java object type
    if (element != null) {
      if (includeNullValues
          || !element
              .getAttribute(
                  NamespaceConstants.NSPREFIX_SCHEMA_XSI
                      + ":"
                      + org.apache.axis.Constants.ATTR_TYPE)
              .equals("anyType")) {
        if (!includeTypeInfo) {
          element.removeAttribute(
              NamespaceConstants.NSPREFIX_SCHEMA_XSI + ":" + org.apache.axis.Constants.ATTR_TYPE);
          element.removeAttribute(NamespaceConstants.NSPREFIX_SCHEMA_XSI + ":null");
        }
        parentElement.appendChild(element);
      }
    } else {
      // Analyze the bean
      Class classOfBean = null;
      if (bean != null) classOfBean = bean.getClass();
      // If the object is an array, then serialize each of the beans in the array.
      if ((classOfBean != null) && (classOfBean.isArray())) {
        String[] arrayInfo = getXsdSoapArrayInfo(classOfBean.getCanonicalName(), nsPrefix);
        int arrayLen = Array.getLength(bean);
        StringBuffer arrayType = new StringBuffer(arrayInfo[1]);
        arrayType.insert(arrayType.indexOf("[]") + 1, arrayLen);
        if (objectName.charAt(objectName.length() - 1) == ';')
          objectName =
              new StringBuffer(objectName).deleteCharAt(objectName.length() - 1).toString();
        element = document.createElement(objectName);
        parentElement.appendChild(element);
        // Get the bean objects from the array and serialize each
        for (int i = 0; i < arrayLen; i++) {
          Object b = Array.get(bean, i);
          if (b != null) {
            String name = null;
            if (objectName.charAt(objectName.length() - 1) == 's') {
              name = formatName(objectName.substring(0, objectName.length() - 1));
            }
            getBeanElements(element, name, b.getClass().getName(), b);
          } else {
            // Array element is null, so don't include it and decrement the # elements in the array
            int index = arrayType.indexOf("[");
            arrayType.replace(index + 1, index + 2, String.valueOf(--arrayLen));
          }
          if (includeTypeInfo) {
            element.setAttributeNS(
                NamespaceConstants.NSURI_SCHEMA_XSI,
                NamespaceConstants.NSPREFIX_SCHEMA_XSI + ":" + Constants.ATTR_TYPE,
                NamespaceConstants.NSPREFIX_SOAP_ENCODING + ":Array");
            element.setAttributeNS(
                NamespaceConstants.NSURI_SOAP_ENCODING,
                NamespaceConstants.NSPREFIX_SOAP_ENCODING + ":" + Constants.ATTR_ARRAY_TYPE,
                arrayInfo[0] + ":" + arrayType.toString());
          }
        }
      } else {
        int beanType = 0;
        String beanName = null;
        if (classOfBean != null) {
          if (classOfBean == Vector.class) {
            beanType = 1;
            beanName = "Vector";
          } else if (classOfBean == ArrayList.class) {
            beanType = 2;
            beanName = "ArrayList";
          } else if (classOfBean == LinkedList.class) {
            beanType = 3;
            beanName = "LinkedList";
          } else if (classOfBean == Hashtable.class) {
            beanType = 4;
            beanName = "Hashtable";
          } else if (classOfBean == Properties.class) {
            beanType = 5;
            beanName = "Properties";
          } else if ((classOfBean == HashMap.class) || (classOfBean == SortedMap.class)) {
            beanType = 6;
            beanName = "Map";
          }
        }
        if (beanType > 0) {
          String prefix = null;
          if ((beanType == 1) || (beanType == 5))
            prefix = NamespaceConstants.NSPREFIX_SOAP_ENCODING;
          if (beanType == 6) prefix = Constants.NS_PREFIX_XMLSOAP;
          else prefix = DEFAULT_NS_PREFIX;
          element = document.createElement(objectName);
          if (includeTypeInfo) {
            element.setAttributeNS(
                NamespaceConstants.NSURI_SCHEMA_XSI,
                NamespaceConstants.NSPREFIX_SCHEMA_XSI + ":" + Constants.ATTR_TYPE,
                prefix + ":" + beanName);
            if (bean == null)
              element.setAttributeNS(
                  NamespaceConstants.NSURI_SCHEMA_XSI,
                  NamespaceConstants.NSPREFIX_SCHEMA_XSI + ":null",
                  "true");
          }
          parentElement.appendChild(element);
          if ((beanType >= 1) && (beanType <= 3)) {
            AbstractCollection collection = (AbstractCollection) bean;
            // Get the bean objects from the vector and serialize each
            Iterator it = collection.iterator();
            while (it.hasNext()) {
              Object b = it.next();
              String name = null;
              if (b != null) {
                if (objectName.charAt(objectName.length() - 1) == 's') {
                  name = formatName(objectName.substring(0, objectName.length() - 1));
                } else name = "item";
              }
              getBeanElements(element, name, b.getClass().getName(), b);
            }
          } else if ((beanType == 4) || (beanType == 5)) {
            Hashtable hashtable = (Hashtable) bean;
            // Get the bean objects from the hashtable or properties and serialize each
            Enumeration en = hashtable.keys();
            while (en.hasMoreElements()) {
              Object key = en.nextElement();
              String keyClassName = key.getClass().getName();
              Object value = hashtable.get(key);
              String beanClassName = null;
              if (value != null) beanClassName = value.getClass().getName();
              Element itemElement = document.createElement("item");
              element.appendChild(itemElement);
              getBeanElements(itemElement, "key", keyClassName, key);
              getBeanElements(itemElement, "value", beanClassName, value);
            }
          } else if (beanType == 6) {
            Map map = null;
            if (classOfBean == HashMap.class) map = (HashMap) bean;
            else if (classOfBean == SortedMap.class) map = (SortedMap) bean;
            // Get the bean objects from the hashmap and serialize each
            Set set = map.keySet();
            Iterator it = set.iterator();
            while (it.hasNext()) {
              Object key = it.next();
              String keyClassName = key.getClass().getName();
              Object value = map.get(key);
              String beanClassName = null;
              if (value != null) beanClassName = value.getClass().getName();
              Element itemElement = document.createElement("item");
              element.appendChild(itemElement);
              getBeanElements(itemElement, "key", keyClassName, key);
              getBeanElements(itemElement, "value", beanClassName, value);
            }
          }
        } else {
          // Create a parent element for this bean's properties
          if (objectName.charAt(objectName.length() - 1) == ';')
            objectName =
                new StringBuffer(objectName).deleteCharAt(objectName.length() - 1).toString();
          objectName = formatName(objectName);
          element = document.createElement(objectName);
          parentElement.appendChild(element);
          if (includeTypeInfo) {
            StringBuffer className = new StringBuffer(objectType);
            element.setAttributeNS(
                NamespaceConstants.NSURI_SCHEMA_XSI,
                NamespaceConstants.NSPREFIX_SCHEMA_XSI + ":" + Constants.ATTR_TYPE,
                nsPrefix + ":" + className.delete(0, className.lastIndexOf(".") + 1).toString());
          }
          if (classOfBean != null) {
            // Get an array of property descriptors
            BeanInfo bi = Introspector.getBeanInfo(classOfBean);
            PropertyDescriptor[] pds = bi.getPropertyDescriptors();
            // For each property of the bean, get a SOAPBodyElement that
            // represents the individual property. Append that SOAPBodyElement
            // to the class name element of the SOAP body.
            for (int i = 0; i < pds.length; i++) {
              PropertyDescriptor pd = pds[i];
              getBeanElementProperties(element, bean, pd);
            }
          } else {
            if (includeTypeInfo)
              element.setAttributeNS(
                  NamespaceConstants.NSURI_SCHEMA_XSI,
                  NamespaceConstants.NSPREFIX_SCHEMA_XSI + ":null",
                  "true");
          }
        }
      }
    }
  }