예제 #1
0
파일: IFD.java 프로젝트: KOST-CECO/SIP-Val
  /**
   * Reads an array of strings from the TIFF file.
   *
   * @param count Number of strings to read
   * @param value Offset from which to read
   */
  protected String[] readASCIIArray(long count, long value) throws IOException {
    _raf.seek(value);

    int nstrs = 0;
    List list = new LinkedList();
    byte[] buf = new byte[(int) count];
    _raf.read(buf);
    StringBuffer strbuf = new StringBuffer();
    for (int i = 0; i < count; i++) {
      int b = buf[i];
      if (b == 0) {
        list.add(strbuf.toString());
        strbuf.setLength(0);
      } else {
        strbuf.append((char) b);
      }
    }
    /* We can't use ArrayList.toArray because that returns an
    Object[], not a String[] ... sigh. */
    String[] strs = new String[nstrs];
    ListIterator iter = list.listIterator();
    for (int i = 0; i < nstrs; i++) {
      strs[i] = (String) iter.next();
    }
    return strs;
  }
  public ListIterator<ICFLibAnyObj> enumerateDetails(MssCFGenContext genContext) {
    final String S_ProcName = "CFAsteriskMssCFIterateHostNodeConfFile.enumerateDetails() ";

    if (genContext == null) {
      throw CFLib.getDefaultExceptionFactory()
          .newNullArgumentException(getClass(), S_ProcName, 1, "genContext");
    }

    ICFLibAnyObj genDef = genContext.getGenDef();
    if (genDef == null) {
      throw CFLib.getDefaultExceptionFactory()
          .newNullArgumentException(getClass(), S_ProcName, 1, "genContext.getGenDef()");
    }

    List<ICFLibAnyObj> list = new LinkedList<ICFLibAnyObj>();

    if (genDef instanceof ICFAsteriskHostNodeObj) {
      Iterator<ICFAsteriskConfigurationFileObj> elements =
          ((ICFAsteriskHostNodeObj) genDef).getOptionalComponentsConfFile().iterator();
      while (elements.hasNext()) {
        list.add(elements.next());
      }
    } else {
      throw CFLib.getDefaultExceptionFactory()
          .newUnsupportedClassException(
              getClass(), S_ProcName, "genContext.getGenDef()", genDef, "ICFAsteriskHostNodeObj");
    }

    return (list.listIterator());
  }
  public ListIterator<ICFLibAnyObj> enumerateDetails(MssCFGenContext genContext) {
    final String S_ProcName = "CFBamMssCFIterateNumberTypeRef.enumerateDetails() ";

    if (genContext == null) {
      throw CFLib.getDefaultExceptionFactory()
          .newNullArgumentException(getClass(), S_ProcName, 1, "genContext");
    }

    ICFLibAnyObj genDef = genContext.getGenDef();
    if (genDef == null) {
      throw CFLib.getDefaultExceptionFactory()
          .newNullArgumentException(getClass(), S_ProcName, 1, "genContext.getGenDef()");
    }

    List<ICFLibAnyObj> list = new LinkedList<ICFLibAnyObj>();

    if (genDef instanceof ICFBamNumberTypeObj) {
      Iterator<ICFBamTableColObj> elements =
          ((ICFBamNumberTypeObj) genDef).getOptionalChildrenRef().iterator();
      while (elements.hasNext()) {
        list.add(elements.next());
      }
    } else {
      throw CFLib.getDefaultExceptionFactory()
          .newUnsupportedClassException(
              getClass(), S_ProcName, "genContext.getGenDef()", genDef, "ICFBamNumberTypeObj");
    }

    return (list.listIterator());
  }
  public ListIterator<ICFLibAnyObj> enumerateDetails(MssCFGenContext genContext) {
    final String S_ProcName = "CFInternetMssCFIterateTSecGroupIncByGroup.enumerateDetails() ";

    if (genContext == null) {
      throw CFLib.getDefaultExceptionFactory()
          .newNullArgumentException(getClass(), S_ProcName, 1, "genContext");
    }

    ICFLibAnyObj genDef = genContext.getGenDef();
    if (genDef == null) {
      throw CFLib.getDefaultExceptionFactory()
          .newNullArgumentException(getClass(), S_ProcName, 1, "genContext.getGenDef()");
    }

    List<ICFLibAnyObj> list = new LinkedList<ICFLibAnyObj>();

    if (genDef instanceof ICFInternetTSecGroupObj) {
      Iterator<ICFSecurityTSecGroupIncludeObj> elements =
          ((ICFInternetTSecGroupObj) genDef).getRequiredChildrenIncByGroup().iterator();
      while (elements.hasNext()) {
        list.add(elements.next());
      }
    } else {
      throw CFLib.getDefaultExceptionFactory()
          .newUnsupportedClassException(
              getClass(), S_ProcName, "genContext.getGenDef()", genDef, "ICFInternetTSecGroupObj");
    }

    return (list.listIterator());
  }
 /** listIterator only returns those elements after the given index */
 public void testListIterator2() {
   List full = populatedArray(3);
   ListIterator i = full.listIterator(1);
   int j;
   for (j = 0; i.hasNext(); j++) assertEquals(j + 1, ((Integer) i.next()).intValue());
   assertEquals(2, j);
 }
 /** listIterator throws an IndexOutOfBoundsException on a negative index */
 public void testListIterator1_IndexOutOfBoundsException() {
   try {
     List c = emptyArray();
     c.listIterator(-1);
     shouldThrow();
   } catch (IndexOutOfBoundsException e) {
   }
 }
 /** listIterator throws an IndexOutOfBoundsException on a too high index */
 public void testListIterator2_IndexOutOfBoundsException() {
   try {
     List c = emptyArray();
     c.add("adasd");
     c.add("asdasdas");
     c.listIterator(100);
     shouldThrow();
   } catch (IndexOutOfBoundsException e) {
   }
 }
