Esempio n. 1
1
  public static int getMinRefrigerator(List<int[]> foodList) {
    int refrigeratorCount = 0;

    HashSet<int[]> foodSet = new HashSet<int[]>();

    int minAndMax[] = getMinAndMax(foodList);

    for (int i = 0; i < foodList.size(); i++) {
      foodSet.add(foodList.get(i));
    }

    while (foodSet.size() > 0) {
      HashMap<String, Integer> counts = new HashMap<String, Integer>();

      for (Iterator<int[]> i = foodSet.iterator(); i.hasNext(); ) {
        int[] item = i.next();
        for (int j = item[0]; j <= item[1]; j++) {
          counts.put(Integer.toString(j), counts.getOrDefault(Integer.toString(j), 0) + 1);
        }
      }

      int maxCount = 0;
      int point = Integer.MAX_VALUE;

      for (int i = minAndMax[0]; i <= minAndMax[1]; i++) {
        if (counts.getOrDefault(Integer.toString(i), 0) > maxCount) {
          maxCount = counts.getOrDefault(Integer.toString(i), 0);
          point = i;
        }
      }

      ArrayList<int[]> lst = new ArrayList<int[]>();

      for (Iterator<int[]> i = foodSet.iterator(); i.hasNext(); ) {
        int[] item = i.next();
        if (item[0] <= point && item[1] >= point) {
          lst.add(item);
          // foodSet.remove(item);
        }
      }

      for (int i = 0; i < lst.size(); i++) {
        foodSet.remove(lst.get(i));
      }

      refrigeratorCount++;
    }

    return refrigeratorCount;
  }
