下面列出了java.util.Iterator#next ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private void removeDeadAndOutOfRangeDoors() {
boolean flag = false;
boolean flag1 = this.world.rand.nextInt(50) == 0;
Iterator<VillageDoorInfo> iterator = this.villageDoorInfoList.iterator();
while (iterator.hasNext()) {
VillageDoorInfo villagedoorinfo = iterator.next();
if (flag1) {
villagedoorinfo.resetDoorOpeningRestrictionCounter();
}
if (world.isBlockLoaded(villagedoorinfo.getDoorBlockPos())) // Forge: check that the door block is loaded to avoid loading chunks
if (!this.isWoodDoor(villagedoorinfo.getDoorBlockPos()) || Math.abs(this.tickCounter - villagedoorinfo.getLastActivityTimestamp()) > 1200) {
this.centerHelper = this.centerHelper.subtract(villagedoorinfo.getDoorBlockPos());
flag = true;
villagedoorinfo.setIsDetachedFromVillageFlag(true);
iterator.remove();
}
}
if (flag) {
this.updateTofuVillageRadiusAndCenter();
}
}
public Set<Map.Entry<K, V>> entrySet() {
return new AbstractSet<Map.Entry<K, V>>() {
public int size() {
return map.size();
}
public Iterator<Map.Entry<K,V>> iterator() {
final Iterator<Map.Entry<K,V>> source = map.entrySet().iterator();
return new Iterator<Map.Entry<K,V>>() {
public boolean hasNext() { return source.hasNext(); }
public Map.Entry<K,V> next() { return source.next(); }
public void remove() { source.remove(); }
};
}
public boolean add(Map.Entry<K,V> e) {
return map.entrySet().add(e);
}
};
}
public Long fetchAccountByEmail(String email) {
logger.debug("enter getAccountByName");
String LOAD_USER_BY_EMAIL = "select userID from jiveUser where email=?";
List queryParams = new ArrayList();
queryParams.add(email);
Long userId = null;
try {
List list = jdbcTempSource.getJdbcTemp().queryMultiObject(queryParams, LOAD_USER_BY_EMAIL);
Iterator iter = list.iterator();
if (iter.hasNext()) {
logger.debug("found the account");
Map map = (Map) iter.next();
userId = (Long) map.get("userID");
}
} catch (Exception e) {
logger.error(e);
}
return userId;
}
/**
* process Mtom policy assertions and if found and is not optional then mtom is enabled on the
* {@link WSDLBoundPortType}
*
* @param key Key that identifies the endpoint scope
* @param policyMap Must be non-null
* @throws PolicyException If retrieving the policy triggered an exception
*/
public Collection<WebServiceFeature> getFeatures(PolicyMapKey key, PolicyMap policyMap) throws PolicyException {
final Collection<WebServiceFeature> features = new LinkedList<WebServiceFeature>();
if ((key != null) && (policyMap != null)) {
Policy policy = policyMap.getEndpointEffectivePolicy(key);
if (null!=policy && policy.contains(OPTIMIZED_MIME_SERIALIZATION_ASSERTION)) {
Iterator <AssertionSet> assertions = policy.iterator();
while(assertions.hasNext()){
AssertionSet assertionSet = assertions.next();
Iterator<PolicyAssertion> policyAssertion = assertionSet.iterator();
while(policyAssertion.hasNext()){
PolicyAssertion assertion = policyAssertion.next();
if(OPTIMIZED_MIME_SERIALIZATION_ASSERTION.equals(assertion.getName())){
features.add(new MTOMFeature(true));
} // end-if non optional mtom assertion found
} // next assertion
} // next alternative
} // end-if policy contains mtom assertion
}
return features;
}
public void reConnect() {
try {
this.group.shutdownGracefully();
this.group = null;
this.connect();
if (future.isSuccess()) {
this.setStatus(true);
this.sentPing();
Iterator<String> it = subscribChannel.iterator();
while (it.hasNext()) {
String channel = it.next();
this.addChannel(channel);
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* BeanContextServicesListener callback, propagates event to all
* currently registered listeners and BeanContextServices children,
* if this BeanContextService does not already implement this service
* itself.
*
* subclasses may override or envelope this method to implement their
* own propagation semantics.
*/
public void serviceRevoked(BeanContextServiceRevokedEvent bcssre) {
synchronized(BeanContext.globalHierarchyLock) {
if (services.containsKey(bcssre.getServiceClass())) return;
fireServiceRevoked(bcssre);
Iterator i;
synchronized(children) {
i = children.keySet().iterator();
}
while (i.hasNext()) {
Object c = i.next();
if (c instanceof BeanContextServices) {
((BeanContextServicesListener)c).serviceRevoked(bcssre);
}
}
}
}
private static String getGeneratedClassName(final Class<?> superType, final List<Class<?>> interfaces) {
// The class we use to primarily name our adapter is either the superclass, or if it is Object (meaning we're
// just implementing interfaces or extending Object), then the first implemented interface or Object.
final Class<?> namingType = superType == Object.class ? (interfaces.isEmpty()? Object.class : interfaces.get(0)) : superType;
final Package pkg = namingType.getPackage();
final String namingTypeName = Type.getInternalName(namingType);
final StringBuilder buf = new StringBuilder();
if (namingTypeName.startsWith(JAVA_PACKAGE_PREFIX) || pkg == null || pkg.isSealed()) {
// Can't define new classes in java.* packages
buf.append(ADAPTER_PACKAGE_PREFIX).append(namingTypeName);
} else {
buf.append(namingTypeName).append(ADAPTER_CLASS_NAME_SUFFIX);
}
final Iterator<Class<?>> it = interfaces.iterator();
if(superType == Object.class && it.hasNext()) {
it.next(); // Skip first interface, it was used to primarily name the adapter
}
// Append interface names to the adapter name
while(it.hasNext()) {
buf.append("$$").append(it.next().getSimpleName());
}
return buf.toString().substring(0, Math.min(MAX_GENERATED_TYPE_NAME_LENGTH, buf.length()));
}
private int getSize(Iterator<?> iterator) {
int size = 0;
while (iterator.hasNext()) {
iterator.next();
size++;
}
return size;
}
public static Long getBlockSizeByName(ExtCmd extCmd, String name) throws StorageException
{
Iterator<JsonNode> elements = getJsonElements(SpdkCommands.lvsByName(extCmd, name));
while (elements.hasNext())
{
JsonNode element = elements.next();
return element.path(SPDK_BLOCK_SIZE).asLong() * element.path(SPDK_NUM_BLOCKS).asLong();
}
throw new StorageException("Volume not found: " + name);
}
/**
* generates an object tree data element
*
* @param name name of the data element
* @return and object tree data element
*/
public ObjectTreeDataElt<TObjectDataElt<E>> generateObjectTreeDataElt(String name) {
logger.fine("generating object tree with objects = " + this.objectregister.size() + ", link = "
+ this.linkregister.size() + ", rootid=" + this.rootnodeid);
ObjectTreeDataElt<TObjectDataElt<E>> tree = new ObjectTreeDataElt<TObjectDataElt<E>>(name,
new TObjectDataEltType<E>(type));
Iterator<E> objectiterator = objectregister.values().iterator();
while (objectiterator.hasNext()) {
E object = objectiterator.next();
String objectid = getObjectId(object);
ArrayList<String> textlinkregister = this.linkregister.get(objectid);
if (objectid.equals(rootnodeid)) {
logger.fine(" - adding object tree as root with " + objectid);
tree.addNodeAsRoot(new TObjectDataElt<E>(name, object), textlinkregister);
} else {
logger.fine(" - adding object tree " + objectid);
tree.addNode(new TObjectDataElt<E>(name, object), textlinkregister);
}
}
ArrayList<String> linksfornull = this.linkregister.get(null);
if (rootnodeid != null)
if (linksfornull != null)
if (linksfornull.size() > 0)
throw new RuntimeException("Non null root node exist, but link from nullid exist also");
if (linksfornull != null)
if (linksfornull.size() > 0) {
ArrayList<String> linkchildrenidarray = new ArrayList<String>();
for (int i = 0; i < linksfornull.size(); i++)
linkchildrenidarray.add(linksfornull.get(i));
tree.addLinksForNullRootNode(linkchildrenidarray);
}
return tree;
}
public CompilationPackage compile(Map<String, String> classesToCompile, String extraJars)
throws CompilerException {
//modified classpath acquirement mode
String belongingJarPath = ClassBodyWrapper.class.getProtectionDomain().getCodeSource()
.getLocation()
.getPath();
List<String> options = Arrays
.asList("-classpath", extraJars
+ System.getProperty("path.separator")
+ System.getProperty("java.class.path")
+ System.getProperty("path.separator")
+ belongingJarPath
);
List<JavaSourceFromString> strFiles = Lists.newArrayList();
Iterator it = classesToCompile.keySet().iterator();
String compilationReport;
while (it.hasNext()) {
String className = (String) it.next();
compilationReport = classesToCompile.get(className);
strFiles.add(new JavaSourceFromString(className, compilationReport));
}
JavaCompiler compiler = this.getSystemJavaCompiler();
DiagnosticCollector<JavaFileObject> collector = this.getDiagnosticCollector();
InMemoryClassManager manager = this.getClassManager(compiler);
JavaCompiler.CompilationTask task = compiler.getTask(null, manager,
collector, options, null, strFiles);
boolean status = task.call();
if (status) {
List<CompilationUnit> compilationUnits = manager.getAllClasses();
return new CompilationPackage(compilationUnits);
} else {
compilationReport = this.buildCompilationReport(collector, options);
throw new CompilerException(compilationReport);
}
}
/**
* Searches the library wide KeyResolvers for Private keys
*
* @return the private key contained in this KeyInfo
* @throws KeyResolverException
*/
PrivateKey getPrivateKeyFromStaticResolvers() throws KeyResolverException {
Iterator<KeyResolverSpi> it = KeyResolver.iterator();
while (it.hasNext()) {
KeyResolverSpi keyResolver = it.next();
keyResolver.setSecureValidation(secureValidation);
Node currentChild = this.constructionElement.getFirstChild();
String uri = this.getBaseURI();
while (currentChild != null) {
if (currentChild.getNodeType() == Node.ELEMENT_NODE) {
// not using StorageResolvers at the moment
// since they cannot return private keys
PrivateKey pk =
keyResolver.engineLookupAndResolvePrivateKey(
(Element) currentChild, uri, null
);
if (pk != null) {
return pk;
}
}
currentChild = currentChild.getNextSibling();
}
}
return null;
}
public String toString() {
String string = name() + " (defaults: ";
Iterator<Argument> iter = defaultArguments().values().iterator();
boolean first = true;
while (iter.hasNext()) {
ArgumentImpl argument = (ArgumentImpl)iter.next();
if (!first) {
string += ", ";
}
string += argument.toString();
first = false;
}
string += ")";
return string;
}
@Test
public void nextReturnsEmptyObjectAtEndOfInputStreamWithNewline() {
InputStream inputStream = createInputStreamFromString("\"WORKERID1\",123\n");
Iterator<TestDTO> iterator = csvInputStreamMapper.apply(inputStream);
assertThat(iterator.hasNext(), equalTo(true));
iterator.next();
assertThat(iterator.hasNext(), equalTo(false));
}
void getXmlnsAttr(Collection<Attr> col) {
int size = levels.size() - 1;
if (cur == null) {
cur = new XmlsStackElement();
cur.level = currentLevel;
lastlevel = currentLevel;
levels.add(cur);
}
boolean parentRendered = false;
XmlsStackElement e = null;
if (size == -1) {
parentRendered = true;
} else {
e = levels.get(size);
if (e.rendered && e.level + 1 == currentLevel) {
parentRendered = true;
}
}
if (parentRendered) {
col.addAll(cur.nodes);
cur.rendered = true;
return;
}
Map<String, Attr> loa = new HashMap<String, Attr>();
for (; size >= 0; size--) {
e = levels.get(size);
Iterator<Attr> it = e.nodes.iterator();
while (it.hasNext()) {
Attr n = it.next();
if (!loa.containsKey(n.getName())) {
loa.put(n.getName(), n);
}
}
}
cur.rendered = true;
col.addAll(loa.values());
}
private static <P, T> List<T> visitTasks(Visitor<P, T> visitor, ProjectAndTaskFilter filter, ProjectView project, P userProjectObject) {
List<T> taskObjects = new ArrayList<T>();
Iterator<TaskView> iterator = project.getTasks().iterator();
while (iterator.hasNext()) {
TaskView task = iterator.next();
if (filter.doesAllowTask(task)) {
T taskObject = visitor.visitTask(task, project, userProjectObject);
taskObjects.add(taskObject);
}
}
return taskObjects;
}
@Override
public void run() {
int instanceId = worldMapInstance.getInstanceId();
int worldId = worldMapInstance.getMapId();
WorldMap map = World.getInstance().getWorldMap(worldId);
PlayerGroup registeredGroup = worldMapInstance.getRegisteredGroup();
if (registeredGroup == null) {
if (worldMapInstance.playersCount() > 0) {
updateSoloInstanceDestroyTime();
return;
}
if (worldMapInstance.playersCount() == 0) {
if (canDestroySoloInstance()) {
map.removeWorldMapInstance(instanceId);
destroyInstance(worldMapInstance);
return;
}
else {
return;
}
}
Iterator<Player> playerIterator = worldMapInstance.playerIterator();
int mapId = worldMapInstance.getMapId();
while (playerIterator.hasNext()) {
Player player = playerIterator.next();
if (player.isOnline() && player.getWorldId() == mapId) {
return;
}
}
map.removeWorldMapInstance(instanceId);
destroyInstance(worldMapInstance);
}
else if (registeredGroup.size() == 0) {
map.removeWorldMapInstance(instanceId);
destroyInstance(worldMapInstance);
}
}
private List<Node> filterByLevel(List<Node> nodes, int level) {
List<Node> nodeList = new ArrayList<>(nodes);
Iterator<Node> iterator = nodeList.iterator();
while (iterator.hasNext()) {
Node node = iterator.next();
int depth = getNodeData(node).getDepth();
if (depth != level) {
iterator.remove();
}
}
return nodeList;
}
/**
* Sends new list after update of playback configurations
* @param iplayerReleased indicates if the change was due to a player being released
*/
private void dispatchPlaybackChange(boolean iplayerReleased) {
synchronized (mClients) {
// typical use case, nobody is listening, don't do any work
if (mClients.isEmpty()) {
return;
}
}
if (DEBUG) { Log.v(TAG, "dispatchPlaybackChange to " + mClients.size() + " clients"); }
final List<AudioPlaybackConfiguration> configsSystem;
// list of playback configurations for "public consumption". It is only computed if there
// are non-system playback activity listeners.
final List<AudioPlaybackConfiguration> configsPublic;
synchronized (mPlayerLock) {
if (mPlayers.isEmpty()) {
return;
}
configsSystem = new ArrayList<AudioPlaybackConfiguration>(mPlayers.values());
}
synchronized (mClients) {
// was done at beginning of method, but could have changed
if (mClients.isEmpty()) {
return;
}
configsPublic = mHasPublicClients ? anonymizeForPublicConsumption(configsSystem) : null;
final Iterator<PlayMonitorClient> clientIterator = mClients.iterator();
while (clientIterator.hasNext()) {
final PlayMonitorClient pmc = clientIterator.next();
try {
// do not spam the logs if there are problems communicating with this client
if (pmc.mErrorCount < PlayMonitorClient.MAX_ERRORS) {
if (pmc.mIsPrivileged) {
pmc.mDispatcherCb.dispatchPlaybackConfigChange(configsSystem,
iplayerReleased);
} else {
// non-system clients don't have the control interface IPlayer, so
// they don't need to flush commands when a player was released
pmc.mDispatcherCb.dispatchPlaybackConfigChange(configsPublic, false);
}
}
} catch (RemoteException e) {
pmc.mErrorCount++;
Log.e(TAG, "Error (" + pmc.mErrorCount +
") trying to dispatch playback config change to " + pmc, e);
}
}
}
}
public void createFromCube(String projectName, String cubeName, String partitionDateStr) throws Exception {
logger.info("Create hybrid for cube[" + cubeName + "], project[" + projectName + "], partition_date[" + partitionDateStr + "].");
CubeInstance cubeInstance = cubeManager.getCube(cubeName);
if (!validateCubeInstance(cubeInstance)) {
return;
}
CubeDesc cubeDesc = cubeDescManager.getCubeDesc(cubeInstance.getDescName());
DataModelDesc dataModelDesc = metadataManager.getDataModelDesc(cubeDesc.getModelName());
if (StringUtils.isEmpty(dataModelDesc.getPartitionDesc().getPartitionDateColumn())) {
logger.error("No incremental cube, no need to extend.");
return;
}
String owner = cubeInstance.getOwner();
long partitionDate = partitionDateStr != null ? DateFormat.stringToMillis(partitionDateStr) : 0;
// get new name for old cube and cube_desc
String newCubeDescName = renameCube(cubeDesc.getName());
String newCubeInstanceName = renameCube(cubeInstance.getName());
while (cubeDescManager.getCubeDesc(newCubeDescName) != null)
newCubeDescName = renameCube(newCubeDescName);
while (cubeManager.getCube(newCubeInstanceName) != null)
newCubeInstanceName = renameCube(newCubeInstanceName);
// create new cube_instance for old segments
CubeInstance newCubeInstance = CubeInstance.getCopyOf(cubeInstance);
newCubeInstance.setName(newCubeInstanceName);
newCubeInstance.setDescName(newCubeDescName);
newCubeInstance.updateRandomUuid();
Iterator<CubeSegment> segmentIterator = newCubeInstance.getSegments().iterator();
CubeSegment currentSeg = null;
while (segmentIterator.hasNext()) {
currentSeg = segmentIterator.next();
if (partitionDateStr != null && (currentSeg.getTSRange().start.v >= partitionDate || currentSeg.getTSRange().end.v > partitionDate)) {
segmentIterator.remove();
logger.info("CubeSegment[" + currentSeg + "] was removed.");
}
}
if (currentSeg != null && partitionDateStr != null && partitionDate != currentSeg.getTSRange().end.v) {
logger.error("PartitionDate must be end date of one segment.");
return;
}
if (currentSeg != null && partitionDateStr == null)
partitionDate = currentSeg.getTSRange().end.v;
cubeManager.createCube(newCubeInstance, projectName, owner);
logger.info("CubeInstance was saved at: " + newCubeInstance.getResourcePath());
// create new cube for old segments
CubeDesc newCubeDesc = CubeDesc.getCopyOf(cubeDesc);
newCubeDesc.setName(newCubeDescName);
newCubeDesc.updateRandomUuid();
newCubeDesc.init(kylinConfig);
newCubeDesc.setPartitionDateEnd(partitionDate);
newCubeDesc.calculateSignature();
cubeDescManager.createCubeDesc(newCubeDesc);
logger.info("CubeDesc was saved at: " + newCubeDesc.getResourcePath());
// update old cube_desc to new-version metadata
cubeDesc.setPartitionDateStart(partitionDate);
cubeDesc.setEngineType(IEngineAware.ID_MR_V2);
cubeDesc.setStorageType(IStorageAware.ID_SHARDED_HBASE);
cubeDesc.calculateSignature();
cubeDescManager.updateCubeDesc(cubeDesc);
logger.info("CubeDesc was saved at: " + cubeDesc.getResourcePath());
// clear segments for old cube
cubeInstance.setSegments(new Segments());
cubeInstance.setStatus(RealizationStatusEnum.DISABLED);
store.checkAndPutResource(cubeInstance.getResourcePath(), cubeInstance, CubeManager.CUBE_SERIALIZER);
logger.info("CubeInstance was saved at: " + cubeInstance.getResourcePath());
// create hybrid model for these two cubes
List<RealizationEntry> realizationEntries = Lists.newArrayListWithCapacity(2);
realizationEntries.add(RealizationEntry.create(RealizationType.CUBE, cubeInstance.getName()));
realizationEntries.add(RealizationEntry.create(RealizationType.CUBE, newCubeInstance.getName()));
HybridInstance hybridInstance = HybridInstance.create(kylinConfig, renameHybrid(cubeInstance.getName()), realizationEntries);
store.checkAndPutResource(hybridInstance.getResourcePath(), hybridInstance, HybridManager.HYBRID_SERIALIZER);
ProjectManager.getInstance(kylinConfig).moveRealizationToProject(RealizationType.HYBRID, hybridInstance.getName(), projectName, owner);
logger.info("HybridInstance was saved at: " + hybridInstance.getResourcePath());
// copy Acl from old cube to new cube
copyAcl(cubeInstance.getId(), newCubeInstance.getId(), projectName);
logger.info("Acl copied from [" + cubeName + "] to [" + newCubeInstanceName + "].");
}