예제 #8
0
  /**
   * Insert the list of <code>newPasses</code> into <code>passes</code> immediately after the pass
   * named <code>id</code>.
   */
  public void afterPass(List passes, Pass.ID id, List newPasses) {
    for (ListIterator i = passes.listIterator(); i.hasNext(); ) {
      Pass p = (Pass) i.next();

      if (p.id() == id) {
        for (Iterator j = newPasses.iterator(); j.hasNext(); ) {
          i.add(j.next());
        }

        return;
      }
    }

    throw new InternalCompilerError("Pass " + id + " not found.");
  }
예제 #9
0
  /** Remove the pass named <code>id</code> from <code>passes</code>. */
  public void removePass(List passes, Pass.ID id) {
    for (ListIterator i = passes.listIterator(); i.hasNext(); ) {
      Pass p = (Pass) i.next();

      if (p.id() == id) {
        if (p instanceof BarrierPass) {
          throw new InternalCompilerError("Cannot remove a barrier pass.");
        }

        i.remove();
        return;
      }
    }

    throw new InternalCompilerError("Pass " + id + " not found.");
  }
예제 #10
0
파일: Map.java 프로젝트: AlanTR/solarus
  /**
   * Brings the specified entities to the front, keeping their layer. The order of the specified
   * entities in the map is unchanged.
   *
   * @param entities the entities to move
   */
  public void bringToFront(List<MapEntity> entities) {

    List<MapEntity> sortedEntities = getSortedEntities(entities);

    // bring to front each entity from sortedEntities
    ListIterator<MapEntity> iterator = sortedEntities.listIterator(0);
    while (iterator.hasNext()) {

      MapEntity entity = iterator.next();
      Layer layer = entity.getLayer();
      allEntities[layer.getId()].remove(entity);
      allEntities[layer.getId()].addLast(entity);
    }

    setChanged();
    notifyObservers();
  }