Esempio n. 2
1
  public void testSITwo() {
    HashSet s1 = new HashSet();
    s1.add("a");
    Iterators.Sequence it = new Iterators.Sequence(new Iterator[] {s1.iterator()});
    assertIteration(it, new Object[] {"a"});
    it.remove();
    assertEquals(Collections.EMPTY_SET, s1);
    assertIllegalState(it);

    List xs = Arrays.asList(new String[] {"a", "b"});
    List ixs = Collections.unmodifiableList(xs);
    Iterators.Sequence it2 = new Iterators.Sequence(new Iterator[] {ixs.iterator()});
    assertIteration(it2, new Object[] {"a", "b"});
    assertUnsupportedOperation(it2); // explicitly not modifiable

    ArrayList xs2 = new ArrayList();
    xs2.add("a");
    xs2.add("b");
    Iterators.Sequence it3 = new Iterators.Sequence(new Iterator[] {xs2.iterator()});
    assertIteration(it3, new Object[] {"a", "b"});
    it3.remove();
    ArrayList xs2expected = new ArrayList();
    xs2expected.add("a");
    assertEquals(xs2expected, xs2);

    ArrayList xs3 = new ArrayList();
    xs3.add("a");
    xs3.add("b");
    Iterators.Sequence it4 = new Iterators.Sequence(new Iterator[] {xs3.iterator()});
    it4.next();
    it4.remove();
    ArrayList xs3expected = new ArrayList();
    xs3expected.add("b");
    assertEquals(xs3expected, xs3);
  }
 public String[] getjavaVMs() {
   // get the internal VM name
   // App Clients never run on the internal VM
   Set res = new HashSet();
   if (!(this instanceof AppClientModuleMdl)) {
     // res.addAll(findNames("j2eeType=JVM,name=" + MOAgentFactory.getAgent().getJVMId()));
   }
   // get the external VM names
   Iterator vmNames = externalVMs.iterator();
   while (vmNames.hasNext()) {
     String vmName = (String) vmNames.next();
     Set x = findNames("j2eeType=JVM,name=" + vmName);
     if (x.size() > 0) {
       res.addAll(x);
     } else {
       // no longer an active VM
       externalVMs.remove(vmName);
       vmNames = externalVMs.iterator();
     }
   }
   Iterator it = res.iterator();
   String[] vms = new String[res.size()];
   int i = 0;
   while (it.hasNext()) {
     vms[i++] = ((ObjectName) it.next()).toString();
   }
   return vms;
 }
 protected final void test_hasProperties_Object_String_String_Throwable_() {
   Iterator iterSubject = getCases().iterator();
   while (iterSubject.hasNext()) {
     PropertyException subject = (PropertyException) iterSubject.next();
     HashSet objects = new HashSet();
     objects.add(new Object());
     objects.add(null);
     Iterator iterOrigin = objects.iterator();
     while (iterOrigin.hasNext()) {
       Object origin = iterOrigin.next();
       Iterator iterPropertyName = new _Test_String().getCasesWithNull().iterator();
       while (iterPropertyName.hasNext()) {
         String propertyName = (String) iterPropertyName.next();
         Iterator iterMessage = new _Test_String().getCasesWithNull().iterator();
         while (iterMessage.hasNext()) {
           String message = (String) iterMessage.next();
           HashSet causes = new HashSet();
           causes.add(null);
           causes.add(new Throwable());
           causes.add(subject.getCause());
           Iterator iterCause = causes.iterator();
           while (iterCause.hasNext()) {
             Throwable cause = (Throwable) iterCause.next();
             test_hasProperties_Object_String_String_Throwable_(
                 subject, origin, propertyName, message, cause);
           }
         }
       }
     }
   }
 }
  /**
   * Determines whether there is an id in neighbors, upPointers, downPointers, fold, surrogateFold,
   * or inverseSurrogateFold that is closer to the targetId than the nextNodeId. Closer is defined
   * as the number of locations in their webId's binary representation in which their respective
   * bits differ.
   *
   * @param nextNodeId the id we think is as close to the target as any other node known to this
   *     node.
   * @param targetId the id we are computing the distance to.
   * @pre <i>None</i>
   * @post result = NOT &exist; nodeId ((nodeId &isin; neighbors OR nodeId &isin; upPointers OR
   *     nodeID &isin; downPointers OR<br>
   *     nodeID = fold OR nodeId = surrogateFold OR nodeId = inverseSurrogateFold) AND nodeId &ge; 0
   *     AND nodeId.distanceTo(targetId) < nextNodeId.distanceTo(targetId))
   */
  public boolean containsCloserNode(final int nextNodeId, final int targetId) {
    final int distance = distanceTo(nextNodeId, targetId);
    boolean result = false;

    Iterator<Integer> iter = neighbors.iterator();
    while (iter.hasNext() && !result) {
      final int neighbor = iter.next();
      final int neighborDistance = distanceTo(neighbor, targetId);
      result = neighborDistance < distance;
    }

    iter = upPointers.iterator();
    while (iter.hasNext() && !result) {
      final int upPointer = iter.next();
      final int upPointerDistance = distanceTo(upPointer, targetId);
      result = upPointerDistance < distance;
    }

    iter = downPointers.iterator();
    while (iter.hasNext() && !result) {
      final int downPointer = iter.next();
      final int downPointerDistance = distanceTo(downPointer, targetId);
      result = downPointerDistance < distance;
    }

    result = result || (distanceTo(fold, targetId) < distance);
    result = result || (distanceTo(surrogateFold, targetId) < distance);
    result = result || (distanceTo(inverseSurrogateFold, targetId) < distance);
    return result;
  }
