List of usage examples for java.lang Iterable iterator
Iterator<T> iterator();
From source file:org.dasein.cloud.openstack.nova.os.NovaOpenStack.java
public synchronized @Nonnull AuthenticationContext getAuthenticationContext() throws CloudException, InternalException { APITrace.begin(this, "Cloud.getAuthenticationContext"); try {/*from ww w . j av a2 s. c om*/ Cache<AuthenticationContext> cache = Cache.getInstance(this, "authenticationContext", AuthenticationContext.class, CacheLevel.REGION_ACCOUNT, new TimePeriod<Day>(1, TimePeriod.DAY)); ProviderContext ctx = getContext(); if (ctx == null) { throw new CloudException("No context was set for this request"); } Iterable<AuthenticationContext> current = cache.get(ctx); AuthenticationContext authenticationContext = null; NovaMethod method = new NovaMethod(this); if (current != null) { authenticationContext = current.iterator().next(); } else { try { authenticationContext = method.authenticate(); } finally { if (authenticationContext == null) { NovaException.ExceptionItems items = new NovaException.ExceptionItems(); items.code = HttpStatus.SC_UNAUTHORIZED; items.type = CloudErrorType.AUTHENTICATION; items.message = "unauthorized"; items.details = "The API keys failed to authenticate with the specified endpoint."; throw new NovaException(items); } cache.put(ctx, Collections.singletonList(authenticationContext)); return authenticationContext; } } return authenticationContext; } finally { APITrace.end(); } }
From source file:org.dasein.cloud.qingcloud.network.QingCloudIpAddress.java
private String getProviderDataCenterId() throws InternalException, CloudException { String regionId = getContext().getRegionId(); if (regionId == null) { throw new InternalException("No region was set for this request"); }/* w ww . jav a 2 s . com*/ Iterable<DataCenter> dataCenters = getProvider().getDataCenterServices().listDataCenters(regionId); return dataCenters.iterator().next().getProviderDataCenterId();//each account has one DC in each region }
From source file:com.sludev.commons.vfs2.provider.azure.AzFileObject.java
/** * Callback for checking the type of the current FileObject. Typically can * be of type.../*w w w .ja va 2 s .com*/ * FILE for regular remote files * FOLDER for regular remote containers * IMAGINARY for a path that does not exist remotely. * * @return * @throws Exception */ @Override protected FileType doGetType() throws Exception { FileType res; Pair<String, String> path = getContainerAndPath(); if (currBlob.exists()) { res = FileType.FILE; } else { // Blob Service does not have folders. Just files with path separators in // their names. // Here's the trick for folders. // // Do a listing on that prefix. If it returns anything, after not // existing, then it's a folder. String prefix = path.getRight(); if (prefix.endsWith("/") == false) { // We need folders ( prefixes ) to end with a slash prefix += "/"; } Iterable<ListBlobItem> blobs = null; if (prefix.equals("/")) { // Special root path case. List the root blobs with no prefix blobs = currContainer.listBlobs(); } else { blobs = currContainer.listBlobs(prefix); } if (blobs.iterator().hasNext()) { res = FileType.FOLDER; } else { res = FileType.IMAGINARY; } } return res; }
From source file:org.dasein.cloud.google.compute.server.GoogleDiskSupport.java
private @Nullable Volume toVolume(JSONObject json) throws CloudException, JSONException { if (json == null) { return null; }/*from w w w .jav a 2s.co m*/ Volume vol = new Volume(); vol.setProviderRegionId(provider.getContext().getRegionId()); vol.setType(VolumeType.HDD); if (json.has("name")) { vol.setProviderVolumeId(json.getString("name")); vol.setName(json.getString("name")); } if (json.has("description")) { vol.setDescription(json.getString("description")); } if (json.has("sizeGb")) { int size = Integer.parseInt(json.getString("sizeGb")); vol.setSize(new Storage<Gigabyte>(size, Storage.GIGABYTE)); } if (json.has("sourceSnapshot")) { vol.setProviderSnapshotId( GoogleMethod.getResourceName(json.getString("sourceSnapshot"), GoogleMethod.SNAPSHOT)); } if (json.has("zone")) { vol.setProviderDataCenterId(GoogleMethod.getResourceName(json.getString("zone"), GoogleMethod.ZONE)); } if (json.has("creationTimestamp")) { SimpleDateFormat fmt = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS"); String value = json.getString("creationTimestamp"); try { vol.setCreationTimestamp(fmt.parse(value).getTime()); } catch (java.text.ParseException e) { logger.error(e); e.printStackTrace(); throw new CloudException(e); } } if (json.has("status")) { String s = json.getString("status"); VolumeState state; if (s.equals("CREATING")) { state = VolumeState.PENDING; } else if (s.equals("READY")) { state = VolumeState.AVAILABLE; } else { state = VolumeState.DELETED; } vol.setCurrentState(state); } try { Iterable<String> vmIds = provider.getComputeServices().getVirtualMachineSupport() .getVirtualMachineWithVolume(vol.getProviderVolumeId()); if (vmIds != null) vol.setProviderVirtualMachineId(vmIds.iterator().next()); } catch (InternalException e) { e.printStackTrace(); logger.error("Setting virutal machine id for disk failed"); throw new CloudException(e); } return vol; }
From source file:com.link_intersystems.lang.reflect.criteria.ClassCriteriaTest.java
@Test public void innerClassesTraversal() { ClassCriteria criteria = new ClassCriteria(); criteria.setTraverseStrategy(TraverseStrategy.DEPTH_FIRST); criteria.setSelection(ClassType.INNER_CLASSES); Iterable<Class<?>> iterable = criteria.getIterable(ClassWithInnerClasses.class); Iterator<Class<?>> classIterator = iterable.iterator(); assertEquals(ClassWithInnerClasses.InnerClass.class, classIterator.next()); assertEquals(ClassWithInnerClasses.InnerInterface.class, classIterator.next()); assertEquals(ClassWithInnerClasses.StaticInnerClass.class, classIterator.next()); assertEquals(ClassWithInnerClasses.StaticInnerInterface.class, classIterator.next()); assertFalse(classIterator.hasNext()); }
From source file:org.jahia.services.usermanager.ldap.JahiaLDAPConfig.java
private String transformPropKeyToBeanAttr(String key) { Iterable<String> upperStrings = Iterables.transform(Arrays.asList(StringUtils.split(key, '.')), new Function<String, String>() { public String apply(String input) { return (input == null) ? null : StringUtils.capitalize(input); }// ww w.ja v a2s . com }); return StringUtils.uncapitalize(StringUtils.join(upperStrings.iterator(), "")); }
From source file:com.uni.dao.etc.UniJpaRepository.java
public void deleteInBatch(Iterable<T> entities) { Assert.notNull(entities, "The given Iterable of entities not be null!"); if (!entities.iterator().hasNext()) { return;/*ww w . j av a 2 s .c o m*/ } applyAndBind(getQueryString(DELETE_ALL_QUERY_STRING, entityInformation.getEntityName()), entities, em) .executeUpdate(); }
From source file:com.link_intersystems.lang.reflect.criteria.ClassCriteriaTest.java
@Test public void innerClassesAndClassesTraversal() { ClassCriteria criteria = new ClassCriteria(); criteria.setTraverseStrategy(TraverseStrategy.DEPTH_FIRST); criteria.setSelection(ClassType.INNER_CLASSES, ClassType.CLASSES); Iterable<Class<?>> iterable = criteria.getIterable(ClassWithInnerClasses.class); Iterator<Class<?>> classIterator = iterable.iterator(); assertEquals(ClassWithInnerClasses.InnerClass.class, classIterator.next()); assertEquals(ClassWithInnerClasses.InnerInterface.class, classIterator.next()); assertEquals(ClassWithInnerClasses.StaticInnerClass.class, classIterator.next()); assertEquals(ClassWithInnerClasses.StaticInnerInterface.class, classIterator.next()); assertEquals(ClassWithInnerClasses.class, classIterator.next()); assertEquals(Object.class, classIterator.next()); assertEquals(Object.class, classIterator.next()); assertEquals(Object.class, classIterator.next()); assertFalse(classIterator.hasNext()); }
From source file:com.infinira.aerospike.dataaccess.repository.AerospikeRepository.java
/** * Find all entities in the database/*from w w w. ja v a2 s. c o m*/ * @return ArrayList of entity objects */ @Override public ArrayList<T> findAll() { final ArrayList<T> scanList = new ArrayList<T>(); Iterable<T> results = findAllUsingQuery(null); Iterator<T> iterator = results.iterator(); try { while (iterator.hasNext()) { scanList.add(iterator.next()); //System.out.println(iterator.next()); } } finally { ((EntityIterator<T>) iterator).close(); } return scanList; }
From source file:it.crs4.seal.demux.DemuxReducer.java
public void reduce(SequenceId key, Iterable<SequencedFragment> sequences, IMRContext<Text, SequencedFragment> context) throws IOException, InterruptedException { // XXX: this function is growing too much. Consider refactoring. ////////////////////////////////////////// // Fragments should all have non-null Read and Lane, as verified by the Mapper. // They should be ordered read 2, read 1, read 3 and over ////////////////////////////////////////// Iterator<SequencedFragment> seqs_it = sequences.iterator(); SequencedFragment fragment;/* w ww .j a v a 2 s . com*/ String flowcellId = ""; String indexSeq = ""; // default index is blank String sampleId; String project; fragment = seqs_it.next(); if (expectIndexRead) { // Fetch the first fragment from the list -- it should be the index sequence if (fragment.getRead() != 2) throw new RuntimeException("Missing read 2 in multiplexed input for location " + key.getLocation() + ". Record: " + fragment); indexSeq = fragment.getSequence().toString(); // Sequenced tags have an additional 'A' base that separates them from the read. For this // reason, when we verify their length we check for BAR_CODE_{MIN,MAX}_LENGTH + 1 if (indexSeq.length() < (SampleSheet.BAR_CODE_MIN_LENGTH + 1) || indexSeq.length() > (SampleSheet.BAR_CODE_MAX_LENGTH + 1)) { throw new RuntimeException( String.format("Unexpected barcode sequence of length %d (expected in interval [%d, %d]", indexSeq.length(), (SampleSheet.BAR_CODE_MIN_LENGTH + 1), (SampleSheet.BAR_CODE_MAX_LENGTH + 1) + "])")); } // We've consumed this index read. Advance to the next one. fragment = seqs_it.next(); } // From here on, they should be all data reads. int lane = fragment.getLane(); BarcodeLookup.Match m = barcodeLookup.getSampleId(lane, indexSeq); if (m == null) { sampleId = "unknown"; project = "."; } else { sampleId = m.getEntry().getSampleId(); flowcellId = m.getEntry().getFlowcellId(); project = m.getEntry().getProject(); if (project == null) project = Demux.DEFAULT_PROJECT; context.increment("Barcode base mismatches", String.valueOf(m.getMismatches()), 1); } // Project/sample results in that directory structure. The key is the same for all reads in iterator // TODO: profile! We're sanitizing and rebuilding the file name for // each set of reads. It may be a significant waste of CPU that could be fixed by a caching mechanism. String keyString = Utils.sanitizeFilename(project) + '/' + Utils.sanitizeFilename(sampleId); outputKey.set(keyString); if (separatesReads) { // append a slash and an 'X' (the latter to make a space for the read number) outputKey.append(SLASH_X, 0, SLASH_X.length); } boolean done = false; do { fragment.setIndexSequence(indexSeq); // When we read qseq, the flowcell id isn't set (the file format doesn't include that data. // Since we have the chance here, we'l extract the flowcell id from the sample sheet // and set it on the outgoing SequencedFragment. if (fragment.getFlowcellId() == null) fragment.setFlowcellId(flowcellId); if (expectIndexRead && fragment.getRead() > 2) fragment.setRead(fragment.getRead() - 1); if (separatesReads) { // Overwrite the last character of the key with the read number. // This technique only supports single digit read numbers outputKey.getBytes()[outputKey.getLength() - 1] = (byte) (fragment.getRead().byteValue() + '0'); } context.write(outputKey, fragment); context.increment("Sample reads", keyString, 1); if (seqs_it.hasNext()) fragment = seqs_it.next(); else done = true; } while (!done); if (fragment.getRead() > 2) { // although the code above is generic and will handle any number of reads, // in our current use cases any more than 2 data reads (non-index) indicate // a problem with the data. // XXX: if someone removes this check, verify the "separatesReads" section above. throw new RuntimeException("Unexpected output read number " + fragment.getRead() + " at location " + key.getLocation() + " (note that if read number may have been decremented by 1 if an index sequence was present)."); } }