예제 #11
0
파일: Map.java 프로젝트: AlanTR/solarus
  /**
   * Brings the specified entities to the back, keeping their layer. The order of the specified
   * entities in the map is unchanged.
   *
   * @param entities the entities to move
   */
  public void bringToBack(List<MapEntity> entities) {

    List<MapEntity> sortedEntities = getSortedEntities(entities);

    // bring to back each entity from sortedEntities
    ListIterator<MapEntity> iterator = sortedEntities.listIterator(sortedEntities.size());
    while (iterator.hasPrevious()) {

      MapEntity entity = iterator.previous();
      Layer layer = entity.getLayer();
      allEntities[layer.getId()].remove(entity);
      allEntities[layer.getId()].addFirst(entity);
    }

    setChanged();
    notifyObservers();
  }
예제 #12
0
  /**
   * Insert the list of <code>newPasses</code> into <code>passes</code> immediately before the pass
   * named <code>id</code>.
   */
  public void beforePass(List passes, Pass.ID id, List newPasses) {
    for (ListIterator i = passes.listIterator(); i.hasNext(); ) {
      Pass p = (Pass) i.next();

      if (p.id() == id) {
        // Backup one position.
        i.previous();

        for (Iterator j = newPasses.iterator(); j.hasNext(); ) {
          i.add(j.next());
        }

        return;
      }
    }

    throw new InternalCompilerError("Pass " + id + " not found.");
  }
예제 #13
0
  public static void dumpcode(final MethodEditor m) {

    final PrintWriter out = new PrintWriter(System.out, true);
    final StackHeightCounter shc = new StackHeightCounter(m);

    out.println("Code for method " + m.name() + m.type());
    final List instructions = m.code();
    final ListIterator iter = instructions.listIterator();
    while (iter.hasNext()) {
      final Object obj = iter.next();
      if (obj instanceof Label) {
        shc.handle((Label) obj);
      } else if (obj instanceof Instruction) {
        shc.handle((Instruction) obj);
      }

      System.out.println("        " + obj + " (sh: " + shc.height() + ")");
    }
  }