Esempio n. 6
0
  /**
   * This method loads the class from a jar file. Beta jars are supported if the beta flag is on.
   */
  @Override
  protected byte[] loadClassBytes(String className) {

    // Support the MultiClassLoader's class name munging facility.
    className = formatClassName(className);
    byte[] resource = null;

    if (jarResources == null) {
      return null;
    }

    // If beta flag is on first check beta versions of jar files before other jars.
    if (beta && betaJarResources != null) {

      Iterator<JarResources> allResources = betaJarResources.iterator();

      while (allResources.hasNext()) {

        JarResources d = allResources.next();

        try {

          resource = d.getResource(className);

          if (resource != null) {
            return resource;
          }
        } catch (Exception e) {

        }
      }
    }

    if (resource == null) {

      Iterator<JarResources> allResources = jarResources.iterator();

      while (allResources.hasNext()) {

        JarResources d = allResources.next();

        try {

          resource = d.getResource(className);

          if (resource != null) {
            break;
          }
        } catch (Exception e) {

        }
      }
    }

    return resource;
  }
 /**
  * In case the method is still under-call then put the record of the method fields where get was
  * used in a seperate map. When a method any next instruction is called again then the record is
  * pop from the map and corresponding instructions are made dirty.
  *
  * <p>This method create that record of method fields.
  *
  * @param methodCallInfo
  * @param instrDataSettingInstr
  */
 private void handlePutRecalls(
     MethodCallInfo methodCallInfo, GCInstruction instrDataSettingInstr, OperandStack stack) {
   if (true) return;
   try {
     /**
      * 1. Firstly get from input instructions the uniqueId for corresponding data reterival
      * instructions. 2. Subsequently, add those instructions in the two different maps depending
      * upon if the method is still under call or not.
      */
     ControllerForFieldInstr contr = ControllerForFieldInstr.getInstanceOf();
     HashSet<Integer> uniqueIdForDataRetrivalInstr = new HashSet<Integer>();
     if (instrDataSettingInstr.getOpCode() != JavaInstructionsOpcodes.AASTORE) {
       int cpIndex = instrDataSettingInstr.getOperandsData().intValueUnsigned();
       uniqueIdForDataRetrivalInstr.add(cpIndex);
     } else {
       uniqueIdForDataRetrivalInstr = getAAStoreNewIds(stack);
     }
     /**
      * following are the all getField or getStatic instruction for the given constant pool index.
      */
     HashSet<FieldRecord> getFieldOrStateRecordSet =
         contr.getRecords(
             uniqueIdForDataRetrivalInstr,
             instrDataSettingInstr.getOpCode() == JavaInstructionsOpcodes.AASTORE);
     /**
      * Now we iterate from all of those instructions and put them in two different maps
      * depenending up if their method is still under call or not.
      */
     Iterator<FieldRecord> fieldRectIt = getFieldOrStateRecordSet.iterator();
     while (fieldRectIt.hasNext()) {
       FieldRecord fieldRec = fieldRectIt.next();
       HashSet<FunctionStateKey> allTheMethodCallsForTheField = fieldRec.getStateKeys();
       Iterator<FunctionStateKey> methodCallIt = allTheMethodCallsForTheField.iterator();
       while (methodCallIt.hasNext()) {
         FunctionStateKey stateKey = methodCallIt.next();
         GCDataFlowAnalyzer dataFlowAnalyzer = GCDataFlowAnalyzer.getInstanceOf();
         HashSet<FunctionStateKey> allMethodInExecution = dataFlowAnalyzer.getMethodsInExecution();
         String methodString = oracle.getMethodOrFieldString(stateKey.getMethod());
         long instrId = fieldRec.getInstr().getInstructionId();
         if (allMethodInExecution.contains(stateKey)) {
           putInMap(fieldsToSetDirtyInUnderCallMethod, stateKey, fieldRec);
         } else {
           putInMap(fieldsToSetDirtyAfterMethodCalled, stateKey, fieldRec);
         }
       }
     }
   } catch (Exception d) {
     d.printStackTrace();
     Miscellaneous.exit();
   }
 }
Esempio n. 8
0
  /** java.util.HashSet#iterator() */
  public void test_iterator() {
    // Test for method java.util.Iterator java.util.HashSet.iterator()
    Iterator i = hs.iterator();
    int x = 0;
    while (i.hasNext()) {
      assertTrue("Failed to iterate over all elements", hs.contains(i.next()));
      ++x;
    }
    assertTrue("Returned iteration of incorrect size", hs.size() == x);

    HashSet s = new HashSet();
    s.add(null);
    assertNull("Cannot handle null", s.iterator().next());
  }
