use of java.util.ListIterator in project OpenAM by OpenRock.
the class SetupUtils method copyAndFilterScripts.
/**
* Copy and replace the variables in the scripts.
*
* @param bundle The ResourceBundle which contains the prompt messages.
* @param lookupProp The properties which contains the variables map, file
* patterns, source directory, and destinated directory.
*/
public static void copyAndFilterScripts(ResourceBundle bundle, Properties lookupProp) throws IOException {
String currentOS = determineOS();
String fromFilePattern = lookupProp.getProperty(currentOS + FROM_FILE);
String toFilePattern = lookupProp.getProperty(currentOS + TO_FILE);
String tempFromDir = lookupProp.getProperty(currentOS + FROM_DIR);
String tempToDir = lookupProp.getProperty(currentOS + TO_DIR);
File fromDir = new File(tempFromDir);
File toDir = new File(tempToDir);
if (toDir.isAbsolute()) {
toDir = new File(toDir.getName());
}
Properties tokens = SetupUtils.getTokens(bundle, lookupProp);
LinkedList fromFilesList = new LinkedList();
LinkedList toFilesList = new LinkedList();
SetupUtils.getFiles(fromDir, toDir, fromFilePattern, toFilePattern, fromFilesList, toFilesList);
ListIterator srcIter = fromFilesList.listIterator();
ListIterator destIter = toFilesList.listIterator();
while ((srcIter.hasNext()) && (destIter.hasNext())) {
File srcFile = (File) srcIter.next();
File destFile = (File) destIter.next();
CopyUtils.copyFile(srcFile, destFile, tokens, true, false);
}
if (!currentOS.equals(WINDOWS)) {
Process proc = Runtime.getRuntime().exec("/bin/chmod -R +x " + toDir.getName());
try {
if (proc.waitFor() != 0) {
System.out.println(bundle.getString("message.info." + "permission.scripts"));
}
} catch (InterruptedException ex) {
System.out.println(bundle.getString("message.info." + "permission.scripts"));
//ex.printStackTrace();
}
}
System.out.println(bundle.getString("message.info.success") + " " + (new File(".")).getCanonicalPath() + FILE_SEPARATOR + toDir.getName());
}
use of java.util.ListIterator in project hibernate-orm by hibernate.
the class EventManager method createHolidayCalendar.
public Long createHolidayCalendar() {
Session session = sessionFactory.getCurrentSession();
session.beginTransaction();
// delete all existing calendars
List calendars = session.createQuery("from HolidayCalendar").setCacheable(true).list();
for (ListIterator li = calendars.listIterator(); li.hasNext(); ) {
session.delete(li.next());
}
HolidayCalendar calendar = new HolidayCalendar();
calendar.init();
Long calendarId = (Long) session.save(calendar);
session.getTransaction().commit();
return calendarId;
}
use of java.util.ListIterator in project NetherEx by LogicTechCorp.
the class EventHandler method onLivingDrops.
@SubscribeEvent
public static void onLivingDrops(LivingDropsEvent event) {
Random rand = new Random();
BlockPos deathPoint = event.getEntity().getPosition();
if (event.getEntity() instanceof EntityGhast) {
event.getDrops().add(new EntityItem(event.getEntity().getEntityWorld(), deathPoint.getX(), deathPoint.getY(), deathPoint.getZ(), new ItemStack(NetherExItems.FOOD_MEAT_GHAST_RAW, rand.nextInt(3) + 1, 0)));
} else if (event.getEntity() instanceof EntityWitherSkeleton) {
ListIterator<EntityItem> iter = event.getDrops().listIterator();
while (iter.hasNext()) {
EntityItem entityItem = iter.next();
ItemStack stack = entityItem.getEntityItem();
if (stack.getItem() == Items.BONE || stack.getItem() == Items.COAL) {
iter.remove();
}
}
event.getDrops().add(new EntityItem(event.getEntity().world, deathPoint.getX(), deathPoint.getY(), deathPoint.getZ(), new ItemStack(NetherExItems.ITEM_BONE_WITHER, rand.nextInt(3), 0)));
}
}
use of java.util.ListIterator in project robovm by robovm.
the class LinkedListTest method test_listIteratorI.
/**
* java.util.LinkedList#listIterator(int)
*/
public void test_listIteratorI() {
// Test for method java.util.ListIterator
// java.util.LinkedList.listIterator(int)
ListIterator i1 = ll.listIterator();
ListIterator i2 = ll.listIterator(0);
Object elm;
int n = 0;
while (i2.hasNext()) {
if (n == 0 || n == objArray.length - 1) {
if (n == 0)
assertTrue("First element claimed to have a previous", !i2.hasPrevious());
if (n == objArray.length)
assertTrue("Last element claimed to have next", !i2.hasNext());
}
elm = i2.next();
assertTrue("Iterator returned elements in wrong order", elm == objArray[n]);
if (n > 0 && n < objArray.length - 1) {
assertTrue("Next index returned incorrect value", i2.nextIndex() == n + 1);
assertTrue("previousIndex returned incorrect value : " + i2.previousIndex() + ", n val: " + n, i2.previousIndex() == n);
}
elm = i1.next();
assertTrue("Iterator returned elements in wrong order", elm == objArray[n]);
++n;
}
i2 = ll.listIterator(ll.size() / 2);
assertTrue((Integer) i2.next() == ll.size() / 2);
List myList = new LinkedList();
myList.add(null);
myList.add("Blah");
myList.add(null);
myList.add("Booga");
myList.add(null);
ListIterator li = myList.listIterator();
assertTrue("li.hasPrevious() should be false", !li.hasPrevious());
assertNull("li.next() should be null", li.next());
assertTrue("li.hasPrevious() should be true", li.hasPrevious());
assertNull("li.prev() should be null", li.previous());
assertNull("li.next() should be null", li.next());
assertEquals("li.next() should be Blah", "Blah", li.next());
assertNull("li.next() should be null", li.next());
assertEquals("li.next() should be Booga", "Booga", li.next());
assertTrue("li.hasNext() should be true", li.hasNext());
assertNull("li.next() should be null", li.next());
assertTrue("li.hasNext() should be false", !li.hasNext());
try {
ll.listIterator(-1);
fail("IndexOutOfBoundsException expected");
} catch (IndexOutOfBoundsException e) {
//expected
}
try {
ll.listIterator(ll.size() + 1);
fail("IndexOutOfBoundsException expected");
} catch (IndexOutOfBoundsException e) {
//expected
}
}
use of java.util.ListIterator in project robovm by robovm.
the class PKIXCertPath method getEncoded.
/**
* Returns the encoded form of this certification path, using
* the specified encoding.
*
* @param encoding the name of the encoding to use
* @return the encoded bytes
* @exception java.security.cert.CertificateEncodingException if an encoding error
* occurs or the encoding requested is not supported
*
**/
public byte[] getEncoded(String encoding) throws CertificateEncodingException {
if (encoding.equalsIgnoreCase("PkiPath")) {
ASN1EncodableVector v = new ASN1EncodableVector();
ListIterator iter = certificates.listIterator(certificates.size());
while (iter.hasPrevious()) {
v.add(toASN1Object((X509Certificate) iter.previous()));
}
return toDEREncoded(new DERSequence(v));
} else if (encoding.equalsIgnoreCase("PKCS7")) {
ContentInfo encInfo = new ContentInfo(PKCSObjectIdentifiers.data, null);
ASN1EncodableVector v = new ASN1EncodableVector();
for (int i = 0; i != certificates.size(); i++) {
v.add(toASN1Object((X509Certificate) certificates.get(i)));
}
SignedData sd = new SignedData(new ASN1Integer(1), new DERSet(), encInfo, new DERSet(v), null, new DERSet());
return toDEREncoded(new ContentInfo(PKCSObjectIdentifiers.signedData, sd));
} else // BEGIN android-removed
// else if (encoding.equalsIgnoreCase("PEM"))
// {
// ByteArrayOutputStream bOut = new ByteArrayOutputStream();
// PemWriter pWrt = new PemWriter(new OutputStreamWriter(bOut));
//
// try
// {
// for (int i = 0; i != certificates.size(); i++)
// {
// pWrt.writeObject(new PemObject("CERTIFICATE", ((X509Certificate)certificates.get(i)).getEncoded()));
// }
//
// pWrt.close();
// }
// catch (Exception e)
// {
// throw new CertificateEncodingException("can't encode certificate for PEM encoded path");
// }
//
// return bOut.toByteArray();
// }
// END android-removed
{
throw new CertificateEncodingException("unsupported encoding: " + encoding);
}
}
Aggregations