예제 #14
0
  // ---------------------------------------------------------------------------
  private BuildAction addToBuildQueue(String target, boolean primaryTarget, int insertPosition)
      throws TablesawException {
    // The target was already checked and does not need to be built
    if (m_noBuildCache.contains(target)) return (null);

    Debug.print("addToBuildQueue(" + target + ", " + primaryTarget + ", " + insertPosition + ")");
    Debug.indent();

    Rule trule = findTargetRule(target);

    CachedFile targetFile = null;
    BuildAction[] buildDep = null;
    BuildAction targetBA = null;
    BuildAction depBA = null;
    BuildAction ret = null;

    if (trule == null) {
      targetFile = m_fileManager.locateFile(target);

      // TODO: Add the rule that required this target to the error message
      if (targetFile == null)
        throw new TablesawException("Unable to locate rule for '" + target + "'");

      if (m_sourceFiles != null)
        m_sourceFiles.add(
            new File(
                targetFile.getPath())); // Doing this because locateFile will return a CachedFile

      // TODO: check file against cache file stamps and if changed return dummy rule
      Debug.print("Cache lookup for " + targetFile.getPath());

      // Add file to cache for next run
      m_newModificationCache.put(targetFile.getPath(), targetFile.lastModified());

      Long cacheModTime = m_modificationCache.get(targetFile.getPath());
      if (cacheModTime != null) {
        Debug.print("Cache hit " + cacheModTime + ":" + targetFile.lastModified());
        if (cacheModTime != targetFile.lastModified()) {
          Debug.print("returning obj for " + targetFile);
          Debug.popIndent();
          targetBA =
              new BuildAction(
                  m_fileManager, new ModifiedFileRule(targetFile.getPath()), m_classAnnotations);
          m_buildQueue.add(insertPosition, targetBA);
          return (targetBA);
        }
      } else Debug.print("Cache miss");

      // System.out.println("File "+targetFile);
      m_noBuildCache.add(target);
      Debug.print("Target " + target + " is a file with no rule");
      Debug.popIndent();
      return (null);
    }

    if ((m_sourceFiles != null) && (trule instanceof SourceFileSet)) {
      m_sourceFiles.addAll(((SourceFileSet) trule).getSourceFiles());
    }

    long targetTime = 0;
    boolean tExists = true;
    boolean tDir = false;
    boolean tPhony = true;

    boolean rebuild = false;

    targetBA = new BuildAction(m_fileManager, trule, m_classAnnotations);
    int index;

    if (m_buildQueueCache.containsKey(targetBA)) {
      // Get the build action from the queue
      targetBA = m_buildQueueCache.get(targetBA);

      Debug.print("target: " + trule + " already in build queue.");
      // Target has already been added to build queue
      Debug.popIndent();
      return (targetBA);
    }

    File f;

    trule.preBuild(m_depCache, m_modificationCache);

    // NOTE: need to add in dependencies that are individually declared
    // NOTE: getPrerequisites is also where dependency parsing happens to include C headers and
    // other java classes
    // String[] prereqs = getPrerequisites(trule, true);
    List<String> prereqs = new ArrayList<String>();

    for (String dn : trule.getDependNames()) {
      Debug.print("adding depend name " + dn);
      prereqs.add(dn);
    }

    for (Rule r : trule.getDependRules()) {
      Debug.print("adding depend rule " + r);
      if (r.getName() == null) {
        // Generate name for rule
        String genRuleName = NAMED_RULE_PREFIX + (m_ruleNameCounter++);
        r.setName(genRuleName);
        m_nameRuleMap.put(genRuleName, r);
      }

      prereqs.add(r.getName());
    }

    Debug.print("rule dependents " + prereqs.size());

    if (prereqs.size() > 0) {
      ListIterator<String> it = prereqs.listIterator();

      while (it.hasNext()) {
        String prereq = it.next();

        if (prereq.equals(target))
          throw new TablesawException("Target " + target + " depends on itself");

        /* //See if the prereq is the name of a rule first
        Rule nameRule = m_nameRuleMap.get(prereq);

        //Add the new rule targets to the prereqs list
        // TODO: some kind of check so we dont add the same named rule again and again.
        if (nameRule != null)
        	{
        	Iterable<String> ruleTargets = nameRule.getTargets();
        	boolean hasTargets = false;
        	for (String t : ruleTargets)
        		{
        		hasTargets = true;
        		it.add(t);
        		it.previous();
        		}

        	if (hasTargets)
        		continue;
        	} */

        // Add dependencies to build queue first.
        // f = m_fileManager.getFile(prereq);
        if ((depBA = addToBuildQueue(prereq, false, insertPosition)) != null) {
          targetBA.addDependency(depBA);
          // trule.addNewerDepend(prereq);
          if (depBA.isBinding()) {
            Debug.print("Rebuild: " + trule + " because rebuild of " + depBA.getTargetRule());
            rebuild = true;
          }
        }
      }
    }

    if (!rebuild) {
      rebuild = trule.needToRun();
      Debug.print("Rule needToRun() returned " + rebuild);
    }

    // TODO: change this to get depends from above and check if no depends
    if ((!rebuild)
        && (primaryTarget
            && (!trule
                .getTargets()
                .iterator()
                .hasNext()))) { // If target is the primary target and it has no targets
      Debug.print("Adding primary target: " + trule + " to build queue.");
      rebuild = true;
    }

    if (rebuild) { // Add target to build queue
      m_buildQueue.add(insertPosition, targetBA);
      m_buildQueueCache.put(targetBA, targetBA);
      Debug.print("Adding " + targetBA + " to build queue at pos " + insertPosition);
      // System.out.println("Adding "+targetBA+" to build queue at pos "+insertPosition);

      ret = targetBA;
    }

    // Add target to cache if it does not need to be built
    // This is to speed up incremental builds
    if (ret == null) m_noBuildCache.add(target);

    Debug.popIndent();
    return (ret);
  }