Esempio n. 9
0
  public Row join(Row pRow, String pField) {
    // dbgMsg("Join!");
    RowFormat newFormat = mFormat.join(pRow.mFormat, pField);
    Row newRow = (Row) newFormat.getRowFactory().makeRow();
    // String[] ourFieldNames = mFormat.getFieldNames();
    // String[] theirFieldNames =pRow.mFormat.getFieldNames();
    // dbgMsg("ourFieldNames="+StringUtils.arrayToString(ourFieldNames, ", "));
    // dbgMsg("theirFieldNames="+StringUtils.arrayToString(theirFieldNames, ", "));

    HashSet ourFields = new HashSet(Arrays.asList(mFormat.getFieldNames()));
    HashSet theirFields = new HashSet(Arrays.asList(pRow.mFormat.getFieldNames()));
    ourFields.remove(pField);
    theirFields.remove(pField);
    HashSet commonFields = new HashSet(ourFields);
    commonFields.retainAll(theirFields);
    ourFields.removeAll(commonFields);
    theirFields.removeAll(commonFields);

    // dbgMsg("join field "+pField);
    // dbgMsg("our fields: "+StringUtils.collectionToString(ourFields, " "));
    // dbgMsg("their fields: "+StringUtils.collectionToString(theirFields, " "));
    // dbgMsg("common fields: "+StringUtils.collectionToString(commonFields, " "));

    // copy join field
    newRow.set(pField, get(pField)); // (copied arbitrarily from...us, as should be same!)

    // copy our fields
    Iterator ourFieldsIter = ourFields.iterator();
    while (ourFieldsIter.hasNext()) {
      String field = (String) ourFieldsIter.next();
      newRow.set(field, (get(field)));
    }

    // copy their fields
    Iterator theirFieldsIter = theirFields.iterator();
    while (theirFieldsIter.hasNext()) {
      String field = (String) theirFieldsIter.next();
      newRow.set(field, (pRow.get(field)));
    }

    // copy common fields (renaming fields becomes necessary)
    Iterator commonFieldsIter = commonFields.iterator();
    while (commonFieldsIter.hasNext()) {
      String field = (String) commonFieldsIter.next();
      newRow.set(field + "1", (get(field)));
      newRow.set(field + "2", (pRow.get(field)));
    }

    return newRow;
  }
 /**
  * counts big X. unclassified nodes are not counted ; no correction for function_unknown nodes
  * (yet)(requires user input)
  */
 public void countBigX() {
   mapBigX = new HashMap();
   int bigX = selectedNodes.size();
   Iterator i = selectedNodes.iterator();
   while (i.hasNext()) {
     HashSet classifications = getNodeClassifications(i.next().toString());
     Iterator iterator = classifications.iterator();
     if (!iterator.hasNext()) {
       bigX--;
     }
   }
   for (Object id : this.mapSmallX.keySet()) {
     mapBigX.put((Integer) id, new Integer(bigX));
   }
 }
Esempio n. 11
0
  public void testSIOne() {
    HashSet s1 = new HashSet();
    Iterators.Sequence it = new Iterators.Sequence(new Iterator[] {s1.iterator()});
    assertIteration(it, new Object[] {});
    assertIllegalState(it);

    HashSet s2 = new HashSet();
    Iterators.Sequence it2 = new Iterators.Sequence(new Iterator[] {s1.iterator(), s2.iterator()});
    assertIteration(it2, new Object[] {});
    assertIllegalState(it2);

    Iterators.Sequence it3 = new Iterators.Sequence(s1.iterator(), s2.iterator());
    assertIteration(it3, new Object[] {});
    assertIllegalState(it3);
  }
Esempio n. 12
0
  @Override
  public URL getResource(String name) {

    if (jarResources == null || betaJarResources == null) {
      initializeJarResources();
    }

    if (jarResources == null) {
      return getParent().getResource(name);
    }

    // If beta classloader first try betaJarResources.
    if (beta) {
      Iterator<JarResources> allResources = betaJarResources.iterator();
      while (allResources.hasNext()) {

        JarResources d = allResources.next();

        try {

          URL resource = d.getPathURL(name);
          if (resource != null && d.hasResource(name)) {
            return resource;
          }
        } catch (Exception e) {
        }
      }

      return this.getClass().getClassLoader().getResource(name);
    }

    Iterator<JarResources> allResources = jarResources.iterator();
    while (allResources.hasNext()) {

      JarResources d = allResources.next();

      try {

        URL resource = d.getPathURL(name);
        if (resource != null && d.hasResource(name)) {
          return resource;
        }
      } catch (Exception e) {
      }
    }

    return this.getClass().getClassLoader().getResource(name);
  }