예제 #15
0
  public static void main(String[] arg) {
    Vector<Boolean> containerTypes = new Vector<Boolean>();
    Vector<String> environmentTypes = new Vector<String>();
    Vector<String> testNames = new Vector<String>();
    Vector<Class> argTests = new Vector<Class>();
    Class[] tests = {};

    for (int i = 0; i < arg.length; i++) {
      if (arg[i].startsWith("-")) {
        switch (arg[i].charAt(1)) {
          case 'c':
            String cType = arg[++i];
            if (cType.equalsIgnoreCase(NODE)) containerTypes.add(true);
            else if (cType.equalsIgnoreCase(WHOLE)) containerTypes.add(false);
            else if (cType.equalsIgnoreCase(ALL)) {
              containerTypes.add(true);
              containerTypes.add(false);
            } else usage();
            break;
          case 'e':
            String eType = arg[++i];
            if (eType.equalsIgnoreCase(NONE)
                || eType.equalsIgnoreCase(TXN)
                || eType.equalsIgnoreCase(CDS)) environmentTypes.add(eType);
            else if (eType.equalsIgnoreCase(ALL)) {
              environmentTypes.add(NONE);
              environmentTypes.add(TXN);
              environmentTypes.add(CDS);
            } else usage();
            break;
          default:
            usage();
        }
      } else testNames.add(arg[i]);
    }
    if (containerTypes.size() == 0) {
      containerTypes.add(true);
      containerTypes.add(false);
    }
    if (environmentTypes.size() == 0) {
      environmentTypes.add(NONE);
      environmentTypes.add(TXN);
      environmentTypes.add(CDS);
    }

    // Get the tests to run
    if (testNames.size() != 0) {
      for (int i = 0; i < testNames.size(); i++) {
        Class testClass = null;
        try {
          testClass = Class.forName("dbxmltest." + testNames.get(i));
        } catch (ClassNotFoundException e) {
          System.out.println("Skipping test " + testClass + ". Test not found.");
        }
        if (testClass != null) argTests.add(testClass);
      }
      if (argTests.size() != 0) tests = argTests.toArray(tests);
      else tests = allTests;
    } else tests = allTests;

    // Run the tests
    int failureCount = 0;
    boolean success = true;
    File errorFile = new File(getEnvironmentPath() + "/errorLog.txt");
    try {
      if (errorFile.exists()) errorFile.delete();
      errorFile.createNewFile();
      System.setErr(new PrintStream(new FileOutputStream(errorFile)));
    } catch (IOException e) {
    }
    for (int j = 0; j < environmentTypes.size(); j++) {
      System.out.println("Testing env type " + environmentTypes.get(j));
      for (int i = 0; i < containerTypes.size(); i++) {
        System.out.println("\tContainer type " + (containerTypes.get(i) ? "node" : "whole"));
        NODE_CONTAINER = containerTypes.get(i);
        ENV_TYPE = environmentTypes.get(j);
        Result res = org.junit.runner.JUnitCore.runClasses(tests);
        if (!res.wasSuccessful()) {
          System.err.println(
              "Number of failures for environment type "
                  + ENV_TYPE
                  + " and is node container "
                  + NODE_CONTAINER
                  + " are "
                  + res.getFailureCount());
          List<Failure> testFailures = res.getFailures();
          ListIterator<Failure> iter = testFailures.listIterator();
          while (iter.hasNext()) {
            Failure fail = iter.next();
            System.err.println(fail.getDescription());
            Throwable e = fail.getException();
            if (e != null) e.printStackTrace();
            else System.err.println(fail.getTrace());
          }
          failureCount += res.getFailureCount();
          success = res.wasSuccessful();
        }
      }
    }
    if (success) System.out.println("All tests successful.");
    else System.out.println(failureCount + " tests failed.");
    System.out.println("Failures printed to " + errorFile.getName());
  }