Esempio n. 13
0
  @Override
  public InputStream getResourceAsStream(String name) {

    if (jarResources == null || betaJarResources == null) {
      initializeJarResources();
    }

    if (jarResources == null) {
      return getParent().getResourceAsStream(name);
    }

    // If beta classloader first try betaJarResources.
    if (beta) {
      Iterator<JarResources> allResources = betaJarResources.iterator();
      while (allResources.hasNext()) {

        JarResources d = allResources.next();

        try {

          byte[] resource = d.getResource(name);
          if (resource != null) {
            return new java.io.ByteArrayInputStream(resource);
          }
        } catch (Exception e) {
        }
      }

      return this.getClass().getClassLoader().getResourceAsStream(name);
    }

    Iterator<JarResources> allResources = jarResources.iterator();
    while (allResources.hasNext()) {

      JarResources d = allResources.next();

      try {

        byte[] resource = d.getResource(name);
        if (resource != null) {
          return new java.io.ByteArrayInputStream(resource);
        }
      } catch (Exception e) {
      }
    }

    return this.getClass().getClassLoader().getResourceAsStream(name);
  }
Esempio n. 14
0
 public java.util.Iterator getPorts() {
   if (ports == null) {
     ports = new java.util.HashSet();
     ports.add(new javax.xml.namespace.QName("http://ws.ideal.com", "ISmsInfoWsHttpPort"));
   }
   return ports.iterator();
 }
Esempio n. 15
0
 Iterator<Row> getDelta() {
   if (delta == null) {
     List<Row> e = Collections.emptyList();
     return e.iterator();
   }
   return delta.iterator();
 }
Esempio n. 16
0
  /**
   * Given an abstract dispatch to an object of type c and a method m, gives a list of possible
   * receiver methods.
   */
  public List resolveAbstractDispatch(SootClass c, SootMethod m) {
    c.checkLevel(SootClass.HIERARCHY);
    m.getDeclaringClass().checkLevel(SootClass.HIERARCHY);
    checkState();

    Iterator<SootClass> classesIt = null;

    if (c.isInterface()) {
      classesIt = getImplementersOf(c).iterator();
      HashSet<SootClass> classes = new HashSet<SootClass>();
      while (classesIt.hasNext()) classes.addAll(getSubclassesOfIncluding(classesIt.next()));
      classesIt = classes.iterator();
    } else classesIt = getSubclassesOfIncluding(c).iterator();

    ArraySet s = new ArraySet();

    while (classesIt.hasNext()) {
      SootClass cl = classesIt.next();
      if (Modifier.isAbstract(cl.getModifiers())) continue;
      s.add(resolveConcreteDispatch(cl, m));
    }

    List l = new ArrayList();
    l.addAll(s);
    return Collections.unmodifiableList(l);
  }
Esempio n. 17
0
  public void Choose() throws IOException {
    File file = new File("PolicySetB.csv");
    BufferedReader bufRdr = new BufferedReader(new FileReader(file));
    String line = null;
    HashSet<String> ps = new HashSet<String>();
    int numPs = 0;
    while ((line = bufRdr.readLine()) != null) {
      String[] field = line.split(",", -1);
      // System.out.println(Arrays.toString(field));
      if (field[0].equals("Policies")) {
        for (String val : field) {
          if (!val.equals("Policies")) {
            ps.add(val);
            numPs++;
          }
        }
        Iterator it1 = ps.iterator();
        System.out.println("===Rule HashSet===");
        while (it1.hasNext()) {
          System.out.println(it1.next());
        }
        // System.out.println(numPs);
        // break;
      }
    }

    bufRdr.close();
  }
 public java.util.Iterator getPorts() {
   if (ports == null) {
     ports = new java.util.HashSet();
     ports.add(new javax.xml.namespace.QName("http://extility.flexiant.com", "FlexiScale"));
   }
   return ports.iterator();
 }
 public java.util.Iterator getPorts() {
   if (ports == null) {
     ports = new java.util.HashSet();
     ports.add(new javax.xml.namespace.QName("http://illuminati.is", "CharityService"));
   }
   return ports.iterator();
 }
  void renderAll(Tessellator var1) {
    HashSet var2 = new HashSet();
    Iterator var3 = this.skies.iterator();

    while (var3.hasNext()) {
      SkyRenderer$Layer var4 = (SkyRenderer$Layer) var3.next();

      if (var4.prepare()) {
        var2.add(SkyRenderer$Layer.access$300(var4));
      }
    }

    HashSet var6 = new HashSet();
    var6.addAll(this.textures);
    var6.removeAll(var2);
    Iterator var7 = var6.iterator();

    while (var7.hasNext()) {
      String var5 = (String) var7.next();
      TexturePackAPI.unloadTexture(var5);
    }

    var7 = this.skies.iterator();

    while (var7.hasNext()) {
      SkyRenderer$Layer var8 = (SkyRenderer$Layer) var7.next();

      if (var8.brightness > 0.0F) {
        var8.render(var1);
        SkyRenderer$Layer.clearBlendingMethod();
      }
    }
  }
  void RemoveColidingBids(
      HashSet<Integer> regions,
      HashSet<Integer> companies,
      Double minValue,
      HashSet<Integer> AvailSet) {
    HashSet<Integer> RemoveSet =
        new HashSet<Integer>(); // HashSet to hold the items to remove from the AvailSet

    // Get an iterator to iterate over all the integers in the availble HashSet
    Iterator<Integer> it = AvailSet.iterator();

    // While there are any left
    while (it.hasNext()) {

      // Get the next integer
      Integer k = it.next();

      if ((_bids.get(k).value <= minValue)
          || // if the value is less than the target
          (companies.contains(_bids.get(k).company))
          || // if the company is already represented
          !Collections.disjoint(
              _bids.get(k).region, regions)) { // if it contains a region already bid on
        // add K to the "Remove" set
        RemoveSet.add(k);
      }
    }
    // Remove every bid from the remove set from the Avail list.
    AvailSet.removeAll(RemoveSet);
  }
Esempio n. 22
0
 public java.util.Iterator getPorts() {
   if (ports == null) {
     ports = new java.util.HashSet();
     ports.add(new javax.xml.namespace.QName("http://ws.cdyne.com/WeatherWS/", "WeatherSoap"));
   }
   return ports.iterator();
 }
 public java.util.Iterator getPorts() {
   if (ports == null) {
     ports = new java.util.HashSet();
     ports.add(new javax.xml.namespace.QName("http://soap/", "ReviewServicePort"));
   }
   return ports.iterator();
 }
Esempio n. 24
0
 /**
  * <b>Note:</b> If multiple PooledDataSources in your JVM share the same <tt>dataSourceName</tt>,
  * which of those multiple DataSources will be returned by this method is undefined!
  *
  * @return a PooledDataSource with the given <tt>dataSourceName</tt>, if at least one exists.
  *     <tt>null</tt> otherwise.
  */
 public static synchronized PooledDataSource pooledDataSourceByName(String dataSourceName) {
   for (Iterator ii = unclosedPooledDataSources.iterator(); ii.hasNext(); ) {
     PooledDataSource pds = (PooledDataSource) ii.next();
     if (pds.getDataSourceName().equals(dataSourceName)) return pds;
   }
   return null;
 }
Esempio n. 25
0
 private void printListOfAllPatterns(PrintStream out, Domain domain, String prefix, int level) {
   Iterator patternsIterator = allPatterns_.entrySet().iterator();
   while (patternsIterator.hasNext()) {
     Map.Entry me = (Map.Entry) patternsIterator.next();
     String patternName = (String) me.getKey();
     HashSet indexEntries = (HashSet) me.getValue();
     String indexUrl;
     if (indexEntries.isEmpty()) {
       // impossible.
       indexUrl = "#";
     } else {
       Iterator it = indexEntries.iterator();
       if (it.hasNext()) {
         PatternIndexEntry entry = (PatternIndexEntry) it.next();
         indexUrl = entry.getPrefix() + entry.getSystemName() + "/index.html#" + patternName;
       } else {
         // impossible
         indexUrl = "#";
       }
     }
     out.println(
         "<A href=\"" + indexUrl + "\" TARGET=\"transformerFrame\" >" + patternName + "</A>");
     out.println("<BR>");
   }
 }
    /** {@inheritDoc} */
    public void rewriteAST(CompilationUnitRewrite cuRewrite, List textEditGroups)
        throws CoreException {
      TextEditGroup group =
          createTextEditGroup(FixMessages.ExpressionsFix_removeUnnecessaryParenthesis_description);
      textEditGroups.add(group);

      ASTRewrite rewrite = cuRewrite.getASTRewrite();

      while (fExpressions.size() > 0) {
        ParenthesizedExpression parenthesizedExpression =
            (ParenthesizedExpression) fExpressions.iterator().next();
        fExpressions.remove(parenthesizedExpression);
        ParenthesizedExpression down = parenthesizedExpression;
        while (fExpressions.contains(down.getExpression())) {
          down = (ParenthesizedExpression) down.getExpression();
          fExpressions.remove(down);
        }

        ASTNode move = rewrite.createMoveTarget(down.getExpression());

        ParenthesizedExpression top = parenthesizedExpression;
        while (fExpressions.contains(top.getParent())) {
          top = (ParenthesizedExpression) top.getParent();
          fExpressions.remove(top);
        }

        rewrite.replace(top, move, group);
      }
    }
Esempio n. 27
0
  private Authentication fresh(Authentication authentication, ServletRequest req) {
    HttpServletRequest request = (HttpServletRequest) req;

    HttpSession session = request.getSession(false);

    if (session != null) {
      SessionRegistry sessionRegistry =
          (SessionRegistry) SpringBeanUtil.getBeanByName("sessionRegistry");
      SessionInformation info = sessionRegistry.getSessionInformation(session.getId());

      if (info != null) {
        // Non-expired - update last request date/time
        Object principal = info.getPrincipal();
        if (principal instanceof org.springframework.security.core.userdetails.User) {
          org.springframework.security.core.userdetails.User userRefresh =
              (org.springframework.security.core.userdetails.User) principal;
          ServletContext sc = session.getServletContext();
          HashSet<String> unrgas = springSecurityService.getUsersNeedRefreshGrantedAuthorities();
          if (unrgas.size() > 0) {
            HashSet<String> loginedUsernames = new HashSet<String>();

            List<Object> loggedUsers = sessionRegistry.getAllPrincipals();
            for (Object lUser : loggedUsers) {
              if (lUser instanceof org.springframework.security.core.userdetails.User) {
                org.springframework.security.core.userdetails.User u =
                    (org.springframework.security.core.userdetails.User) lUser;
                loginedUsernames.add(u.getUsername());
              }
            }
            // 清除已经下线的但需要刷新的username
            for (Iterator iterator = unrgas.iterator(); iterator.hasNext(); ) {
              String unrgs = (String) iterator.next();
              if (!loginedUsernames.contains(unrgs)) {
                iterator.remove();
              }
            }
            if (unrgas.contains(userRefresh.getUsername())) {
              // 如果需要刷新权限的列表中有当前的用户,刷新登录用户权限
              // FIXME:与springSecurityServiceImpl中的功能,相重复,需重构此方法和springSecurityServiceImpl
              MyJdbcUserDetailsManager mdudm =
                  (MyJdbcUserDetailsManager)
                      SpringBeanUtil.getBeanByType(MyJdbcUserDetailsManager.class);
              SecurityContextHolder.getContext()
                  .setAuthentication(
                      new UsernamePasswordAuthenticationToken(
                          userRefresh,
                          userRefresh.getPassword(),
                          mdudm.getUserAuthorities(userRefresh.getUsername())));
              session.setAttribute(
                  HttpSessionSecurityContextRepository.SPRING_SECURITY_CONTEXT_KEY,
                  SecurityContextHolder.getContext());
              unrgas.remove(userRefresh.getUsername());
              return SecurityContextHolder.getContext().getAuthentication();
            }
          }
        }
      }
    }
    return authentication;
  }
 /**
  * Should be called Before virtual execution of instructions putfield and putstatic so that all
  * corresponding getFields are set dirty. Similarly should also be called before virtual execution
  * of instructions AASTORE so that corresponding AALOAD are set dirty.
  *
  * @param method
  * @param callingParms
  * @param instr
  * @param stack
  * @param localVariables
  */
 public void fixOrderRelatedInstrs(
     MethodInfo method,
     Vector callingParms,
     GCInstruction instr,
     GCOperandStack stack,
     GCLocalVariables localVariables) {
   if (!isFieldIsObjectBased(instr)) {
     return;
   }
   String methodStr = oracle.getMethodOrFieldString(method);
   if (instr.getOpCode() == JavaInstructionsOpcodes.PUTSTATIC
       || instr.getOpCode() == JavaInstructionsOpcodes.PUTFIELD
       || instr.getOpCode() == JavaInstructionsOpcodes.AASTORE) {
     GCType type = (GCType) stack.peep();
     if (!type.isReference()) {
       return;
     }
     HashSet<TTReference> refSet = type.getReferences();
     if (refSet.size() == 1) {
       TTReference ref = refSet.iterator().next();
       if (ref.getClassThisPointer() == Type.NULL || ref.getNewId() < 0) {
         return;
       }
     }
     debugPrint("\n\n++++++++++ ", "fix-Order");
     debugPrint("method Str =", oracle.getMethodOrFieldString(method));
     debugPrint("instr =", instr);
     handlePutRecalls(new MethodCallInfo(method, callingParms), instr, stack);
   }
 }
  /**
   * Returns a textual description of this classifier.
   *
   * @return a textual description of this classifier.
   */
  @Override
  public String toString() {

    if (m_probOfClass == null) {
      return "NaiveBayesMultinomialText: No model built yet.\n";
    }

    StringBuffer result = new StringBuffer();

    // build a master dictionary over all classes
    HashSet<String> master = new HashSet<String>();
    for (int i = 0; i < m_data.numClasses(); i++) {
      LinkedHashMap<String, Count> classDict = m_probOfWordGivenClass.get(i);

      for (String key : classDict.keySet()) {
        master.add(key);
      }
    }

    result.append("Dictionary size: " + master.size()).append("\n\n");

    result.append("The independent frequency of a class\n");
    result.append("--------------------------------------\n");

    for (int i = 0; i < m_data.numClasses(); i++) {
      result
          .append(m_data.classAttribute().value(i))
          .append("\t")
          .append(Double.toString(m_probOfClass[i]))
          .append("\n");
    }

    result.append("\nThe frequency of a word given the class\n");
    result.append("-----------------------------------------\n");

    for (int i = 0; i < m_data.numClasses(); i++) {
      result.append(Utils.padLeft(m_data.classAttribute().value(i), 11)).append("\t");
    }

    result.append("\n");

    Iterator<String> masterIter = master.iterator();
    while (masterIter.hasNext()) {
      String word = masterIter.next();

      for (int i = 0; i < m_data.numClasses(); i++) {
        LinkedHashMap<String, Count> classDict = m_probOfWordGivenClass.get(i);
        Count c = classDict.get(word);
        if (c == null) {
          result.append("<laplace=1>\t");
        } else {
          result.append(Utils.padLeft(Double.toString(c.m_count), 11)).append("\t");
        }
      }
      result.append(word);
      result.append("\n");
    }

    return result.toString();
  }
Esempio n. 30
0
 private void sendFrameNotify()
 {
   while (true)
   {
     Iterator localIterator;
     try
     {
       HashSet localHashSet = new HashSet();
       synchronized (this.lock)
       {
         localHashSet.addAll(this._handlerSet);
         localIterator = localHashSet.iterator();
         boolean bool = localIterator.hasNext();
         if (!bool)
           return;
       }
     }
     finally
     {
     }
     IFrameHandler localIFrameHandler = (IFrameHandler)localIterator.next();
     if (localIFrameHandler != null)
       localIFrameHandler.OnFrame();
   }
 }